U eC.@s ddlmZddlTddlmZddlmZddlmZddl Z dd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5g.Z e Z z ddlZWn"ek rdZe d)YnXzeWnek reZYnXzeWnek rd6d7ZYnXd8ZzNddlZeed9rBed:n,dd;lmZmZmZdZZZ Z!eefZWn6ek rdZZZZZZ Z Z!YnXerJz ddlm%Z!ee!f7ZWnek rHYnXdZ&Z'Z(Z)Z*dd?d2Z+d@dZ,dAd Z-dBdCZ.ddDd Z dEd5Z/zddFl0m1Z1e1Z2Wnek re3Z2dZ1YnXGdGd d e2Z4e4Z5e1dkre4Z1e4Z6GdHdIdIe7Z8e8dJe3fiZ9dKdLZ:dMd Z;dNdZ,dOdPZe+e?GdVdWdWeZ@dZZ%ZZ$Z#Z"ZAZBGdXdde3Ze8dYe3fiZCGdZddeZDdd[lEmZe4e_4eDe_D[Gd\d]d]eZFGd^d_d_ZGGd`d d eHZIe8de7fiZJGdadde7ZKer(GdbddeKeZKeKZeLeKMd!e3fdce?ddZNeNeOdedfZPeNdgdhZQeNdidjZReNeOdkdlZSeNeTdmdnZUeNeOdodpZVeNeOdqdrZWeNeOdsdtZXeNdudvZYeNdwdxZZe[reNdydzZ\eNd{d|Z]eNd}d~Z^eNddZ_eNddZ`eNddZaeNddZbeNddZceNddZdeNddZeeNe4ddZfeNe4ddZgeNe4ddZhepe3ZieKd!eifeNjZ[NddZkekZlddZmddZne!ree!fZonefZoeKd(eoddiZ%Gdd"d"epe%ZGdd#d#eqe%Z$Gdd&d&e$ZrGdd'd'e$Zse[rHGdddeZte udGdddeZvGdddeZwGdddeZxGdddeZyGdddeZzerGdd)d)eZ{GdddeZ|dddZ}ddZ~dddZddZzddlmZWn&ek rGdd+d+e$ZYnXe+ee?er6eefZnefZeLeKMd$ede?ddZeed<eed<eddnZUeeOddZeed<eeOddZeeOddpZVeeOddZeeOddZeddZedd„ZeddĄZeddvZYeddxZZereddȄZn eddʄZedd̄Zedd΄ZeddЄZedd҄Zeed<eed<eed<eKd$eejZ#[Gdd%d%epe%e#Z"dd؄ZddڄZdd܄ZddބZdddZerddlmZddZddZdd0Zdd1ZGdd3d3e3ZdS))print_function)*) NamedConstant) NamedTuple) defaultdictN bit_count is_single_bitbinpropertybitsAddValue MagicValue MultiValueNoAliasUniqueenumauto AddValueEnumMultiValueEnum NoAliasEnum UniqueEnumAutoNumberEnum OrderedEnumuniqueno_arg extend_enum enum_propertyEnumTypeEnumMetaEnumDictEnumIntEnumStrEnumFlagIntFlag LowerStrEnum UpperStrEnumReprEnum SqliteEnumsqlite3 FlagBoundarySTRICTCONFORMEJECTKEEPadd_stdlib_integrationremove_stdlib_integrationexport cls2module_reduce_ex_by_nameshow_flag_valuescCs|D]}|rdSqdS)NTF)iterableelementr6r69/opt/hc_python/lib/python3.8/site-packages/aenum/_enum.pyany'sr:r6versionz wrong version)rr!r")r%r$)r#)r(csdkr|fdd}|St|trN|jD]\}}t|tr0||<q0nHt|tsftrt|tr|j}|D]\}}||<qtntd|f|S)z export([collection,] namespace) -> Export members to target namespace. If collection is not given, act as a decorator. Ncs t|SN)r2) collection namespacer6r9export_decoratorVsz export..export_decoratorz %r is not a supported collection) issubclassr__dict__items isinstancer! stdlib_enums __members__ TypeError)r=r?r@ncdatamr6r>r9r2Ns       cCs"d}|r||dM}|d7}q|S)aR return number of set bits Counting bits set, Brian Kernighan's way* unsigned int v; // count the number of bits set in v unsigned int c; // c accumulates the total bits set in v for (c = 0; v; c++) { v &= v - 1; } //clear the least significant bit set This method goes through as many iterations as there are set bits. So if we have a 32-bit word with only the high bit set, then it will only go once through the loop. * The C Programming Language 2nd Ed., Kernighan & Ritchie, 1988. This works because each subtraction "borrows" from the lowest 1-bit. For example: loop pass 1 loop pass 2 ----------- ----------- 101000 100000 - 1 - 1 = 100111 = 011111 & 101000 & 100000 = 100000 = 0 It is an excellent technique for Python, since the size of the integer need not be determined beforehand. (from https://wiki.python.org/moin/BitManipulation) rrr6numcountr6r6r9res !  cCs |dkr dS||dM}|dkS)z> True if only one bit set in value (should be an int) rFrr6valuer6r6r9r s ccs&|r"||d@}|V||N}qdS)zZ Return each bit value one at a time. >>> list(_iter_bits_lsb(6)) [2, 4] rNr6)rPbitr6r6r9_iter_bits_lsbsrRcCsd|}|dkr,t||ddd}nt||d|A}|dd}|dd}|sbd}|dk rt||kr|d||| d}d ||fS) z Like built-in bin(), except negative values are represented in twos-compliment, and the leading bit always indicates sign (0=positive, 1=negative). >>> bin(10) '0b0 1010' >>> bin(~10) # ~10 is -11 '0b1 0101' r10rNz%s %s) bit_length _bltin_binreplacelen)rPZmax_bitsZceilingssigndigitsr6r6r9r s    cCs tt|Sr<)listrRrOr6r6r9r5s)DynamicClassAttributec@s\eZdZdZdddZddZddZd d Zd d Zdd dZ ddZ ddZ ddZ dS)r a This is a descriptor, used to define attributes that act differently when accessed through an enum member and through an enum class. Instance access is the same as property(), but access to an attribute through the enum class will look in the class' _member_map_. NcCs>||_||_||_|p|j|_|dk|_tt|dd|_dS)N__isabstractmethod__F)fgetfsetfdel__doc__ overwrite_docboolgetattrra)selfrbrcrddocr6r6r9__init__s   zproperty.__init__cCs<|jr |jnd}t|||j|j|p(|j}|jdk|_|Sr<)rfretypercrd)rirbfdocresultr6r6r9getters zproperty.gettercCs8|jr tjnd}t||j||j|j}|jdk|_|Sr<)rfrbrerlrd)rircrmrnr6r6r9setters zproperty.settercCs8|jr tjnd}t||j|j||j}|jdk|_|Sr<)rfrbrerlrc)rirdrmrnr6r6r9deleters zproperty.deletercCsZ|jj|j}|jp |jp |j}g}|r8|d||rL|d|jdd |S)N%rz function=%sz property(%s), ) ownerclass _member_map_getnamerbrcrdappend__name__join)rimemberfuncstringsr6r6r9__repr__szproperty.__repr__cCs|dkr@z|j|jWStk r<td||jfYqXnh|jdk rT||S|jdk rrtd|j|fn6z|j|jWStk rtd||jfYnXdS)Nz%r has no attribute %rzcannot read attribute %r on %rz%r member has no attribute %r)rurwKeyErrorAttributeErrorrbrcrB)riinstancertr6r6r9__get__s&      zproperty.__get__cCsH|jdkr8|jdk r*td|j|jfqD||j|j<n |||SdS)Nz%cannot set attribute %r on )rcrbrrwclsnamerB)rirrPr6r6r9__set__s  zproperty.__set__cCsh|jdkrZ|js|jr,td|j|jfqd|j|jkrD|j|j=qdtd|j|jfn ||SdS)Nz(cannot delete attribute %r on z$no attribute %r on member)rdrbrcrrwrrB)rirr6r6r9 __delete__s    zproperty.__delete__cCs||_|j|_||_dSr<)rwryrrt)rirtrwr6r6r9 __set_name__+szproperty.__set_name__)NNNN)N) ry __module__ __qualname__rerkrorprqr~rrrrr6r6r6r9r s   c@seZdZddZdS) SentinelTypecCs d|jS)Nz<%s>ryclsr6r6r9r~9szSentinelType.__repr__N)ryrrr~r6r6r6r9r8srSentinelcCs|dkr dS|dt|kS)NrFrS) _high_bitrOr6r6r9 _power_of_two=srcCs^|dkrt|Sd}|dkr&d}|}t|d?t|d@}|rZdddd |D}|S) N)rrFrTrrTcSsg|]}d|dkqS)10rTr6).0dr6r6r9 Kszbits..)strr rz)rMnegativernr6r6r9r BscCs"d}|r||dM}|d7}q|S)ae return number of set bits Counting bits set, Brian Kernighan's way* unsigned int v; // count the number of bits set in v unsigned int c; // c accumulates the total bits set in v for (c = 0; v; c++) { v &= v - 1; } //clear the least significant bit set This method goes through as many iterations as there are set bits. So if we have a 32-bit word with only the high bit set, then it will only go once through the loop. * The C Programming Language 2nd Ed., Kernighan & Ritchie, 1988. This works because each subtraction "borrows" from the lowest 1-bit. For example: loop pass 1 loop pass 2 ----------- ----------- 101000 100000 - 1 - 1 = 100111 = 011111 & 101000 & 100000 = 100000 = 0 It is an excellent technique for Python, since the size of the integer need not be determined beforehand. rrr6rLr6r6r9rOs   cCsd}|r|d7}|dL}q|S)Nrrr6)rMlengthr6r6r9bit_lenss  rcCs|dko||d@dkS)z< True if only one bit set in num (should be an int) rrr6)rMr6r6r9r zscCs@t|tr|t}t|d|}t|\}}}}|dk o>|dk S)z6check if new generate method supports *args and **kwdsim_funcN)rD staticmethodrrlrh getargspec)methodargsvarargskeywordsdefaultsr6r6r9_check_auto_argss    rcs|s|St|dttsLtfdd|ddDsDtdt|St|ddzszenumsort..rNz$cannot sort items of different typesc3s|]}t|dkVqdS)rNrrrr6r9rscSs|dSNrr6ir6r6r9zenumsort..keyztry name sort insteadcSs|dSNrr6rr6r6r9rr)rlrAtupleallrGsorted)Zthingsr6rr9enumsorts   rc@sFeZdZeddZeddZeddZeddZed d Zd d Z d S) EnumConstantsaddvaluez;prepends value(s) from _generate_next_value_ to each member magicvaluez7calls _generate_next_value_ when no arguments are given multivaluez#each member can have several valuesnoaliasz2duplicate valued members are distinct, not aliasedrz(duplicate valued members are not allowedcCs|jSr<_name_rir6r6r9r~szEnumConstants.__repr__N) ryrrconstantr rrrrr~r6r6r6r9rs      rc@sPeZdZdZddZeddZeddZdd Zd d Z d d Z ddZ dS)rz+ Helper class to track args, kwds. cOs(||_t||_t||_d|_dSr<)_argsdictrC_kwdshash_hashrw)rirkwdsr6r6r9rks z enum.__init__cCs|jSr<)rrr6r6r9rsz enum.argscCs |jSr<)rcopyrr6r6r9rsz enum.kwdscCs|jSr<)rrr6r6r9__hash__sz enum.__hash__cCs(t||jstS|j|jko&|j|jkSr<rD __class__NotImplementedrrriotherr6r6r9__eq__s z enum.__eq__cCs(t||jstS|j|jkp&|j|jkSr<rrr6r6r9__ne__s z enum.__ne__cCsng}ddd|jD}|r(||dddtt|jD}|rX||d|jjd|fS)NrscSsg|]}d|fqS)rrr6rar6r6r9rsz!enum.__repr__..cSsg|]\}}d||fqS)%s=%rr6rkrr6r6r9rs%s(%s)) rzrrxrr_rrCrry)rifinalrrr6r6r9r~s " z enum.__repr__N) ryrrrerkbltin_propertyrrrrrr~r6r6r6r9rs  Zno_valuec@s<eZdZdZeZeZgZddZddZ ddZ dd Z d d Z d d Z ddZddZddZddZddZddZerddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Z d2d3Z!d4d5Z"d6d7Z#d8d9Z$d:d;Z%dd?Z'e(d@dAZ)e)j*dBdAZ)dFdDdEZ+dCS)GrzP Instances are replaced with an appropriate value in Enum class suites. cCs0|}|jdd|_|jt||ff|Sr<r _operationsrxZ_and_rirnew_autor6r6r9__and__sz auto.__and__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rand__sz auto.__rand__cCs.|}|jdd|_|jt|ff|Sr<)rrrxZ_inv_rirr6r6r9 __invert__szauto.__invert__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_or_rr6r6r9__or__ sz auto.__or__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__ror__sz auto.__ror__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_xor_rr6r6r9__xor__sz auto.__xor__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rxor__sz auto.__rxor__cCs.|}|jdd|_|jt|ff|Sr<)rrrxZ_abs_rr6r6r9__abs__$sz auto.__abs__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_add_rr6r6r9__add__*sz auto.__add__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__radd__0sz auto.__radd__cCs.|}|jdd|_|jt|ff|Sr<)rrrxZ_neg_rr6r6r9__neg__6sz auto.__neg__cCs.|}|jdd|_|jt|ff|Sr<)rrrxZ_pos_rr6r6r9__pos__<sz auto.__pos__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_div_rr6r6r9__div__Csz auto.__div__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rdiv__Isz auto.__rdiv__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ _floordiv_rr6r6r9 __floordiv__Oszauto.__floordiv__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9 __rfloordiv__Uszauto.__rfloordiv__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ _truediv_rr6r6r9 __truediv__[szauto.__truediv__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9 __rtruediv__aszauto.__rtruediv__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_lshift_rr6r6r9 __lshift__gszauto.__lshift__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9 __rlshift__mszauto.__rlshift__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_rshift_rr6r6r9 __rshift__sszauto.__rshift__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9 __rrshift__yszauto.__rrshift__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_mod_rr6r6r9__mod__sz auto.__mod__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rmod__sz auto.__rmod__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_mul_rr6r6r9__mul__sz auto.__mul__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rmul__sz auto.__rmul__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_pow_rr6r6r9__pow__sz auto.__pow__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rpow__sz auto.__rpow__cCs0|}|jdd|_|jt||ff|Sr<rrrxZ_sub_rr6r6r9__sub__sz auto.__sub__cCs0|}|jdd|_|jt||ff|Sr<rrr6r6r9__rsub__sz auto.__rsub__cCs"|jr dSd|j|j|jfSdS)Nz auto(...)zauto(%r, *%r, **%r))r_valuerrrr6r6r9r~sz auto.__repr__cCsL|jtk r|jrtdn.|jtkr0|js0|jS|jtk r@|jS|SdS)Nzauto() object out of sync)r _auto_nullrrG_resolverr6r6r9rPs  z auto.valuecCs|jr||}||_dSr<)rrrrirPr6r6r9rPs NcCs|j}|jD]j\}}g}|D]P}t||rb|jtkrT|dkrHtS||ql||jq||q||}q g|jdd<||_|Sr<)rrrDrPrrxr)riZ base_valueropparamsvaluesparamrPr6r6r9rs      z auto._resolve)N),ryrrrer enum_memberrrrrrrrrrrrrrrPY2rrrrrrrrrrrrrrrrrrr~rrPrprr6r6r6r9rsR  )_commonc@s(eZdZdZdZdZdZdZddZdS) _EnumArgSpec)rz all args except *args and **kwds)rzthe name of the *args variable)rSzthe name of the **kwds variable)rVzany default values)z0number of required values (no default available)cCsNt|}|\}}}}|r,|dt| }n |dd}tt|||||fSr)rr[r__new__r )rZ _new_funcZargspecrrrrreqsr6r6r9rs   z_EnumArgSpec.__new__N) ryrrrrrrrequiredrr6r6r6r9r s r c@s eZdZdZddZddZdS) _proto_memberzW intermediate step for enum members between class execution and final creation cCs ||_dSr<rOrr6r6r9rksz_proto_member.__init__c st|||ji}d}d}d}d}ttrLrLtdtrL}dttrnjtkrnj}j}nlttrj}jfj}jnFttrj}j}n.tt rĈjf}nttsֈf}n}|dk rf|ddi}}~|j sd|j kr|j rb|d}|dd}d|j krH|dd}n|}|dd}|dn|j r|j r|t|j  dd}|js|dt|j j}|dn@|j r|dd}|dd}|dn|j r|dn|}n|}|jtkr|f}|js||} n|j|f||} t| ds|jtkrN| _nJz|j||| _Wn6tk r} ztd} | | _| W5d} ~ XYnX| j|| _|| _| j||t|j| _tdk rt|tr|j O_ t!r|j"O_"d|j #d|_$|j%r*|j&|nTt't(} zz&|j)} |j*rX| | j+&|Wn^tk r|j,D]<\} }|j+}| | jkrr|j*r| |&||} qqrt-YnXWnft-k r"tdkst|ts|j&|n,tdk rt|trt!r|j&|YnX| r~g}| .D].\}}d /|}|&d ||||jfq6t0d |j1d /|ft|jtr| |j_2d}d}d}|j3ddD]p}|j45|}|dk rt|t6t7fr|}|}d }q n0t8|r|}|pd}|p |}qnd}|}q|rt6}| |_9|:|||dkrt;|dd|_t;|dd|_?t;|dd|_@t;|dd|_A||_B||_CtD|||n tD||| | |jE|<f|}|j r||kr||f7}|| _F|D]|j r<|j)ks.tGfdd|j,Dr %s [%r]z%s: duplicate names found: %sz; rdescattr)rrrbrrcrrdrc3s|]\}}|kVqdSr<r6rrrKrOr6r9rsz-_proto_member.__set_name__..z%r has already been usedzcannot use dict to store value)HdelattrrPrDrrrrrrZMember _multivalue__creating_init_ _auto_init_ _new_args_r[ _auto_args_ _member_type_ _use_args_ _new_member_hasattrobjectr ExceptionrG __cause__r __objclass__rk_member_names_ _sort_order_r$rA _flag_mask_r _singles_mask_rX _all_bits_ _noalias_rxrr__value2member_map__unique_rw_value2member_seq_rrCrz ValueErrorryr __mro__rBrvr r` is_descriptorr{rrhrb_getrc_setrdZ_delZ _attr_typeZ _cls_typesetattrru_values_r:)ri enum_class member_namerrZ init_argsZ extra_mv_argsrZmv_argr excteZ nonuniqueZunhashable_valuecanonical_memberrwmessagealiasesZ bad_aliasesZfound_descriptorZdescriptor_typeZ class_typebaserredirectrr6rOr9rsT                                     z_proto_member.__set_name__N)ryrrrerkrr6r6r6r9rsrcsHeZdZdZfddZfddZfddZdd Zd d ZZ S) r zTrack enum member order and ensure member names are not reused. EnumType will use the names found in self._member_names as the enumeration member names. cstt|||_||_||_||_d|_g|_t |_ ||_ t |k|_ }t|k|_t|k|_|j rz|jrztd||jr|jrtd|||_||_d|_d|_t|k|_g|_g|_|jrdddg|_d|_d|_g|_d|_dS) Nz2%r: AddValue and MagicValue are mutually exclusivez4%r: MultiValue and MagicValue are mutually exclusiver6Fr r classmethodT)superr rk _cls_name_constructor_init_constructor_start_constructor_boundary_generate_next_value _member_namesset_member_names_set _settingsr _addvaluer _magicvaluer _multivaluerG_startZ_addvalue_value _new_args _auto_args_locked_init_ignore_ignore_init_done _allow_init _last_values _auto_called)ricls_namesettingsstartconstructor_initconstructor_startconstructor_boundaryrrr6r9rks:        zEnumDict.__init__cs||jkr|j|krtS|js@||ks@||jks@t|s@t|rPtt||S|j r| ||j t |j |jdd}||||StddS)Nz"Magic is not set -- why am I here?)rArrPrR is_sunder is_dunderr@r __getitem__rKrErMr[rFrU __setitem__r#rirrPr]r6r9r`s$" zEnumDict.__getitem__cstd}t|j|rnt|j|r$nt|r|dkrLtd|j|fq|jsp|dkrptd|j|fq|dkr|jrtd|jt|t r| }nt |}||_ t ||j@}|rtd|jd d d |Dfd|_q|d kr|jrtd |jq|dkr:|jr0td|j||_q|dkrt|t tfsZ|f}t|t snt |}|j|O_t|krt|krtd|jn"t|krt|krtd|jtdddddg}|jD],}||krtd|j||fd||<q|d|_|d|_|d|_|j |_|jrN|jsNdddg|_ |jrx|jrxd|jkrx|jddt|j}n|dkr|j rtd|j|}t|t r|!d d! }|jrd|jkr|jdd|jrtd"|j||_|}nz|d#kr|j"r"td$|}|d%k rvt|t#rD|j$}n(t|t%r`td&|jn |}t#|}t&||_'t(|d'|n.t)|r|d(krd)}|jstd|j|fnF|d*krt|t#r|j$}t*||_+n|d+krt|t%st%|}t,|rd|_n||jkr6td,|j|fn~||j krFnnt,|sd-|_||krxtd.|j|||ft-|t.kr||_/|jr.td/|jn|jr|js|0||}nh|jr(t-|tk r|f}t|dt1r|2||df|d0d%}|jr.|0||}nt|t1rB|2||}nt-|tkrt3d1d |Drg} |D]>} t| t1rd-}|2|| } | j4} |j56| | 6| qlt| }nxt|t1s.d2p|j+o|j+j7} t8|jp| } t|trt8|} nd0} t8|jd0kp| }| | kr.|0||}n|jrt|t1rJ|j9}nt|ts^|f}n|}t8|jt8|krtd3|j||j|f|j:6||j;|n d|_d-|_t|s^t)|s^t|j|s^t,|s^|sd}nrt|t1r|j56|j4nVt-|tkrR|r^t|dt1r@|j56|dj4n|j56|dn |j56|t||d%S)4zChanges anything not sundured, dundered, nor a descriptor. If an enum member name is used twice, an error is raised; duplicate values are not checked for. Single underscore (sunder) names are reserved. T)_init_ _settings__order__ignore__start__create_pseudo_member__create_pseudo_member_values__generate_next_value_ _boundary__numeric_repr_ _missing__missing_value__missing_name_ _iter_member__iter_member_by_value__iter_member_by_def_z@%r: _sunder_ names, such as %r, are reserved for future Enum use)Zcreate_pseudo_member_rmrnroz"%r: cannot set %r after init phaserfz%%r: ignore can only be specified oncez0%r: _ignore_ cannot specify already set names %srscss|]}t|VqdSr<reprrr6r6r9rCsz'EnumDict.__setitem__..rkz4%r: boundary specified in constructor and class bodyrgz1%r: start specified in constructor and class bodyrd-%r: NoAlias and Unique are mutually exclusivez*cannot specify both MultiValue and NoAliasrrrrrz"%r: unknown qualifier %r (from %r)r r?rrPrrcz3%r: init specified in constructor and in class bodyr z0%r: _init_ and MagicValue are mutually exclusiverjz4_generate_next_value_ must be defined before membersNzB%r: _generate_next_value must be a staticmethod, not a classmethodrE __order__rer__init_subclass__z%r: attempt to reuse name: %rFz%r: %s already defined as %rz(%r: enum() and AddValue are incompatiblercss|]}t|tVqdSr<)rDrrr6r6r9rsr6z=%s.%s: number of fields provided do not match init [%r != %r])?Zis_internal_classrAis_private_namer^r/rTrSrGrD basestringsplitr_rRrGrHrzrDrCrMrrIrrrrfromkeysrLrJrKrPrQinsertrBrZrVr__func__r?rrOr4r_r rNr1rlrrw_gnvr _convert_autor:rPrUrxrr[rrFaddr@r ra)rirrPZ auto_storealreadyallowed_settingsargrcZgnvZ auto_valuedrnew_args target_len source_len multi_argsZ test_valuer]r6r9rasL                                           "           ,  zEnumDict.__setitem__cCs|js|js|jtkr|js"|jr*|j}nd}dp>|jo>|jj}t|jpJ|pPd}t|t krht|}nd}t|jdkp||}||kr| ||}d|_ |jr||_ n||_|S)Nr6rT) rrrPrrNrr[rQrlrrrVr)rirrPrrrrrr6r6r9rs"    zEnumDict._convert_autocCs|jr@t|ts|f}|j||jt|j|jddf|}n"|||jt|j|jdd}t|trt|dkr|d}|SNrr)rOrDrrErMr[rFrUrbr6r6r9rs *"z EnumDict._gnv) ryrrrerkr`rarr __classcell__r6r6r]r9r s #  RcseZdZdZed6ddZddZd7fdd Zd d Ze ddddd dfd dZ ddZ ddZ ddZ eddZddZddZddZddZeZdd Zd!d"Zd#d$Zd8d&d'Zd9d(d)Zed*d+Zed,d-Zed.d/Zed0d1Zed2d3Zed4d5Z Z!S):rzMetaclass for EnumNr6c s|||tdkr"|dkr"d}nd}|dk } |dk } |dk } t|tsN|f}t|}d} d} |||\}|dk rt|dd} t| d| } |||O}|p|jdd}|j } |dkr|j }nd}t |kr|rd|krt|t r| ddnd |}t|krt|krtd |t|kr.css|]}|tkVqdSr<)r$rr6r6r9rCsc_sd|f|S)NrSr6)rwrYrNrrrr6r6r9rjLsz3EnumType.__prepare__.._generate_next_value_cs||}||_|Sr<)rr)r flag_valueZ type_valueobj member_typer6r9rOs z%EnumType.__prepare__..__new__r__new_member__rrvre)$_check_for_existing_members_r$rDrrG _get_mixins_rh_get_settings_r_order_function_rgr r_r}rrrGrrr|r Z _member_typer:Z _base_type baseintegerr"rr rrNr!Z_inherited_gnvrzrZr{rQ)metaclsrbasesinitrYrXboundaryrZ initial_flagrZr[r\generateorder first_enumrr enum_dictrjrr6rr9 __prepare__s        .            zEnumType.__prepare__cOsdSr<r6)rrrr6r6r9rkiszEnumType.__init__c9 sb t|tk rH|dd}|dd}|dd}|d|dd} |dd} |dd} |d d} |d d} |d d}|d d}|d d}|dd}|dd}|dd}|dd}|dd}t|d|}t|d|}tfdd|D}|}|j|||d}|r,||d<|p6|j}| dkr`|d} | dk r`| } t |t rt|}nB| dkrddt t |D}nt | tr| dd}} nt| r|rt |tsd|}td|rd|pddg}g}|D]\}}|r:t |ts.|f}|f|}n t||f}|jt|krtd|jd |jt|d d!d|Df|||qd"dt|| d#D}n| }d$D]"}t|}|dk r|||<q|D].}z||||<Wntk r YnXq|D]\}}||kr|||<q~ ~ ~ ~ ~ ~~~d%|_|j} t| td&d'g@}!|!rt d(d |!f|dd} t | tr| dd} |j}|j!}|j"}g}"|j#}#|j$}$d)}%|dk rd%}%|dd}"d|"kr |"d*dkr td+t%|k}&t&|k}'t'|k}(t(|k})|)dgd|d}*|*D]}+||+dqH|pl|dd}|d },|,dk rt|,t*k rt*|,},t|}|,dk r|,|d <|+|\}-|,||-\}}.}/t*||d,<|/|d-<| D]}||}t-|||<q|"|d.<|'|d/<|&|d0<|(|d1<|)|d2<g|d3<t |d4<|d5<i|d6<d|d7<||d<||d<||d8<|#|d9<|$|d:<d|d;<|.||d<<|pt|-dd|d<d*|d=<d*|d><d*|d?<d|d@<|D] \}}0t |0t/r|0j0||<qd)}1dA|kr@t1k r@dB}2t2fdCdD|2Ds@t3|d%}1dE|krRdF|dE<zd}3t4|||Wn0t5k r}4z|4j6p|4}3W5d}4~4XYnX|3dk r|3t7t8kr2| D]}j9|:|qj9D]0\}}0|| krqt;|0dGr|0:|qtt?dk rt?|krt1krXtdIdJ|krtj@_@j@|dJ<dK|krjA}5|5t1jAkrjB}5|5_AjA|dK<dLD]r}||krqt|}6t|d}7t|-|d}8|7dk r|7|6kr|dAkr|1rqtC||8|8||<qtDdk rdtEtDrddMD]*}||kr8tC|ttD||8||<q8t7tFkrtEtGrtCdNttGdNn0tHrtEtGrdOD]}5tC|5ttG|5qttKd?tKd@nXtDdk rtEtD rdSdDtdSdDk r҈jL_M| rfdTd| D} j9D]2\}}t |tN rt |j0tO r|j0j0|_0 q| r^fdUd| D} | jPk r^tdVjP| fS)WNrcrgrdr6rerwrfrhrirjrmrnrorkrprqrrrrr~cs:g|]2\}}t|st|st|st|s||fqSr6)r^r_ryr1rrr6r9rs  z$EnumType.__new__..)rrYcSsg|] \}}|qSr6r6rrwrPr6r6r9rsrrvr{zname rwrPz)%d values expected (%s), %d received (%s)rscSsg|] }t|qSr6rsrr6r6r9rscSsg|] }|jqSr6rwrrKr6r6r9rsr)rmrnrorfrhrirjrerrmrnrorkrprqrrTmrorzinvalid enum member name(s): %sFrz7'value', if specified, must be the first item in 'init'r rrrZ _magicvalue_r+r-r&rurr,r.rrrr _value_repr_r(r)r* _inverted_ __reduce_ex__)__getnewargs_ex____getnewargs__r __reduce__c3s|]}|jkVqdSr<rBrrr6r9r7sz#EnumType.__new__..rezAn enumeration.rrxzOReprEnum subclasses must be mixed with a data type (i.e. int, str, float, etc.) __format____str__)r~rrr)rrrrrrrZ__cmp__)__le____lt____gt____ge__rrrrcSsg|] }|jqSr6rrr6r6r9rsr$cSsg|] }|jqSr6rrr6r6r9rscs(g|] }|jks t|jr|qSr6)rur rror6r6r9rs cs.g|]&}|jks&|jkr|jkr|qSr6)rur&rrr6r9rs   z*member order does not match _order_: %r %r)Qrlr poprhrrCrrQrvrrD OrderedDictrr_rzrZr{callablerzrrZ _defined_len_r[rGZ_fields_rxrlocalsrrPrFrGr/rMrIrNrOrrrr setdefaultrr _find_new_r_find_data_repr_Z nonmemberrPr"r:make_class_unpicklabler RuntimeErrorr$pyverPY3_6rBrr!r!r@rxr(rrr~r4r$rAZPY2_6intr r~rrrrrprrr&)9rrrclsdictrrYrXrrrerfrhrirjrmrnrorkrprqrrr enum_membersZ original_dictZ calced_orderr{rwrP name_valuerrrZ member_names invalid_namesZ creating_initrZ auto_argsZ auto_initrrrrignorerrrsave_new new_uses_argsrZ unpicklablemethodsr8er class_method obj_method enum_methodr])rr6rr9rls                                                                                       "   zEnumType.__new__cCsdS)z6 classes/types should always be True. Tr6rr6r6r9__bool__szEnumType.__bool__rc Cs,|dkr|||S|j|||||||dS)aEither returns an existing member, or creates a new enum class. This method is used both when an enum class is given a value to match to an enumeration member (i.e. Color(3)) and for the functional API (i.e. Color = Enum('Color', names='red green blue')). When used for the functional API: `module`, if set, will be stored in the new class' __module__ attribute; `type`, if set, will be mixed in as the first base class. Note: if `module` is not set this routine will attempt to discover the calling module by walking the frame stack; if this is unsuccessful the resulting class will not be pickleable. N)modulequalnamerlrYr)r_create_)rrPnamesrrrlrYrr6r6r9__call__s zEnumType.__call__cCsHt||rdSz ||jkWStk rB|dd|jDkYSXdS)zReturn True if `value` is in `cls`. `value` is in `cls` if: 1) `value` is a member of `cls`, or 2) `value` is the value of one of the `cls`'s members. TcSsg|] \}}|qSr6r6rr6r6r9rsz)EnumType.__contains__..N)rDr,rGr.rrPr6r6r9 __contains__s   zEnumType.__contains__cCsp||jkrtd|j|ft||}t|trDtd|j|fnt|tr`td|j|ft||dS)Nz!%s: cannot delete Enum member %r.z%s: cannot delete constant %rz%s: cannot delete property %r) rurryget_attr_from_chainrDrr rl __delattr__)rr found_attrr6r6r9r s       zEnumType.__delattr__c Cst|jddddddddd g }|jtjk r6|d |jtjk rL|d ttd r`|d d D],}t ||t t|t t |fkrd||qd|j tkrt |St tt |j |BSdS)Nrrrer`__iter____len__rFrryrrxr)rkrr~r)rGr&r r"rrrxr!r!rhr$rrdir)r interestingrr6r6r9__dir__s.        zEnumType.__dir__cCs |jS)zReturns a mapping of member name->value. This mapping lists all enum members, including aliases. Note that this is a copy of the internal mapping. )rurrr6r6r9rF1szEnumType.__members__cCsz |j|WStk r,td}YnXtdk rt|trd|krz*|d}|dD]}|||O}q\|WStk r|YnX||}t||r|S|dS)Nr|r) rur_sysexc_infor$rAr{rorD)rrwr8rnrHr6r6r9r`:s     zEnumType.__getitem__csfddjDS)Nc3s|]}j|VqdSr<rurrwrr6r9rOsz$EnumType.__iter__..r&rr6rr9rNszEnumType.__iter__csfddtjDS)Nc3s|]}j|VqdSr<rrrr6r9rRsz(EnumType.__reversed__..)reversedr&rr6rr9 __reversed__QszEnumType.__reversed__cCs t|jSr<)r[r&rr6r6r9rTszEnumType.__len__cCs d|jfS)Nz rrr6r6r9r~YszEnumType.__repr__cCs|jdi}||kr(td|j|ft||}t|trPtd|j|fn*t|ttfrzt|tsztd|j|ft |||dS)aBlock attempts to reassign Enum members/constants. A simple assignment to the class namespace only changes one of the several possible ways to get an Enum member from the Enum class, resulting in an inconsistent Enumeration. ruz%s: cannot rebind member %r.z%s: cannot rebind constant %rz%s: cannot rebind property %rN) rBrvrryrrDrrr rl __setattr__)rrwrP member_maprr6r6r9r\s     zEnumType.__setattr__cOs$ddl}|jdtdd|j||S)NrzB_convert is deprecated and will be removed, use _convert_ instead.rS) stacklevel)warningswarnDeprecationWarning _convert_)rrrrr6r6r9_convertss zEnumType._convertFc sttj|}rtn|fddD}z|jdddWn$tk rp|jdddYnX|||||ptd}t|_|rt |n | |j |||<|S)z[ Create a new Enum subclass that replaces a collection of global constants cs g|]}|r||fqSr6r6)rrfiltersourcer6r9rsz&EnumType._convert_..cSs|d|dfSrr6tr6r6r9rrz$EnumType._convert_..rcSs|dSrr6rr6r6r9rr)rr) varsrmoduleskeyssortrGr/r4r global_enumupdaterF) rrwrrrrZ as_globalmodule_globalsmembersr6rr9rys    zEnumType._convert_c Cstr@t|tr@z|d}Wn"tk r>td|fYnX|j}|dkrV|f} n||f} ||| \} } t| dd} t| d| } t|t r| dd }t|t t fr|rt|dt r|g} }g}t| D]6\}}| ||||dd}|||||fqd}d}|D]Z}|dkrLt|t r@i}n ||| }t|t rh|||}}n|\}}|||<q |dkr||| }|j||| ||d }|dkrztd jd }Wnttfk rYnX|dkrt|n||_|dk r ||_|S) a|Convenience method to create a new Enum class. `names` can be: * A string containing member names, separated either with spaces or commas. Values are auto-numbered from 1. * An iterable of member names. Values are auto-numbered from 1. * An iterable of (member name, value) pairs. * A mapping of member name -> value. asciiz %r is not representable in ASCIINrjrrrvr)rrSry)r rDunicodeencodeUnicodeEncodeErrorrGrrrhrzrZr{rr_ enumeraterxrrr _getframe f_globalsrrrrr)r class_namerrrrlrYrrr_rroriginal_names last_valuesrNrwrPitemrr7 member_valuer6r6r6r9rs^     &             zEnumType._create_cCsFtdkr dS|D]0}|jD]$}t|tr|jrtd||fqqdS)Nz cannot extend %r)r!r0rAr&rGmclsrrchainr=r6r6r9rs z%EnumType._check_for_existing_members_cCsp|r tdkrttfS||||d}|tkr8|d}t|tsJtd|||pXt}|jrhtd||fS)zReturns the type for creating enum members, and the first inherited enum class. bases: the tuple of bases that was given to __new__ NrWzZnew enumerations should be created as `EnumName([mixin_type, ...] [data_type,] enum_type)`z*cannot extend enumerations via subclassing)r!r"rrErArG_find_data_type_r&)r rrrrr6r6r9rs   zEnumType._get_mixins_cCs|D]}|jD]v}|tftkr$qqt|tr<|jSd|jkrd|jkrrd|jkrr|jdjrrtS|jdSqqdS)Nr~__dataclass_fields____dataclass_params__) r0r"rErDrrrBrt_dataclass_reprrr6r6r9rs      zEnumType._find_data_repr_cCst}|D]}d}|jD]}|tftkr.qqt|trT|jtk r||jq qd|jkshd|jkrt|trvqnt dk rt |t rq||p|q q|p|}qq t |dkrt d||fn|r| SdSdS)Nrr rz%r: too many data types: %r)rGr0r"rErDrrrrB StdlibFlagrAr[rGr)r rr data_typesr  candidater=r6r6r9r s.       zEnumType._find_data_type_cCs@t}|D]0}|jD]$}t|tr|jD]}||q(qq |S)zuReturns the combined _settings_ of all Enum base classes bases: the tuple of bases given to __new__ )rGr0rAr!rdr)rrXr r=r\r6r6r9r5s   zEnumType._get_settings_c Cs|dd}|dk o|dk }|dkr|dD]L}||fD]2}t||d}|ddjtjtjtjfkr4|}qhq4|dk r(q|q(tj}|dks|tjtjfkrd} nd} ||| fS)a Returns the __new__ to be used for creating the enum members. clsdict: the class dictionary given to __new__ member_type: the data type whose __new__ will be used by default first_enum: enumeration to check for an overriding __new__ rN)rrFT)rvrhrr"r! StdlibEnum) r rrrrrrpossibletargetrr6r6r9rCs,   zEnumType._find_new_)NNr6N)NNr6N)NNF)NNNrN)"ryrrrer?rrkrrrrrrrrrFr`rrr __nonzero__r~rrrrrrrr rrrrr6r6r]r9rsH Wx   G     c@s eZdZdS)rN)ryrrr6r6r6r9rwszNGeneric enumeration. Derive from this class to define new enumerations. )rrjnscCs|jr dSdSdS)Nz (*values)z\(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)rrr6r6r9 __signature__srcOs|j}|dkrdSd|kr&|dd}|rt|t|krVtdt||t||ft||D]\}}t|||q`t|t|kr|t|d}|D]2}||t}|tkrtd|ft|||q|rtdd|dS)NrPrz,%d arguments expected (%s), %d received (%s)zmissing value for: %rzinvalid keyword(s): %srs) rr[rGzipr4r undefinedrzr)rirrrrwrremaining_argsrPr6r6r9rks*  rkcCst|jkrtdt||kr"|Sz |j|WStk rBYn8tk rx|jD]\}}||krV|YSqVYnX||}t||r|S|dk rt |ddt kr|S|dkr|t krt d|j fqt d||j fntd|j |fdS)Nz1NoAlias enumerations cannot be looked up by valuerkz"%s() should be called with a value%r is not a valid %szDerror in %s._missing_: returned %r instead of None or a valid member)rrdrGrlr,rr.rnrDrhr.rr/ry)rrPrr{rnr6r6r9rs4     rcKs2ttkr|r.td|fntt|jf|dS)Nz unconsumed keyword arguments: %r)rrrGr@r!rx)rrr6r6r9rxsrxc OsPt|D],}z|d}Wq:Wqtk r2YqXq|}|rH|f|S|SdSr)rrG)rwrYrNrrr last_value new_valuer6r6r9rjs   rjcCsdS)z'deprecated, use _missing_value_ insteadNr6rr6r6r9rmsrmcCs ||S)zused for failed value access)rmrr6r6r9rnsrncCsdS)zused for failed item accessNr6)rrwr6r6r9rosrocCs,|jjp|jjj}d|jj|j||jfS)Nz <%s.%s: %s>)rrrr~ryr)riZv_reprr6r6r9r~sr~cCsd|jj|jfSN%s.%s)rryrrr6r6r9rsrcsjjtkr tdddddg}ntfddtD}tdgD]}|d d krH||qHjD]r}|j D]b\}}|d d krq|t |t r|j d k s|j kr||q||q|t |js|||q|qnt|S) z< Returns all members and all public methods rrerrrc3s|]}|jkr|VqdSr<r)rrHrr6r9r s z__dir__..rBrrN)rrr"rGrrhrrrBrCrDr rbrudiscardr)rirrwrrr6rr9r s"        rcCstt||Sr<)rr)ri format_specr6r6r9r srcCs t|jSr<)rrrr6r6r9r! srcCs|j|jffSr<)rrriprotor6r6r9r% srcCstd|jj|jjfdS)Nzunorderable types: %s() <= %s()rGrryrr6r6r9r) srcCstd|jj|jjfdS)Nzunorderable types: %s() < %s()r%rr6r6r9r- srcCstd|jj|jjfdS)Nzunorderable types: %s() >= %s()r%rr6r6r9r1 srcCstd|jj|jjfdS)Nzunorderable types: %s() > %s()r%rr6r6r9r5 srcCst||jr||kStSr<rDrrrr6r6r9r: s rcCst||jr||k StSr<r&rr6r6r9r@ s rcCs|jSr<rrr6r6r9rwN srwcCs|jSr<rrr6r6r9rPS srPcCs|jSr<)r5rr6r6r9rX srcCs|jSr<rr#r6r6r9pickle_by_global_namec sr'cCst|j|jffSr<)rhrrr#r6r6r9pickle_by_enum_nameh sr(cs$jdfddDS)Nrsc3s*|]"}|jrd|t|fVqdS)rN)rtrh)rrZdcfrir6r9rn s z"_dataclass_repr..)r rzrrr6r)r9rl srrezIOnly changes the repr(), leaving str() and format() to the mixed-in type.c@seZdZdZdS)r"z8 Enum where members are also (and must be) ints N)ryrrrer6r6r6r9r" sc@s&eZdZdZddZejZddZdS)r#zr Enum where members are also (and must already be) strings default value is member name, lower-cased cOsb|rtd|j|rDt|dtsDtd|j|dt|dft|}t||}||_|S)Nz#%r: keyword arguments not supportedrz#%s: values must be str [%r is a %r])rGryrDrrlrr)rrrrPr{r6r6r9r s  zStrEnum.__new__cCs|S)zD Return the lower-cased version of the member name. )lower)rwrYrNrr6r6r9rj szStrEnum._generate_next_value_N)ryrrrerrrrjr6r6r6r9r# s c@seZdZdZddZdS)r&z} Enum where members are also (and must already be) lower-case strings default value is member name, lower-cased cOs0tj||f||}||kr,td||S)Nz%r is not lower-case)r#rr*r/rrPrrrr6r6r9r s  zLowerStrEnum.__new__Nryrrrerr6r6r6r9r& sc@s eZdZdZddZddZdS)r'z} Enum where members are also (and must already be) upper-case strings default value is member name, upper-cased cOs0tj||f||}||kr,td||S)Nz%r is not upper-case)r#rupperr/r+r6r6r9r s  zUpperStrEnum.__new__cOs|Sr<)r-)rwrYrNrrrr6r6r9rj sz"UpperStrEnum._generate_next_value_N)ryrrrerrjr6r6r6r9r' sc@seZdZdZeZdS)AutoEnumza automatically use _generate_next_value_ when values are missing (Python 3 only) N)ryrrrerrdr6r6r6r9r. sr.c@seZdZdZddZdS)rz Automatically assign increasing values to members. Py3: numbers match creation order Py2: numbers are assigned alphabetically by member name (unless `_order_` is specified) cOsRt|jd}|jtkr&t||}n"|jtkr>t||}n t|}||_|Sr)r[rFrrrlongr"r)rrrrPrr6r6r9r s   zAutoNumberEnum.__new__Nr,r6r6r6r9r sc@seZdZeZdS)rN)ryrrr rdr6r6r6r9r sc@seZdZdZeZdS)rz1 Multiple values can map to each member. N)ryrrrerrdr6r6r6r9r sc@seZdZdZeZdS)rzQ Duplicate value members are distinct, but cannot be looked up by value. N)ryrrrerrdr6r6r6r9r sc@s0eZdZdZddZddZddZdd Zd S) rz7 Add ordering based on values of Enum members. cCs|j|jkr|j|jkStSr<rrrrr6r6r9r s  zOrderedEnum.__ge__cCs|j|jkr|j|jkStSr<r0rr6r6r9r s  zOrderedEnum.__gt__cCs|j|jkr|j|jkStSr<r0rr6r6r9r s  zOrderedEnum.__le__cCs|j|jkr|j|jkStSr<r0rr6r6r9r s  zOrderedEnum.__lt__N)ryrrrerrrrr6r6r6r9r s c@seZdZddZdS)r)cCs|tjkr|jSdSr<)r*ZPrepareProtocolrw)riprotocolr6r6r9 __conform__ s zSqliteEnum.__conform__N)ryrrr2r6r6r6r9r) sc@seZdZdZeZdS)rz+ Ensure no duplicate values exist. N)ryrrrerrdr6r6r6r9r scsfttj|}|rt|}n|}tfdd|D}||||d}t|_||j|||<dS)aL Create a new Enum subclass that replaces a collection of global constants enum: Enum, IntEnum, ... name: name of new Enum module: name of module (__name__ in global context) filter: function that returns True if name should be converted to Enum member source: namespace to check (defaults to 'module') c3s"|]\}}|r||fVqdSr<r6rrr6r9r. szconvert..rN) rrrrrCr4rrrF)rrwrrrrrr6r3r9convert s  r5c$ Os<||jks.||jks.|ddt|ddDkrLtd||j|||fd}|jddD]>}|j|}|dk r^t|ttfrqq^td||j fq^z2|j}|j }|j }|j } t d d|D} Wn"tk rtd |fYnXz4|j} t|jk} t|jk} t|jk}|jp$g}Wn*tk rRg} d } d } d }g}YnX| rn|sntd |j |j}t|d dpt|ddp|}|s dd|D}t|}t|dd}|dkr|r|ddpd}t|dd}|dk r|||||f}n|f}|tjkrd }nd}t|dkr8|\}n|}d}i}t|tr\|j}|j}t|tsp|f}n|}d|krd|kr|d}n|d|dd}}n.| r|d|ddd}}}|r|f}|tkr|f}|s ||}t|ds2||_ n&||f||}t|ds2|||_ |j }| rXd|krN|}n |f|}||_!|j"|_#|j$||f||_%t|j |_&d}}t|dr|j'|B}|j(|B}|j)dkrt*t+||@}|rtdt,d-dd|Df| r t.||||dS|j%}|/D]v}t|d|j g}|D]Z} |D]N}!| |!kr8|sR| rdtd||fn t.|||||dd Sq8q0qt0t1krt2f}"nt2t3f}"t4||"r.t|dr.t5|rt.||||dS||j(@|kr| |dk r| |}#t.||#|||dd St.||||dd!Sn t.||SdS)"z/ Add a new member to an existing Enum. cSsg|] }|dqS)rr6)rrr6r6r9rB szextend_enum..r.r6z%r already in use as %rNr"%r already in use in superclass %rcSsg|]}|jD]}|qqSr6r)rrrr6r6r9rS sz%r is not a supported EnumFz*no values specified for MultiValue enum %rr rcSsg|] }|jqSr6rOrr6r6r9ri srgrWrjTrPrrr*Zkeepz%invalid Flag %r -- missing values: %srscss|]}t|VqdSr<)r)rrr6r6r9r szextend_enum..)r maskr5z%r is a duplicate of %r)rwr r7is_alias)r r7r8)6rBrurhrGrvr0rDr r`ryr&rr,rGrrr.rrdrrrr/rr[r"rrrrrr!rrrr%rkr5r'r*r(rkr_rRrrz_finalize_extend_enumrrrr$rrAr )$ enumerationrwrr descriptorr=rur&rr,Zbase_attributesr.Z _multi_value_Z _no_alias_r-rZmt_new_newrrNrYrrrPZ more_values new_memberr*r(missed new_valuesr:Zcanonical_values_Zcanonical_valuerZ flag_bases canonicalr6r6r9r4 s                                  ,    Fc Cs|p|j}d}|jddD]>}|j|}|dk rt|ttfrHq\qtd||jfq|s~t}| ||t ||||s|j |||j |<t|d|jgD]<} z||j| <Wqtk r|j| |ff7_YqXq|r||_||_t|jr|j|jO_|S)Nrr6r5)rwr0rBrvrDr r`rGryrr4r&rxrurhrr,r.r*r(r r)) r:r=rwr r7r8r;r=r>rr6r6r9r9 s4       r9cCs^g}|jD]"\}}||jkr|||jfq|rZddd|D}td||f|S)zS Class decorator that ensures only unique members exist in an enumeration. rscSsg|]\}}d||fqS)z%s -> %sr6)raliasrwr6r6r9r szunique..zduplicate names found in %r: %s)rFrCrwrxrzr/)r: duplicatesrwr{Zduplicate_namesr6r6r9r s  )r+c@s(eZdZdZeZeZeZeZdS)r+z control how out of range values are handled "strict" -> error is raised [default] "conform" -> extra bits are discarded "eject" -> lose flag status (becomes a normal integer) N) ryrrrerr,r-r.r/r6r6r6r9r+ s zRGeneric flag enumeration. Derive from this class to define new flag enumerations.rkrlc Os|s0|rd|f|dk f|Sd|f|dk SnXt|}z.t|}d|d}|r^|f|WS|WSWntk rzYnXtd|dS)z Generate the next value when not given. name: the name of the member start: the initital start value or None count: the number of existing members last_value: the last value assigned or None rNrSzinvalid Flag value: %r)maxrr#rG) rwrYrNrrrrhigh_bitrnr6r6r9rj/ s    ccs&t||j@D]}|j|VqdS)zY Extract all members from the value in definition (i.e. increasing value) order. N)rRr)r,rv)rrPvalr6r6r9rqK srqrpccs2t||}|jddd|D] }|Vq"dS)zA Extract all members from the value in definition order. cSs|jSr<r'rKr6r6r9r] rz&_iter_member_by_def_..rN)r_rqr)rrPrr{r6r6r9rrV srrcCs ||S)z; return a member matching the given value, or None )rhrr6r6r9rma scGs|d}}t|ts(td||jf|j}|j}|j}||A}||@}|j} d|f|dk} | r| |kr| tkr||S| t krd| | }q| t krd| | |@}qtd||jfn |d| }||@} ||@|@} ||@} | tkr | r<|Sn2| t krd} n"| t kr<| r.rrrrcSsg|] }|jqSr6rrr6r6r9r sz*_create_pseudo_member_..z|%s)rDrr/ryr(r)r*rkr.r/rXr-r,r_rprurCrrxrrirhrr"rr!rzrrlr,r)rrrPZ error_valueZ flag_maskZ singles_maskZall_bitsZ unknown_bitsZ unnamed_bitsrZ neg_valuerZ unnamed_valueZ unknown_valuerZ final_valueZ still_unknownfoundrHpmr pseudo_memberr6r6r9rhi s                       rhcGs6|jttfkr|St|dkr.||fS|SdS)zB Return values to be fed to __new__ to create new member. rSN)rrr"r[)rrrr6r6r9ri s  ricCsPt||js&tdt|j|jjf|jdks:|jdkr>dS|j|j@|jkS)zH Returns True if self has at least the same flags set as other. 3unsupported operand type(s) for 'in': '%s' and '%s'rF)rDrrGrlryrrr6r6r9r s rccs||jD] }|Vq dS)z, Returns flags in definition order. N)rpr)rir{r6r6r9r srcCs t|jSr<)rrrr6r6r9r srcCs8|j}|jdkr d|j|jfSd|j|j|jfSdS)Nz<%s: %r>z <%s.%s: %r>rrryrrirr6r6r9r~ s cCs4|j}|jdkr d|j|jfSd|j|jfSdS)Nrr rLrMr6r6r9r s cCs t|jSr<rgrrr6r6r9r srcCs t|jSr<rNrr6r6r9r srcCsDt||jr|j}n |jtk r0t||jr0|}ntS||j|BSr<rDrrrr"rrirZ other_valuer6r6r9r s  rcCsDt||jr|j}n |jtk r0t||jr0|}ntS||j|@Sr<rOrPr6r6r9r" s  rcCsDt||jr|j}n |jtk r0t||jr0|}ntS||j|ASr<rOrPr6r6r9r, s  rcCs<|jdkr6||j|j@|_t|j|jr6||j_|jSr<)rrr)rrDrr6r6r9r6 s  rrrrc@seZdZdZeZddZdS)r%zSupport for integer-based FlagscCsft|tr||}n&t||js.r)rrr{ryrrr rkr+r/rzrwisdigitrx)rirWrwrHr6r4r9global_flag_reprj s     rTcCs*|jdkr |jj}d||jfS|jSdS)z2 use enum_name instead of class.enum_name Nz%s(%r))rrryr)rirWr6r6r9 global_str s rUcCsFt|trt|_nt|_t|tr&|r,t|_tj |j j |j |S)z decorator that makes the repr() of an enum member reference its module instead of its class; also exports all members to the enum's module's global namespace )rAr$rTr~rRr(rUrrrrrBrrF)rZ update_strr6r6r9r s r)WeakSetcCs|t|tstd|fz|jdWn\tk rJt|_t|_Yn:tk rddl }| \}}}td}t |YnX||jkrdS||jkrdS||kr|j |dS|t |dd kr|j |dS|tkrt|tr|j |dS|tkr t|tr |j |dS|tkrFt|trF|j |dS|tkrlt|trl|j |dS|j |dS) z9 Override for issubclass(subclass, cls). z+issubclass() arg 1 must be a class (got %r)_subclass_cache_rNpossible causes for endless recursion: - __getattribute__ is not ignoring __dunder__ attibutes - __instancecheck__ and/or __subclasscheck_ are (mutually) recursive see `aenum.remove_stdlib_integration` for temporary work-aroundTFr0r6)rDrlrGrBrrVrWZ_subclass_negative_cache_RecursionErrorsysrraise_from_nonerrh StdlibIntFlagrAr%rr$ StdlibIntEnumr"rr!)rsubclassrZr8tbr6r6r9__subclasscheck__ sH           r`cCsR|j}z ||WStk rLddl}|\}}}td}t|YnXdS)NrrX)rr`rYrZrr[)rrr^rZr8r_r6r6r9__instancecheck__ s racCstrtt_tt_dSr<)rr`StdlibEnumMetarar6r6r6r9r0 scCstr t`t`dS)a Remove the __instancecheck__ and __subclasscheck__ overrides from the stdlib Enum. Those overrides are in place so that code detecting stdlib enums will also detect aenum enums. If a buggy __getattribute__, __instancecheck__, or __subclasscheck__ is defined on a custom EnumMeta then RecursionErrors can result; using this function after importing aenum will solve that problem, but the better solution is to fix the buggy method. N)rrbrar`r6r6r6r9r1 s c@seZdZddZddZdS)r3cGsZ|j|_|j|_g|_|j}|s2dd|D}|D]}|||j|<|j|q6dS)NcSs"g|]\}}t|ttfr|qSr6)rDrr!rr6r6r9r sz'cls2module.__init__..)ryr_parent_module__all__rBrCrx)rirrZ all_objectsrwr6r6r9rk szcls2module.__init__cCs|tjd|j|jf<dSr)rrrcryrr6r6r9register szcls2module.registerN)ryrrrkrer6r6r6r9r3 s )N)N)N)NNNF)F) __future__rr Z _constantr_tupler collectionsrrZrrdr rYr* ImportErrorremoverY NameErrorrr:rErr!rrbr!rr"r]rr\Z StdlibStrEnumZStdlibReprEnumr%r$r#r(rr rrrr2rr rRr5typesr`r=r"r Z_RouteClassAttributeToGetattrrrlrrrr rrrglobalsrr.r/rrrr rrr rrZ _Addendumrrr?rrkrrxrrjrmrnror~rPY3rrrrrrrrrrrwrPrZ _enum_baseresolver'r4r(rZ _repr_basesrrr&r'r.rxrrrrrr)rr5rr9rr+Z _flag_basesZ flag_dictr,rtrqrrrhrirrrr rrrrrrrrRrTrUr _weakrefsetrVr`rar0r1r3r6r6r6r9sx          &   '    i  $- )i l3n    (                         -         m               .