U e5d@sddlZddlmZmZddddddd gZd d Zd d ZddZddZe Z GdddZ Gddde Z dZGdddeZGdddedZGdddeeZddZGdddeZGdddeeZddZdd Zd d!Zd"d#ZdS)$N)MappingProxyTypeDynamicClassAttributeEnumMetaEnumIntEnumFlagIntFlagautouniquecCst|dpt|dpt|dS)N__get____set__ __delete__)hasattr)objr/usr/lib64/python3.8/enum.py_is_descriptor s  rcCsLt|dkoJ|dd|ddko.dknoJ|ddkoJ|ddkS)N___lennamerrr _is_dunders &  rcCsLt|dkoJ|d|dko&dknoJ|dddkoJ|dddkS)Nrrrrrrrrr _is_sunder!s r cCsdd}||_d|_dS)NcSstd|dS)Nz%r cannot be pickled) TypeErrorselfprotorrr_break_on_call_reduce0sz6_make_class_unpicklable.._break_on_call_reducez ) __reduce_ex__ __module__)clsr%rrr_make_class_unpicklable,sr)c@seZdZeZdS)r N)__name__r' __qualname__ _auto_nullvaluerrrrr 6scs(eZdZfddZfddZZS) _EnumDictcs&tg|_g|_g|_d|_dS)NF)super__init__ _member_names _last_values_ignore _auto_calledr# __class__rrr0Ds  z_EnumDict.__init__csdt|r|dkrtd|dkr<|jr.tdt|d|nV|dkrt|tr`|dd}nt |}||_ t |t |j @}|rtd |fnt |r|d krd }n||j krtd |n||j krnt|sR||krtd |||ft|tr:|jtkr4||dt|j |jdd|_d|_|j}|j ||j|t||dS)N)_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: %r __order__r8zAttempted to reuse key: %rz%r already defined as: %rrT)r ValueErrorr4r!setattr isinstancestrreplacesplitlistr3setr1rrr r-r,r=rr2appendr/ __setitem__)r#keyr-alreadyr6rrrJKsT          z_EnumDict.__setitem__)r*r'r+r0rJ __classcell__rrr6rr.=s r.cseZdZeddZfddZddZd.ddddd d d Zd d ZfddZ ddZ ddZ ddZ ddZ ddZeddZddZddZfd d!Zddddd d"d#Zd/d$d%Zd&d'Zed(d)Zed*d+Zed,d-ZZS)0rcCs>|||t}|||\}}|dk r:t|dd|d<|S)Nr:)_check_for_existing_membersr. _get_mixins_getattr)metaclsr(bases enum_dict member_type first_enumrrr __prepare__s zEnumMeta.__prepare__c sdgdd}|D]}|dq|||\}||\}}} fddjD} jD] } | =qndd} t| ddh@} | rtdd | d krd d <t |||}g|_ i|_ |_d d |D}i|_d kr2tk r2d}tfdd|Ds2t|jD]*}| |}t|tsZ|f}n|}tkrn|f}| s||}t|ds||_n6||f|}t|dsƈtkr||_n ||_|j}||_||_|j||j D]"\} }|j|jkr|}qq|j |||kr2t|||||j |<z||j|<Wntk r`YnXq8dD]V} | kr|qjt|| }t| d}t|| d}|dk rj||krjt|| |qjtdk r|r||_ tj |_ | dk rt| t!r| "dd#} | |j krtd|S)Nr<csi|]}||qSrr).0k) classdictrr sz$EnumMeta.__new__..r8mrozInvalid enum member name: {0}r>__doc__zAn enumeration.cSs.h|]&}|jD]\}}t|tr|qqSr)__dict__itemsrCr)rWcrXvrrr s   z#EnumMeta.__new__..r&)__getnewargs_ex____getnewargs__r& __reduce__c3s|]}|jkVqdSN)r^rWm)rTrr sz#EnumMeta.__new__.._value_)__repr____str__ __format__r&r?z#member order does not match _order_)$ setdefaultrIpoprO _find_new_r1rHrAformatjoinr/__new___member_names_ _member_map_ _member_type_r[_value2member_map_objectanyr)rCtuplerrj_name_ __objclass__r0r_rBr!rPr__new_member__rDrErF)rQr(rRrYignorerKrUrssave_newuse_args enum_membersrr8 invalid_names enum_classdynamic_attributesmethods member_namer-args enum_membercanonical_member class_method obj_method enum_methodr6)rYrTrrss                           zEnumMeta.__new__cCsdS)NTrr5rrr__bool__3szEnumMeta.__bool__NrmodulequalnametypestartcCs*|dkr|||S|j||||||dS)Nr)rs_create_)r(r-namesrrrrrrr__call__9s zEnumMeta.__call__cCs:t|ts$tdt|j|jjft||o8|j|jkSNz3unsupported operand type(s) for 'in': '%s' and '%s')rCrr!rr+r7r{ru)r(memberrrr __contains__^s zEnumMeta.__contains__cs(||jkrtd|jt|dS)Nz%s: cannot delete Enum member.)ruAttributeErrorr*r/ __delattr__)r(attrr6rrres zEnumMeta.__delattr__cCsddddg|jS)Nr7r] __members__r'rtr5rrr__dir__ls zEnumMeta.__dir__cCs@t|rt|z |j|WStk r:t|dYnXdSrf)rrruKeyErrorr(rrrr __getattr__rs  zEnumMeta.__getattr__cCs |j|Srfrurrrr __getitem__szEnumMeta.__getitem__csfddjDS)Nc3s|]}j|VqdSrfrrWrr(rrrisz$EnumMeta.__iter__..rrrrr__iter__szEnumMeta.__iter__cCs t|jSrf)rrtrrrr__len__szEnumMeta.__len__cCs t|jSrf)rrurrrrrszEnumMeta.__members__cCs d|jS)Nz )r*rrrrrkszEnumMeta.__repr__csfddtjDS)Nc3s|]}j|VqdSrfrrrrrrisz(EnumMeta.__reversed__..)reversedrtrrrr __reversed__szEnumMeta.__reversed__cs0|jdi}||krtdt||dS)NruzCannot reassign members.)r^getrr/ __setattr__)r(rr- member_mapr6rrrszEnumMeta.__setattr__c Cs~|j}|dkr|fn||f}|||\} } |||} t|trR|dd}t|ttfr|rt|dtr|g} }g} t | D]8\}}| |||| dd}| || ||fq|D].}t|tr|||}}n|\}}|| |<q| |||| }|dkrPzt djd}Wn*tttfk rN}zW5d}~XYnX|dkrdt|n||_|dk rz||_|S)Nr>r?rrr*)r7rOrVrCrDrErFrzrG enumerater:rIrssys _getframe f_globalsrrArr)r'r+)r( class_namerrrrrrQrRrrUrYoriginal_names last_valuescountrr-itemr member_valuerexcrrrrs<            zEnumMeta._create_csttj|}|rt|}n|}fdd|D}z|jdddWn$tk rn|jdddYnX||||d}t|_||j |||<|S)Ncs g|]\}}|r||fqSrr)rWrr-filterrr sz&EnumMeta._convert_..cSs|d|dfS)Nrrrtrrrz$EnumMeta._convert_..)rKcSs|dSNrrrrrrrr)r) varsrmodulesr_sortr!_reduce_ex_by_namer&updater)r(rrrsourcemodule_globalsmembersrrr _convert_s    zEnumMeta._convert_cOs$ddl}|jdtdd|j||S)NrzI_convert is deprecated and will be removed in 3.9, use _convert_ instead.r) stacklevel)warningswarnDeprecationWarningr)r(rkwargsrrrr_converts zEnumMeta._convertcCs<|D]2}|jD]&}t|tr|jrtd||jfqqdS)Nz %s: cannot extend enumeration %r)__mro__ issubclassrrtr!r*)rrRchainbaserrrrN s 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)rxrrr!rt)rrRrrUrTrrrrOs   zEnumMeta._get_mixins_c Cs|dd}|dk }|dkrpdD]H}||fD].}t||d}|ddjtjtjhkr,|}q\q,|dk r qpq tj}|tjkrd}nd}|||fS)Nrs)r}rsFT)rrPrsrxr) rYrTrUrsrmethodpossibletargetrrrrrpCs*    zEnumMeta._find_new_)N)N)r*r'r+ classmethodrVrsrrrrrrrrrpropertyrrkrrrrr staticmethodrNrOrprMrrr6rrs6 %   5 !  .c@speZdZddZddZeddZddZd d Zd d Z d dZ ddZ ddZ e ddZe ddZdS)rc Cst||kr|Sz |j|WStk r0Yn:tk rh|jD]}|j|krH|YSqHYnXzd}||}Wn*tk r}z |}d}W5d}~XYnXzdt ||r|WTSt d||j f}|dkr|dkr|n|dkrtd|j |f}||_ |W5d}d}XdS)N%r is not a valid %szDerror in %s._missing_: returned %r instead of None or a valid member) rrwrr!ruvaluesrjr; ExceptionrCrAr* __context__)r(r-rrresulteve_excrrrrsws@     z Enum.__new__c Cs6t|D](}z|dWStk r.YqXq|SNr)rr!)rrrr last_valuerrrr:s zEnum._generate_next_value_cCsdSrfr)r(r-rrrr;szEnum._missing_cCsd|jj|j|jfS)N <%s.%s: %r>)r7r*r{rjr5rrrrks z Enum.__repr__cCsd|jj|jfS)N%s.%s)r7r*r{r5rrrrlsz Enum.__str__cs6fddjDddjD}dddg|S)Ncs2g|]*}|jD]}|ddkr|jkr|qqSrr)r^ru)rWr(rhr5rrrs  z Enum.__dir__..cSsg|]}|ddkr|qSrrrgrrrrs r7r]r')r7r[r^)r#added_behaviorrr5rrs  z Enum.__dir__cCsJt|jtjtjfk}|jtks$|r2t}t|}n |j}|j}|||Srf) rrlrrrvrxrDrjrm)r# format_specstr_overriddenr(valrrrrms  zEnum.__format__cCs t|jSrf)hashr{r5rrr__hash__sz Enum.__hash__cCs|j|jffSrfr7rjr"rrrr&szEnum.__reduce_ex__cCs|jSrf)r{r5rrrrsz Enum.namecCs|jSrfrjr5rrrr-sz Enum.valueN)r*r'r+rsr:rr;rkrlrrmrr&rrr-rrrrrqs-    ) metaclassc@s eZdZdS)rN)r*r'r+rrrrrscCs|jSrfrr"rrrrsrc@sleZdZddZeddZeddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZdS)rc Csd|s|dk r|SdSt|D]:}zt|}WqXWqtk rTtd|dYqXqd|dS)NrzInvalid Flag value: %rr)r _high_bitrr!)rrrrrhigh_bitrrrr:s   zFlag._generate_next_value_cCs.|}|dkr|}||}|dkr*|}|Sr)r9)r(r-original_valuepossible_memberrrrr;s zFlag._missing_cCsb|j|d}|dkr^t||\}}|r:td||jft|}d|_||_|j ||}|SNr) rwr _decomposerAr*rxrsr{rjrn)r(r- pseudo_memberr extra_flagsrrrr9#s zFlag._create_pseudo_member_cCs8t||js&tdt|j|jjf|j|j@|jkSr)rCr7r!rr+rjr#otherrrrr7s zFlag.__contains__cCsV|j}|jdk r$d|j|j|jfSt||j\}}d|jddd|D|jfS)Nr|cSsg|]}t|jp|jqSrrDr{rjrgrrrrHsz!Flag.__repr__..)r7r{r*rjrrrr#r(r uncoveredrrrrkAs z Flag.__repr__cCs|j}|jdk r d|j|jfSt||j\}}t|dkr^|djdkr^d|j|djfSd|jddd|DfSdS)Nrrrz%s.%rrcSsg|]}t|jp|jqSrrrgrrrrVsz Flag.__str__..)r7r{r*rrjrrrrrrrrlLs z Flag.__str__cCs t|jSrf)boolrjr5rrrrYsz Flag.__bool__cCs"t||jstS||j|jBSrfrCr7NotImplementedrjrrrr__or__\s z Flag.__or__cCs"t||jstS||j|j@Srfrrrrr__and__as z Flag.__and__cCs"t||jstS||j|jASrfrrrrr__xor__fs z Flag.__xor__cCsNt|j|j\}}|d}|jD] }||kr"|j|j@s"||B}q"||Sr)rr7rj)r#rrinvertedrhrrr __invert__ks    zFlag.__invert__N)r*r'r+r:rr;r9rrkrlrrrrrrrrrrs     c@sPeZdZeddZeddZddZddZd d ZeZ eZ eZ d d Z d S)rcCs*t|tstd||jf||}|Sr)rCintrAr*r9)r(r- new_memberrrrr;ys  zIntFlag._missing_cCs|j|d}|dkr|g}t||\}}|rtt|}d|}||jkrZ||krZ|||| krjd}q*||N}q*t|D]*}t||}d|_||_ |j ||}q||S)Nrr) rwrrrrIrrrsr{rjrn)r(r-rneed_to_createrrbit flag_valuerrrr9s(      zIntFlag._create_pseudo_member_cCs0t||jtfstS||j||jB}|SrfrCr7rrrj)r#rrrrrrszIntFlag.__or__cCs,t||jtfstS||j||j@Srfr rrrrrszIntFlag.__and__cCs,t||jtfstS||j||jASrfr rrrrrszIntFlag.__xor__cCs||j}|Srfr)r#rrrrrszIntFlag.__invert__N) r*r'r+rr;r9rrr__ror____rand____rxor__rrrrrrts  cCs |dSr) bit_lengthr-rrrrsrcCs^g}|jD]"\}}||jkr|||jfq|rZddd|D}td||f|S)Nz, cSsg|]\}}d||fqS)z%s -> %sr)rWaliasrrrrrszunique..z duplicate values found in %r: %s)rr_rrIrrrA) enumeration duplicatesrr alias_detailsrrrr s  cCs|}|dk}|r*ddt|jD}nddt|jD}g}|D],\}}|rJ||@|krJ||||M}qJ|s||jkr||j||jddddt|d kr|dj|kr|d||fS) NrcSs"g|]\}}|jdk r||fqSrfrrWrarhrrrrs z_decompose..cSs*g|]"\}}|jdk st|r||fqSrf)r _power_of_tworrrrrs cSs|jSrfr)rhrrrrrz_decompose..T)rKreverser)rGrwr_rIrrr-ro)flagr- not_coverednegativeflags_to_checkrrrrrrrs(      rcCs|dkr dS|dt|kS)NrFr)rrrrrrsr)rtypesrr__all__rrr r)rxr,r dictr.rrrrrrrrrr rrrrrrs>    LivI%