Kirill Simonov avatar Kirill Simonov committed 2d77d67

Fix !!python/name for Python 2.3. Clear the yaml module namespace.

Comments (0)

Files changed (8)

lib/yaml/__init__.py

 
 from error import *
 
-from reader import *
-from scanner import *
-from parser import *
-from composer import *
-from constructor import *
-
-from emitter import *
-from serializer import *
-from representer import *
-
-from resolver import *
-
 from tokens import *
 from events import *
 from nodes import *

lib/yaml/constructor.py

             raise ConstructorError("while constructing a Python object", mark,
                     "expected non-empty name appended to the tag", mark)
         if u'.' in name:
-            module_name, object_name = name.rsplit('.', 1)
+            # Python 2.4 only
+            #module_name, object_name = name.rsplit('.', 1)
+            items = name.split('.')
+            object_name = items.pop()
+            module_name = '.'.join(items)
         else:
             module_name = '__builtin__'
             object_name = name

tests/data/construct-python-name-module.code

-[file, Loader, dump, abs, xml.parsers]
+[file, Loader, dump, abs, yaml.tokens]

tests/data/construct-python-name-module.data

 - !!python/name:yaml.Loader
 - !!python/name:yaml.dump
 - !!python/name:abs
-- !!python/module:xml.parsers
+- !!python/module:yaml.tokens

tests/test_appliance.py

 import unittest, os
 
 from yaml import *
+from yaml.composer import *
+from yaml.constructor import *
+from yaml.resolver import *
 
 class TestAppliance(unittest.TestCase):
 

tests/test_constructor.py

 
 from yaml import *
 
-import xml.parsers
+import yaml.tokens
 
 class MyLoader(Loader):
     pass

tests/test_errors.py

     def _emit(self, events):
         try:
             emit(events)
-        except EmitterError, exc:
+        except YAMLError, exc:
             #print '.'*70
             #print "%s:" % exc.__class__.__name__, exc
             raise

tests/test_structure.py

 
 TestResolver.add_tests('testResolver', '.data', '.canonical')
 
-class MyConstructor:
-
+class MyLoader(Loader):
     def construct_sequence(self, node):
-        return tuple(Constructor.construct_sequence(self, node))
+        return tuple(Loader.construct_sequence(self, node))
 
     def construct_mapping(self, node):
         pairs = self.construct_pairs(node)
     def construct_undefined(self, node):
         return self.construct_scalar(node)
 
-class MyLoader(MyConstructor, Loader):
-    pass
 MyLoader.add_constructor(None, MyLoader.construct_undefined)
 
-class MyCanonicalLoader(MyConstructor, test_appliance.CanonicalLoader):
-    pass
+class MyCanonicalLoader(test_appliance.CanonicalLoader):
+
+    def construct_sequence(self, node):
+        return tuple(test_appliance.CanonicalLoader.construct_sequence(self, node))
+
+    def construct_mapping(self, node):
+        pairs = self.construct_pairs(node)
+        pairs.sort()
+        return pairs
+
+    def construct_undefined(self, node):
+        return self.construct_scalar(node)
+
 MyCanonicalLoader.add_constructor(None, MyCanonicalLoader.construct_undefined)
 
 class TestConstructor(test_appliance.TestAppliance):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.