add-determinism 0.7.3

RPM buildroot helper to strip nondeterministic bits in files
Documentation
3

�
�^F�c@s>ddlZddlmZmZddlmZddlmZyddl	m
Z
Wn ek
r`ddlm
Z
YnXdddd	d
ddgZ
d
d�Zdd�Zdd�Zdd�Ze�ZGdd�d�ZGdd�de�ZdZGdd�de�ZGdd�ded�ZGdd�dee�Zdd�ZGdd	�d	e�ZGdd
�d
ee�Zd d!�Zd"d�Z d#d$�Z!d%d&�Z"dS)'�N)�MappingProxyType�DynamicClassAttribute)�reduce)�or_)�OrderedDict�EnumMeta�Enum�IntEnum�Flag�IntFlag�auto�uniquecCst|d�pt|d�pt|d�S)z5Returns True if obj is a descriptor, False otherwise.Z__get__Z__set__Z
__delete__)�hasattr)Zobj�r�/usr/lib64/python3.6/enum.py�_is_descriptors

rcCsT|dd�|dd�ko"dknoR|dd�dkoR|dd	�dkoRt|�dkS)
z3Returns True if a __dunder__ name, False otherwise.N�Z__i�_i�����i����r��len��namerrr�
_is_dunders(rcCsL|d|dkodknoJ|dd�dkoJ|dd�dkoJt|�dkS)z1Returns True if a _sunder_ name, False otherwise.r�rr�����rrrrrrr�
_is_sunder$s rcCsdd�}||_d|_dS)z"Make the given class un-picklable.cSstd|��dS)Nz%r cannot be pickled)�	TypeError��selfZprotorrr�_break_on_call_reduce-�z6_make_class_unpicklable.<locals>._break_on_call_reducez	<unknown>N)�
__reduce_ex__�
__module__)�clsrrrr�_make_class_unpicklable+sr$c@seZdZdZeZdS)rzP
    Instances are replaced with an appropriate value in Enum class suites.
    N)�__name__r"�__qualname__�__doc__�
_auto_null�valuerrrrr3scs,eZdZdZ�fdd�Z�fdd�Z�ZS)�	_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|_g|_dS�N)�super�__init__�
_member_names�_last_values�r��	__class__rrr-As
z_EnumDict.__init__cs�t|�r.|dkrtd��|dkr�t|d|�n�t|�rD|dkr�d}n�||jkr\td|��nxt|�s�||kr�td	|||f��t|t�r�|j	t
kr�|j|d
t|j�|j
dd��|_	|j	}|jj|�|j
j|�t�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.

        �_order_�_create_pseudo_member_�_generate_next_value_�	_missing_z(_names_ are reserved for future Enum use�_generate_next_valueZ	__order__zAttempted to reuse key: %rz%r already defined as: %rrN)r3r4r5r6)r�
ValueError�setattrrr.rr�
isinstancerr)r(r7rr/�appendr,�__setitem__)r�keyr)r1rrr<Fs,	


"z_EnumDict.__setitem__)r%r"r&r'r-r<�
__classcell__rrr1rr*:sr*cs�eZdZdZedd��Z�fdd�Zdd�Zd)dddd	d
�dd�Zd
d�Z	�fdd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zedd��Zdd�Zdd �Z�fd!d"�Zdddd	d
�d#d$�Zed%d&��Zed'd(��Z�ZS)*rzMetaclass for EnumcCs0t�}|j|�\}}|dk	r,t|dd�|d<|S)Nr5)r*�_get_mixins_�getattr)�metaclsr#�basesZ	enum_dict�member_type�
first_enumrrr�__prepare__rs
zEnumMeta.__prepare__cs�|j|�\�}|j��|�\}}}�fdd��jD�}x�jD]
}	�|	=q>W�jdd�}
t|�dh@}|r~tdjdj|����d�kr�d�d<t�j	|||��}g|_
t�|_�|_
d	d
�|j�D�}
i|_d�k�r�tk	�rd}t�fdd�|D���st|��x6�jD�]*}||}t|t��s0|f}n|}�tk�rD|f}|�sf||�}t|d��s�||_n6||f|��}t|d��s��tk�r�||_n
�|�|_|j}||_||_|j|�x8|jj�D]\}	}|j|jk�r�|}P�q�W|j
j|�||
k�rt|||�||j|<y||j|<Wntk
�r6YnX�qWxPdD]H}	t||	�}t�|	d�}t||	d�}|dk	�rD||k�rDt||	|��qDWtdk	�r�|�r�||_ tj	|_	|
dk	�r�t|
t!��r�|
j"dd�j#�}
|
|j
k�r�td��|S)Ncsi|]}�||�qSrr)�.0�k)�	classdictrrz
<dictcomp>��z$EnumMeta.__new__.<locals>.<dictcomp>r3�mrozInvalid enum member name: {0}�,r'zAn enumeration.cSs.h|]&}|jj�D]\}}t|t�r|�qqSr)�__dict__�itemsr:r)rFZcrG�vrrrz	<setcomp>�sz#EnumMeta.__new__.<locals>.<setcomp>r!�__getnewargs_ex__�__getnewargs__�
__reduce__c3s|]}|�jkVqdSr+)rL�rF�m)rCrr�	<genexpr>��z#EnumMeta.__new__.<locals>.<genexpr>�_value_�__repr__�__str__�
__format__� z#member order does not match _order_)rOrPr!rQ)rWrXrYr!)$r?�
_find_new_r.�popZsetr8Zformat�joinr,�__new__�_member_names_r�_member_map_�
_member_type_rJ�_value2member_map_�objectZanyr$r:�tupler
rV�_name_Z__objclass__r-rMr;r9rr@r�__new_member__�str�replace�split)rAr#rBrHrDr^�save_new�use_argsZenum_membersrr3Z
invalid_names�
enum_classZdynamic_attributesZmethods�member_namer)ZargsZenum_memberZcanonical_memberZclass_methodZ
obj_methodZenum_methodr1)rHrCrr^|s�












zEnumMeta.__new__cCsdS)z6
        classes/types should always be True.
        Trr0rrr�__bool__szEnumMeta.__bool__Nr��module�qualname�type�startcCs*|dkr|j||�S|j||||||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 `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.

        Nro)r^�_create_)r#r)�namesrprqrrrsrrr�__call__szEnumMeta.__call__cCst||�o|j|jkSr+)r:rer`)r#�memberrrr�__contains__)r zEnumMeta.__contains__cs(||jkrtd|j��t�j|�dS)Nz%s: cannot delete Enum member.)r`�AttributeErrorr%r,�__delattr__)r#Zattrr1rrrz,s
