| Index: third_party/protobuf/python/google/protobuf/internal/python_message.py
|
| diff --git a/third_party/protobuf/python/google/protobuf/internal/python_message.py b/third_party/protobuf/python/google/protobuf/internal/python_message.py
|
| index f8f73dd20486fb83c5576aea8e8ab7528b2eb25a..dc6565d42b8cedc7b3c205ee2a6d9cac0b9e0e5d 100755
|
| --- a/third_party/protobuf/python/google/protobuf/internal/python_message.py
|
| +++ b/third_party/protobuf/python/google/protobuf/internal/python_message.py
|
| @@ -63,7 +63,10 @@ except ImportError:
|
| # nothing like hermetic Python. This means lesser control on the system and
|
| # the six.moves package may be missing (is missing on 20150321 on gMac). Be
|
| # extra conservative and try to load the old replacement if it fails.
|
| - import copy_reg as copyreg
|
| + try:
|
| + import copy_reg as copyreg #PY26
|
| + except ImportError:
|
| + import copyreg
|
|
|
| # We use "as" to avoid name collisions with variables.
|
| from google.protobuf.internal import containers
|
| @@ -76,7 +79,6 @@ from google.protobuf.internal import well_known_types
|
| from google.protobuf.internal import wire_format
|
| from google.protobuf import descriptor as descriptor_mod
|
| from google.protobuf import message as message_mod
|
| -from google.protobuf import symbol_database
|
| from google.protobuf import text_format
|
|
|
| _FieldDescriptor = descriptor_mod.FieldDescriptor
|
| @@ -98,16 +100,12 @@ class GeneratedProtocolMessageType(type):
|
| classes at runtime, as in this example:
|
|
|
| mydescriptor = Descriptor(.....)
|
| - class MyProtoClass(Message):
|
| - __metaclass__ = GeneratedProtocolMessageType
|
| - DESCRIPTOR = mydescriptor
|
| + factory = symbol_database.Default()
|
| + factory.pool.AddDescriptor(mydescriptor)
|
| + MyProtoClass = factory.GetPrototype(mydescriptor)
|
| myproto_instance = MyProtoClass()
|
| myproto.foo_field = 23
|
| ...
|
| -
|
| - The above example will not work for nested types. If you wish to include them,
|
| - use reflection.MakeClass() instead of manually instantiating the class in
|
| - order to create the appropriate class structure.
|
| """
|
|
|
| # Must be consistent with the protocol-compiler code in
|
| @@ -385,13 +383,15 @@ def _GetInitializeDefaultForMap(field):
|
| if _IsMessageMapField(field):
|
| def MakeMessageMapDefault(message):
|
| return containers.MessageMap(
|
| - message._listener_for_children, value_field.message_type, key_checker)
|
| + message._listener_for_children, value_field.message_type, key_checker,
|
| + field.message_type)
|
| return MakeMessageMapDefault
|
| else:
|
| value_checker = type_checkers.GetTypeChecker(value_field)
|
| def MakePrimitiveMapDefault(message):
|
| return containers.ScalarMap(
|
| - message._listener_for_children, key_checker, value_checker)
|
| + message._listener_for_children, key_checker, value_checker,
|
| + field.message_type)
|
| return MakePrimitiveMapDefault
|
|
|
| def _DefaultValueConstructorForField(field):
|
| @@ -926,26 +926,33 @@ def _InternalUnpackAny(msg):
|
| Returns:
|
| The unpacked message.
|
| """
|
| + # TODO(amauryfa): Don't use the factory of generated messages.
|
| + # To make Any work with custom factories, use the message factory of the
|
| + # parent message.
|
| + # pylint: disable=g-import-not-at-top
|
| + from google.protobuf import symbol_database
|
| + factory = symbol_database.Default()
|
| +
|
| type_url = msg.type_url
|
| - db = symbol_database.Default()
|
|
|
| if not type_url:
|
| return None
|
|
|
| # TODO(haberman): For now we just strip the hostname. Better logic will be
|
| # required.
|
| - type_name = type_url.split("/")[-1]
|
| - descriptor = db.pool.FindMessageTypeByName(type_name)
|
| + type_name = type_url.split('/')[-1]
|
| + descriptor = factory.pool.FindMessageTypeByName(type_name)
|
|
|
| if descriptor is None:
|
| return None
|
|
|
| - message_class = db.GetPrototype(descriptor)
|
| + message_class = factory.GetPrototype(descriptor)
|
| message = message_class()
|
|
|
| message.ParseFromString(msg.value)
|
| return message
|
|
|
| +
|
| def _AddEqualsMethod(message_descriptor, cls):
|
| """Helper for _AddMessageMethods()."""
|
| def __eq__(self, other):
|
|
|