CasperSecurity

Current Path : /lib/python3/dist-packages/constantly/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/constantly/__pycache__/_constants.cpython-310.pyc

o

?f�U�>�@sdZddlmZmZgd�ZddlmZddlmZddl	m
Z
mZmZe
�Zeee��ZGdd�de
�ZGd	d
�d
e�ZGdd�ded
e
fi��ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�ZGdd�de�ZGdd�de�ZdS)zi
Symbolic constant support, including collections and constants with text,
numeric, and bit flag values.
�)�division�absolute_import)�
NamedConstant�
ValueConstant�FlagConstant�Names�Values�Flags)�partial)�count)�and_�or_�xorc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�	_Constanta�
    @ivar _index: A C{int} allocated from a shared counter in order to keep
        track of the order in which L{_Constant}s are instantiated.

    @ivar name: A C{str} giving the name of this constant; only set once the
        constant is initialized by L{_ConstantsContainer}.

    @ivar _container: The L{_ConstantsContainer} subclass this constant belongs
        to; C{None} until the constant is initialized by that subclass.
    cCsd|_t�|_dS�N)�
_container�_constantOrder�_index��self�r�7/usr/lib/python3/dist-packages/constantly/_constants.py�__init__#sz_Constant.__init__cCsd|jj|jfS)zq
        Return text identifying both which constant this is and which
        collection it belongs to.
        z<%s=%s>)r�__name__�namerrrr�__repr__(sz_Constant.__repr__cCs(t||j�r|j|jkstS|j|jkS)aC
        Implements C{<}.  Order is defined by instantiation order.

        @param other: An object.

        @return: C{NotImplemented} if C{other} is not a constant belonging to
            the same container as this constant, C{True} if this constant is
            defined before C{other}, otherwise C{False}.
        ��
isinstance�	__class__r�NotImplementedr�r�otherrrr�__lt__0�

�z_Constant.__lt__cCs0t||j�r|j|jkstS||up|j|jkS)aP
        Implements C{<=}.  Order is defined by instantiation order.

        @param other: An object.

        @return: C{NotImplemented} if C{other} is not a constant belonging to
            the same container as this constant, C{True} if this constant is
            defined before or equal to C{other}, otherwise C{False}.
        rr rrr�__le__B�

�z_Constant.__le__cCs(t||j�r|j|jkstS|j|jkS)aB
        Implements C{>}.  Order is defined by instantiation order.

        @param other: An object.

        @return: C{NotImplemented} if C{other} is not a constant belonging to
            the same container as this constant, C{True} if this constant is
            defined after C{other}, otherwise C{False}.
        rr rrr�__gt__Tr#z_Constant.__gt__cCs0t||j�r|j|jkstS||up|j|jkS)aO
        Implements C{>=}.  Order is defined by instantiation order.

        @param other: An object.

        @return: C{NotImplemented} if C{other} is not a constant belonging to
            the same container as this constant, C{True} if this constant is
            defined after or equal to C{other}, otherwise C{False}.
        rr rrr�__ge__fr%z_Constant.__ge__cCs||_||_dS)ao
        Complete the initialization of this L{_Constant}.

        @param container: The L{_ConstantsContainer} subclass this constant is
            part of.

        @param name: The name of this constant in its container.

        @param value: The value of this constant; not used, as named constants
            have no value apart from their identity.
        N)rr)r�	containerr�valuerrr�_realizexs
z_Constant._realizeN)r�
__module__�__qualname__�__doc__rrr"r$r&r'r*rrrrrs
rcs eZdZdZ�fdd�Z�ZS)�_ConstantsContainerTypeza
    L{_ConstantsContainerType} is a metaclass for creating constants container
    classes.
    cs�tt|��||||�}t|dd�}|dur|Sg}|��D]!\}}t||j�r>|jdur5td||j	f��|�
|j||f�qi}t|�D]\}	}
}|�
|
|�}|�||
|�|||
<qE||_|S)a�
        Create a new constants container class.

        If C{attributes} includes a value of C{None} for the C{"_constantType"}
        key, the new class will not be initialized as a constants container and
        it will behave as a normal class.

        @param name: The name of the container class.
        @type name: L{str}

        @param bases: A tuple of the base classes for the new container class.
        @type bases: L{tuple} of L{_ConstantsContainerType} instances

        @param attributes: The attributes of the new container class, including
            any constants it is to contain.
        @type attributes: L{dict}
        �
