Changeset 116 for pyyaml/trunk/lib/yaml/constructor.py
- Timestamp:
- 03/18/06 08:37:09 (7 years ago)
- File:
-
- 1 edited
-
pyyaml/trunk/lib/yaml/constructor.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/lib/yaml/constructor.py
r59 r116 71 71 raise ConstructorError(None, None, 72 72 "expected a scalar node, but found %s" % node.id, 73 node.start_mark er)73 node.start_mark) 74 74 return node.value 75 75 … … 78 78 raise ConstructorError(None, None, 79 79 "expected a sequence node, but found %s" % node.id, 80 node.start_mark er)80 node.start_mark) 81 81 return [self.construct_object(child) for child in node.value] 82 82 … … 85 85 raise ConstructorError(None, None, 86 86 "expected a mapping node, but found %s" % node.id, 87 node.start_mark er)87 node.start_mark) 88 88 mapping = {} 89 89 merge = None … … 91 91 if key_node.tag == u'tag:yaml.org,2002:merge': 92 92 if merge is not None: 93 raise ConstructorError("while constructing a mapping", node.start_mark er,94 "found duplicate merge key", key_node.start_mark er)93 raise ConstructorError("while constructing a mapping", node.start_mark, 94 "found duplicate merge key", key_node.start_mark) 95 95 value_node = node.value[key_node] 96 96 if isinstance(value_node, MappingNode): … … 101 101 if not isinstance(subnode, MappingNode): 102 102 raise ConstructorError("while constructing a mapping", 103 node.start_mark er,103 node.start_mark, 104 104 "expected a mapping for merging, but found %s" 105 % subnode.id, subnode.start_mark er)105 % subnode.id, subnode.start_mark) 106 106 merge.append(self.construct_mapping(subnode)) 107 107 merge.reverse() 108 108 else: 109 raise ConstructorError("while constructing a mapping", node.start_mark er,109 raise ConstructorError("while constructing a mapping", node.start_mark, 110 110 "expected a mapping or list of mappings for merging, but found %s" 111 % value_node.id, value_node.start_mark er)111 % value_node.id, value_node.start_mark) 112 112 elif key_node.tag == u'tag:yaml.org,2002:value': 113 113 if '=' in mapping: 114 raise ConstructorError("while construction a mapping", node.start_mark er,115 "found duplicate value key", key_node.start_mark er)114 raise ConstructorError("while construction a mapping", node.start_mark, 115 "found duplicate value key", key_node.start_mark) 116 116 value = self.construct_object(node.value[key_node]) 117 117 mapping['='] = value … … 121 121 duplicate_key = key in mapping 122 122 except TypeError, exc: 123 raise ConstructorError("while constructing a mapping", node.start_mark er,124 "found unacceptable key (%s)" % exc, key_node.start_mark er)123 raise ConstructorError("while constructing a mapping", node.start_mark, 124 "found unacceptable key (%s)" % exc, key_node.start_mark) 125 125 if duplicate_key: 126 raise ConstructorError("while constructing a mapping", node.start_mark er,127 "found duplicate key", key_node.start_mark er)126 raise ConstructorError("while constructing a mapping", node.start_mark, 127 "found duplicate key", key_node.start_mark) 128 128 value = self.construct_object(node.value[key_node]) 129 129 mapping[key] = value … … 139 139 raise ConstructorError(None, None, 140 140 "expected a mapping node, but found %s" % node.id, 141 node.start_mark er)141 node.start_mark) 142 142 pairs = [] 143 143 for key_node in node.value: … … 235 235 except (binascii.Error, UnicodeEncodeError), exc: 236 236 raise ConstructorError(None, None, 237 "failed to decode base64 data: %s" % exc, node.start_mark er)237 "failed to decode base64 data: %s" % exc, node.start_mark) 238 238 239 239 timestamp_regexp = re.compile( … … 272 272 # CPU-expensive. 273 273 if not isinstance(node, SequenceNode): 274 raise ConstructorError("while constructing an ordered map", node.start_mark er,275 "expected a sequence, but found %s" % node.id, node.start_mark er)274 raise ConstructorError("while constructing an ordered map", node.start_mark, 275 "expected a sequence, but found %s" % node.id, node.start_mark) 276 276 omap = [] 277 277 for subnode in node.value: 278 278 if not isinstance(subnode, MappingNode): 279 raise ConstructorError("while constructing an ordered map", node.start_mark er,279 raise ConstructorError("while constructing an ordered map", node.start_mark, 280 280 "expected a mapping of length 1, but found %s" % subnode.id, 281 subnode.start_mark er)281 subnode.start_mark) 282 282 if len(subnode.value) != 1: 283 raise ConstructorError("while constructing an ordered map", node.start_mark er,283 raise ConstructorError("while constructing an ordered map", node.start_mark, 284 284 "expected a single mapping item, but found %d items" % len(subnode.value), 285 subnode.start_mark er)285 subnode.start_mark) 286 286 key_node = subnode.value.keys()[0] 287 287 key = self.construct_object(key_node) … … 293 293 # Note: the same code as `construct_yaml_omap`. 294 294 if not isinstance(node, SequenceNode): 295 raise ConstructorError("while constructing pairs", node.start_mark er,296 "expected a sequence, but found %s" % node.id, node.start_mark er)295 raise ConstructorError("while constructing pairs", node.start_mark, 296 "expected a sequence, but found %s" % node.id, node.start_mark) 297 297 pairs = [] 298 298 for subnode in node.value: 299 299 if not isinstance(subnode, MappingNode): 300 raise ConstructorError("while constructing pairs", node.start_mark er,300 raise ConstructorError("while constructing pairs", node.start_mark, 301 301 "expected a mapping of length 1, but found %s" % subnode.id, 302 subnode.start_mark er)302 subnode.start_mark) 303 303 if len(subnode.value) != 1: 304 raise ConstructorError("while constructing pairs", node.start_mark er,304 raise ConstructorError("while constructing pairs", node.start_mark, 305 305 "expected a single mapping item, but found %d items" % len(subnode.value), 306 subnode.start_mark er)306 subnode.start_mark) 307 307 key_node = subnode.value.keys()[0] 308 308 key = self.construct_object(key_node) … … 331 331 raise ConstructorError(None, None, 332 332 "could not determine a constructor for the tag %r" % node.tag.encode('utf-8'), 333 node.start_mark er)333 node.start_mark) 334 334 335 335 Constructor.add_constructor( … … 403 403 raise ConstructorError(None, None, 404 404 "found undefined constructor for the tag %r" 405 % node.tag.encode('utf-8'), node.start_mark er)405 % node.tag.encode('utf-8'), node.start_mark) 406 406 from_yaml = classmethod(from_yaml) 407 407
Note: See TracChangeset
for help on using the changeset viewer.
