projects
/
python-bulletml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
BulletML: FromDocument for parity with FromElement.
[python-bulletml.git]
/
bulletml
/
parser.py
diff --git
a/bulletml/parser.py
b/bulletml/parser.py
index
b39437a
..
edb9d29
100644
(file)
--- a/
bulletml/parser.py
+++ b/
bulletml/parser.py
@@
-443,22
+443,25
@@
class BulletML(object):
fire=FireDef,
)
fire=FireDef,
)
- def __init__(self, source):
+ def __init__(self, type="none", bullets={}, fires={}, actions={}):
+ self.type = type
self.bullets = {}
self.actions = {}
self.fires = {}
self.bullets = {}
self.actions = {}
self.fires = {}
- self._bullet_refs = []
- self._action_refs = []
- self._fire_refs = []
-
+ @classmethod
+ def FromDocument(cls, source):
if isinstance(source, (str, unicode)):
source = StringIO(source)
tree = ElementTree()
root = tree.parse(source)
if isinstance(source, (str, unicode)):
source = StringIO(source)
tree = ElementTree()
root = tree.parse(source)
- self.type = root.get("type", "none")
+ self = cls(type=root.get("type", "none"))
+
+ self._bullet_refs = []
+ self._action_refs = []
+ self._fire_refs = []
for element in root.getchildren():
tag = realtag(element)
for element in root.getchildren():
tag = realtag(element)
@@
-483,6
+486,8
@@
class BulletML(object):
self.actions.pop(None, None)
self.fires.pop(None, None)
self.actions.pop(None, None)
self.fires.pop(None, None)
+ return self
+
@property
def top(self):
"""Get a list of all top-level actions."""
@property
def top(self):
"""Get a list of all top-level actions."""