Changeset 58 for branches/pyyaml3000/lib/yaml/constructor.py
- Timestamp:
- 02/25/06 11:08:26 (7 years ago)
- File:
-
- 1 edited
-
branches/pyyaml3000/lib/yaml/constructor.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pyyaml3000/lib/yaml/constructor.py
r57 r58 93 93 raise ConstructorError("while constructing a mapping", node.start_marker, 94 94 "found duplicate merge key", key_node.start_marker) 95 value_node = node.value[key_node]96 if isinstance(value_node, MappingNode):97 merge = [self.construct_mapping(value_node)]98 elif isinstance(value_node, SequenceNode):99 merge = []100 for subnode in value_node.value:101 if not isinstance(subnode, MappingNode):102 raise ConstructorError("while constructing a mapping",103 node.start_marker,104 "expected a mapping for merging, but found %s"105 % subnode.id, subnode.start_marker)106 merge.append(self.construct_mapping(subnode))107 merge.reverse()108 else:109 raise ConstructorError("while constructing a mapping", node.start_marker,110 "expected a mapping or list of mappings for merging, but found %s"111 % value_node.id, value_node.start_marker)95 value_node = node.value[key_node] 96 if isinstance(value_node, MappingNode): 97 merge = [self.construct_mapping(value_node)] 98 elif isinstance(value_node, SequenceNode): 99 merge = [] 100 for subnode in value_node.value: 101 if not isinstance(subnode, MappingNode): 102 raise ConstructorError("while constructing a mapping", 103 node.start_marker, 104 "expected a mapping for merging, but found %s" 105 % subnode.id, subnode.start_marker) 106 merge.append(self.construct_mapping(subnode)) 107 merge.reverse() 108 else: 109 raise ConstructorError("while constructing a mapping", node.start_marker, 110 "expected a mapping or list of mappings for merging, but found %s" 111 % value_node.id, value_node.start_marker) 112 112 elif key_node.tag == u'tag:yaml.org,2002:value': 113 113 if '=' in mapping: … … 212 212 sign = +1 213 213 if value[0] == '-': 214 value= -1214 sign = -1 215 215 if value[0] in '+-': 216 216 value = value[1:] … … 237 237 except (binascii.Error, UnicodeEncodeError), exc: 238 238 raise ConstructorError(None, None, 239 "failed to decode base64 data: %s" % exc, node.start_mark )239 "failed to decode base64 data: %s" % exc, node.start_marker) 240 240 241 241 timestamp_regexp = re.compile( … … 243 243 -(?P<month>[0-9][0-9]?) 244 244 -(?P<day>[0-9][0-9]?) 245 (?: [Tt]|[ \t]+)245 (?:(?:[Tt]|[ \t]+) 246 246 (?P<hour>[0-9][0-9]?) 247 247 :(?P<minute>[0-9][0-9]) … … 249 249 (?:\.(?P<fraction>[0-9]*))? 250 250 (?:[ \t]*(?:Z|(?P<tz_hour>[-+][0-9][0-9]?) 251 (?::(?P<tz_minute>[0-9][0-9])?) ))?$''', re.X),251 (?::(?P<tz_minute>[0-9][0-9])?)?))?)?$''', re.X) 252 252 253 253 def construct_yaml_timestamp(self, node): 254 254 value = self.construct_scalar(node) 255 match = self.timestamp_ expr.match(node.value)255 match = self.timestamp_regexp.match(node.value) 256 256 values = match.groupdict() 257 257 for key in values: … … 261 261 values[key] = 0 262 262 fraction = values['fraction'] 263 if micro:263 if fraction: 264 264 while 10*fraction < 1000000: 265 265 fraction *= 10 … … 282 282 "expected a mapping of length 1, but found %s" % subnode.id, 283 283 subnode.start_marker) 284 if len(subnode.value) != 1: 285 raise ConstructorError("while constructing an ordered map", node.start_marker, 286 "expected a single mapping item, but found %d items" % len(subnode.value), 287 subnode.start_marker) 288 key_node = subnode.value.keys()[0] 289 key = self.construct_object(key_node) 290 value = self.construct_object(subnode.value[key_node]) 291 omap.append((key, value)) 284 if len(subnode.value) != 1: 285 raise ConstructorError("while constructing an ordered map", node.start_marker, 286 "expected a single mapping item, but found %d items" % len(subnode.value), 287 subnode.start_marker) 288 key_node = subnode.value.keys()[0] 289 key = self.construct_object(key_node) 290 value = self.construct_object(subnode.value[key_node]) 291 omap.append((key, value)) 292 return omap 292 293 293 294 def construct_yaml_pairs(self, node): … … 296 297 raise ConstructorError("while constructing pairs", node.start_marker, 297 298 "expected a sequence, but found %s" % node.id, node.start_marker) 298 omap= []299 pairs = [] 299 300 for subnode in node.value: 300 301 if not isinstance(subnode, MappingNode): … … 302 303 "expected a mapping of length 1, but found %s" % subnode.id, 303 304 subnode.start_marker) 304 if len(subnode.value) != 1: 305 raise ConstructorError("while constructing pairs", node.start_marker, 306 "expected a single mapping item, but found %d items" % len(subnode.value), 307 subnode.start_marker) 308 key_node = subnode.value.keys()[0] 309 key = self.construct_object(key_node) 310 value = self.construct_object(subnode.value[key_node]) 311 omap.append((key, value)) 305 if len(subnode.value) != 1: 306 raise ConstructorError("while constructing pairs", node.start_marker, 307 "expected a single mapping item, but found %d items" % len(subnode.value), 308 subnode.start_marker) 309 key_node = subnode.value.keys()[0] 310 key = self.construct_object(key_node) 311 value = self.construct_object(subnode.value[key_node]) 312 pairs.append((key, value)) 313 return pairs 312 314 313 315 def construct_yaml_set(self, node): … … 350 352 351 353 Constructor.add_constructor( 352 u'tag:yaml.org,2002:timestamp', 353 Constructor.construct_yaml_timestamp) 354 u'tag:yaml.org,2002:binary', 355 Constructor.construct_yaml_binary) 356 357 if datetime_available: 358 Constructor.add_constructor( 359 u'tag:yaml.org,2002:timestamp', 360 Constructor.construct_yaml_timestamp) 354 361 355 362 Constructor.add_constructor( … … 385 392 super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds) 386 393 if 'yaml_tag' in kwds and kwds['yaml_tag'] is not None: 387 cls.yaml_constructor _class.add_constructor(cls.yaml_tag, cls.from_yaml)394 cls.yaml_constructor.add_constructor(cls.yaml_tag, cls.from_yaml) 388 395 389 396 class YAMLObject(object): … … 391 398 __metaclass__ = YAMLObjectMetaclass 392 399 393 yaml_constructor _class= Constructor400 yaml_constructor = Constructor 394 401 395 402 yaml_tag = None
Note: See TracChangeset
for help on using the changeset viewer.