zEnumMeta.__delattr__cCsddddg|jS)Nr2r'�__members__r"�r_r0rrr�__dir__4s
zEnumMeta.__dir__cCs>t|�rt|��y
|j|Stk
r8t|�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)rryr`ZKeyError�r#rrrr�__getattr__8s	
zEnumMeta.__getattr__cCs
|j|Sr+�r`r~rrr�__getitem__Hr zEnumMeta.__getitem__cs�fdd��jD�S)Nc3�|]}�j|VqdSr+r��rFr�r#rrrTLrUz$EnumMeta.__iter__.<locals>.<genexpr>r|r�rr�r�__iter__Kr zEnumMeta.__iter__cC�
t|j�Sr+)rr_r�rrr�__len__Nr zEnumMeta.__len__cCr�)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.

        )rr`r�rrrr{QszEnumMeta.__members__cCs
d|jS)Nz	<enum %r>)r%r�rrrrW[r zEnumMeta.__repr__cs�fdd�t�j�D�S)Nc3r�r+r�r�r�rrrT_rUz(EnumMeta.__reversed__.<locals>.<genexpr>)�reversedr_r�rr�r�__reversed__^r zEnumMeta.__reversed__cs0|jjdi�}||krtd��t�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.

        r`zCannot reassign members.N)rL�getryr,�__setattr__)r#rr)Z
member_mapr1rrr�aszEnumMeta.__setattr__cCs�|j}|dkr|fn||f}|j|�\}	}
|j||�}t|t�rP|jdd�j�}t|ttf�r�|r�t|dt�r�|g}}g}
xDt	|�D]8\}}|
j
||||
dd��}|
j|�|j||f�q�Wx6|D].}t|t�r�|||}}n|\}}|||<q�W|j||||�}|dk�rTyt
jd�jd}Wn(ttfk
�rR}zWYdd}~XnX|dk�rht|�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 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.

        NrKrZrrr%)r2r?rEr:rgrhrird�listZ	enumerater5r;r^�sysZ	_getframeZ	f_globalsryr8r$r"r&)r#Z
class_namerurprqrrrsrArBrrDrHZoriginal_names�last_values�countrr)Zitemrm�member_valuerlZexcrrrrtns<
 







