diff options
Diffstat (limited to 'python/google/protobuf/message_factory.py')
-rw-r--r-- | python/google/protobuf/message_factory.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/python/google/protobuf/message_factory.py b/python/google/protobuf/message_factory.py index e4fb065e..f3ab0a55 100644 --- a/python/google/protobuf/message_factory.py +++ b/python/google/protobuf/message_factory.py @@ -39,9 +39,18 @@ my_proto_instance = message_classes['some.proto.package.MessageName']() __author__ = 'matthewtoia@google.com (Matt Toia)' +from google.protobuf.internal import api_implementation from google.protobuf import descriptor_pool from google.protobuf import message -from google.protobuf import reflection + +if api_implementation.Type() == 'cpp': + from google.protobuf.pyext import cpp_message as message_impl +else: + from google.protobuf.internal import python_message as message_impl + + +# The type of all Message classes. +_GENERATED_PROTOCOL_MESSAGE_TYPE = message_impl.GeneratedProtocolMessageType class MessageFactory(object): @@ -70,11 +79,11 @@ class MessageFactory(object): descriptor_name = descriptor.name if str is bytes: # PY2 descriptor_name = descriptor.name.encode('ascii', 'ignore') - result_class = reflection.GeneratedProtocolMessageType( + result_class = _GENERATED_PROTOCOL_MESSAGE_TYPE( descriptor_name, (message.Message,), {'DESCRIPTOR': descriptor, '__module__': None}) - # If module not set, it wrongly points to the reflection.py module. + # If module not set, it wrongly points to message_factory module. self._classes[descriptor] = result_class for field in descriptor.fields: if field.message_type: |