a
    dbOP                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ g dZ	G dd	 d	e
ZG d
d deZG dd de
Ze ZG dd deZG dd deZdS )    N)error)calling)
constraint)tag)tagmap)Asn1ItemAsn1ItemBaseAbstractSimpleAsn1ItemAbstractConstructedAsn1Itemc                   @   s   e Zd ZedddZdS )r      c                 C   s2   zt  j|7  _W n ty*   |t _Y n0 t jS N)r   Z_typeCounterAttributeError)cls	increment r   a/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/pyasn1/type/base.py	getTypeId   s
    zAsn1Item.getTypeIdN)r   )__name__
__module____qualname__classmethodr   r   r   r   r   r      s   r   c                   @   s   e Zd Ze Ze ZdZ	dd Z
dd Zdd Zedd	 Zed
d Zedd Zd"ddZd#ddZedd Zd$ddZdd Zdd Zdd Zdd Zd d! ZdS )%r   Nc                 K   s.   | j | jd}|| | j| || _d S )NtagSetsubtypeSpec)r   r   update__dict__	_readOnlyselfkwargsreadOnlyr   r   r   __init__(   s    
zAsn1ItemBase.__init__c                 C   s2   |d dkr$|| j v r$td| || j|< d S )Nr   _z!read-only instance attribute "%s")r   r   PyAsn1Errorr   )r   namevaluer   r   r   __setattr__4   s    zAsn1ItemBase.__setattr__c                 C   s   |   S r   )prettyPrintr   r   r   r   __str__:   s    zAsn1ItemBase.__str__c                 C   s   | j S r   )r   r(   r   r   r   r    =   s    zAsn1ItemBase.readOnlyc                 C   s   | j S )z3For |ASN.1| type is equivalent to *tagSet*
        r   r(   r   r   r   effectiveTagSetA   s    zAsn1ItemBase.effectiveTagSetc                 C   s   t | j| iS )zvReturn a :class:`~pyasn1.type.tagmap.TagMap` object mapping ASN.1 tags to ASN.1 objects within callee object.
        )r   ZTagMapr   r(   r   r   r   tagMapG   s    zAsn1ItemBase.tagMapTc                 C   s,   | |u p*| s| j |j ko*| p*| j|jkS )aC  Examine |ASN.1| type for equality with other ASN.1 type.

        ASN.1 tags (:py:mod:`~pyasn1.type.tag`) and constraints
        (:py:mod:`~pyasn1.type.constraint`) are examined when carrying
        out ASN.1 types comparison.

        Python class inheritance relationship is NOT considered.

        Parameters
        ----------
        other: a pyasn1 type object
            Class instance representing ASN.1 type.

        Returns
        -------
        : :class:`bool`
            :class:`True` if *other* is |ASN.1| type,
            :class:`False` otherwise.
        r   r   otherZ	matchTagsZmatchConstraintsr   r   r   isSameTypeWithM   s    zAsn1ItemBase.isSameTypeWithc                 C   s(   | p&| j |j o&| p&| j|jS )ap  Examine |ASN.1| type for subtype relationship with other ASN.1 type.

        ASN.1 tags (:py:mod:`~pyasn1.type.tag`) and constraints
        (:py:mod:`~pyasn1.type.constraint`) are examined when carrying
        out ASN.1 types comparison.

        Python class inheritance relationship is NOT considered.

        Parameters
        ----------
            other: a pyasn1 type object
                Class instance representing ASN.1 type.

        Returns
        -------
            : :class:`bool`
                :class:`True` if *other* is a subtype of |ASN.1| type,
                :class:`False` otherwise.
        )r   ZisSuperTagSetOfr   isSuperTypeOfr-   r   r   r   r0   e   s    zAsn1ItemBase.isSuperTypeOfc                  G   s   | D ]}|t ur dS qdS )NFT)noValue)valuesr%   r   r   r   	isNoValue}   s    zAsn1ItemBase.isNoValuer   c                 C   s
   t  d S r   )NotImplementedErrorr   Zscoper   r   r   r'      s    zAsn1ItemBase.prettyPrintc                 C   s   | j S r   r*   r(   r   r   r   	getTagSet   s    zAsn1ItemBase.getTagSetc                 C   s   | j S r   )r+   r(   r   r   r   getEffectiveTagSet   s    zAsn1ItemBase.getEffectiveTagSetc                 C   s   | j S r   )r,   r(   r   r   r   	getTagMap   s    zAsn1ItemBase.getTagMapc                 C   s   | j S r   )r   r(   r   r   r   getSubtypeSpec   s    zAsn1ItemBase.getSubtypeSpecc                 C   s   | j S r   )isValuer(   r   r   r   hasValue   s    zAsn1ItemBase.hasValue)TT)TT)r   )r   r   r   r   ZTagSetr   r   ZConstraintsIntersectionr   ZtypeIdr!   r&   r)   propertyr    r+   r,   r/   r0   staticmethodr3   r'   r6   r7   r8   r9   r;   r   r   r   r   r      s,   






