From a3e1d53bbac8d5dc770802ab0cc9c85aeed65b3f Mon Sep 17 00:00:00 2001 From: xi Date: Fri, 24 Feb 2006 21:16:14 +0000 Subject: [PATCH] Fix a few bugs. git-svn-id: http://svn.pyyaml.org/branches/pyyaml3000@57 18f92427-320e-0410-9341-c67f048884a3 --- lib/yaml/__init__.py | 14 +++++++------- lib/yaml/composer.py | 2 ++ lib/yaml/constructor.py | 11 +++++++++++ lib/yaml/parser.py | 2 ++ lib/yaml/resolver.py | 7 +++++++ lib/yaml/scanner.py | 3 +++ tests/data/spec-08-09.data | 2 +- tests/test_structure.py | 10 +++------- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/lib/yaml/__init__.py b/lib/yaml/__init__.py index 10832dd..55e3f38 100644 --- a/lib/yaml/__init__.py +++ b/lib/yaml/__init__.py @@ -1,11 +1,11 @@ -from error import YAMLError -from reader import Reader -from scanner import Scanner -from parser import Parser -from composer import Composer -from resolver import Resolver -from constructor import Constructor +from error import * +from reader import * +from scanner import * +from parser import * +from composer import * +from resolver import * +from constructor import * from tokens import * from events import * diff --git a/lib/yaml/composer.py b/lib/yaml/composer.py index 7d60bc1..0f00062 100644 --- a/lib/yaml/composer.py +++ b/lib/yaml/composer.py @@ -1,4 +1,6 @@ +__all__ = ['Composer', 'ComposerError'] + from error import MarkedYAMLError from events import * from nodes import * diff --git a/lib/yaml/constructor.py b/lib/yaml/constructor.py index 90d9152..1e7fea0 100644 --- a/lib/yaml/constructor.py +++ b/lib/yaml/constructor.py @@ -1,4 +1,7 @@ +__all__ = ['BaseConstructor', 'Constructor', 'ConstructorError', + 'YAMLObject', 'YAMLObjectMetaclass'] + from error import * from nodes import * @@ -324,6 +327,11 @@ class Constructor(BaseConstructor): def construct_yaml_map(self, node): return self.construct_mapping(node) + def construct_undefined(self, node): + raise ConstructorError(None, None, + "could not determine a constructor for the tag %r" % node.tag.encode('utf-8'), + node.start_marker) + Constructor.add_constructor( u'tag:yaml.org,2002:null', Constructor.construct_yaml_null) @@ -368,6 +376,9 @@ Constructor.add_constructor( u'tag:yaml.org,2002:map', Constructor.construct_yaml_map) +Constructor.add_constructor(None, + Constructor.construct_undefined) + class YAMLObjectMetaclass(type): def __init__(cls, name, bases, kwds): diff --git a/lib/yaml/parser.py b/lib/yaml/parser.py index 2a77d82..a66dc81 100644 --- a/lib/yaml/parser.py +++ b/lib/yaml/parser.py @@ -61,6 +61,8 @@ # flow_sequence_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY } # flow_mapping_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY } +__all__ = ['Parser', 'ParserError'] + from error import MarkedYAMLError from tokens import * from events import * diff --git a/lib/yaml/resolver.py b/lib/yaml/resolver.py index 749a018..e3706c5 100644 --- a/lib/yaml/resolver.py +++ b/lib/yaml/resolver.py @@ -1,8 +1,15 @@ +__all__ = ['BaseResolver', 'Resolver', 'ResolverError'] + +from error import MarkedYAMLError from nodes import * import re +# Not really used. +class ResolverError(MarkedYAMLError): + pass + class BaseResolver: DEFAULT_SCALAR_TAG = u'tag:yaml.org,2002:str' diff --git a/lib/yaml/scanner.py b/lib/yaml/scanner.py index d9ae9de..09e3bd6 100644 --- a/lib/yaml/scanner.py +++ b/lib/yaml/scanner.py @@ -19,6 +19,9 @@ # ANCHOR(value) # TAG(value) # SCALAR(value, plain) +# +# Read comments in the Scanner code for more details. +# __all__ = ['Scanner', 'ScannerError'] diff --git a/tests/data/spec-08-09.data b/tests/data/spec-08-09.data index 8d286d3..69da042 100644 --- a/tests/data/spec-08-09.data +++ b/tests/data/spec-08-09.data @@ -5,7 +5,7 @@ scalars: single: 'some text' double: "some text" collections: - sequence: !!seq [ !str entry, + sequence: !!seq [ !!str entry, # Mapping entry: key: value ] mapping: { key: value } diff --git a/tests/test_structure.py b/tests/test_structure.py index f1ec330..985d2c3 100644 --- a/tests/test_structure.py +++ b/tests/test_structure.py @@ -1,13 +1,7 @@ import test_appliance -from yaml.reader import Reader -from yaml.scanner import Scanner -from yaml.parser import * -from yaml.composer import * -from yaml.resolver import * -from yaml.constructor import * -from yaml.nodes import * +from yaml import * class TestStructure(test_appliance.TestAppliance): @@ -160,6 +154,8 @@ class MyConstructor(Constructor): pairs.sort() return pairs +MyConstructor.add_constructor(None, MyConstructor.construct_scalar) + class TestConstructor(test_appliance.TestAppliance): def _testConstructor(self, test_name, data_filename, canonical_filename): -- 2.11.4.GIT