a |_ɉ@sddlZddlmZmZgdZddZddZdd Zd d Ze Z Gd d d Z Gddde Z dZGdddeZGdddedZGdddeeZddZGdddeZGdddeeZddZdd Zd!d"ZdS)#N)MappingProxyTypeDynamicClassAttribute)EnumMetaEnumIntEnumFlagIntFlagautouniquecCst|dpt|dpt|dS)z5Returns True if obj is a descriptor, False otherwise.__get____set__ __delete__)hasattr)objr /usr/local/lib/python3.9/enum.py_is_descriptor s  rcCsLt|dkoJ|dd|ddko.dknoJ|ddkoJ|ddkS)z3Returns True if a __dunder__ name, False otherwise.N___lennamerrr _is_dunders &  rcCsLt|dkoJ|d|dko&dknoJ|dddkoJ|dddkS)z1Returns True if a _sunder_ name, False otherwise.rrrrrrrrr _is_sunders r cCsdd}||_d|_dS)z"Make the given class un-picklable.cSstd|dS)Nz%r cannot be pickled) TypeErrorselfZprotorrr_break_on_call_reduce&sz6_make_class_unpicklable.._break_on_call_reducez N) __reduce_ex__ __module__)clsr$rrr_make_class_unpicklable$sr(c@seZdZdZeZdS)r zP Instances are replaced with an appropriate value in Enum class suites. N)__name__r& __qualname____doc__ _auto_nullvaluerrrrr ,sr cs,eZdZdZfddZfddZZS) _EnumDictzTrack 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__rrr0:s  z_EnumDict.__init__csdt|r|dvrtd|dkr<|jr.tdt|d|nV|dkrt|tr`|dd}nt |}||_ t |t |j @}|rtd |fnt |r|d krd }n||j vrtd |n||j vrnt|sR||vrtd |||ft|tr:|jtkr4||dt|j |jdd|_d|_|j}|j ||j|t||dS)zChanges 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. )_order__create_pseudo_member__generate_next_value_ _missing__ignore_z(_names_ are reserved for future Enum user:z4_generate_next_value_ must be defined before members_generate_next_valuer<, z-_ignore_ cannot specify already set names: %rZ __order__r8zAttempted to reuse key: %rz%r already defined as: %rrNT)r ValueErrorr4r!setattr isinstancestrreplacesplitlistr3setr1rrr r-r,r=rr2appendr/ __setitem__)r#keyr-Zalreadyr6rrrIAsB       "  z_EnumDict.__setitem__)r)r&r*r+r0rI __classcell__rrr6rr.3s r.cseZdZdZeddZfddZddZd-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)/rzMetaclass for EnumcCs>|||t}|||\}}|dur:t|dd|d<|S)Nr:)_check_for_existing_membersr. _get_mixins_getattr)metaclsr'basesZ enum_dict member_type first_enumrrr __prepare__|s  zEnumMeta.__prepare__c sdgdd}|D]}|dq|||\}||\}}} fddjD} jD] } | =qndd} t| ddh@} | rtdd | d vrd d <t |||}g|_ i|_ |_d d |D}i|_d vr2tur2d}tfdd|Ds2t|jD]*}| |}t|tsZ|f}n|}turn|f}| s||}t|ds||_n8||g|R}t|dsȈtur||_n ||_|j}||_||_|j||j D]"\} }|j|jkr|}qq|j |||vr4t|||||j |<z||j|<Wnty`Yn0q8dD]V} | vr|qjt|| }t| d}t|| d}|durj||urjt|| |qjtdur|r||_ tj |_ | durt| t!r| "dd#} | |j krtd|S)Nr<csi|]}||qSrr).0k) classdictrr z$EnumMeta.__new__..r8mrozInvalid enum member name: {0}r>r+zAn enumeration.cSs.h|]&}|jD]\}}t|tr|qqSr)__dict__itemsrBr)rTcrUvrrr s z#EnumMeta.__new__..r%)Z__getnewargs_ex____getnewargs__r% __reduce__c3s|]}|jvVqdSN)r[rTm)rQrr rXz#EnumMeta.__new__.._value_)__repr____str__ __format__r%r?z#member order does not match _order_)$ setdefaultrHpoprM _find_new_r1rGr@formatjoinr/__new___member_names_ _member_map_ _member_type_rY_value2member_map_objectanyr(rBtuplerrf_name_ __objclass__r0r\rAr!rNr__new_member__rCrDrE)rOr'rPrVignorerJrRrosave_newuse_argsZ enum_membersrr8Z invalid_names enum_classZdynamic_attributesmethods member_namer-argsZ enum_memberZcanonical_memberZ class_methodZ obj_methodZ enum_methodr6)rVrQrros                           zEnumMeta.__new__cCsdS)z6 classes/types should always be True. Trr5rrr__bool__szEnumMeta.__bool__NrmodulequalnametypestartcCs*|dur|||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: `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)ro_create_)r'r-namesrrrrrrr__call__!s zEnumMeta.__call__cCs:t|ts$tdt|j|jjft||o8|j|jvSNz3unsupported operand type(s) for 'in': '%s' and '%s')rBrr!rr*r7rwrq)r'memberrrr __contains__?s zEnumMeta.__contains__cs(||jvrtd|jt|dS)Nz%s: cannot delete Enum member.)rqAttributeErrorr)r/ __delattr__)r'attrr6rrrFs  zEnumMeta.__delattr__cCsgd|jS)N)r7r+ __members__r&rpr5rrr__dir__NszEnumMeta.__dir__cCs>t|rt|z |j|WSty8t|dYn0dS)a5Return 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)rrrqKeyErrorr'rrrr __getattr__Rs   zEnumMeta.__getattr__cCs |j|Srbrqrrrr __getitem__bszEnumMeta.__getitem__csfddjDS)Nc3s|]}j|VqdSrbrrTrr'rrrefrXz$EnumMeta.__iter__..rrrrr__iter__eszEnumMeta.__iter__cCs t|jSrb)rrprrrr__len__hszEnumMeta.__len__cCs t|jS)zReturns 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. )rrqrrrrrkszEnumMeta.__members__cCs d|jS)Nz )r)rrrrrguszEnumMeta.__repr__csfddtjDS)Nc3s|]}j|VqdSrbrrrrrreyrXz(EnumMeta.__reversed__..)reversedrprrrr __reversed__xszEnumMeta.__reversed__cs0|jdi}||vrtdt||dS)zBlock 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. rqzCannot reassign members.N)r[getrr/ __setattr__)r'rr-Z member_mapr6rrr{szEnumMeta.__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)aConvenience 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. Nr>r?rrr))r7rMrSrBrCrDrErvrF enumerater:rHrosys _getframe f_globalsrr@rr(r&r*)r' class_namerrrrrrOrPrrRrVZoriginal_names last_valuescountrr-itemr member_valuer}rrrrs<            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)rTrr-filterrr sz&EnumMeta._convert_..cSs|d|dfS)NrrrtrrrrXz$EnumMeta._convert_..)rJcSs|dSNrrrrrrrrX)r) varsrmodulesr\sortr!_reduce_ex_by_namer%updater)r'rrrsourceZmodule_globalsmembersrrr _convert_s     zEnumMeta._convert_cCs<|D]2}|jD]&}t|tr|jrtd||jfqqdS)Nz %s: cannot extend enumeration %r)__mro__ issubclassrrpr!r))rrPchainbaserrrrLs 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)rtrrr!rp)rrPrrRrQrrrrMs   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__ roN)ryroFT)rrNrortr) rVrQrRror{methodZpossibletargetr|rrrrls*    zEnumMeta._find_new_)N)N)r)r&r*r+ classmethodrSrorrrrrrrrrpropertyrrgrrrr staticmethodrLrMrlrKrrr6rrzs6    5 !  *rc@steZdZdZddZddZeddZdd Zd d Z d d Z ddZ ddZ ddZ eddZeddZdS)rzRGeneric enumeration. Derive from this class to define new enumerations. c Cst||ur|Sz |j|WSty.Yn8tyd|jD]}|j|krD|YSqDYn0zd}||}Wn,ty}z|}d}WYd}~n d}~00t ||r|St d||j f}|dur|dur|n|durtd|j |f}||_ |dS)N%r is not a valid %szDerror in %s._missing_: returned %r instead of None or a valid member)rrsrr!rqvaluesrfr; ExceptionrBr@r*r) __context__)r'r-rexcresulteZve_excrrrroDs:      z Enum.__new__c Cs4t|D]&}z|dWSty,Yq0q|S)Nr)rr!)rrrr last_valuerrrr:ls   zEnum._generate_next_value_cCsdSrbr)r'r-rrrr;uszEnum._missing_cCsd|jj|j|jfS)N <%s.%s: %r>)r7r)rwrfr5rrrrgysz Enum.__repr__cCsd|jj|jfS)N%s.%s)r7r)rwr5rrrrh}sz Enum.__str__cs$fddjD}gd|S)Ncs2g|]*}|jD]}|ddkr|jvr|qqS)rr)r[rq)rTr'rdr5rrrs z Enum.__dir__..)r7r+r&)r7rY)r#Zadded_behaviorrr5rrs z Enum.__dir__cCsDt|jtjk}|jtus|r,t}t|}n |j}|j}|||Srb)rrhrrrrtrCrfri)r# format_specZstr_overriddenr'valrrrris zEnum.__format__cCs t|jSrb)hashrwr5rrr__hash__sz Enum.__hash__cCs|j|jffSrbr7rfr"rrrr%szEnum.__reduce_ex__cCs|jS)zThe name of the Enum member.)rwr5rrrrsz Enum.namecCs|jS)zThe value of the Enum member.rfr5rrrr-sz Enum.valueN)r)r&r*r+ror:rr;rgrhrrirr%rrr-rrrrr>s(     r) metaclassc@seZdZdZdS)rz.Enum where members are also (and must be) intsN)r)r&r*r+rrrrrsrcCs|jSrbrr"rrrrsrc@speZdZdZddZeddZeddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZdS)rzSupport for flagsc Csb|s|dur|SdSt|D]8}zt|}WqVWqtyRtd|dYq0qd|dS)z 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 NrzInvalid Flag value: %rr)r _high_bitrr!)rrrrrZhigh_bitrrrr:s    zFlag._generate_next_value_cCs.|}|dkr|}||}|dkr*|}|Sr)r9)r'r-Zoriginal_valueZpossible_memberrrrr;s zFlag._missing_cCsb|j|d}|dur^t||\}}|r:td||jft|}d|_||_|j ||}|S)zL Create a composite member iff value contains only members. Nr) rsr _decomposer@r*rtrorwrfrj)r'r- pseudo_memberr extra_flagsrrrr9s zFlag._create_pseudo_member_cCs8t||js&tdt|j|jjf|j|j@|jkSr)rBr7r!rr*rfr#otherrrrrs zFlag.__contains__cCsV|j}|jdur$d|j|j|jfSt||j\}}d|jddd|D|jfS)Nr|cSsg|]}t|jp|jqSrrCrwrfrcrrrrrXz!Flag.__repr__..)r7rwr)rfrrnr#r'r uncoveredrrrrgs z Flag.__repr__cCs|j}|jdur d|j|jfSt||j\}}t|dkr^|djdur^d|j|djfSd|jddd|DfSdS)Nrrrz%s.%rrcSsg|]}t|jp|jqSrrrcrrrrrXz Flag.__str__..)r7rwr)rrfrrnrrrrrhs z Flag.__str__cCs t|jSrb)boolrfr5rrrr sz Flag.__bool__cCs"t||jstS||j|jBSrbrBr7NotImplementedrfrrrr__or__s z Flag.__or__cCs"t||jstS||j|j@Srbrrrrr__and__s z Flag.__and__cCs"t||jstS||j|jASrbrrrrr__xor__s z Flag.__xor__cCsNt|j|j\}}|d}|jD] }||vr"|j|j@s"||B}q"||Sr)rr7rf)r#rrZinvertedrdrrr __invert__s    zFlag.__invert__N)r)r&r*r+r:rr;r9rrgrhrrrrrrrrrrs    rc@sTeZdZdZeddZeddZddZdd Zd d Z eZ eZ e Z d d Z dS)rzSupport for integer-based FlagscCs*t|tstd||jf||}|S)Nr)rBintr@r*r9)r'r-Z new_memberrrrr;)s  zIntFlag._missing_cCs|j|d}|dur|g}t||\}}|rtt|}d|}||jvrZ||vrZ|||| krjd}q*||N}q*t|D]*}t||}d|_||_ |j ||}q||S)Nrr) rsrrrrHrrrorwrfrj)r'r-rZneed_to_createrrZbit flag_valuerrrr90s(      zIntFlag._create_pseudo_member_cCs0t||jtfstS||j||jB}|SrbrBr7rrrf)r#rrrrrrNszIntFlag.__or__cCs,t||jtfstS||j||j@SrbrrrrrrTszIntFlag.__and__cCs,t||jtfstS||j||jASrbrrrrrrYszIntFlag.__xor__cCs||j}|Srbr)r#rrrrrbszIntFlag.__invert__N)r)r&r*r+rr;r9rrr__ror____rand____rxor__rrrrrr&s  rcCs |dS)z@returns index of highest bit, or -1 if value is zero or negativer) bit_length)r-rrrrgsrcCs^g}|jD]"\}}||jkr|||jfq|rZddd|D}td||f|S)z?Class decorator for enumerations ensuring unique member values.z, cSsg|]\}}d||fqS)z%s -> %sr)rTaliasrrrrrsrXzunique..z duplicate values found in %r: %s)rr\rrHrnr@)Z enumerationZ duplicatesrrZ alias_detailsrrrr ks  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|jSrbr)rdrrrrrXz_decompose..T)rJreverser)r-rHrrsrrrk) Zflagr-Z not_coverednegativerrrZtmprrrrrxs,       r)rtypesrr__all__rrr r(rtr,r dictr.rrrrrrrrrr rrrrrs,DGsnA