Your IP : 18.117.231.160


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/enum.cpython-34.pyc

�
e f"T�@s�ddlZddlmZddlmZmZdddgZdd�Zd	d
�Zdd�Z	d
d�Z
Gdd�de�ZdZ
Gdd�de�ZGdd�dde�Z
Gdd�dee
�Zdd�Zdd�ZdS)�N)�OrderedDict)�MappingProxyType�DynamicClassAttribute�Enum�IntEnum�uniquecCs+t|d�p*t|d�p*t|d�S)z5Returns True if obj is a descriptor, False otherwise.�__get__�__set__�
__delete__)�hasattr)�obj�r
�)/opt/alt/python34/lib64/python3.4/enum.py�_is_descriptorsrcCsl|dd�|dd�ko+dknok|dd�dkok|dd	�dkokt|�dkS)
z3Returns True if a __dunder__ name, False otherwise.N��__��_�������r)�len)�namer
r
r�
_is_dunders0rcCs`|d|dkodkno_|dd�dko_|dd�dko_t|�dkS)z1Returns True if a _sunder_ name, False otherwise.r�rr���rr)r)rr
r
r�
_is_sunders$rcCs"dd�}||_d|_dS)z"Make the given class un-picklable.cSstd|��dS)Nz%r cannot be pickled)�	TypeError)�self�protor
r
r�_break_on_call_reduce"sz6_make_class_unpicklable.<locals>._break_on_call_reducez	<unknown>N)�
__reduce_ex__�
__module__)�clsr r
r
r�_make_class_unpicklable s	r$cs:eZdZdZ�fdd�Z�fdd�Z�S)�	_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.

    cst�j�g|_dS)N)�super�__init__�
_member_names)r)�	__class__r
rr'/s
z_EnumDict.__init__cs�t|�rtd��nst|�r*nd||jkrLtd|��nBt|�s�||kr{td||��n|jj|�nt�j||�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.

        z(_names_ are reserved for future Enum usezAttempted to reuse key: %rzKey already defined as: %rN)	r�
ValueErrorrr(rr�appendr&�__setitem__)r�key�value)r)r
rr,3s	z_EnumDict.__setitem__)�__name__r"�__qualname__�__doc__r'r,r
r
)r)rr%(sr%c	sBeZdZdZedd��Z�fdd�Zdd�Zdd	dd
ddddd
�Zdd�Z	�fdd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zedd��Zdd�Zd d!�Z�fd"d#�Zdd	dd
dddd$d%�Zed&d'��Zed(d)��Z�S)*�EnumMetazMetaclass for EnumcCst�S)N)r%)�metaclsr#�basesr
r
r�__prepare__TszEnumMeta.__prepare__cs4|j|�\�}|j��|�\}}}�fdd��jD�}x�jD]
}	�|	=qYWt|�dh@}
|
r�tdjdj|
����nt�j|||��}g|_	t
�|_�|_i|_
d�kr6�tk	r6d}t�fd
d�|D��s3t|�q3q6nx[�jD]P}
||
}t|t�sk|f}n|}�tkr�|f}n|s�||�}t|d�s�||_q�n0|||�}t|d�s��|�|_n|j}|
|_||_|j|�xI|jj�D](\}	}|j|jkr!|}Pq!q!W|j	j|
�||j|
<y||j
|<Wq@tk
r�Yq@Xq@WxldD]d}	t||	�}t�|	d�}t||	d�}|dk	r�||kr�t||	|�q�q�Wtdk	r0|r!||_ntj|_n|S)Ncsi|]}�||�qSr
r
)�.0�k)�	classdictr
r�
<dictcomp>cs	z$EnumMeta.__new__.<locals>.<dictcomp>�mrozInvalid enum member name: {0}�,r!�__getnewargs_ex__�__getnewargs__�
__reduce__c3s|]}|�jkVqdS)N)�__dict__)r6�m)�member_typer
r�	<genexpr>�sz#EnumMeta.__new__.<locals>.<genexpr>�_value_�__repr__�__str__�
__format__)r<z__getnewargs__�
__reduce_ex__z
__reduce__)z__repr__z__str__z
__format__rG)�_get_mixins_�
_find_new_r(�setr*�format�joinr&�__new__�_member_names_r�_member_map_�
_member_type_�_value2member_map_�object�anyr$�
isinstance�tuplerrC�_name_�__objclass__r'�itemsr+r�getattr�setattrr�__new_member__)r3r#r4r8�
first_enumrM�save_new�use_args�membersrZ
invalid_names�
enum_class�methods�member_namer.�argsZenum_memberZcanonical_memberZclass_methodZ
obj_methodZenum_method)r))r8rArrMXsx				
			


	
zEnumMeta.__new__cCsdS)z6
        classes/types should always be True.
        Tr
)rr
r
r�__bool__�szEnumMeta.__bool__N�module�qualname�typec	Cs>|dkr|j||�S|j||d|d|d|�S)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 1), 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.

        Nrerfrg)rM�_create_)r#r.�namesrerfrgr
r
r�__call__�szEnumMeta.__call__cCst||�o|j|jkS)N)rTrVrO)r#�memberr
r
r�__contains__�szEnumMeta.__contains__cs9||jkr%td|j��nt�j|�dS)Nz%s: cannot delete Enum member.)rO�AttributeErrorr/r&�__delattr__)r#�attr)r)r
rrn�szEnumMeta.__delattr__cCsddddg|jS)Nr)r1�__members__r")rN)rr
r
r�__dir__�szEnumMeta.__dir__cCsRt|�rt|��ny|j|SWn!tk
rMt|�d�YnXdS)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)rrmrO�KeyError)r#rr
r
r�__getattr__�s	
zEnumMeta.__getattr__cCs|j|S)N)rO)r#rr
r
r�__getitem__szEnumMeta.__getitem__cs�fdd��jD�S)Nc3s|]}�j|VqdS)N)rO)r6r)r#r
rrBsz$EnumMeta.__iter__.<locals>.<genexpr>)rN)r#r
)r#r�__iter__
szEnumMeta.__iter__cCs
t|j�S)N)rrN)r#r
r
r�__len__
szEnumMeta.__len__cCs
t|j�S)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.

        )rrO)r#r
r
rrpszEnumMeta.__members__cCsd|jS)Nz	<enum %r>)r/)r#r
r
rrDszEnumMeta.__repr__cs �fdd�t�j�D�S)Nc3s|]}�j|VqdS)N)rO)r6r)r#r
rrBsz(EnumMeta.__reversed__.<locals>.<genexpr>)�reversedrN)r#r
)r#r�__reversed__szEnumMeta.__reversed__csG|jjdi�}||kr0td��nt�j||�dS)z�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.

        rOzCannot reassign members.N)r?�getrmr&�__setattr__)r#rr.Z
member_map)r)r
rrz szEnumMeta.__setattr__cCs�|j}|dkr|fn	||f}|j||�}t|t�rf|jdd�j�}nt|ttf�r�t|dt�r�dd�t|d�D�}nxG|D]?}	t|	t�r�|	||	}
}n|	\}
}|||
<q�W|j	||||�}|dkrfyt
jd�jd	}Wqft
tfk
rb}
zWYdd}
~
XqfXn|dkrt|�n	||_|dk	r�||_n|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.

        Nr;� rcSs"g|]\}}||f�qSr
r
)r6�i�er
r
r�
<listcomp>As	z%EnumMeta._create_.<locals>.<listcomp>rrr/)r)r5rT�str�replace�splitrU�list�	enumeraterM�sys�	_getframe�	f_globalsrmr*r$r"r0)r#Z
class_namerirerfrgr3r4r8�itemrbZmember_valuer`�excr
r
rrh-s0	!(

	zEnumMeta._create_cCs|sttfSd}}xA|D]9}|tk	r!t|t�r!|jr!td��q!q!Wt|t�s|td��nt|dt�s�|d}|d}nTxQ|djD]B}t|t�r�|dkr�|}q�q�|dkr�|}q�q�W||fS)z�Returns the type for creating enum members, and the first inherited
        enum class.

        bases: the tuple of bases that was given to __new__

        NzCannot extend enumerationszHnew enumerations must be created as `ClassName([mixin_type,] enum_type)`rrr)rRr�
