Partial representations with PyYAML

Geert Jansen <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
Hi,

i'm using version 3.09 of PyYAML. When parsing a document with
unresolvable tags, the default behavior of PyYAML seems to be to raise
an exception. However i believe the YAML spec allows for a "partial"
representation to be returned instead, according to section 3.3.2 of
the YAML 1.1 spec:

"""If a document contains unresolved tags, the YAML processor is
unable to compose a complete representation graph. In such a case, the
YAML processor may compose an partial representation, based on each
node’s kind and allowing for non-specific tags."""

These partial representations are useful with documents that you get
from other sources and for which do you not have constructors for all
tags.

Example:

  s = "!tag test"
  print yaml.load(s)

raises an exception.

It's possible to parse the document by using this hack:

  from yaml import Loader
  del Loader.yaml_constructors[None]

Two questions...

 - Would it be possible to return partial representations by default
in case of unresolvable tags?
 - If not, would it be possible to have an API to enable it (so that i
don't need to mess around with PyYAML internals).

Thanks,
Geert

------------------------------------------------------------------------------

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.