r   c                   @   s4   e Zd ZdZedZdZdd Zdd Zdd	 Z	dS )
NoValueaz  Create a singleton instance of NoValue class.

    The *NoValue* sentinel object represents an instance of ASN.1 schema
    object as opposed to ASN.1 value object.

    Only ASN.1 schema-related operations can be performed on ASN.1
    schema objects.

    Warning
    -------
    Any operation attempted on the *noValue* object will raise the
    *PyAsn1Error* exception.
    )	__slots____getattribute____getattr__r&   __delattr__	__class__r!   __del____new____repr__r   __objclass__Zim_class
__sizeof__
__reduce____reduce_ex____getnewargs____getinitargs____getstate____setstate__Nc                    s\    j d u rVdd } fddttttfD }t|D ]}t ||| q4t  _  j S )Nc                    s    fdd}|S )Nc                    s   t d  d S )N/Attempted "%s" operation on ASN.1 schema objectr   r#   )r   argskwr$   r   r   plug   s    z.NoValue.__new__.<locals>.getPlug.<locals>.plugr   )r$   rT   r   rS   r   getPlug   s    z NoValue.__new__.<locals>.getPlugc                    sL   g | ]D}t |D ]6}| jvr|d r|d rtt||r|qqS )__)dirskipMethods
startswithendswithr   callablegetattr).0typr$   r   r   r   
<listcomp>   s   


z#NoValue.__new__.<locals>.<listcomp>)		_instancestrintlistdictsetsetattrobjectrE   )r   rU   Zop_namesr$   r   r_   r   rE      s    


zNoValue.__new__c                 C   s(   || j v rtd| td| d S )NzAttribute %s not presentrO   )rX   r   r   r#   )r   attrr   r   r   rA      s    
zNoValue.__getattr__c                 C   s   d| j jt| f S )Nz<%s object at %s>)rC   r   idr(   r   r   r   rF      s    zNoValue.__repr__)
r   r   r   __doc__rf   rX   ra   rE   rA   rF   r   r   r   r   r>      s   r>   c                   @   s   e Zd ZeZefddZdd Zdd Zdd Zd	d
 Z	dd Z
