diff options
Diffstat (limited to 'python/google')
-rwxr-xr-x | python/google/protobuf/descriptor.py | 5 | ||||
-rwxr-xr-x | python/google/protobuf/text_format.py | 11 |
2 files changed, 6 insertions, 10 deletions
diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 6840d1f4..95b703fc 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -36,6 +36,8 @@ file, in types that make this information accessible in Python. __author__ = 'robinson@google.com (Will Robinson)' +import six + from google.protobuf.internal import api_implementation @@ -73,7 +75,7 @@ else: DescriptorMetaclass = type -class DescriptorBase(object): +class DescriptorBase(six.with_metaclass(DescriptorMetaclass)): """Descriptors base class. @@ -88,7 +90,6 @@ class DescriptorBase(object): avoid some bootstrapping issues. """ - __metaclass__ = DescriptorMetaclass if _USE_C_DESCRIPTORS: # The class, or tuple of classes, that are considered as "virtual # subclasses" of this descriptor class. 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: |