summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxi <xi@18f92427-320e-0410-9341-c67f048884a3>2008-12-29 18:11:08 +0000
committerxi <xi@18f92427-320e-0410-9341-c67f048884a3>2008-12-29 18:11:08 +0000
commitacc558ffdc125d1f78a81a9e4b4267c4fb4bd9a8 (patch)
tree9ee1e29a1433b67ac5ede33beaa9abdf69f9b179
parent0dfeb9f5f403658a12a0305d1cf2ff54ccb88f20 (diff)
downloadpyyaml-acc558ffdc125d1f78a81a9e4b4267c4fb4bd9a8.tar.gz
Fixed the remaining Python 3 compatibility issues.
git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@329 18f92427-320e-0410-9341-c67f048884a3
-rw-r--r--lib3/yaml/constructor.py2
-rw-r--r--lib3/yaml/emitter.py3
-rw-r--r--tests3/data/construct-python-bytes.code1
-rw-r--r--tests3/data/construct-python-bytes.data1
-rw-r--r--tests3/data/construct-python-long-short.code2
-rw-r--r--tests3/data/construct-python-name-module.code2
-rw-r--r--tests3/data/construct-python-name-module.data2
-rw-r--r--tests3/data/construct-python-object.code3
-rw-r--r--tests3/data/construct-python-object.data3
-rw-r--r--tests3/data/construct-python-str-utf8.code2
-rw-r--r--tests3/data/construct-python-unicode-ascii.code2
-rw-r--r--tests3/data/construct-python-unicode-utf8.code2
-rw-r--r--tests3/data/construct-str-utf8.code2
-rw-r--r--tests3/data/recursive-set.recursive4
-rw-r--r--tests3/test_constructor.py22
-rw-r--r--tests3/test_recursive.py5
16 files changed, 18 insertions, 40 deletions
diff --git a/lib3/yaml/constructor.py b/lib3/yaml/constructor.py
index 2f6ed15..5e23c20 100644
--- a/lib3/yaml/constructor.py
+++ b/lib3/yaml/constructor.py
@@ -509,7 +509,7 @@ class Constructor(SafeConstructor):
if '.' in name:
module_name, object_name = name.rsplit('.', 1)
else:
- module_name = '__builtin__'
+ module_name = 'builtins'
object_name = name
try:
__import__(module_name)
diff --git a/lib3/yaml/emitter.py b/lib3/yaml/emitter.py
index b5521fa..5815909 100644
--- a/lib3/yaml/emitter.py
+++ b/lib3/yaml/emitter.py
@@ -180,8 +180,7 @@ class Emitter:
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
diff --git a/tests3/data/construct-python-bytes.code b/tests3/data/construct-python-bytes.code
new file mode 100644
index 0000000..b9051d8
--- /dev/null
+++ b/tests3/data/construct-python-bytes.code
@@ -0,0 +1 @@
+b'some binary data'
diff --git a/tests3/data/construct-python-bytes.data b/tests3/data/construct-python-bytes.data
new file mode 100644
index 0000000..9528725
--- /dev/null
+++ b/tests3/data/construct-python-bytes.data
@@ -0,0 +1 @@
+--- !!python/bytes 'c29tZSBiaW5hcnkgZGF0YQ=='
diff --git a/tests3/data/construct-python-long-short.code b/tests3/data/construct-python-long-short.code
index fafc3f1..190a180 100644
--- a/tests3/data/construct-python-long-short.code
+++ b/tests3/data/construct-python-long-short.code
@@ -1 +1 @@
-123L
+123
diff --git a/tests3/data/construct-python-name-module.code b/tests3/data/construct-python-name-module.code
index 8f93503..6f39148 100644
--- a/tests3/data/construct-python-name-module.code
+++ b/tests3/data/construct-python-name-module.code
@@ -1 +1 @@
-[file, yaml.Loader, yaml.dump, abs, yaml.tokens]
+[str, yaml.Loader, yaml.dump, abs, yaml.tokens]
diff --git a/tests3/data/construct-python-name-module.data b/tests3/data/construct-python-name-module.data
index c8f8036..f0c9712 100644
--- a/tests3/data/construct-python-name-module.data
+++ b/tests3/data/construct-python-name-module.data
@@ -1,4 +1,4 @@
-- !!python/name:file
+- !!python/name:str
- !!python/name:yaml.Loader
- !!python/name:yaml.dump
- !!python/name:abs
diff --git a/tests3/data/construct-python-object.code b/tests3/data/construct-python-object.code
index 7f1edf1..bfc840a 100644
--- a/tests3/data/construct-python-object.code
+++ b/tests3/data/construct-python-object.code
@@ -8,9 +8,6 @@ AnInstance(1, 'two', [3,3,3]),
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]),
diff --git a/tests3/data/construct-python-object.data b/tests3/data/construct-python-object.data
index bce8b2e..6f7a7ce 100644
--- a/tests3/data/construct-python-object.data
+++ b/tests3/data/construct-python-object.data
@@ -7,9 +7,6 @@
- !!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] }
diff --git a/tests3/data/construct-python-str-utf8.code b/tests3/data/construct-python-str-utf8.code
index 47b28ab..9f66032 100644
--- a/tests3/data/construct-python-str-utf8.code
+++ b/tests3/data/construct-python-str-utf8.code
@@ -1 +1 @@
-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'
diff --git a/tests3/data/construct-python-unicode-ascii.code b/tests3/data/construct-python-unicode-ascii.code
index d4cd82c..d9d62f6 100644
--- a/tests3/data/construct-python-unicode-ascii.code
+++ b/tests3/data/construct-python-unicode-ascii.code
@@ -1 +1 @@
-u"ascii string"
+"ascii string"
diff --git a/tests3/data/construct-python-unicode-utf8.code b/tests3/data/construct-python-unicode-utf8.code
index 2793ac7..9f66032 100644
--- a/tests3/data/construct-python-unicode-utf8.code
+++ b/tests3/data/construct-python-unicode-utf8.code
@@ -1 +1 @@
-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'
diff --git a/tests3/data/construct-str-utf8.code b/tests3/data/construct-str-utf8.code
index 2793ac7..9f66032 100644
--- a/tests3/data/construct-str-utf8.code
+++ b/tests3/data/construct-str-utf8.code
@@ -1 +1 @@
-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'
diff --git a/tests3/data/recursive-set.recursive b/tests3/data/recursive-set.recursive
index 457c50d..d1a7ca3 100644
--- a/tests3/data/recursive-set.recursive
+++ b/tests3/data/recursive-set.recursive
@@ -1,7 +1,3 @@
-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))
diff --git a/tests3/test_constructor.py b/tests3/test_constructor.py
index c9c7f55..c632b4f 100644
--- a/tests3/test_constructor.py
+++ b/tests3/test_constructor.py
@@ -6,14 +6,14 @@ import datetime
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
@@ -99,7 +99,7 @@ def _make_objects():
else:
return False
- class AnObject(object):
+ class AnObject:
def __new__(cls, foo=None, bar=None, baz=None):
self = object.__new__(cls)
self.foo = foo
@@ -143,20 +143,6 @@ def _make_objects():
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)
diff --git a/tests3/test_recursive.py b/tests3/test_recursive.py
index 1ab79bd..321a75f 100644
--- a/tests3/test_recursive.py
+++ b/tests3/test_recursive.py
@@ -23,8 +23,9 @@ class AnInstanceWithState(AnInstance):
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