a DOg@sddlZddlmZmZgdZddZddZdd Zd d Zd d Z e Z GdddZ Gddde ZdZGdddeZGdddedZGdddeeZddZGdddeZGdddeeZdd Zd!d"Zd#d$ZdS)%N)MappingProxyTypeDynamicClassAttribute)EnumMetaEnumIntEnumFlagIntFlagautouniquecCst|dpt|dpt|dS)z? Returns True if obj is a descriptor, False otherwise. __get____set__ __delete__)hasattr)objr)/opt/alt/python39/lib64/python3.9/enum.py_is_descriptor s  rcCsLt|dkoJ|dd|ddko.dknoJ|ddkoJ|ddkS)z= Returns True if a __dunder__ name, False otherwise. N___lennamerrr _is_dunders &  rcCsLt|dkoJ|d|dko&dknoJ|dddkoJ|dddkS)z; Returns True if a _sunder_ name, False otherwise. rrrrrrrrr _is_sunder!s r cCsTd|f}t|dkrL||rL|t|dkrL|ddksH|ddkrLdSdSdS)Nz_%s__rrrTF)r startswith)cls_namerpatternrrr _is_private,s    r%cCsdd}||_d|_dS)z, Make the given class un-picklable. cSstd|dS)Nz%r cannot be pickled) TypeErrorselfprotorrr_break_on_call_reduce=sz6_make_class_unpicklable.._break_on_call_reducez N) __reduce_ex__ __module__)clsr*rrr_make_class_unpicklable9sr.c@seZdZdZeZdS)r zP Instances are replaced with an appropriate value in Enum class suites. N)__name__r, __qualname____doc__ _auto_nullvaluerrrrr Csr cs,eZdZdZfddZfddZZS) _EnumDictz Track enum member order and ensure member names are not reused. EnumMeta will use the names found in self._member_names as the enumeration member names. cs&tg|_g|_g|_d|_dS)NF)super__init__ _member_names _last_values_ignore _auto_calledr( __class__rrr6Qs  z_EnumDict.__init__cst|j|r*ddl}|jd|ftddt|r|dvrBtd|dkrf|jrXtd t |d |nV|d krt |t r| d d  }nt|}||_t|t|j@}|rtd|fnt|r|dkrd}n||jvrtd|n||jvrnt|s~||vr td|||ft |trf|jtkr`||dt|j|jdd|_d|_|j}|j||j|t||dS)z Changes anything not dundered or not 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. rNz@private variables, such as %r, will be normal attributes in 3.10r) stacklevel)_order__create_pseudo_member__generate_next_value_ _missing__ignore_z(_names_ are reserved for future Enum userAz4_generate_next_value_ must be defined before members_generate_next_valuerC, z-_ignore_ cannot specify already set names: %r __order__r?zAttempted to reuse key: %rz%r already defined as: %rrT)r% _cls_namewarningswarnDeprecationWarningr ValueErrorr:r&setattr isinstancestrreplacesplitlistr9setr7rrr r3r2rDrr8appendr5 __setitem__)r(keyr3rIalreadyr<rrrUXsf           z_EnumDict.__setitem__)r/r,r0r1r6rU __classcell__rrr<rr4Js r4cseZdZdZeddZfddZddZd-dddd d d d Zd dZ fddZ ddZ ddZ ddZ ddZddZeddZddZdd Zfd!d"Zdddd d d#d$Zd.d%d&Zed'd(Zed)d*Zed+d,ZZS)/rz Metaclass for Enum cKsD|||t}||_|||\}}|dur@t|dd|d<|S)NrA)_check_for_existing_membersr4rH _get_mixins_getattr)metaclsr-baseskwds enum_dict member_type first_enumrrr __prepare__s zEnumMeta.__prepare__c sdgdd}|D]}|dq|||\}||\}} } fddjD} jD] } | =qndd} t| ddh@}|rtdd |d vrd d <t j |||fi|}g|_ i|_ |_d d |D}i|_d vr̈turd}tfdd|DsdvrFt|nd}|D]n}|jD]PturlqXn:tfdd|Drd}qndjvrXd}qqX|durNqqN|rt|jD]*}| |}t|ts|f}n|}tur|f}| s*||}t|dsb||_n8||g|R}t|dsbturX||_n ||_|j}||_||_|j||j D]"\} }|j|jkr|}qq|j |||vrt|||||j |<z||j|<WntyYn0qdD]V} | vrqt || }t | d}t || d}|dur||urt|| |qt!durz| rr||_"t!j |_ | durt| t#r| $dd%} | |j krtd|S)NrCcsi|]}||qSrr).0k) classdictrr z$EnumMeta.__new__..r?mrozInvalid enum member name: {0}rEr1zAn enumeration.cSs.h|]&}|jD]\}}t|tr|qqSr)__dict__itemsrNr)rccrdvrrr s z#EnumMeta.__new__..r+)__getnewargs_ex____getnewargs__r+ __reduce__c3s|]}|jvVqdSNrjrcm)r`rr rgz#EnumMeta.__new__..__new__c3s|]}|jvVqdSrrrsrt)baserrrvrgFT_value_)__repr____str__ __format__r+rFz#member order does not match _order_)& setdefaultrTpoprZ _find_new_r7rSrLformatjoinr5rw_member_names_ _member_map_ _member_type_rh_value2member_map_objectanyr.__mro__rjrNtuplerry_name_ __objclass__r6rkrMr&r[r__new_member__rOrPrQ)r\r-r]rer^ignorerVrarwsave_newuse_args enum_membersrr? invalid_names enum_classdynamic_attributesmethodssabotagechain member_namer3args enum_membercanonical_member class_method obj_method enum_methodr<)rxrer`rrws                                   zEnumMeta.__new__cCsdS)z6 classes/types should always be True. Trr;rrr__bool__`szEnumMeta.__bool__NrmodulequalnametypestartcCs*|dur|||S|j||||||dS)a! Either 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: `value` will be the name of the new class. `names` should be either a string of white-space/comma delimited names (values will start at `start`), or an iterator/mapping of name, value pairs. `module` should be set to the module this class is being created in; if it is not set, an attempt to find that module will be made, but if it fails the class will not be picklable. `qualname` should be set to the actual location this class can be found at in its module; by default it is set to the global scope. If this is not correct, unpickling will fail in some circumstances. `type`, if set, will be mixed in as the first base class. Nr)rw_create_)r-r3namesrrrrrrr__call__fs zEnumMeta.__call__cCs:t|ts$tdt|j|jjft||o8|j|jvS)N3unsupported operand type(s) for 'in': '%s' and '%s')rNrr&rr0r=rr)r-memberrrr __contains__s zEnumMeta.__contains__cs(||jvrtd|jt|dS)Nz%s: cannot delete Enum member.)rAttributeErrorr/r5 __delattr__)r-attrr<rrrs zEnumMeta.__delattr__cCsgd|jS)N)r=r1 __members__r,rr;rrr__dir__szEnumMeta.__dir__cCs>t|rt|z |j|WSty8t|dYn0dS)a= Return the enum member matching `name` We use __getattr__ instead of descriptors or inserting into the enum class' __dict__ in order to support `name` and `value` being both properties for enum members (which live in the class' __dict__) and enum members themselves. N)rrrKeyErrorr-rrrr __getattr__s   zEnumMeta.__getattr__cCs |j|Srrrrrrr __getitem__szEnumMeta.__getitem__csfddjDS)z6 Returns members in definition order. c3s|]}j|VqdSrrrrcrr-rrrvrgz$EnumMeta.__iter__..rrrrr__iter__szEnumMeta.__iter__cCs t|jSrr)rrrrrr__len__szEnumMeta.__len__cCs t|jS)z Returns a mapping of member name->value. This mapping lists all enum members, including aliases. Note that this is a read-only view of the internal mapping. )rrrrrrrszEnumMeta.__members__cCs d|jS)Nz )r/rrrrrzszEnumMeta.__repr__csfddtjDS)z> Returns members in reverse definition order. c3s|]}j|VqdSrrrrrrrrvrgz(EnumMeta.__reversed__..)reversedrrrrr __reversed__szEnumMeta.__reversed__cs0|jdi}||vrtdt||dS)a Block attempts to reassign Enum members. 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. rzCannot reassign members.N)rjgetrr5 __setattr__)r-rr3 member_mapr<rrrszEnumMeta.__setattr__c Csn|j}|dur|fn||f}|||\} } |||} t|trR|dd}t|ttfr|rt|dtr|g} }g} t | D]8\}}| |||| dd}| || ||fq|D].}t|tr|||}}n|\}}|| |<q| |||| }|dur@zt djd}Wntttfy>Yn0|durTt|n||_|durj||_|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 incremented by 1 from `start`. * An iterable of member names. Values are incremented by 1 from `start`. * An iterable of (member name, value) pairs. * A mapping of member name -> value pairs. NrErFrrr/)r=rZrbrNrOrPrQrrR enumeraterArTrwsys _getframe f_globalsrrLrr.r,r0)r- class_namerrrrrr\r]rrareoriginal_names last_valuescountrr3itemr member_valuerrrrrs<            zEnumMeta._create_csttj|}|rt|}n|}fdd|D}z|jdddWn"tyl|jdddYn0||||d}t|_||j |||<|S)z[ Create a new Enum subclass that replaces a collection of global constants cs g|]\}}|r||fqSrr)rcrr3filterrr !sz&EnumMeta._convert_..cSs|d|dfS)Nrrrtrrr'rgz$EnumMeta._convert_..)rVcSs|dSNrrrrrrr*rg)r) varsrmodulesrksortr&_reduce_ex_by_namer+updater)r-rrrsourcemodule_globalsmembersrrr _convert_s     zEnumMeta._convert_cCs<|D]2}|jD]&}t|tr|jrtd||jfqqdS)Nz %s: cannot extend enumeration %r)r issubclassrrr&r/)rr]rrxrrrrY1s z$EnumMeta._check_for_existing_memberscsT|s ttfSfdd}|d}t|ts2td||p._find_data_typerzZnew enumerations should be created as `EnumName([mixin_type, ...] [data_type,] enum_type)`zCannot extend enumerations)rrrr&r)rr]rrar`rrrrZ;s   zEnumMeta._get_mixins_c Cs|dd}|du}|durpdD]H}||fD].}t||d}|ddjtjtjhvr,|}q\q,|dur qpq tj}|tjurd}nd}|||fS)a Returns the __new__ to be used for creating the enum members. classdict: 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__ rwN)rrwFT)rr[rwrr) rer`rarwrmethodpossibletargetrrrrrjs*    zEnumMeta._find_new_)N)N)r/r,r0r1 classmethodrbrwrrrrrrrrrpropertyrrzrrrr staticmethodrYrZrrXrrr<rrs6  .%   5 !  .rc@steZdZdZddZddZeddZdd Zd d Z d d Z ddZ ddZ ddZ eddZeddZdS)rzV Generic enumeration. Derive from this class to define new enumerations. c Cs(t||ur|Sz |j|WSty.Yn8tyd|jD]}|j|krD|YSqDYn0zd}||}Wn,ty}z|}d}WYd}~n d}~00zrt ||r|Wd}d}St d||j f}|dur|dur|n|durtd|j |f}||_ |Wd}d}n d}d}0dS)N%r is not a valid %szDerror in %s._missing_: returned %r instead of None or a valid member)rrrr&rvaluesryrB ExceptionrNrLr0r/ __context__)r-r3rexcresulteve_excrrrrwsJ       z Enum.__new__c Cs4t|D]&}z|dWSty,Yq0q|S) Generate the next value when not given. name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None rN)rr&)rrrr last_valuerrrrAs  zEnum._generate_next_value_cCsdSrrr)r-r3rrrrBszEnum._missing_cCsd|jj|j|jfS)N <%s.%s: %r>)r=r/rryr;rrrrzsz Enum.__repr__cCsd|jj|jfS)N%s.%s)r=r/rr;rrrr{sz Enum.__str__cs4fddjDddjD}gd|S)z< Returns all members and all public methods cs2g|]*}|jD]}|ddkr|jvr|qqSrr)rjr)rcr-rur;rrrs z Enum.__dir__..cSsg|]}|ddkr|qSrrrtrrrrrg)r=r1r,)r=rhrj)r(added_behaviorrr;rrs  z Enum.__dir__cCsJt|jtjtjfv}|jtus$|r2t}t|}n |j}|j}|||S)z\ Returns format using actual value type unless __str__ has been overridden. ) rr{rrrrrOryr|)r( format_specstr_overriddenr-valrrrr|s  zEnum.__format__cCs t|jSrr)hashrr;rrr__hash__sz Enum.__hash__cCs|j|jffSrrr=ryr'rrrr+ szEnum.__reduce_ex__cCs|jS)zThe name of the Enum member.)rr;rrrrsz Enum.namecCs|jS)zThe value of the Enum member.ryr;rrrr3sz Enum.valueN)r/r,r0r1rwrArrBrzr{rr|rr+rrr3rrrrrs-    r) metaclassc@seZdZdZdS)rz.Enum where members are also (and must be) intsN)r/r,r0r1rrrrrsrcCs|jSrrrr'rrrr"src@speZdZdZddZeddZeddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZdS)rz Support for flags c Csb|s|dur|SdSt|D]8}zt|}WqVWqtyRtd|dYq0qd|dS)rNrzInvalid Flag value: %rr)r _high_bitrr&)rrrrrhigh_bitrrrrA*s    zFlag._generate_next_value_cCs.|}|dkr|}||}|dkr*|}|S)V Returns member (possibly creating it) if one can be found for value. r)r@)r-r3original_valuepossible_memberrrrrB=s zFlag._missing_cCsb|j|d}|dur^t||\}}|r:td||jft|}d|_||_|j ||}|S)L Create a composite member iff value contains only members. Nr) rr _decomposerLr0rrwrryr})r-r3 pseudo_memberr extra_flagsrrrr@Js zFlag._create_pseudo_member_cCs8t||js&tdt|j|jjf|j|j@|jkS)zP Returns True if self has at least the same flags set as other. r)rNr=r&rr0ryr(otherrrrr^s zFlag.__contains__cCsV|j}|jdur$d|j|j|jfSt||j\}}d|jddd|D|jfS)Nr|cSsg|]}t|jp|jqSrrOrryrtrrrrorgz!Flag.__repr__..)r=rr/ryrrr(r-r uncoveredrrrrzhs z Flag.__repr__cCs|j}|jdur d|j|jfSt||j\}}t|dkr^|djdur^d|j|djfSd|jddd|DfSdS)Nrrrz%s.%rrcSsg|]}t|jp|jqSrrrtrrrr}rgz Flag.__str__..)r=rr/rryrrrrrrr{ss z Flag.__str__cCs t|jSrr)boolryr;rrrrsz Flag.__bool__cCs"t||jstS||j|jBSrrrNr=NotImplementedryrrrr__or__s z Flag.__or__cCs"t||jstS||j|j@Srrr rrrr__and__s z Flag.__and__cCs"t||jstS||j|jASrrr rrrr__xor__s z Flag.__xor__cCsNt|j|j\}}|d}|jD] }||vr"|j|j@s"||B}q"||Sr)rr=ry)r(rrinvertedrurrr __invert__s    zFlag.__invert__N)r/r,r0r1rArrBr@rrzr{rr r rrrrrrr%s     rc@sTeZdZdZeddZeddZddZdd Zd d Z eZ eZ e Z d d Z dS)rz) Support for integer-based Flags cCs*t|tstd||jf||}|S)rr)rNintrLr0r@)r-r3 new_memberrrrrBs  zIntFlag._missing_cCs|j|d}|dur|g}t||\}}|rtt|}d|}||jvrZ||vrZ|||| krjd}q*||N}q*t|D]*}t||}d|_||_ |j ||}q||S)rNrr) rrrrrTrrrwrryr})r-r3rneed_to_createrrbit flag_valuerrrr@s(      zIntFlag._create_pseudo_member_cCs0t||jtfstS||j||jB}|SrrrNr=rr ry)r(rrrrrr szIntFlag.__or__cCs,t||jtfstS||j||j@Srrrrrrrr szIntFlag.__and__cCs,t||jtfstS||j||jASrrrrrrrrszIntFlag.__xor__cCs||j}|Srrr)r(rrrrrszIntFlag.__invert__N)r/r,r0r1rrBr@r r r__ror____rand____rxor__rrrrrrs  rcCs |dS)zJ returns index of highest bit, or -1 if value is zero or negative r) bit_length)r3rrrrsrcCs^g}|jD]"\}}||jkr|||jfq|rZddd|D}td||f|S)zI Class decorator for enumerations ensuring unique member values. z, cSsg|]\}}d||fqS)z%s -> %sr)rcaliasrrrrrrgzunique..z duplicate values found in %r: %s)rrkrrTrrL) enumeration duplicatesrr alias_detailsrrrr s  r c Cs|}|dk}g}|D].}|j}|r||@|kr||||M}q|s|}|rdt|}||jvr||j|||M}||M}qL|s||jvr||j||jddddt|dkr|dj|kr|d||fS)z- Extract all members from the value. rrcSs|jSrrr)rurrrrrgz_decompose..T)rVreverser)r3rTrrrrr~) flagr3 not_coverednegativerrrtmprrrrrs,       r)rtypesrr__all__rrr r%r.rr2r dictr4rrrrrrrrrr rrrrrs0     T{vI