From 1a7a7fca804afa1cf67f8be5e71092898ba40334 Mon Sep 17 00:00:00 2001 From: Jisi Liu Date: Wed, 18 Oct 2017 12:22:18 -0700 Subject: Merge from google internal --- python/google/protobuf/text_format.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (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 aaca78ad..6b12632e 100755 --- a/python/google/protobuf/text_format.py +++ b/python/google/protobuf/text_format.py @@ -485,7 +485,10 @@ def Parse(text, ParseError: On text parsing problems. """ if not isinstance(text, str): - text = text.decode('utf-8') + if six.PY3: + text = text.decode('utf-8') + else: + text = text.encode('utf-8') return ParseLines(text.split('\n'), message, allow_unknown_extension, @@ -517,6 +520,11 @@ def Merge(text, Raises: ParseError: On text parsing problems. """ + if not isinstance(text, str): + if six.PY3: + text = text.decode('utf-8') + else: + text = text.encode('utf-8') return MergeLines( text.split('\n'), message, @@ -1559,6 +1567,11 @@ def ParseEnum(field, value): (enum_descriptor.full_name, value)) else: # Numeric value. + if hasattr(field.file, 'syntax'): + # Attribute is checked for compatibility. + if field.file.syntax == 'proto3': + # Proto3 accept numeric unknown enums. + return number enum_value = enum_descriptor.values_by_number.get(number, None) if enum_value is None: raise ValueError('Enum type "%s" has no value with number %d.' % -- cgit v1.2.3