zEnumMeta._create_cCs�|sttfSd}}x,|D]$}|tk	rt|t�r|jrtd��qWt|t�sTtd��t|dt�st|d}|d}n8x6|djD](}t|t�r�|dkr�|}q�|dkr�|}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)rcrZ
issubclassr_rZ__mro__)rBrCrDZbaserrrr?�s(




zEnumMeta._get_mixins_c	Cs�|jdd�}|dk	}|dkrtxVdD]H}x8||fD],}t||d�}|ddjtjtjhkr0|}Pq0W|dk	r"Pq"Wtj}|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__

        r^NrfFT)rfr^)r�r@r^rcr)	rHrCrDr^rjZmethodZpossibleZtargetrkrrrr[�s(


zEnumMeta._find_new_r+)r%r"r&r'�classmethodrEr^rnrvrxrzr}rr�r�r�Zpropertyr{rWr�r�rtZstaticmethodr?r[r>rrr1rrps(



5-c@s�eZdZdZdd�Zdd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
edd��Zedd��Zeddd��ZdS)rzRGeneric enumeration.

    Derive from this class to define new enumerations.

    cCsjt|�|kr|Sy||jkr&|j|SWn6tk
r^x |jj�D]}|j|krD|SqDWYnX|j|�Sr+)rrrbrr`ZvaluesrVr6)r#r)rwrrrr^s

zEnum.__new__cCs8x2t|�D]"}y|dStk
r*Yq
Xq
W|SdS)Nr)r�r)rrsr�r��
last_valuerrrr5s
zEnum._generate_next_value_cCstd||jf��dS�N�%r is not a valid %s)r8r%)r#r)rrrr6"�zEnum._missing_cCsd|jj|j|jfS)N�<%s.%s: %r>)r2r%rerVr0rrrrW&sz
Enum.__repr__cCsd|jj|jfS)N�%s.%s)r2r%rer0rrrrX*r zEnum.__str__cs&�fdd��jj�D�}dddg|S)Ncs2g|]*}|jD]}|ddkr|�jkr|�qqS)rr)rLr`)rFr#rSr0rr�
<listcomp>/s
z Enum.__dir__.<locals>.<listcomp>r2r'r")r2rJ)rZadded_behaviorrr0rr}-s
zEnum.__dir__cCs0|jtkrt}t|�}n|j}|j}|j||�Sr+)rarcrgrVrY)rZformat_specr#ZvalrrrrY6s

zEnum.__format__cCr�r+)Zhashrer0rrr�__hash__Er z
Enum.__hash__cCs|j|jffSr+�r2rVrrrrr!Hr zEnum.__reduce_ex__cC�|jS)zThe name of the Enum member.)rer0rrrrR�z	Enum.namecCr�)zThe value of the Enum member.�rVr0rrrr)Wr�z
Enum.valueNc
s�ttj|�}�rt���n|���fdd��j�D�}y|jdd�d�Wn$tk
rp|jdd�d�YnX||||d�}t|_|j|j	�|||<|S)z[
        Create a new Enum subclass that replaces a collection of global constants
        cs g|]}�|�r|�|f�qSrrr���filter�sourcerrr�qsz!Enum._convert.<locals>.<listcomp>cSs|d|dfS)Nrrr�Ztrrr�<lambda>v�zEnum._convert.<locals>.<lambda>)r=cSs|dS�Nrrr�rrrr�yr�)rp)
Zvarsr�ZmodulesZkeys�sortr�_reduce_ex_by_namer!Zupdater{)r#rrpr�r�Zmodule_globals�membersrr�r�_convert\s

z
Enum._convertr+)r%r"r&r'r^r5r�r6rWrXr}rYr�r!rrr)r�rrrrr�s		
)Z	metaclassc@seZdZdZdS)rz.Enum where members are also (and must be) intsN)r%r"r&r'rrrrr�scCr�r+rrrrrr��r r�c@speZdZdZdd�Zedd��Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)r	zSupport for flagscCsd|s|dk	r|SdSxBt|�D]6}yt|�}PWqtk
rRtd|�d�YqXqWd|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
        NrzInvalid Flag value: %rr)r��	_high_bitZ	Exceptionr)rrsr�r�r�Zhigh_bitrrrr5�s	zFlag._generate_next_value_cCs.|}|dkr|}|j|�}|dkr*|}|Sr�)r4)r#r)Zoriginal_valueZpossible_memberrrrr6�s
zFlag._missing_cCsb|jj|d�}|dkr^t||�\}}|r:td||jf��tj|�}d|_||_|jj	||�}|S)zL
        Create a composite member iff value contains only members.
        Nr�)
