Changeset 25 for trunk/lib/syck/loaders.py
- Timestamp:
- 08/25/05 01:30:06 (8 years ago)
- File:
-
- 1 edited
-
trunk/lib/syck/loaders.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/syck/loaders.py
r22 r25 1 """ 2 syck.loaders is a high-level wrapper for the Syck YAML parser. 3 Do not use it directly, use the module 'syck' instead. 4 """ 1 5 2 6 # Python 2.2 compatibility … … 27 31 28 32 class GenericLoader(_syck.Parser): 33 """ 34 GenericLoader constructs primitive Python objects from YAML documents. 35 """ 29 36 30 37 def load(self): 38 """ 39 Loads a YAML document from the source and return a native Python 40 object. On EOF, returns None and set the eof attribute on. 41 """ 31 42 node = self.parse() 32 43 if self.eof: … … 71 82 72 83 def construct(self, node): 84 """Constructs a Python object by the given node.""" 73 85 return node.value 74 86 75 87 class Merge: 88 """Represents the merge key '<<'.""" 76 89 pass 77 90 78 91 class Default: 92 """Represents the default key '='.""" 79 93 pass 80 94 81 95 class Loader(GenericLoader): 96 """ 97 Loader constructs native Python objects from YAML documents. 98 """ 82 99 83 100 inf_value = 1e300000 … … 109 126 110 127 def find_constructor(self, node): 128 """ 129 Returns the contructor for generating a Python object for the given 130 node. 131 132 The node tags are mapped to constructors by the following rule: 133 134 Tag Constructor 135 --- ----------- 136 tag:yaml.org,2002:type construct_type 137 tag:python.yaml.org,2002:type construct_python_type 138 x-private:type construct_private_type 139 tag:domain.tld,2002:type construct_domain_tld_2002_type 140 141 See the method code for more details. 142 """ 111 143 parts = [] 112 144 if node.tag: … … 130 162 131 163 def construct(self, node): 164 """Constructs a Python object by the given node.""" 132 165 if node.kind == 'map' and self.merge_key in node.value: 133 166 self.merge_maps(node) … … 301 334 if isinstance(state, tuple) and len(state) == 2: 302 335 state, slotstate = state 303 object.__dict__.update(state) 336 if hasattr(object, '__dict__'): 337 object.__dict__.update(state) 338 elif state: 339 slotstate.update(state) 304 340 for key, value in slotstate.items(): 305 341 setattr(object, key, value) … … 349 385 350 386 def parse_documents(source, Loader=Loader, **parameters): 351 """Iterates over 'source' and yields the root node ofeach document."""387 """Iterates over 'source' and yields the root 'Node' for each document.""" 352 388 loader = Loader(source, **parameters) 353 389 while True: … … 358 394 359 395 def load_documents(source, Loader=Loader, **parameters): 360 """Iterates over 'source' and yields the root object ofeach document."""396 """Iterates over 'source' and yields the root object for each document.""" 361 397 loader = Loader(source, **parameters) 362 398 while True:
Note: See TracChangeset
for help on using the changeset viewer.
