当前位置: 首页>>代码示例>>Python>>正文


Python descriptor.EnumDescriptor方法代码示例

本文整理汇总了Python中google.protobuf.descriptor.EnumDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Python descriptor.EnumDescriptor方法的具体用法?Python descriptor.EnumDescriptor怎么用?Python descriptor.EnumDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.protobuf.descriptor的用法示例。


在下文中一共展示了descriptor.EnumDescriptor方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _CheckConflictRegister

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def _CheckConflictRegister(self, desc):
    """Check if the descriptor name conflicts with another of the same name.

    Args:
      desc: Descriptor of a message, enum, service or extension.
    """
    desc_name = desc.full_name
    for register, descriptor_type in [
        (self._descriptors, descriptor.Descriptor),
        (self._enum_descriptors, descriptor.EnumDescriptor),
        (self._service_descriptors, descriptor.ServiceDescriptor),
        (self._toplevel_extensions, descriptor.FieldDescriptor)]:
      if desc_name in register:
        file_name = register[desc_name].file.name
        if not isinstance(desc, descriptor_type) or (
            file_name != desc.file.name):
          warn_msg = ('Conflict register for file "' + desc.file.name +
                      '": ' + desc_name +
                      ' is already defined in file "' +
                      file_name + '"')
          warnings.warn(warn_msg, RuntimeWarning)
        return 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:descriptor_pool.py

示例2: _AddDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def _AddDescriptor(self, desc):
    """Adds a Descriptor to the pool, non-recursively.

    If the Descriptor contains nested messages or enums, the caller must
    explicitly register them. This method also registers the FileDescriptor
    associated with the message.

    Args:
      desc: A Descriptor.
    """
    if not isinstance(desc, descriptor.Descriptor):
      raise TypeError('Expected instance of descriptor.Descriptor.')

    self._CheckConflictRegister(desc, desc.full_name, desc.file.name)

    self._descriptors[desc.full_name] = desc
    self._AddFileDescriptor(desc.file)

  # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add()
  # or AddSerializedFile() to add a FileDescriptorProto instead. 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:descriptor_pool.py

示例3: FindEnumTypeByName

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def FindEnumTypeByName(self, full_name):
    """Loads the named enum descriptor from the pool.

    Args:
      full_name (str): The full name of the enum descriptor to load.

    Returns:
      EnumDescriptor: The enum descriptor for the named type.

    Raises:
      KeyError: if the enum cannot be found in the pool.
    """

    full_name = _NormalizeFullyQualifiedName(full_name)
    if full_name not in self._enum_descriptors:
      self._FindFileContainingSymbolInDb(full_name)
    return self._enum_descriptors[full_name] 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:descriptor_pool.py

示例4: AddEnumDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def AddEnumDescriptor(self, enum_desc):
    """Adds an EnumDescriptor to the pool.

    This method also registers the FileDescriptor associated with the enum.

    Args:
      enum_desc: An EnumDescriptor.
    """

    if not isinstance(enum_desc, descriptor.EnumDescriptor):
      raise TypeError('Expected instance of descriptor.EnumDescriptor.')

    self._CheckConflictRegister(enum_desc)
    self._enum_descriptors[enum_desc.full_name] = enum_desc
    self._AddFileDescriptor(enum_desc.file) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:17,代码来源:descriptor_pool.py

示例5: _ConvertEnumDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
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 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:descriptor_pool.py

示例6: _MakeServiceDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
                             package, file_desc):
    """Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.

    Args:
      service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
      service_index: The index of the service in the File.
      scope: Dict mapping short and full symbols to message and enum types.
      package: Optional package name for the new message EnumDescriptor.
      file_desc: The file containing the service descriptor.

    Returns:
      The added descriptor.
    """

    if package:
      service_name = '.'.join((package, service_proto.name))
    else:
      service_name = service_proto.name

    methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
                                          scope, index)
               for index, method_proto in enumerate(service_proto.method)]
    desc = descriptor.ServiceDescriptor(name=service_proto.name,
                                        full_name=service_name,
                                        index=service_index,
                                        methods=methods,
                                        options=_OptionsOrNone(service_proto),
                                        file=file_desc)
    self._CheckConflictRegister(desc)
    self._service_descriptors[service_name] = desc
    return desc 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:34,代码来源:descriptor_pool.py