dd Zdd Zejd dkrhdd Zndd Zdd Zedd ZefddZefddZdd  Zd!d" Zd(d#d$Zd)d%d&Zd'S )*r	   c                 K   s|   t j| fi | |tu r"| j}nP| |}z| | W n6 tjyp   t	 \}}}|d|| j
jf Y n0 || _d S )Nz%s at %s)r   r!   r1   defaultValueprettyInr   r   r#   sysexc_inforC   r   _value)r   r%   r   ZexTypeZexValueZexTbr   r   r   r!      s    
zAbstractSimpleAsn1Item.__init__c                 C   s   d| j j| jrdpdt| f }| j D ]\}}|r*|d||f 7 }q*| jr|  }t|dkr~|d d d |dd   }|d	| 7 }d
| S )N%s %s object at 0x%xr%   schemaz %s %s       z...i payload [%s]<%s>)rC   r   r:   rj   r    itemsr'   lenr   Zrepresentationri   r%   r   r   r   rF      s    zAbstractSimpleAsn1Item.__repr__c                 C   s   | |u rdp| j |kS NTrp   r   r.   r   r   r   __eq__  s    zAbstractSimpleAsn1Item.__eq__c                 C   s
   | j |kS r   r{   r|   r   r   r   __ne__  s    zAbstractSimpleAsn1Item.__ne__c                 C   s
   | j |k S r   r{   r|   r   r   r   __lt__  s    zAbstractSimpleAsn1Item.__lt__c                 C   s
   | j |kS r   r{   r|   r   r   r   __le__  s    zAbstractSimpleAsn1Item.__le__c                 C   s
   | j |kS r   r{   r|   r   r   r   __gt__  s    zAbstractSimpleAsn1Item.__gt__c                 C   s
   | j |kS r   r{   r|   r   r   r   __ge__  s    zAbstractSimpleAsn1Item.__ge__r      c                 C   s   | j r
dpdS NTFr{   r(   r   r   r   __nonzero__  s    z"AbstractSimpleAsn1Item.__nonzero__c                 C   s   | j r
dpdS r   r{   r(   r   r   r   __bool__!  s    zAbstractSimpleAsn1Item.__bool__c                 C   s
   t | jS r   )hashrp   r(   r   r   r   __hash__$  s    zAbstractSimpleAsn1Item.__hash__c                 C   s
   | j tuS )aW  Indicate that |ASN.1| object represents ASN.1 value.

        If *isValue* is `False` then this object represents just ASN.1 schema.

        If *isValue* is `True` then, in addition to its ASN.1 schema features,
        this object can also be used like a Python built-in object (e.g. `int`,
        `str`, `dict` etc.).

        Returns
        -------
        : :class:`bool`
            :class:`False` if object represents just ASN.1 schema.
            :class:`True` if object represents ASN.1 schema and can be used as a normal value.

        Note
        ----
        There is an important distinction between PyASN1 schema and value objects.
        The PyASN1 schema objects can only participate in ASN.1 schema-related
        operations (e.g. defining or testing the structure of the data). Most
        obvious uses of ASN.1 schema is to guide serialisation codecs whilst
        encoding/decoding serialised ASN.1 contents.

        The PyASN1 value objects can **additionally** participate in many operations
        involving regular Python objects (e.g. arithmetic, comprehension etc).
        )rp   r1   r(   r   r   r   r:   '  s    zAbstractSimpleAsn1Item.isValuec                 K   s<   |t u r|s| S | j}| j }|| | j|fi |S )a`  Create a modified version of |ASN.1| schema or value object.

        The `clone()` method accepts the same set arguments as |ASN.1|
        class takes on instantiation except that all arguments
        of the `clone()` method are optional.

        Whatever arguments are supplied, they are used to create a copy
        of `self` taking precedence over the ones used to instantiate `self`.

        Note
        ----
        Due to the immutable nature of the |ASN.1| object, if no arguments
        are supplied, no new |ASN.1| object will be created and `self` will
        be returned instead.
        )r1   rp   r    copyr   rC   )r   r%   r   initilaizersr   r   r   cloneD  s    

zAbstractSimpleAsn1Item.clonec                 K   s   |t u r|s| S | j}| j }|dd}|durD| j||d< |dd}|durh| j||d< | D ]\}}||  |7  < qp| j	|fi |S )a  Create a specialization of |ASN.1| schema or value object.

        The subtype relationship between ASN.1 types has no correlation with
        subtype relationship between Python types. ASN.1 type is mainly identified
        by its tag(s) (:py:class:`~pyasn1.type.tag.TagSet`) and value range
        constraints (:py:class:`~pyasn1.type.constraint.ConstraintsIntersection`).
        These ASN.1 type properties are implemented as |ASN.1| attributes.  

        The `subtype()` method accepts the same set arguments as |ASN.1|
        class takes on instantiation except that all parameters
        of the `subtype()` method are optional.

        With the exception of the arguments described below, the rest of
        supplied arguments they are used to create a copy of `self` taking
        precedence over the ones used to instantiate `self`.

        The following arguments to `subtype()` create a ASN.1 subtype out of
        |ASN.1| type:

        Other Parameters
        ----------------
        implicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Implicitly apply given ASN.1 tag object to `self`'s
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        explicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Explicitly apply given ASN.1 tag object to `self`'s
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Add ASN.1 constraints object to one of the `self`'s, then
            use the result as new object's ASN.1 constraints.

        Returns
        -------
        :
            new instance of |ASN.1| schema or value object

        Note
        ----
        Due to the immutable nature of the |ASN.1| object, if no arguments
        are supplied, no new |ASN.1| object will be created and `self` will
        be returned instead.
        implicitTagNr   explicitTag)