_constantTypeNz0Cannot use %s as the value of an attribute on %s)�superr.�__new__�getattr�itemsrr/r�
ValueErrorr�appendr�sorted�_constantFactoryr*�_enumerants)rr�bases�
attributes�cls�constantType�	constants�
descriptor�
enumerants�index�	enumerantr)�rrrr1�s0
�
���
z_ConstantsContainerType.__new__)rr+r,r-r1�
__classcell__rrrBrr.�sr.c@s@eZdZdZdZdd�Zedd��Zedd��Zed	d
��Z	dS)�_ConstantsContainera�
    L{_ConstantsContainer} is a class with attributes used as symbolic
    constants.  It is up to subclasses to specify what kind of constants are
    allowed.

    @cvar _constantType: Specified by a L{_ConstantsContainer} subclass to
        specify the type of constants allowed by that subclass.

    @cvar _enumerants: A C{dict} mapping the names of constants (eg
        L{NamedConstant} instances) found in the class definition to those
        instances.
    NcCstd|jf��)z�
        Classes representing constants containers are not intended to be
        instantiated.

        The class object itself is used directly.
        z%s may not be instantiated.)�	TypeErrorr)r;rrrr1�sz_ConstantsContainer.__new__cCstS)a�
        Construct the value for a new constant to add to this container.

        @param name: The name of the constant to create.

        @param descriptor: An instance of a L{_Constant} subclass (eg
            L{NamedConstant}) which is assigned to C{name}.

        @return: L{NamedConstant} instances have no value apart from identity,
            so return a meaningless dummy value.
        )�_unspecified)r;rr>rrrr7�s
z$_ConstantsContainer._constantFactorycCs||jvr
t||�St|��)a�
        Retrieve a constant by its name or raise a C{ValueError} if there is no
        constant associated with that name.

        @param name: A C{str} giving the name of one of the constants defined
            by C{cls}.

        @raise ValueError: If C{name} is not the name of one of the constants
            defined by C{cls}.

        @return: The L{NamedConstant} associated with C{name}.
        )r8r2r4)r;rrrr�lookupByName�s

z _ConstantsContainer.lookupByNamecCs|j��}tt|dd�d��S)z�
        Iteration over a L{Names} subclass results in all of the constants it
        contains.

        @return: an iterator the elements of which are the L{NamedConstant}
            instances defined in the body of this L{Names} subclass.
        cSs|jSr)r)r>rrr�<lambda>sz3_ConstantsContainer.iterconstants.<locals>.<lambda>)�key)r8�values�iterr6)r;r=rrr�
iterconstantss
	�z!_ConstantsContainer.iterconstants)
rr+r,r-r/r1�classmethodr7rGrLrrrrrD�s



rD�c@seZdZdZdS)ra
    L{NamedConstant} defines an attribute to be a named constant within a
    collection defined by a L{Names} subclass.

    L{NamedConstant} is only for use in the definition of L{Names}
    subclasses.  Do not instantiate L{NamedConstant} elsewhere and do not
    subclass it.
    N)rr+r,r-rrrrrsrc@seZdZdZeZdS)rze
    A L{Names} subclass contains constants which differ only in their names and
    identities.
    N)rr+r,r-rr/rrrrr!src@seZdZdZdd�ZdS)ra
    L{ValueConstant} defines an attribute to be a named constant within a
    collection defined by a L{Values} subclass.

    L{ValueConstant} is only for use in the definition of L{Values} subclasses.
    Do not instantiate L{ValueConstant} elsewhere and do not subclass it.
    cC�t�|�||_dSr�rrr)�rr)rrrr2�

zValueConstant.__init__N)rr+r,r-rrrrrr*src@s eZdZdZeZedd��ZdS)rza
    A L{Values} subclass contains constants which are associated with arbitrary
    values.
    cCs(|��D]}|j|kr|Sqt|��)a�
        Retrieve a constant by its value or raise a C{ValueError} if there is
        no constant associated with that value.

        @param value: The value of one of the constants defined by C{cls}.

        @raise ValueError: If C{value} is not the value of one of the constants
            defined by C{cls}.

        @return: The L{ValueConstant} associated with C{value}.
        )rLr)r4)r;r)�constantrrr�
lookupByValue?s

�zValues.lookupByValueN)rr+r,r-rr/rMrTrrrrr8s
rcCs6||j|j�}||j|j�}t�}|�|j||�|S)a�
    Implement a binary operator for a L{FlagConstant} instance.

    @param op: A two-argument callable implementing the binary operation.  For
        example, C{operator.or_}.

    @param left: The left-hand L{FlagConstant} instance.
    @param right: The right-hand L{FlagConstant} instance.

    @return: A new L{FlagConstant} instance representing the result of the
        operation.
    )r)�namesrr*r)�op�left�rightr)rU�resultrrr�_flagOpSs