示例7: testFindEnumTypeByName

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def testFindEnumTypeByName(self):
    enum1 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory1Enum')
    self.assertIsInstance(enum1, descriptor.EnumDescriptor)
    self.assertEqual(0, enum1.values_by_name['FACTORY_1_VALUE_0'].number)
    self.assertEqual(1, enum1.values_by_name['FACTORY_1_VALUE_1'].number)
    self.assertFalse(enum1.has_options)

    nested_enum1 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory1Message.NestedFactory1Enum')
    self.assertIsInstance(nested_enum1, descriptor.EnumDescriptor)
    self.assertEqual(
        0, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_0'].number)
    self.assertEqual(
        1, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_1'].number)

    enum2 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory2Enum')
    self.assertIsInstance(enum2, descriptor.EnumDescriptor)
    self.assertEqual(0, enum2.values_by_name['FACTORY_2_VALUE_0'].number)
    self.assertEqual(1, enum2.values_by_name['FACTORY_2_VALUE_1'].number)

    nested_enum2 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory2Message.NestedFactory2Enum')
    self.assertIsInstance(nested_enum2, descriptor.EnumDescriptor)
    self.assertEqual(
        0, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_0'].number)
    self.assertEqual(
        1, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_1'].number) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:31,代码来源:descriptor_pool_test.py

示例8: AddEnumDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def AddEnumDescriptor(self, enum_desc):
    """Adds an EnumDescriptor to the pool.

    This method also registers the FileDescriptor associated with the message.

    Args:
      enum_desc: An EnumDescriptor.
    """

    if not isinstance(enum_desc, descriptor.EnumDescriptor):
      raise TypeError('Expected instance of descriptor.EnumDescriptor.')

    self._enum_descriptors[enum_desc.full_name] = enum_desc
    self.AddFileDescriptor(enum_desc.file) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:16,代码来源:descriptor_pool.py

示例9: _ConvertEnumDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
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 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:39,代码来源:descriptor_pool.py

示例10: _MakeServiceDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
                             package, file_desc):
    """Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.

    Args:
      service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
      service_index: The index of the service in the File.
      scope: Dict mapping short and full symbols to message and enum types.
      package: Optional package name for the new message EnumDescriptor.
      file_desc: The file containing the service descriptor.

    Returns:
      The added descriptor.
    """

    if package:
      service_name = '.'.join((package, service_proto.name))
    else:
      service_name = service_proto.name

    methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
                                          scope, index)
               for index, method_proto in enumerate(service_proto.method)]
    desc = descriptor.ServiceDescriptor(name=service_proto.name,
                                        full_name=service_name,
                                        index=service_index,
                                        methods=methods,
                                        options=_OptionsOrNone(service_proto),
                                        file=file_desc)
    return desc 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:32,代码来源:descriptor_pool.py

示例11: _ConvertEnumDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
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 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:39,代码来源:descriptor_pool.py

示例12: testFindEnumTypeByName

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def testFindEnumTypeByName(self):
    enum1 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory1Enum')
    self.assertIsInstance(enum1, descriptor.EnumDescriptor)
    self.assertEqual(0, enum1.values_by_name['FACTORY_1_VALUE_0'].number)
    self.assertEqual(1, enum1.values_by_name['FACTORY_1_VALUE_1'].number)

    nested_enum1 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory1Message.NestedFactory1Enum')
    self.assertIsInstance(nested_enum1, descriptor.EnumDescriptor)
    self.assertEqual(
        0, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_0'].number)
    self.assertEqual(
        1, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_1'].number)

    enum2 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory2Enum')
    self.assertIsInstance(enum2, descriptor.EnumDescriptor)
    self.assertEqual(0, enum2.values_by_name['FACTORY_2_VALUE_0'].number)
    self.assertEqual(1, enum2.values_by_name['FACTORY_2_VALUE_1'].number)

    nested_enum2 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory2Message.NestedFactory2Enum')
    self.assertIsInstance(nested_enum2, descriptor.EnumDescriptor)
    self.assertEqual(
        0, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_0'].number)
    self.assertEqual(
        1, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_1'].number) 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:30,代码来源:descriptor_pool_test.py

示例13: testFindEnumTypeByName

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def testFindEnumTypeByName(self):
    enum1 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory1Enum')
    self.assertIsInstance(enum1, descriptor.EnumDescriptor)
    self.assertEquals(0, enum1.values_by_name['FACTORY_1_VALUE_0'].number)
    self.assertEquals(1, enum1.values_by_name['FACTORY_1_VALUE_1'].number)

    nested_enum1 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory1Message.NestedFactory1Enum')
    self.assertIsInstance(nested_enum1, descriptor.EnumDescriptor)
    self.assertEquals(
        0, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_0'].number)
    self.assertEquals(
        1, nested_enum1.values_by_name['NESTED_FACTORY_1_VALUE_1'].number)

    enum2 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory2Enum')
    self.assertIsInstance(enum2, descriptor.EnumDescriptor)
    self.assertEquals(0, enum2.values_by_name['FACTORY_2_VALUE_0'].number)
    self.assertEquals(1, enum2.values_by_name['FACTORY_2_VALUE_1'].number)

    nested_enum2 = self.pool.FindEnumTypeByName(
        'google.protobuf.python.internal.Factory2Message.NestedFactory2Enum')
    self.assertIsInstance(nested_enum2, descriptor.EnumDescriptor)
    self.assertEquals(
        0, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_0'].number)
    self.assertEquals(
        1, nested_enum2.values_by_name['NESTED_FACTORY_2_VALUE_1'].number) 
开发者ID:katharosada,项目名称:botchallenge,代码行数:30,代码来源:descriptor_pool_test.py

示例14: AddEnumDescriptor

# 需要导入模块: from google.protobuf import descriptor [as 别名]
# 或者: from google.protobuf.descriptor import EnumDescriptor [as 别名]
def AddEnumDescriptor(self, enum_desc):
    """Adds an EnumDescriptor to the pool.

    This method also registers the FileDescriptor associated with the enum.

    Args:
      enum_desc: An EnumDescriptor.
    """

    if not isinstance(enum_desc, descriptor.EnumDescriptor):
      raise TypeError('Expected instance of descriptor.EnumDescriptor.')

    self._enum_descriptors[enum_desc.full_name] = enum_desc
    self._AddFileDescriptor(enum_desc.file) 
开发者ID:apple,项目名称:coremltools,代码行数:16,代码来源:descriptor_pool.py


注:本文中的google.protobuf.descriptor.EnumDescriptor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。