當前位置: 首頁>>代碼示例>>Python>>正文


Python enum._EnumDict方法代碼示例

本文整理匯總了Python中enum._EnumDict方法的典型用法代碼示例。如果您正苦於以下問題:Python enum._EnumDict方法的具體用法?Python enum._EnumDict怎麽用?Python enum._EnumDict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在enum的用法示例。


在下文中一共展示了enum._EnumDict方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_multiple_mixin_mro

# 需要導入模塊: import enum [as 別名]
# 或者: from enum import _EnumDict [as 別名]
def test_multiple_mixin_mro(self):
        class auto_enum(EnumMeta):
            def __new__(metacls, cls, bases, classdict):
                original_dict = classdict
                classdict = enum._EnumDict()
                for k, v in original_dict.items():
                    classdict[k] = v
                temp = type(classdict)()
                names = set(classdict._member_names)
                i = 0
                for k in classdict._member_names:
                    v = classdict[k]
                    if v == ():
                        v = i
                    else:
                        i = v
                    i += 1
                    temp[k] = v
                for k, v in classdict.items():
                    if k not in names:
                        temp[k] = v
                return super(auto_enum, metacls).__new__(
                        metacls, cls, bases, temp)

        AutoNumberedEnum = auto_enum('AutoNumberedEnum', (Enum,), {})

        AutoIntEnum = auto_enum('AutoIntEnum', (IntEnum,), {})

        class TestAutoNumber(AutoNumberedEnum):
            a = ()
            b = 3
            c = ()

        class TestAutoInt(AutoIntEnum):
            a = ()
            b = 3
            c = () 
開發者ID:typeintandem,項目名稱:tandem,代碼行數:39,代碼來源:test.py

示例2: _import_protos

# 需要導入模塊: import enum [as 別名]
# 或者: from enum import _EnumDict [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


注:本文中的enum._EnumDict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。