Python google.protobuf.descriptor_pb2.EnumDescriptorProto() Examples
The following are 30
code examples of google.protobuf.descriptor_pb2.EnumDescriptorProto().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.protobuf.descriptor_pb2
, or try the search function
.
Example #1
Source File: descriptor_test.py From lambda-packs with MIT License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2.ForeignEnum.DESCRIPTOR, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #2
Source File: descriptor_test.py From keras-lambda with MIT License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2.ForeignEnum.DESCRIPTOR, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #3
Source File: descriptor_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2.ForeignEnum.DESCRIPTOR, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #4
Source File: generate_proto_docs.py From hangups with MIT License | 6 votes |
def generate_enum_doc(enum_descriptor, locations, path, name_prefix=''): """Generate doc for an enum. Args: enum_descriptor: descriptor_pb2.EnumDescriptorProto instance for enum to generate docs for. locations: Dictionary of location paths tuples to descriptor_pb2.SourceCodeInfo.Location instances. path: Path tuple to the enum definition. name_prefix: Optional prefix for this enum's name. """ print(make_subsection(name_prefix + enum_descriptor.name)) location = locations[path] if location.HasField('leading_comments'): print(textwrap.dedent(location.leading_comments)) row_tuples = [] for value_index, value in enumerate(enum_descriptor.value): field_location = locations[path + (2, value_index)] row_tuples.append(( make_code(value.name), value.number, textwrap.fill(get_comment_from_location(field_location), INFINITY), )) print_table(('Name', 'Number', 'Description'), row_tuples)
Example #5
Source File: test_field.py From gapic-generator-python with Apache License 2.0 | 6 votes |
def test_mock_value_enum(): values = [ descriptor_pb2.EnumValueDescriptorProto(name='UNSPECIFIED', number=0), descriptor_pb2.EnumValueDescriptorProto(name='SPECIFIED', number=1), ] enum = wrappers.EnumType( values=[wrappers.EnumValueType(enum_value_pb=i) for i in values], enum_pb=descriptor_pb2.EnumDescriptorProto(value=values), meta=metadata.Metadata(address=metadata.Address( module='bogus', name='Enumerable', )), ) field = make_field( type='TYPE_ENUM', type_name='bogus.Enumerable', enum=enum, ) assert field.mock_value == 'bogus.Enumerable.SPECIFIED'
Example #6
Source File: test_api.py From gapic-generator-python with Apache License 2.0 | 6 votes |
def test_enums(): L = descriptor_pb2.SourceCodeInfo.Location enum_pb = descriptor_pb2.EnumDescriptorProto(name='Silly', value=( descriptor_pb2.EnumValueDescriptorProto(name='ZERO', number=0), descriptor_pb2.EnumValueDescriptorProto(name='ONE', number=1), descriptor_pb2.EnumValueDescriptorProto(name='THREE', number=3), )) fdp = make_file_pb2(package='google.enum.v1', enums=(enum_pb,), locations=( L(path=(5, 0), leading_comments='This is the Silly enum.'), L(path=(5, 0, 2, 0), leading_comments='This is the zero value.'), L(path=(5, 0, 2, 1), leading_comments='This is the one value.'), )) proto = api.Proto.build(fdp, file_to_generate=True, naming=make_naming()) assert len(proto.enums) == 1 enum = proto.enums['google.enum.v1.Silly'] assert enum.meta.doc == 'This is the Silly enum.' assert isinstance(enum, wrappers.EnumType) assert len(enum.values) == 3 assert all([isinstance(i, wrappers.EnumValueType) for i in enum.values]) assert enum.values[0].name == 'ZERO' assert enum.values[0].meta.doc == 'This is the zero value.' assert enum.values[1].name == 'ONE' assert enum.values[1].meta.doc == 'This is the one value.' assert enum.values[2].name == 'THREE' assert enum.values[2].meta.doc == ''
Example #7
Source File: test_utils.py From gapic-generator-python with Apache License 2.0 | 6 votes |
def make_enum( name: str, package: str = 'foo.bar.v1', module: str = 'baz', values: typing.Tuple[str, int] = (), meta: metadata.Metadata = None, ) -> wrappers.EnumType: enum_value_pbs = [ desc.EnumValueDescriptorProto(name=i[0], number=i[1]) for i in values ] enum_pb = desc.EnumDescriptorProto( name=name, value=enum_value_pbs, ) return wrappers.EnumType( enum_pb=enum_pb, values=[wrappers.EnumValueType(enum_value_pb=evpb) for evpb in enum_value_pbs], meta=meta or metadata.Metadata(address=metadata.Address( name=name, package=tuple(package.split('.')), module=module, )), )
Example #8
Source File: descriptor_test.py From go2mapillary with GNU General Public License v3.0 | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2.ForeignEnum.DESCRIPTOR, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #9
Source File: descriptor_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2._FOREIGNENUM, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #10
Source File: descriptor_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2.ForeignEnum.DESCRIPTOR, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #11
Source File: descriptor_test.py From botchallenge with MIT License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2._FOREIGNENUM, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #12
Source File: descriptor_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2._FOREIGNENUM, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #13
Source File: descriptor_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testCopyToProto_ForeignEnum(self): TEST_FOREIGN_ENUM_ASCII = """ name: 'ForeignEnum' value: < name: 'FOREIGN_FOO' number: 4 > value: < name: 'FOREIGN_BAR' number: 5 > value: < name: 'FOREIGN_BAZ' number: 6 > """ self._InternalTestCopyToProto( unittest_pb2.ForeignEnum.DESCRIPTOR, descriptor_pb2.EnumDescriptorProto, TEST_FOREIGN_ENUM_ASCII)
Example #14
Source File: protobuf-json-docs.py From ga4gh-schemas with Apache License 2.0 | 5 votes |
def convert_protodef_to_editable(proto): """ Protobuf objects can't have arbitrary fields addedd and we need to later on add comments to them, so we instead make "Editable" objects that can do so """ class Editable(object): def __init__(self, prot): self.kind = type(prot) self.name = prot.name self.comment = "" self.options = dict([(key.name, value) for (key, value) in prot.options.ListFields()]) if isinstance(prot, EnumDescriptorProto): self.value = [convert_protodef_to_editable(x) for x in prot.value] elif isinstance(prot, DescriptorProto): self.field = [convert_protodef_to_editable(x) for x in prot.field] self.enum_type = [convert_protodef_to_editable(x) for x in prot.enum_type] self.nested_type = prot.nested_type self.oneof_decl = prot.oneof_decl elif isinstance(prot, EnumValueDescriptorProto): self.number = prot.number elif isinstance(prot, FieldDescriptorProto): if prot.type in [11, 14]: self.ref_type = prot.type_name[1:] self.type = prot.type self.label = prot.label elif isinstance(prot, ServiceDescriptorProto): self.method = [convert_protodef_to_editable(x) for x in prot.method] elif isinstance(prot, MethodDescriptorProto): self.input_type = prot.input_type self.output_type = prot.output_type else: raise Exception, type(prot) return Editable(proto)
Example #15
Source File: test_utils.py From gapic-generator-python with Apache License 2.0 | 5 votes |
def make_enum_pb2( name: str, *values: typing.Sequence[str], **kwargs ) -> desc.EnumDescriptorProto: enum_value_pbs = [ desc.EnumValueDescriptorProto(name=n, number=i) for i, n in enumerate(values) ] enum_pb = desc.EnumDescriptorProto(name=name, value=enum_value_pbs, **kwargs) return enum_pb
Example #16
Source File: test_utils.py From gapic-generator-python with Apache License 2.0 | 5 votes |
def make_file_pb2(name: str = 'my_proto.proto', package: str = 'example.v1', *, messages: typing.Sequence[desc.DescriptorProto] = (), enums: typing.Sequence[desc.EnumDescriptorProto] = (), services: typing.Sequence[desc.ServiceDescriptorProto] = (), locations: typing.Sequence[desc.SourceCodeInfo.Location] = (), ) -> desc.FileDescriptorProto: return desc.FileDescriptorProto( name=name, package=package, message_type=messages, enum_type=enums, service=services, source_code_info=desc.SourceCodeInfo(location=locations), )
Example #17
Source File: api.py From gapic-generator-python with Apache License 2.0 | 5 votes |
def _load_enum(self, enum: descriptor_pb2.EnumDescriptorProto, address: metadata.Address, path: Tuple[int], ) -> wrappers.EnumType: """Load enum descriptions from EnumDescriptorProtos.""" address = address.child(enum.name, path) # Put together wrapped objects for the enum values. values = [] for enum_value, i in zip(enum.value, range(0, sys.maxsize)): values.append(wrappers.EnumValueType( enum_value_pb=enum_value, meta=metadata.Metadata( address=address, documentation=self.docs.get(path + (2, i), self.EMPTY), ), )) # Load the enum itself. self.proto_enums[address.proto] = wrappers.EnumType( enum_pb=enum, meta=metadata.Metadata( address=address, documentation=self.docs.get(path, self.EMPTY), ), values=values, ) return self.proto_enums[address.proto]
Example #18
Source File: test_api.py From gapic-generator-python with Apache License 2.0 | 5 votes |
def test_proto_builder_constructor(): sentinel_message = descriptor_pb2.DescriptorProto() sentinel_enum = descriptor_pb2.EnumDescriptorProto() sentinel_service = descriptor_pb2.ServiceDescriptorProto() # Create a file descriptor proto. It does not matter that none # of the sentinels have actual data because this test just ensures # they are sent off to the correct methods unmodified. fdp = make_file_pb2( messages=(sentinel_message,), enums=(sentinel_enum,), services=(sentinel_service,), ) # Test the load function. with mock.patch.object(api._ProtoBuilder, '_load_children') as lc: pb = api._ProtoBuilder(fdp, file_to_generate=True, naming=make_naming(), ) # There should be three total calls to load the different types # of children. assert lc.call_count == 3 # The enum type should come first. _, args, _ = lc.mock_calls[0] assert args[0][0] == sentinel_enum assert args[1] == pb._load_enum # The message type should come second. _, args, _ = lc.mock_calls[1] assert args[0][0] == sentinel_message assert args[1] == pb._load_message # The services should come third. _, args, _ = lc.mock_calls[2] assert args[0][0] == sentinel_service assert args[1] == pb._load_service
Example #19
Source File: descriptor_pool.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None): """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor """ if package: enum_name = '.'.join((package, enum_proto.name)) else: enum_name = enum_proto.name if file_desc is None: file_name = None else: file_name = file_desc.name values = [self._MakeEnumValueDescriptor(value, index) for index, value in enumerate(enum_proto.value)] desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=enum_proto.options) scope['.%s' % enum_name] = desc self._enum_descriptors[enum_name] = desc return desc
Example #20
Source File: test_field.py From gapic-generator-python with Apache License 2.0 | 5 votes |
def test_type_enum(): enum = wrappers.EnumType( values={}, enum_pb=descriptor_pb2.EnumDescriptorProto(), ) field = make_field( type='TYPE_ENUM', type_name='bogus.Enumerable', enum=enum, ) assert field.type == enum
Example #21
Source File: test_utils.py From gapic-generator-python with Apache License 2.0 | 5 votes |
def get_enum(dot_path: str) -> wrappers.EnumType: pieces = dot_path.split('.') pkg, module, name = pieces[:-2], pieces[-2], pieces[-1] return wrappers.EnumType( enum_pb=desc.EnumDescriptorProto(name=name), meta=metadata.Metadata(address=metadata.Address( name=name, package=tuple(pkg), module=module, )), values=[], )
Example #22
Source File: jar_extract.py From pbtk with GNU General Public License v3.0 | 5 votes |
def create_enum(jar, enums, fenum, msg_path_to_obj): if fenum not in msg_path_to_obj: enum_code = jar.decomp(enums[fenum], True).raw enum = EnumDescriptorProto() enum.name = fenum.split('.')[-1] for fname, fnumber in findall('(?:[\w.$]+|<init>)\("(.+?)", \d+, (-?\d+)[LDF]?\);', enum_code): if (fname, fnumber) != ('UNRECOGNIZED', '-1'): value = enum.value.add() value.name = fname value.number = int(fnumber) msg_path_to_obj[fenum] = enum
Example #23
Source File: descriptor_pool.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None): """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor """ if package: enum_name = '.'.join((package, enum_proto.name)) else: enum_name = enum_proto.name if file_desc is None: file_name = None else: file_name = file_desc.name values = [self._MakeEnumValueDescriptor(value, index) for index, value in enumerate(enum_proto.value)] desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=_OptionsOrNone(enum_proto)) scope['.%s' % enum_name] = desc self._enum_descriptors[enum_name] = desc return desc
Example #24
Source File: descriptor_pool.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None): """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor """ if package: enum_name = '.'.join((package, enum_proto.name)) else: enum_name = enum_proto.name if file_desc is None: file_name = None else: file_name = file_desc.name values = [self._MakeEnumValueDescriptor(value, index) for index, value in enumerate(enum_proto.value)] desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=_OptionsOrNone(enum_proto)) scope['.%s' % enum_name] = desc self._CheckConflictRegister(desc) self._enum_descriptors[enum_name] = desc return desc
Example #25
Source File: descriptor_pool.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None): """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor """ if package: enum_name = '.'.join((package, enum_proto.name)) else: enum_name = enum_proto.name if file_desc is None: file_name = None else: file_name = file_desc.name values = [self._MakeEnumValueDescriptor(value, index) for index, value in enumerate(enum_proto.value)] desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=_OptionsOrNone(enum_proto)) scope['.%s' % enum_name] = desc self._enum_descriptors[enum_name] = desc return desc
Example #26
Source File: descriptor_pool.py From keras-lambda with MIT License | 5 votes |
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None): """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor """ if package: enum_name = '.'.join((package, enum_proto.name)) else: enum_name = enum_proto.name if file_desc is None: file_name = None else: file_name = file_desc.name values = [self._MakeEnumValueDescriptor(value, index) for index, value in enumerate(enum_proto.value)] desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=_OptionsOrNone(enum_proto)) scope['.%s' % enum_name] = desc self._enum_descriptors[enum_name] = desc return desc
Example #27
Source File: descriptor_pool.py From lambda-packs with MIT License | 5 votes |
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None, containing_type=None, scope=None): """Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor """ if package: enum_name = '.'.join((package, enum_proto.name)) else: enum_name = enum_proto.name if file_desc is None: file_name = None else: file_name = file_desc.name values = [self._MakeEnumValueDescriptor(value, index) for index, value in enumerate(enum_proto.value)] desc = descriptor.EnumDescriptor(name=enum_proto.name, full_name=enum_name, filename=file_name, file=file_desc, values=values, containing_type=containing_type, options=_OptionsOrNone(enum_proto)) scope['.%s' % enum_name] = desc self._CheckConflictRegister(desc) self._enum_descriptors[enum_name] = desc return desc
Example #28
Source File: descriptor.py From luci-py with Apache License 2.0 | 5 votes |
def CopyToProto(self, proto): """Copies this to a descriptor_pb2.EnumDescriptorProto. Args: proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto. """ # This function is overridden to give a better doc comment. super(EnumDescriptor, self).CopyToProto(proto)
Example #29
Source File: descriptor.py From luci-py with Apache License 2.0 | 5 votes |
def CopyToProto(self, proto): """Copies this to a descriptor_pb2.EnumDescriptorProto. Args: proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto. """ # This function is overridden to give a better doc comment. super(EnumDescriptor, self).CopyToProto(proto)
Example #30
Source File: descriptor.py From luci-py with Apache License 2.0 | 5 votes |
def CopyToProto(self, proto): """Copies this to a descriptor_pb2.EnumDescriptorProto. Args: proto (descriptor_pb2.EnumDescriptorProto): An empty descriptor proto. """ # This function is overridden to give a better doc comment. super(EnumDescriptor, self).CopyToProto(proto)