diff options
Diffstat (limited to 'lib3/yaml')
-rw-r--r-- | lib3/yaml/constructor.py | 10 | ||||
-rw-r--r-- | lib3/yaml/reader.py | 2 | ||||
-rw-r--r-- | lib3/yaml/representer.py | 5 |
3 files changed, 13 insertions, 4 deletions
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): |