rZc@s`eZdZdZefdd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
e
ZdS)ra
    L{FlagConstant} defines an attribute to be a flag constant within a
    collection defined by a L{Flags} subclass.

    L{FlagConstant} is only for use in the definition of L{Flags} subclasses.
    Do not instantiate L{FlagConstant} elsewhere and do not subclass it.
    cCrOrrPrQrrrrprRzFlagConstant.__init__cCsdt|t�r
|}t|g�}nt|�dkr|\}ndd�t|��d}t�||||�||_||_	dS)aR
        Complete the initialization of this L{FlagConstant}.

        This implementation differs from other C{_realize} implementations in
        that a L{FlagConstant} may have several names which apply to it, due to
        flags being combined with various operators.

        @param container: The L{Flags} subclass this constant is part of.

        @param names: When a single-flag value is being initialized, a C{str}
            giving the name of that flag.  This is the case which happens when
            a L{Flags} subclass is being initialized and L{FlagConstant}
            instances from its body are being realized.  Otherwise, a C{set} of
            C{str} giving names of all the flags set on this L{FlagConstant}
            instance.  This is the case when two flags are combined using C{|},
            for example.
        ��{�,�}N)
r�str�set�len�joinr6rr*r)rU)rr(rUr)rrrrr*us

zFlagConstant._realizecC�tt||�S)z�
        Define C{|} on two L{FlagConstant} instances to create a new
        L{FlagConstant} instance with all flags set in either instance set.
        )rZr
r rrr�__or__��zFlagConstant.__or__cCrc)z�
        Define C{&} on two L{FlagConstant} instances to create a new
        L{FlagConstant} instance with only flags set in both instances set.
        )rZrr rrr�__and__�rezFlagConstant.__and__cCrc)z�
        Define C{^} on two L{FlagConstant} instances to create a new
        L{FlagConstant} instance with only flags set on exactly one instance
        set.
        )rZrr rrr�__xor__�szFlagConstant.__xor__cCsDt�}|�|jt�d�|j��D]}|j|j@dkr||O}q|S)z�
        Define C{~} on a L{FlagConstant} instance to create a new
        L{FlagConstant} instance with all flags not set on this instance set.
        r)rr*rr`rLr))rrY�flagrrr�
__invert__�s�zFlagConstant.__invert__cs�fdd��jD�S)zI
        @return: An iterator of flags set on this instance set.
        c3s�|]	}�j�|�VqdSr)rrG)�.0rrrr�	<genexpr>�s�z(FlagConstant.__iter__.<locals>.<genexpr>)rUrrrr�__iter__�szFlagConstant.__iter__cCst||@�S)z�
        @param flag: The flag to test for membership in this instance
            set.

        @return: C{True} if C{flag} is in this instance set, else
            C{False}.
        )�bool)rrhrrr�__contains__�s	zFlagConstant.__contains__cCs
t|j�S)zL
        @return: C{False} if this flag's value is 0, else C{True}.
        )rmr)rrrr�__nonzero__�s
zFlagConstant.__nonzero__N)rr+r,r-rFrr*rdrfrgrirlrnro�__bool__rrrrrhs	
rc@s$eZdZdZeZdZedd��ZdS)r	z�
    A L{Flags} subclass contains constants which can be combined using the
    common bitwise operators (C{|}, C{&}, etc) similar to a I{bitvector} from a
    language like C.
    r[cCs6|jtur|j}|jdK_|S|j}|d>|_|S)a

        For L{FlagConstant} instances with no explicitly defined value, assign
        the next power of two as its value.

        @param name: The name of the constant to create.

        @param descriptor: An instance of a L{FlagConstant} which is assigned
            to C{name}.

        @return: Either the value passed to the C{descriptor} constructor, or
            the next power of 2 value which will be assigned to C{descriptor},
            relative to the value of the last defined L{FlagConstant}.
        r[)r)rF�_value)r;rr>r)rrrr7�s
�
zFlags._constantFactoryN)	rr+r,r-rr/rqrMr7rrrrr	�sr	N)r-�
__future__rr�__all__�	functoolsr
�	itertoolsr�operatorrr
r�objectrF�nextrr�typer.rDrrrrrZrr	rrrr�<module>s$q?M	m
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY