本文整理匯總了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)
示例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
示例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)