Changeset 58
- Timestamp:
- 02/25/06 11:08:26 (7 years ago)
- Location:
- branches/pyyaml3000
- Files:
-
- 50 added
- 3 edited
-
LICENSE (added)
-
README (added)
-
lib/yaml/constructor.py (modified) (12 diffs)
-
tests/data/construct-binary.code (added)
-
tests/data/construct-binary.data (added)
-
tests/data/construct-bool.code (added)
-
tests/data/construct-bool.data (added)
-
tests/data/construct-custom.code (added)
-
tests/data/construct-custom.data (added)
-
tests/data/construct-float.code (added)
-
tests/data/construct-float.data (added)
-
tests/data/construct-int.code (added)
-
tests/data/construct-int.data (added)
-
tests/data/construct-map.code (added)
-
tests/data/construct-map.data (added)
-
tests/data/construct-merge.code (added)
-
tests/data/construct-merge.data (added)
-
tests/data/construct-null.code (added)
-
tests/data/construct-null.data (added)
-
tests/data/construct-omap.code (added)
-
tests/data/construct-omap.data (added)
-
tests/data/construct-pairs.code (added)
-
tests/data/construct-pairs.data (added)
-
tests/data/construct-seq.code (added)
-
tests/data/construct-seq.data (added)
-
tests/data/construct-set.code (added)
-
tests/data/construct-set.data (added)
-
tests/data/construct-str.code (added)
-
tests/data/construct-str.data (added)
-
tests/data/construct-timestamp.code (added)
-
tests/data/construct-timestamp.data (added)
-
tests/data/construct-value.code (added)
-
tests/data/construct-value.data (added)
-
tests/data/duplicate-key.error-message (added)
-
tests/data/duplicate-merge-key.error-message (added)
-
tests/data/duplicate-value-key.error-message (added)
-
tests/data/expected-mapping.error-message (added)
-
tests/data/expected-scalar.error-message (added)
-
tests/data/expected-sequence.error-message (added)
-
tests/data/invalid-base64-data.error-message (added)
-
tests/data/invalid-merge-1.error-message (added)
-
tests/data/invalid-merge-2.error-message (added)
-
tests/data/invalid-omap-1.error-message (added)
-
tests/data/invalid-omap-2.error-message (added)
-
tests/data/invalid-omap-3.error-message (added)
-
tests/data/invalid-pairs-1.error-message (added)
-
tests/data/invalid-pairs-2.error-message (added)
-
tests/data/invalid-pairs-3.error-message (added)
-
tests/data/unacceptable-key.error-message (added)
-
tests/data/undefined-constructor.error-message (added)
-
tests/test_constructor.py (added)
-
tests/test_errors.py (modified) (3 diffs)
-
tests/test_yaml.py (modified) (1 diff)
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 -
branches/pyyaml3000/tests/test_errors.py
r53 r58 2 2 import test_appliance 3 3 4 from yaml.error import YAMLError 5 from yaml.reader import * 6 from yaml.scanner import * 7 from yaml.parser import * 8 from yaml.composer import * 9 from yaml.resolver import * 4 from yaml import * 10 5 11 6 class TestErrors(test_appliance.TestAppliance): … … 26 21 composer = Composer(parser) 27 22 resolver = Resolver(composer) 28 return list(composer) 23 constructor = Constructor(resolver) 24 return list(constructor) 29 25 except YAMLError, exc: 30 26 #except ScannerError, exc: … … 42 38 composer = Composer(parser) 43 39 resolver = Resolver(composer) 44 return list(composer) 45 except YAMLError, exc: 40 constructor = Constructor(resolver) 41 return list(constructor) 42 #except YAMLError, exc: 46 43 #except ScannerError, exc: 47 44 #except ParserError, exc: 48 45 #except ComposerError, exc: 49 #print '.'*70 50 #print "%s:" % filename 51 #print "%s:" % exc.__class__.__name__, exc 46 except ConstructorError, exc: 47 print '.'*70 48 print "%s:" % filename 49 print "%s:" % exc.__class__.__name__, exc 52 50 raise 53 51 -
branches/pyyaml3000/tests/test_yaml.py
r55 r58 9 9 from test_errors import * 10 10 from test_detector import * 11 from test_constructor import * 11 12 from test_syck import * 12 13
Note: See TracChangeset
for help on using the changeset viewer.
