- @property
- def top(self):
- """Get a list of all top-level actions."""
- return [dfn for name, dfn in self.actions.iteritems()
- if name and name.startswith("top")]
+ # Late import to avoid a circular dependency.
+ try:
+ import bulletml.bulletyaml
+ import yaml
+ except ImportError:
+ raise ParseError("PyYAML is not available")
+ else:
+ try:
+ return yaml.load(source)
+ except Exception, exc:
+ raise ParseError(str(exc))
+
+ @classmethod
+ def FromDocument(cls, source):
+ """Create a BulletML instance based on a seekable file or string.
+
+ This attempts to autodetect if the stream is XML or YAML.
+ """
+ if not hasattr(source, 'read'):
+ source = StringIO(source)
+ start = source.read(1)
+ source.seek(0)
+ if start == "<":
+ return cls.FromXML(source)
+ elif start == "!" or start == "#":
+ return cls.FromYAML(source)
+ else:
+ raise ParseError("unknown initial character %r" % start)