OLD | NEW |
1 # Protocol Buffers - Google's data interchange format | 1 # Protocol Buffers - Google's data interchange format |
2 # Copyright 2008 Google Inc. All rights reserved. | 2 # Copyright 2008 Google Inc. All rights reserved. |
3 # http://code.google.com/p/protobuf/ | 3 # http://code.google.com/p/protobuf/ |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 20 matching lines...) Expand all Loading... |
31 # Needs to stay compatible with Python 2.5 due to GAE. | 31 # Needs to stay compatible with Python 2.5 due to GAE. |
32 # | 32 # |
33 # Copyright 2007 Google Inc. All Rights Reserved. | 33 # Copyright 2007 Google Inc. All Rights Reserved. |
34 | 34 |
35 """Descriptors essentially contain exactly the information found in a .proto | 35 """Descriptors essentially contain exactly the information found in a .proto |
36 file, in types that make this information accessible in Python. | 36 file, in types that make this information accessible in Python. |
37 """ | 37 """ |
38 | 38 |
39 __author__ = 'robinson@google.com (Will Robinson)' | 39 __author__ = 'robinson@google.com (Will Robinson)' |
40 | 40 |
41 from google.protobuf.internal import api_implementation | 41 from protobuf26.internal import api_implementation |
42 | 42 |
43 | 43 |
44 if api_implementation.Type() == 'cpp': | 44 if api_implementation.Type() == 'cpp': |
45 # Used by MakeDescriptor in cpp mode | 45 # Used by MakeDescriptor in cpp mode |
46 import os | 46 import os |
47 import uuid | 47 import uuid |
48 | 48 |
49 if api_implementation.Version() == 2: | 49 if api_implementation.Version() == 2: |
50 from google.protobuf.pyext import _message | 50 from protobuf26.pyext import _message |
51 else: | 51 else: |
52 from google.protobuf.internal import cpp_message | 52 from protobuf26.internal import cpp_message |
53 | 53 |
54 | 54 |
55 class Error(Exception): | 55 class Error(Exception): |
56 """Base error for this module.""" | 56 """Base error for this module.""" |
57 | 57 |
58 | 58 |
59 class TypeTransformationError(Error): | 59 class TypeTransformationError(Error): |
60 """Error transforming between python proto type and corresponding C++ type.""" | 60 """Error transforming between python proto type and corresponding C++ type.""" |
61 | 61 |
62 | 62 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 self.has_options = options is not None | 99 self.has_options = options is not None |
100 | 100 |
101 def GetOptions(self): | 101 def GetOptions(self): |
102 """Retrieves descriptor options. | 102 """Retrieves descriptor options. |
103 | 103 |
104 This method returns the options set or creates the default options for the | 104 This method returns the options set or creates the default options for the |
105 descriptor. | 105 descriptor. |
106 """ | 106 """ |
107 if self._options: | 107 if self._options: |
108 return self._options | 108 return self._options |
109 from google.protobuf import descriptor_pb2 | 109 from protobuf26 import descriptor_pb2 |
110 try: | 110 try: |
111 options_class = getattr(descriptor_pb2, self._options_class_name) | 111 options_class = getattr(descriptor_pb2, self._options_class_name) |
112 except AttributeError: | 112 except AttributeError: |
113 raise RuntimeError('Unknown options class name %s!' % | 113 raise RuntimeError('Unknown options class name %s!' % |
114 (self._options_class_name)) | 114 (self._options_class_name)) |
115 self._options = options_class() | 115 self._options = options_class() |
116 return self._options | 116 return self._options |
117 | 117 |
118 | 118 |
119 class _NestedDescriptorBase(DescriptorBase): | 119 class _NestedDescriptorBase(DescriptorBase): |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 build_file_if_cpp: Update the C++ descriptor pool if api matches. | 767 build_file_if_cpp: Update the C++ descriptor pool if api matches. |
768 Set to False on recursion, so no duplicates are created. | 768 Set to False on recursion, so no duplicates are created. |
769 Returns: | 769 Returns: |
770 A Descriptor for protobuf messages. | 770 A Descriptor for protobuf messages. |
771 """ | 771 """ |
772 if api_implementation.Type() == 'cpp' and build_file_if_cpp: | 772 if api_implementation.Type() == 'cpp' and build_file_if_cpp: |
773 # The C++ implementation requires all descriptors to be backed by the same | 773 # The C++ implementation requires all descriptors to be backed by the same |
774 # definition in the C++ descriptor pool. To do this, we build a | 774 # definition in the C++ descriptor pool. To do this, we build a |
775 # FileDescriptorProto with the same definition as this descriptor and build | 775 # FileDescriptorProto with the same definition as this descriptor and build |
776 # it into the pool. | 776 # it into the pool. |
777 from google.protobuf import descriptor_pb2 | 777 from protobuf26 import descriptor_pb2 |
778 file_descriptor_proto = descriptor_pb2.FileDescriptorProto() | 778 file_descriptor_proto = descriptor_pb2.FileDescriptorProto() |
779 file_descriptor_proto.message_type.add().MergeFrom(desc_proto) | 779 file_descriptor_proto.message_type.add().MergeFrom(desc_proto) |
780 | 780 |
781 # Generate a random name for this proto file to prevent conflicts with | 781 # Generate a random name for this proto file to prevent conflicts with |
782 # any imported ones. We need to specify a file name so BuildFile accepts | 782 # any imported ones. We need to specify a file name so BuildFile accepts |
783 # our FileDescriptorProto, but it is not important what that file name | 783 # our FileDescriptorProto, but it is not important what that file name |
784 # is actually set to. | 784 # is actually set to. |
785 proto_name = str(uuid.uuid4()) | 785 proto_name = str(uuid.uuid4()) |
786 | 786 |
787 if package: | 787 if package: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 field_proto.name, full_name, field_proto.number - 1, | 840 field_proto.name, full_name, field_proto.number - 1, |
841 field_proto.number, field_proto.type, | 841 field_proto.number, field_proto.type, |
842 FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), | 842 FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), |
843 field_proto.label, None, nested_desc, enum_desc, None, False, None, | 843 field_proto.label, None, nested_desc, enum_desc, None, False, None, |
844 has_default_value=False) | 844 has_default_value=False) |
845 fields.append(field) | 845 fields.append(field) |
846 | 846 |
847 desc_name = '.'.join(full_message_name) | 847 desc_name = '.'.join(full_message_name) |
848 return Descriptor(desc_proto.name, desc_name, None, None, fields, | 848 return Descriptor(desc_proto.name, desc_name, None, None, fields, |
849 nested_types.values(), enum_types.values(), []) | 849 nested_types.values(), enum_types.values(), []) |
OLD | NEW |