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


Python enum_type_wrapper.EnumTypeWrapper方法代码示例

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


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

示例1: _AddEnumValues

# 需要导入模块: from google.protobuf.internal import enum_type_wrapper [as 别名]
# 或者: from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper [as 别名]
def _AddEnumValues(descriptor, cls):
  """Sets class-level attributes for all enum fields defined in this message.

  Also exporting a class-level object that can name enum values.

  Args:
    descriptor: Descriptor object for this message type.
    cls: Class we're constructing for this message type.
  """
  for enum_type in descriptor.enum_types:
    setattr(cls, enum_type.name, enum_type_wrapper.EnumTypeWrapper(enum_type))
    for enum_value in enum_type.values:
      setattr(cls, enum_value.name, enum_value.number) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:python_message.py

示例2: _AddEnumValues

# 需要导入模块: from google.protobuf.internal import enum_type_wrapper [as 别名]
# 或者: from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper [as 别名]
def _AddEnumValues(message_descriptor, dictionary):
  """Sets class-level attributes for all enum fields defined in this message.

  Args:
    message_descriptor: Descriptor object for this message type.
    dictionary: Class dictionary that should be populated.
  """
  for enum_type in message_descriptor.enum_types:
    dictionary[enum_type.name] = enum_type_wrapper.EnumTypeWrapper(enum_type)
    for enum_value in enum_type.values:
      dictionary[enum_value.name] = enum_value.number 
开发者ID:katharosada,项目名称:botchallenge,代码行数:13,代码来源:cpp_message.py

示例3: _import_protos

# 需要导入模块: from google.protobuf.internal import enum_type_wrapper [as 别名]
# 或者: from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper [as 别名]
def _import_protos(path):
    """
    Imports items selectively from the auto-generated proto package.

    Importing is done dynamically so we can selectively blacklist items. We
    also dynamically define enums that build on top of the auto-generated
    protobuf enums, to create a more pythonic API.

    More broadly, the dark magic in here allows us to maintain parity with
    Pachyderm protobufs when they change, without having to maintain a manual
    mapping of protobuf to python_pachyderm values.
    """

    g = globals()
    module = _importlib.import_module(path)
    uppercase_letters = set(_string.ascii_uppercase)
    lowercase_letters = set(_string.ascii_lowercase)

    def import_item(g, module, key):
        value = getattr(module, key)

        if isinstance(value, _EnumTypeWrapper):
            # Dynamically define an enum class that is exported
            enum_values = _enum._EnumDict()
            enum_values.update(dict(value.items()))
            enum_class = type(key, (_enum.IntEnum,), enum_values)
            g[key] = enum_class
        else:
            # Export the value
            g[key] = value

        __all__.append(key)

    def should_import(key):
        return key[0] in uppercase_letters and any(c in lowercase_letters for c in key[1:])

    for key in dir(module):
        if should_import(key):
            import_item(g, module, key)
        elif key.startswith("google_dot_protobuf_dot_"):
            sub_module = getattr(module, key)
            for key in dir(sub_module):
                if should_import(key):
                    import_item(g, sub_module, key) 
开发者ID:pachyderm,项目名称:python-pachyderm,代码行数:46,代码来源:__init__.py


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