rbr��
_decomposer8r%rcr^rerV�
setdefault)r#r)�
pseudo_memberr�extra_flagsrrrr4�s
zFlag._create_pseudo_member_cCs"t||j�stS|j|j@|jkSr+�r:r2�NotImplementedrV�r�otherrrrrx��zFlag.__contains__cCsV|j}|jdk	r$d|j|j|jfSt||j�\}}d|jdjdd�|D��|jfS)Nr��|cS�g|]}t|jp|j��qSr�rgrerVrRrrrr��rIz!Flag.__repr__.<locals>.<listcomp>)r2rer%rVr�r]�rr#r��	uncoveredrrrrW�s
z
Flag.__repr__cCs�|j}|jdk	r d|j|jfSt||j�\}}t|�dkr^|djdkr^d|j|djfSd|jdjdd�|D��fSdS)Nr�rrz%s.%rr�cSr�rr�rRrrrr��rIz Flag.__str__.<locals>.<listcomp>)r2rer%r�rVrr]r�rrrrX�s
zFlag.__str__cCr�r+)ZboolrVr0rrrrn�r z
Flag.__bool__cCs"t||j�stS|j|j|jB�Sr+r�r�rrr�__or__�r�zFlag.__or__cCs"t||j�stS|j|j|j@�Sr+r�r�rrr�__and__�r�zFlag.__and__cCs"t||j�stS|j|j|jA�Sr+r�r�rrr�__xor__�r�zFlag.__xor__csDt�j�j�\�}��fdd��jD�}tt|�jd��}�j|�S)Ncs&g|]}|�kr|j�j@r|�qSrr�rR�r�rrrr��sz#Flag.__invert__.<locals>.<listcomp>r)r�r2rVr�_or_)rr�Zinverted_membersZinvertedrr�r�
__invert__�szFlag.__invert__N)r%r"r&r'r5r�r6r4rxrWrXrnr�r�r�r�rrrrr	�s

c@sTeZdZdZedd��Zedd��Zdd�Zdd	�Zd
d�Z	eZ
eZe	Zdd
�Z
dS)r
zSupport for integer-based FlagscCs*t|t�std||jf��|j|�}|Sr�)r:�intr8r%r4)r#r)Z
new_memberrrrr6�s

zIntFlag._missing_cCs�|jj|d�}|dkr�|g}t||�\}}xL|rvt|�}d|}||jkr\||kr\|j|�||krld}q,||N}q,Wx6t|�D]*}tj||�}d|_||_	|jj
||�}q�W|S)Nrr)rbr�r�r�r;r�r�r^rerVr�)r#r)r�Zneed_to_createrr�ZbitZ
flag_valuerrrr4�s&


zIntFlag._create_pseudo_member_cCs0t||jtf�stS|j|j|j|�jB�}|Sr+�r:r2r�r�rV)rr��resultrrrr�szIntFlag.__or__cCs,t||jtf�stS|j|j|j|�j@�Sr+r�r�rrrr�#�zIntFlag.__and__cCs,t||jtf�stS|j|j|j|�jA�Sr+r�r�rrrr�(r�zIntFlag.__xor__cCs|j|j�}|Sr+r�)rr�rrrr�1szIntFlag.__invert__N)r%r"r&r'r�r6r4r�r�r�Z__ror__Z__rand__Z__rxor__r�rrrrr
�scCs|j�dS)z@returns index of highest bit, or -1 if value is zero or negativer)Z
bit_length�r)rrrr�6r�r�cCsbg}x0|jj�D]"\}}||jkr|j||jf�qW|r^djdd�|D��}td||f��|S)z?Class decorator for enumerations ensuring unique member values.z, cSsg|]\}}d||f�qS)z%s -> %sr)rFZaliasrrrrr�BrIzunique.<locals>.<listcomp>z duplicate values found in %r: %s)r{rMrr;r]r8)ZenumerationZ
duplicatesrrwZ
alias_detailsrrrr:s
cCs�|}|dk}|r*dd�t|jj��D�}ndd�t|jj��D�}g}x4|D],\}}|rL||@|krL|j|�||M}qLW|r�||jkr�|j|j|�|jdd�dd�t|�d	kr�|dj|kr�|jd�||fS)
z#Extract all members from the value.rcSs"g|]\}}|jdk	r||f�qSr+r�rFrNrSrrrr�R�z_decompose.<locals>.<listcomp>cSs*g|]"\}}|jdk	st|�r||f�qSr+)r�
_power_of_twor�rrrr�Yr�cSr�r+r�)rSrrrr�dr�z_decompose.<locals>.<lambda>T)r=Zreverser)r�rbrMr;r�rr)r\)Zflagr)Znot_coveredZnegativeZflags_to_checkr�rwr�rrrr�Gs$

r�cCs|dkrdS|dt|�kS)NrFr)r�r�rrrr�jsr�)#r�ZtypesrrZ	functoolsrZoperatorrr�Z_collectionsrZImportErrorZcollectionsZ__all__rrrr$rcr(rZdictr*rrrrr�rr�r	r
r�rr�r�rrrrZ<module>s@3mA
#