diff options
author | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2009-08-30 19:32:07 +0000 |
---|---|---|
committer | xi <xi@18f92427-320e-0410-9341-c67f048884a3> | 2009-08-30 19:32:07 +0000 |
commit | 95035cb9eaaa9a9d61b35e7d86efd8b87a173871 (patch) | |
tree | dedf58a1e7da9cef1471b784fc10ef30b4848ad6 | |
parent | e32d44988ab41f6d8aab82990815d6f3db1481da (diff) | |
download | pyyaml-95035cb9eaaa9a9d61b35e7d86efd8b87a173871.tar.gz |
Fixed Python 3.1 incompatibility issues.
git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@361 18f92427-320e-0410-9341-c67f048884a3
-rw-r--r-- | ext/_yaml.pyx | 9 | ||||
-rw-r--r-- | lib3/yaml/constructor.py | 10 | ||||
-rw-r--r-- | lib3/yaml/reader.py | 2 | ||||
-rw-r--r-- | lib3/yaml/representer.py | 5 |
4 files changed, 18 insertions, 8 deletions
diff --git a/ext/_yaml.pyx b/ext/_yaml.pyx index 3be0f4f..ac56b5f 100644 --- a/ext/_yaml.pyx +++ b/ext/_yaml.pyx @@ -954,11 +954,12 @@ cdef class CEmitter: raise MemoryError self.stream = stream self.dump_unicode = 0 - try: - if stream.encoding: + if PY_MAJOR_VERSION < 3: + if hasattr(stream, 'encoding'): + self.dump_unicode = 1 + else: + if hasattr(stream, u'encoding'): self.dump_unicode = 1 - except AttributeError: - pass self.use_encoding = encoding yaml_emitter_set_output(&self.emitter, output_handler, <void *>self) if canonical: diff --git a/lib3/yaml/constructor.py b/lib3/yaml/constructor.py index 5e23c20..bd25b79 100644 --- a/lib3/yaml/constructor.py +++ b/lib3/yaml/constructor.py @@ -285,7 +285,10 @@ class SafeConstructor(BaseConstructor): "failed to convert base64 data into ascii: %s" % exc, node.start_mark) try: - return base64.decodestring(value) + if hasattr(base64, 'decodebytes'): + return base64.decodebytes(value) + else: + return base64.decodestring(value) except binascii.Error as exc: raise ConstructorError(None, None, "failed to decode base64 data: %s" % exc, node.start_mark) @@ -477,7 +480,10 @@ class Constructor(SafeConstructor): "failed to convert base64 data into ascii: %s" % exc, node.start_mark) try: - return base64.decodestring(value) + if hasattr(base64, 'decodebytes'): + return base64.decodebytes(value) + else: + return base64.decodestring(value) except binascii.Error as exc: raise ConstructorError(None, None, "failed to decode base64 data: %s" % exc, node.start_mark) diff --git a/lib3/yaml/reader.py b/lib3/yaml/reader.py index f5fb924..f70e920 100644 --- a/lib3/yaml/reader.py +++ b/lib3/yaml/reader.py @@ -156,7 +156,7 @@ class Reader(object): data, converted = self.raw_decode(self.raw_buffer, 'strict', self.eof) except UnicodeDecodeError as exc: - character = exc.object[exc.start] + character = self.raw_buffer[exc.start] if self.stream is not None: position = self.stream_pointer-len(self.raw_buffer)+exc.start else: diff --git a/lib3/yaml/representer.py b/lib3/yaml/representer.py index 1a9a574..67cd6fd 100644 --- a/lib3/yaml/representer.py +++ b/lib3/yaml/representer.py @@ -144,7 +144,10 @@ class SafeRepresenter(BaseRepresenter): return self.represent_scalar('tag:yaml.org,2002:str', data) def represent_binary(self, data): - data = base64.encodestring(data).decode('ascii') + if hasattr(base64, 'encodebytes'): + data = base64.encodebytes(data).decode('ascii') + else: + data = base64.encodestring(data).decode('ascii') return self.represent_scalar('tag:yaml.org,2002:binary', data, style='|') def represent_bool(self, data): |