issubclassrNr�__mro__)r4rAr\�baser
r
rrH\s(


	


zEnumMeta._get_mixins_c	Cs�|jdd�}|dk	}|dkr�x~dD]j}xQ||fD]C}t||d�}|ddjtjtjhkrD|}PqDqDW|dk	r1Pq1q1Wtj}n|tjkr�d}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__

        rMNr[FT)z__new_member__z__new__)ryrYrMrRr)	r8rAr\rMr]�methodZpossible�targetr^r
r
rrI�s(
	zEnumMeta._find_new_)r/r"r0r1�classmethodr5rMrdrjrlrnrqrsrtrurv�propertyrprDrxrzrh�staticmethodrHrIr
r
)r)rr2Rs&l!

!/-r2c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
edd��Zedd��Z
eddd��ZdS)rzRGeneric enumeration.

    Derive from this class to define new enumerations.

    cCs�t|�|kr|Sy||jkr3|j|SWn?tk
rux*|jj�D]}|j|krT|SqTWYnXtd||jf��dS)Nz%r is not a valid %s)rgrQrrO�valuesrCr*r/)r#r.rkr
r
rrM�s

zEnum.__new__cCsd|jj|j|jfS)Nz<%s.%s: %r>)r)r/rVrC)rr
r
rrD�sz
Enum.__repr__cCsd|jj|jfS)Nz%s.%s)r)r/rV)rr
r
rrE�szEnum.__str__cCs3dd�|jj�D�}dddddg|S)NcSs6g|],}|jD]}|ddkr|�qqS)rr)r?)r6r#r@r
r
rr~�s	
z Enum.__dir__.<locals>.<listcomp>r)r1r"rr.)r)r:)rZadded_behaviorr
r
rrq�s	zEnum.__dir__cCsF|jtkr$t}t|�}n|j}|j}|j||�S)N)rPrRrrCrF)rZformat_specr#�valr
r
rrF�s		zEnum.__format__cCs
t|j�S)N)�hashrV)rr
r
r�__hash__�sz
Enum.__hash__cCs|j|jffS)N)r)rC)rrr
r
rr!�szEnum.__reduce_ex__cCs|jS)zThe name of the Enum member.)rV)rr
r
rr�sz	Enum.namecCs|jS)zThe value of the Enum member.)rC)rr
r
rr.sz
Enum.valueNcs�ttj|�}|r(t|�}n|}�fdd�|j�D�}|||d|�}t|_|j|j�|||<|S)z[
        Create a new Enum subclass that replaces a collection of global constants
        cs+i|]!\}}�|�r||�qSr
r
)r6rr.)�filterr
rr9s		z!Enum._convert.<locals>.<dictcomp>re)�varsr��modulesrX�_reduce_ex_by_namer!�updaterp)r#rrer��source�module_globalsr_r
)r�r�_converts
	
z
Enum._convert)r/r"r0r1rMrDrErqrFr�r!rrr.r�r�r
r
r
rr�s

�	metaclassc@seZdZdZdS)rz.Enum where members are also (and must be) intsN)r/r"r0r1r
r
r
rr scCs|jS)N)r)rrr
r
rr�$sr�cCs�g}xE|jj�D]4\}}||jkr|j||jf�qqW|r�djdd�|D��}td||f��n|S)z?Class decorator for enumerations ensuring unique member values.z, cSs&g|]\}}d||f�qS)z%s -> %sr
)r6�aliasrr
r
rr~/s	zunique.<locals>.<listcomp>z duplicate values found in %r: %s)rprXrr+rLr*)ZenumerationZ
duplicatesrrkZ
alias_detailsr
r
rr's)r��collectionsr�typesrr�__all__rrrr$�dictr%rrgr2�intrr�rr
r
r
r�<module>s'�gh

?>