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


Python symbol_database.Default方法代码示例

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


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

示例1: testGetSymbol

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testGetSymbol(self):
    self.assertEqual(
        unittest_pb2.TestAllTypes, symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes'))
    self.assertEqual(
        unittest_pb2.TestAllTypes.NestedMessage,
        symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes.NestedMessage'))
    with self.assertRaises(KeyError):
      symbol_database.Default().GetSymbol('protobuf_unittest.NestedMessage')
    self.assertEqual(
        unittest_pb2.TestAllTypes.OptionalGroup,
        symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes.OptionalGroup'))
    self.assertEqual(
        unittest_pb2.TestAllTypes.RepeatedGroup,
        symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes.RepeatedGroup')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:generator_test.py

示例2: _BuildMessageFromTypeName

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def _BuildMessageFromTypeName(type_name, descriptor_pool):
  """Returns a protobuf message instance.

  Args:
    type_name: Fully-qualified protobuf  message type name string.
    descriptor_pool: DescriptorPool instance.

  Returns:
    A Message instance of type matching type_name, or None if the a Descriptor
    wasn't found matching type_name.
  """
  # pylint: disable=g-import-not-at-top
  if descriptor_pool is None:
    from google.protobuf import descriptor_pool as pool_mod
    descriptor_pool = pool_mod.Default()
  from google.protobuf import symbol_database
  database = symbol_database.Default()
  try:
    message_descriptor = descriptor_pool.FindMessageTypeByName(type_name)
  except KeyError:
    return None
  message_type = database.GetPrototype(message_descriptor)
  return message_type() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:25,代码来源:text_format.py

示例3: testEnumDefaultValue

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testEnumDefaultValue(self):
    """Test the default value of enums which don't start at zero."""
    def _CheckDefaultValue(file_descriptor):
      default_value = (file_descriptor
                       .message_types_by_name['DescriptorPoolTest1']
                       .fields_by_name['nested_enum']
                       .default_value)
      self.assertEqual(default_value,
                       descriptor_pool_test1_pb2.DescriptorPoolTest1.BETA)
    # First check what the generated descriptor contains.
    _CheckDefaultValue(descriptor_pool_test1_pb2.DESCRIPTOR)
    # Then check the generated pool. Normally this is the same descriptor.
    file_descriptor = symbol_database.Default().pool.FindFileByName(
        'google/protobuf/internal/descriptor_pool_test1.proto')
    self.assertIs(file_descriptor, descriptor_pool_test1_pb2.DESCRIPTOR)
    _CheckDefaultValue(file_descriptor)

    # Then check the dynamic pool and its internal DescriptorDatabase.
    descriptor_proto = descriptor_pb2.FileDescriptorProto.FromString(
        descriptor_pool_test1_pb2.DESCRIPTOR.serialized_pb)
    self.pool.Add(descriptor_proto)
    # And do the same check as above
    file_descriptor = self.pool.FindFileByName(
        'google/protobuf/internal/descriptor_pool_test1.proto')
    _CheckDefaultValue(file_descriptor) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:27,代码来源:descriptor_pool_test.py

示例4: _BuildMessageFromTypeName

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def _BuildMessageFromTypeName(type_name, descriptor_pool):
  """Returns a protobuf message instance.

  Args:
    type_name: Fully-qualified protobuf  message type name string.
    descriptor_pool: DescriptorPool instance.

  Returns:
    A Message instance of type matching type_name, or None if the a Descriptor
    wasn't found matching type_name.
  """
  # pylint: disable=g-import-not-at-top
  from google.protobuf import symbol_database
  database = symbol_database.Default()
  try:
    message_descriptor = descriptor_pool.FindMessageTypeByName(type_name)
  except KeyError:
    return None
  message_type = database.GetPrototype(message_descriptor)
  return message_type() 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:22,代码来源:text_format.py

示例5: _UnpackAny

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def _UnpackAny(msg):
  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)

  if descriptor is None:
    return None

  message_class = db.GetPrototype(descriptor)
  message = message_class()

  message.ParseFromString(msg.value)
  return message 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:22,代码来源:python_message.py

示例6: testGetSymbol

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testGetSymbol(self):
    self.assertEquals(
        unittest_pb2.TestAllTypes, symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes'))
    self.assertEquals(
        unittest_pb2.TestAllTypes.NestedMessage,
        symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes.NestedMessage'))
    with self.assertRaises(KeyError):
      symbol_database.Default().GetSymbol('protobuf_unittest.NestedMessage')
    self.assertEquals(
        unittest_pb2.TestAllTypes.OptionalGroup,
        symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes.OptionalGroup'))
    self.assertEquals(
        unittest_pb2.TestAllTypes.RepeatedGroup,
        symbol_database.Default().GetSymbol(
            'protobuf_unittest.TestAllTypes.RepeatedGroup')) 
开发者ID:katharosada,项目名称:botchallenge,代码行数:20,代码来源:generator_test.py

示例7: _CreateMessageFromTypeUrl

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def _CreateMessageFromTypeUrl(type_url):
  # TODO(jieluo): Should add a way that users can register the type resolver
  # instead of the default one.
  db = symbol_database.Default()
  type_name = type_url.split('/')[-1]
  try:
    message_descriptor = db.pool.FindMessageTypeByName(type_name)
  except KeyError:
    raise TypeError(
        'Can not find message descriptor by type_url: {0}.'.format(type_url))
  message_class = db.GetPrototype(message_descriptor)
  return message_class() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:json_format.py

示例8: testEnums

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testEnums(self):
    self.assertEqual(
        'protobuf_unittest.ForeignEnum',
        symbol_database.Default().pool.FindEnumTypeByName(
            'protobuf_unittest.ForeignEnum').full_name)
    self.assertEqual(
        'protobuf_unittest.TestAllTypes.NestedEnum',
        symbol_database.Default().pool.FindEnumTypeByName(
            'protobuf_unittest.TestAllTypes.NestedEnum').full_name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:11,代码来源:generator_test.py

示例9: testFindFileByName

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testFindFileByName(self):
    self.assertEqual(
        'google/protobuf/unittest.proto',
        symbol_database.Default().pool.FindFileByName(
            'google/protobuf/unittest.proto').name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:generator_test.py

示例10: setUp

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def setUp(self):
    self.pool = descriptor_pool.Default()
    self.factory_test1_fd = descriptor_pb2.FileDescriptorProto.FromString(
        factory_test1_pb2.DESCRIPTOR.serialized_pb)
    self.factory_test2_fd = descriptor_pb2.FileDescriptorProto.FromString(
        factory_test2_pb2.DESCRIPTOR.serialized_pb) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:descriptor_pool_test.py

示例11: _InternalUnpackAny

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def _InternalUnpackAny(msg):
  """Unpacks Any message and returns the unpacked message.

  This internal method is different from public Any Unpack method which takes
  the target message as argument. _InternalUnpackAny method does not have
  target message type and need to find the message type in descriptor pool.

  Args:
    msg: An Any message to be unpacked.

  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

  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 = factory.pool.FindMessageTypeByName(type_name)

  if descriptor is None:
    return None

  message_class = factory.GetPrototype(descriptor)
  message = message_class()

  message.ParseFromString(msg.value)
  return message 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:40,代码来源:python_message.py

示例12: GetDescriptorPool

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def GetDescriptorPool(self):
    return symbol_database.Default().pool 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:descriptor_test.py

示例13: testFileDescriptor

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testFileDescriptor(self):
    self.assertEqual(self.my_file.name, 'some/filename/some.proto')
    self.assertEqual(self.my_file.package, 'protobuf_unittest')
    self.assertEqual(self.my_file.pool, self.pool)
    self.assertFalse(self.my_file.has_options)
    self.assertEqual('proto2', self.my_file.syntax)
    file_proto = descriptor_pb2.FileDescriptorProto()
    self.my_file.CopyToProto(file_proto)
    self.assertEqual(self.my_file.serialized_pb,
                     file_proto.SerializeToString())
    # Generated modules also belong to the default pool.
    self.assertEqual(unittest_pb2.DESCRIPTOR.pool, descriptor_pool.Default()) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:descriptor_test.py

示例14: testFileDescriptor

# 需要导入模块: from google.protobuf import symbol_database [as 别名]
# 或者: from google.protobuf.symbol_database import Default [as 别名]
def testFileDescriptor(self):
    self.assertEqual(self.my_file.name, 'some/filename/some.proto')
    self.assertEqual(self.my_file.package, 'protobuf_unittest')
    self.assertEqual(self.my_file.pool, self.pool)
    # Generated modules also belong to the default pool.
    self.assertEqual(unittest_pb2.DESCRIPTOR.pool, descriptor_pool.Default()) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:8,代码来源:descriptor_test.py


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