r1   rp   r    r   popr   tagImplicitlytagExplicitlyrw   rC   )r   r%   r   initializersr   r   argoptionr   r   r   subtype_  s    /
zAbstractSimpleAsn1Item.subtypec                 C   s   |S r   r   r   r%   r   r   r   rm     s    zAbstractSimpleAsn1Item.prettyInc                 C   s   t |S r   )rb   r   r   r   r   	prettyOut  s    z AbstractSimpleAsn1Item.prettyOutc                 C   s   |  | jS r   )r   rp   r5   r   r   r   r'     s    z"AbstractSimpleAsn1Item.prettyPrintc                 C   s   d| j | jjf S )Nz%s -> %s)r   rC   r   r5   r   r   r   prettyPrintType  s    z&AbstractSimpleAsn1Item.prettyPrintTypeN)r   )r   )r   r   r   r1   rl   r!   rF   r}   r~   r   r   r   r   rn   version_infor   r   r   r<   r:   r   r   rm   r   r'   r   r   r   r   r   r	      s*   

D
r	   c                   @   s   e Zd ZdZdZdZdd Zdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zejd dkrldd Zndd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd0d&d'Zd(d) Zd*d+ Zd,d- Zd.d/ ZdS )1r
   FNc                 K   s4   | j | jd}|| tj| fi | g | _d S )N)componentTypesizeSpec)r   r   r   r   r!   _componentValuesr   r   r   r   r!     s    
