Kirill Simonov avatar Kirill Simonov committed aff0a2b

Fixed the remaining Python 3 compatibility issues.

Comments (0)

Files changed (16)

lib3/yaml/constructor.py

         if '.' in name:
             module_name, object_name = name.rsplit('.', 1)
         else:
-            module_name = '__builtin__'
+            module_name = 'builtins'
             object_name = name
         try:
             __import__(module_name)

lib3/yaml/emitter.py

                 self.write_version_directive(version_text)
             self.tag_prefixes = self.DEFAULT_TAG_PREFIXES.copy()
             if self.event.tags:
-                handles = self.event.tags.keys()
-                handles.sort()
+                handles = sorted(self.event.tags.keys())
                 for handle in handles:
                     prefix = self.event.tags[handle]
                     self.tag_prefixes[prefix] = handle

tests3/data/construct-python-bytes.code

+b'some binary data'

tests3/data/construct-python-bytes.data

+--- !!python/bytes 'c29tZSBiaW5hcnkgZGF0YQ=='

tests3/data/construct-python-long-short.code

-123L
+123

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

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

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

-- !!python/name:file
+- !!python/name:str
 - !!python/name:yaml.Loader
 - !!python/name:yaml.dump
 - !!python/name:abs

tests3/data/construct-python-object.code

 AState(1, 'two', [3,3,3]),
 ACustomState(1, 'two', [3,3,3]),
 
-InitArgs(1, 'two', [3,3,3]),
-InitArgsWithState(1, 'two', [3,3,3]),
-
 NewArgs(1, 'two', [3,3,3]),
 NewArgsWithState(1, 'two', [3,3,3]),
 

tests3/data/construct-python-object.data

 - !!python/object:test_constructor.AState { _foo: 1, _bar: two, _baz: [3,3,3] }
 - !!python/object/new:test_constructor.ACustomState { state: !!python/tuple [1, two, [3,3,3]] }
 
-- !!python/object/new:test_constructor.InitArgs [1, two, [3,3,3]]
-- !!python/object/new:test_constructor.InitArgsWithState { args: [1, two], state: [3,3,3] }
-
 - !!python/object/new:test_constructor.NewArgs [1, two, [3,3,3]]
 - !!python/object/new:test_constructor.NewArgsWithState { args: [1, two], state: [3,3,3] }
 

tests3/data/construct-python-str-utf8.code

-u'\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430'.encode('utf-8')
+'\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430'

tests3/data/construct-python-unicode-ascii.code

-u"ascii string"
+"ascii string"

tests3/data/construct-python-unicode-utf8.code

-u'\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430'
+'\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430'

tests3/data/construct-str-utf8.code

-u'\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430'
+'\u042d\u0442\u043e \u0443\u043d\u0438\u043a\u043e\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430'

tests3/data/recursive-set.recursive

-try:
-    set
-except NameError:
-    from sets import Set as set
 value = set()
 value.add(AnInstance(foo=value, bar=value))
 value.add(AnInstance(foo=value, bar=value))

tests3/test_constructor.py

 import yaml.tokens
 
 def execute(code):
+    global value
     exec(code)
     return value
 
 def _make_objects():
     global MyLoader, MyDumper, MyTestClass1, MyTestClass2, MyTestClass3, YAMLObject1, YAMLObject2,  \
-            AnObject, AnInstance, AState, ACustomState, InitArgs, InitArgsWithState,    \
-            NewArgs, NewArgsWithState, Reduce, ReduceWithState, MyInt, MyList, MyDict,  \
-            FixedOffset, execute
+            AnObject, AnInstance, AState, ACustomState, NewArgs, NewArgsWithState,  \
+            Reduce, ReduceWithState, MyInt, MyList, MyDict, FixedOffset, execute
 
     class MyLoader(yaml.Loader):
         pass
             else:
                 return False
 
-    class AnObject(object):
+    class AnObject:
         def __new__(cls, foo=None, bar=None, baz=None):
             self = object.__new__(cls)
             self.foo = foo
         def __setstate__(self, state):
             self.foo, self.bar, self.baz = state
 
-    class InitArgs(AnInstance):
-        def __getinitargs__(self):
-            return (self.foo, self.bar, self.baz)
-        def __getstate__(self):
-            return {}
-
-    class InitArgsWithState(AnInstance):
-        def __getinitargs__(self):
-            return (self.foo, self.bar)
-        def __getstate__(self):
-            return self.baz
-        def __setstate__(self, state):
-            self.baz = state
-
     class NewArgs(AnObject):
         def __getnewargs__(self):
             return (self.foo, self.bar, self.baz)

tests3/test_recursive.py

         self.foo, self.bar = state['attributes']
 
 def test_recursive(recursive_filename, verbose=False):
-    exec(open(recursive_filename, 'rb').read())
-    value1 = value
+    context = globals().copy()
+    exec(open(recursive_filename, 'rb').read(), context)
+    value1 = context['value']
     output1 = None
     value2 = None
     output2 = None
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.