From 38eef02aab2cf52bce537ef43870387ba30381c8 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 22 Aug 2015 13:02:24 -0400 Subject: Fix metaclass issue on Python 3. Get text handling tests passing on Python 3. Signed-off-by: Dan O'Reilly --- python/google/protobuf/text_format.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'python/google/protobuf/text_format.py') diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py index 7bdde33f..145bb656 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -69,19 +69,15 @@ class ParseError(Error): class TextWriter(object): def __init__(self, as_utf8): - self._utf8 = as_utf8 - if as_utf8: + if six.PY2: self._writer = io.BytesIO() else: self._writer = io.StringIO() def write(self, val): - if self._utf8: + if six.PY2: if isinstance(val, six.text_type): val = val.encode('utf-8') - else: - if isinstance(val, bytes): - val = val.decode('utf-8') return self._writer.write(val) def close(self): @@ -245,8 +241,7 @@ def PrintFieldValue(field, value, out, indent=0, as_utf8=False, out_as_utf8 = False else: out_as_utf8 = as_utf8 - out_text = text_encoding.CEscape(out_value, out_as_utf8) - out.write(out_text) + out.write(text_encoding.CEscape(out_value, out_as_utf8)) out.write('\"') elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_BOOL: if value: -- cgit v1.2.3