z$AbstractConstructedAsn1Item.__init__c                 C   s~   d| j j| jrdpdt| f }| j D ] \}}|tur*|d||f 7 }q*| jrv| jrv|dddd | jD  7 }d	| S )
Nrq   r%   rr   z %s=%rru   z, c                 S   s   g | ]}t |qS r   )repr)r]   xr   r   r   r`         z8AbstractConstructedAsn1Item.__repr__.<locals>.<listcomp>rv   )	rC   r   r:   rj   r    rw   r1   r   joinry   r   r   r   rF     s    z$AbstractConstructedAsn1Item.__repr__c                 C   s   | |u rdp| j |kS rz   r   r|   r   r   r   r}     s    z"AbstractConstructedAsn1Item.__eq__c                 C   s
   | j |kS r   r   r|   r   r   r   r~     s    z"AbstractConstructedAsn1Item.__ne__c                 C   s
   | j |k S r   r   r|   r   r   r   r     s    z"AbstractConstructedAsn1Item.__lt__c                 C   s
   | j |kS r   r   r|   r   r   r   r     s    z"AbstractConstructedAsn1Item.__le__c                 C   s
   | j |kS r   r   r|   r   r   r   r     s    z"AbstractConstructedAsn1Item.__gt__c                 C   s
   | j |kS r   r   r|   r   r   r   r     s    z"AbstractConstructedAsn1Item.__ge__r   r   c                 C   s   | j r
dpdS r   r   r(   r   r   r   r     s    z'AbstractConstructedAsn1Item.__nonzero__c                 C   s   | j r
dpdS r   r   r(   r   r   r   r     s    z$AbstractConstructedAsn1Item.__bool__c                 C   s
   t | jS r   )rx   r   r(   r   r   r   __len__  s    z#AbstractConstructedAsn1Item.__len__c                 C   s   d S r   r   )r   ZmyClonecloneValueFlagr   r   r   _cloneComponentValues  s    z1AbstractConstructedAsn1Item._cloneComponentValuesc                 K   sD   | dd}| j }|| | jf i |}|r@| || |S )a%  Create a modified version of |ASN.1| schema object.

        The `clone()` method accepts the same set arguments as |ASN.1|
        class takes on instantiation except that all arguments
        of the `clone()` method are optional.

        Whatever arguments are supplied, they are used to create a copy
        of `self` taking precedence over the ones used to instantiate `self`.

        Possible values of `self` are never copied over thus `clone()` can
        only create a new schema object.

        Returns
        -------
        :
            new instance of |ASN.1| type/value

        Note
        ----
        Due to the mutable nature of the |ASN.1| object, even if no arguments
        are supplied, new |ASN.1| object will always be created as a shallow
        copy of `self`.
        r   F)r   r    r   r   rC   r   )r   r   r   r   r   r   r   r   r     s    

z!AbstractConstructedAsn1Item.clonec           	      K   s   | j  }|dd}|dd}|dur:| j||d< |dd}|dur^| j||d< | D ]\}}||  |7  < qf| jf i |}|r| || |S )a(  Create a specialization of |ASN.1| schema object.

        The `subtype()` method accepts the same set arguments as |ASN.1|
        class takes on instantiation except that all parameters
        of the `subtype()` method are optional.

        With the exception of the arguments described below, the rest of
        supplied arguments they are used to create a copy of `self` taking
        precedence over the ones used to instantiate `self`.

        The following arguments to `subtype()` create a ASN.1 subtype out of
        |ASN.1| type.

        Other Parameters
        ----------------
        implicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Implicitly apply given ASN.1 tag object to `self`'s
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        explicitTag: :py:class:`~pyasn1.type.tag.Tag`
            Explicitly apply given ASN.1 tag object to `self`'s
            :py:class:`~pyasn1.type.tag.TagSet`, then use the result as
            new object's ASN.1 tag(s).

        subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
            Add ASN.1 constraints object to one of the `self`'s, then
            use the result as new object's ASN.1 constraints.


        Returns
        -------
        :
            new instance of |ASN.1| type/value

        Note
        ----
        Due to the immutable nature of the |ASN.1| object, if no arguments
        are supplied, no new |ASN.1| object will be created and `self` will
        be returned instead.
        r   Fr   Nr   r   )	r    r   r   r   r   r   rw   rC   r   )	r   r   r   r   r   r   r   r   r   r   r   r   r   )  s    +
z#AbstractConstructedAsn1Item.subtypec                 C   s   |  |  d S r   )r   r(   r   r   r   verifySizeSpecj  s    z*AbstractConstructedAsn1Item.verifySizeSpecc                 C   s   t dd S NzMethod not implementedrP   )r   idxr   r   r   getComponentByPositionm  s    z2AbstractConstructedAsn1Item.getComponentByPositionTc                 C   s   t dd S r   rP   )r   r   r%   ZverifyConstraintsr   r   r   setComponentByPositionp  s    z2AbstractConstructedAsn1Item.setComponentByPositionc                 O   s4   t |D ]\}}|| |< q|D ]}|| | |< q| S r   )	enumerate)r   rQ   r   r   r%   kr   r   r   setComponentss  s
    
z)AbstractConstructedAsn1Item.setComponentsc                 C   s
   g | _ d S r   r   r(   r   r   r   clearz  s    z!AbstractConstructedAsn1Item.clearc                 C   s   d S r   r   r(   r   r   r   setDefaultComponents  s    z0AbstractConstructedAsn1Item.setDefaultComponentsc                 C   s   | j S r   )r   r(   r   r   r   getComponentType  s    z,AbstractConstructedAsn1Item.getComponentType)T)r   r   r   ZstrictConstraintsr   r   r!   rF   r}   r~   r   r   r   r   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
     s2   
$A
r
   )rn   Zpyasn1r   Zpyasn1.compatr   Zpyasn1.typer   r   r   __all__rh   r   r   r>   r1   r	   r
   r   r   r   r   <module>   s   
}J ^