B
    à%Q[QP  ã               @   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 ddd	d
g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   s4   yt  j|7  _W n tk
r,   |t _Y nX t jS )N)r   Z_typeCounterÚAttributeError)ÚclsÚ	increment© r   úTC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6i93dh7p\pyasn1\pyasn1\type\base.pyÚ	getTypeId   s
    zAsn1Item.getTypeIdN)r   )Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r   r   r   r   r      s   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 k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 )N)ÚprettyPrint)r   r   r   r   Ú__str__:   s    zAsn1ItemBase.__str__c             C   s   | j S )N)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,   | |k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   )r   ÚotherÚ	matchTagsÚ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   ÚisSuperTypeOf)r   r(   r)   r*   r   r   r   r,   e   s    zAsn1ItemBase.isSuperTypeOfc              G   s   x| D ]}|t k	rdS qW dS )NFT)ÚnoValue)Úvaluesr"   r   r   r   Ú	isNoValue}   s    
zAsn1ItemBase.isNoValuer   c             C   s
   t ƒ ‚d S )N)ÚNotImplementedError)r   Úscoper   r   r   r$   „   s    zAsn1ItemBase.prettyPrintc             C   s   | j S )N)r   )r   r   r   r   Ú	getTagSet‰   s    zAsn1ItemBase.getTagSetc             C   s   | j S )N)r&   )r   r   r   r   ÚgetEffectiveTagSetŒ   s    zAsn1ItemBase.getEffectiveTagSetc             C   s   | j S )N)r'   )r   r   r   r   Ú	getTagMap�   s    zAsn1ItemBase.getTagMapc             C   s   | j S )N)r   )r   r   r   r   ÚgetSubtypeSpec’   s    zAsn1ItemBase.getSubtypeSpecc             C   s   | j S )N)ÚisValue)r   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+   r,   Ústaticmethodr/   r$   r2   r3   r4   r5   r7   r   r   r   r   r      s$   


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 krZdd„ }‡ fdd„ttttfD ƒ}x t|ƒD ]}tˆ |||ƒƒ q6W t ˆ ¡ˆ _ ˆ j S )Nc                s   ‡ fdd„}|S )Nc                s   t  dˆ  ¡‚d S )Nz/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!   rM   r   )r!   r   ÚgetPlugÅ   s    z NoValue.__new__.<locals>.getPlugc                sL   g | ]D}t |ƒD ]6}|ˆ jk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ÚobjectrA   )r   rN   Zop_namesr!   r   )r   r   rA   Ã   s    

zNoValue.__new__c             C   s(   || j krtd| ƒ‚t d| ¡‚d S )NzAttribute %s not presentz/Attempted "%s" operation on ASN.1 schema object)rQ   r   r   r    )r   Úattrr   r   r   r=   Ù   s    
zNoValue.__getattr__c             C   s   d| j jt| ƒf S )Nz<%s object at 0x%x>)r?   r   Úid)r   r   r   r   rB   ß   s    zNoValue.__repr__)
r   r   r   Ú__doc__r^   rQ   rY   rA   r=   rB   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   sz   t j| f|Ž |tkr| j}nR|  |¡}y|  |¡ W n8 tjk
rn   t 	¡ \}}}|d|| j
jf ƒ‚Y nX || _d S )Nz%s at %s)r   r   r-   ÚdefaultValueÚprettyInr   r   r    ÚsysÚexc_infor?   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 }x*| j ¡ D ]\}}|r,|d||f 7 }q,W | jrŽ|  ¡ }t|ƒdkr‚|d d… d |dd …  }|d	| 7 }d
| S )Nz%s %s object at 0x%xr"   Úschemaz %s %sé    é   z...iðÿÿÿz payload [%s]z<%s>)r?   r   r6   rb   r   Úitemsr$   Úlen)r   Úrepresentationra   r"   r   r   r   rB   ú   s    zAbstractSimpleAsn1Item.__repr__c             C   s   | |krdp| j |kS )NT)rh   )r   r(   r   r   r   Ú__eq__  s    zAbstractSimpleAsn1Item.__eq__c             C   s
   | j |kS )N)rh   )r   r(   r   r   r   Ú__ne__  s    zAbstractSimpleAsn1Item.__ne__c             C   s
   | j |k S )N)rh   )r   r(   r   r   r   Ú__lt__  s    zAbstractSimpleAsn1Item.__lt__c             C   s
   | j |kS )N)rh   )r   r(   r   r   r   Ú__le__  s    zAbstractSimpleAsn1Item.__le__c             C   s
   | j |kS )N)rh   )r   r(   r   r   r   Ú__gt__  s    zAbstractSimpleAsn1Item.__gt__c             C   s
   | j |kS )N)rh   )r   r(   r   r   r   Ú__ge__  s    zAbstractSimpleAsn1Item.__ge__r   é   c             C   s   | j r
dpdS )NTF)rh   )r   r   r   r   Ú__nonzero__  s    z"AbstractSimpleAsn1Item.__nonzero__c             C   s   | j r
dpdS )NTF)rh   )r   r   r   r   Ú__bool__!  s    zAbstractSimpleAsn1Item.__bool__c             C   s
   t | jƒS )N)Úhashrh   )r   r   r   r   Ú__hash__$  s    zAbstractSimpleAsn1Item.__hash__c             C   s
   | j tk	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).
        )rh   r-   )r   r   r   r   r6   '  s    zAbstractSimpleAsn1Item.isValuec             K   s8   |t kr|s| S | j}| j ¡ }| |¡ | j|f|Ž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.
        )r-   rh   r   Úcopyr   r?   )r   r"   r   Úinitilaizersr   r   r   ÚcloneD  s    

zAbstractSimpleAsn1Item.clonec             K   sœ   |t kr|s| S | j}| j ¡ }| dd¡}|dk	rD| j |¡|d< | dd¡}|dk	rh| j |¡|d< x$| ¡ D ]\}}||  |7  < qrW | j	|f|Ž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)
r-   rh   r   rz   Úpopr   ÚtagImplicitlyÚtagExplicitlyrl   r?   )r   r"   r   Úinitializersr}   r~   ÚargÚoptionr   r   r   Úsubtype_  s    /
zAbstractSimpleAsn1Item.subtypec             C   s   |S )Nr   )r   r"   r   r   r   re   £  s    zAbstractSimpleAsn1Item.prettyInc             C   s   t |ƒS )N)rZ   )r   r"   r   r   r   Ú	prettyOut¦  s    z AbstractSimpleAsn1Item.prettyOutc             C   s   |   | j¡S )N)r†   rh   )r   r1   r   r   r   r$   ©  s    z"AbstractSimpleAsn1Item.prettyPrintc             C   s   d| j | jjf S )Nz%s -> %s)r   r?   r   )r   r1   r   r   r   ÚprettyPrintType­  s    z&AbstractSimpleAsn1Item.prettyPrintTypeN)r   )r   )r   r   r   r-   rd   r   rB   ro   rp   rq   rr   rs   rt   rf   Úversion_inforv   rw   ry   r8   r6   r|   r…   re   r†   r$   r‡   r   r   r   r   r	   ç   s(   
D
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   s0   | j | jdœ}| |¡ tj| f|Ž g | _d S )N)ÚcomponentTypeÚsizeSpec)r‰   rŠ   r   r   r   Ú_componentValues)r   r   r   r   r   r   r   Í  s
    

z$AbstractConstructedAsn1Item.__init__c             C   s‚   d| j j| jrdpdt| ƒf }x.| j ¡ D ] \}}|tk	r,|d||f 7 }q,W | jrz| jrz|dd dd„ | jD ƒ¡ 7 }d	| S )
Nz%s %s object at 0x%xr"   ri   z %s=%rz payload [%s]z, c             S   s   g | ]}t |ƒ‘qS r   )Úrepr)rV   Úxr   r   r   rX   â  s    z8AbstractConstructedAsn1Item.__repr__.<locals>.<listcomp>z<%s>)	r?   r   r6   rb   r   rl   r-   r‹   Újoin)r   rn   ra   r"   r   r   r   rB   Ø  s    z$AbstractConstructedAsn1Item.__repr__c             C   s   | |krdp| j |kS )NT)r‹   )r   r(   r   r   r   ro   æ  s    z"AbstractConstructedAsn1Item.__eq__c             C   s
   | j |kS )N)r‹   )r   r(   r   r   r   rp   é  s    z"AbstractConstructedAsn1Item.__ne__c             C   s
   | j |k S )N)r‹   )r   r(   r   r   r   rq   ì  s    z"AbstractConstructedAsn1Item.__lt__c             C   s
   | j |kS )N)r‹   )r   r(   r   r   r   rr   ï  s    z"AbstractConstructedAsn1Item.__le__c             C   s
   | j |kS )N)r‹   )r   r(   r   r   r   rs   ò  s    z"AbstractConstructedAsn1Item.__gt__c             C   s
   | j |kS )N)r‹   )r   r(   r   r   r   rt   õ  s    z"AbstractConstructedAsn1Item.__ge__r   ru   c             C   s   | j r
dpdS )NTF)r‹   )r   r   r   r   rv   ù  s    z'AbstractConstructedAsn1Item.__nonzero__c             C   s   | j r
dpdS )NTF)r‹   )r   r   r   r   rw   ü  s    z$AbstractConstructedAsn1Item.__bool__c             C   s
   t | jƒS )N)rm   r‹   )r   r   r   r   Ú__len__ÿ  s    z#AbstractConstructedAsn1Item.__len__c             C   s   d S )Nr   )r   ZmyCloneÚcloneValueFlagr   r   r   Ú_cloneComponentValues  s    z1AbstractConstructedAsn1Item._cloneComponentValuesc             K   s@   |  dd¡}| j ¡ }| |¡ | jf |Ž}|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   rz   r   r?   r‘   )r   r   r�   r{   r|   r   r   r   r|     s    

z!AbstractConstructedAsn1Item.clonec       	      K   s¤   | j  ¡ }| dd¡}| dd¡}|dk	r:| j |¡|d< | dd¡}|dk	r^| j |¡|d< x$| ¡ D ]\}}||  |7  < qhW | jf |Ž}|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   rz   r   r   r€   r�   rl   r?   r‘   )	r   r   r‚   r�   r}   r~   rƒ   r„   r|   r   r   r   r…   )  s    +
z#AbstractConstructedAsn1Item.subtypec             C   s   |   | ¡ d S )N)rŠ   )r   r   r   r   ÚverifySizeSpecj  s    z*AbstractConstructedAsn1Item.verifySizeSpecc             C   s   t  d¡‚d S )NzMethod not implemented)r   r    )r   Úidxr   r   r   ÚgetComponentByPositionm  s    z2AbstractConstructedAsn1Item.getComponentByPositionTc             C   s   t  d¡‚d S )NzMethod not implemented)r   r    )r   r“   r"   ZverifyConstraintsr   r   r   ÚsetComponentByPositionp  s    z2AbstractConstructedAsn1Item.setComponentByPositionc             O   s<   xt |ƒD ]\}}|| |< q
W x|D ]}|| | |< q$W | S )N)Ú	enumerate)r   rK   r   r“   r"   Úkr   r   r   ÚsetComponentss  s
    
z)AbstractConstructedAsn1Item.setComponentsc             C   s
   g | _ d S )N)r‹   )r   r   r   r   Úclearz  s    z!AbstractConstructedAsn1Item.clearc             C   s   d S )Nr   )r   r   r   r   ÚsetDefaultComponents  s    z0AbstractConstructedAsn1Item.setDefaultComponentsc             C   s   | j S )N)r‰   )r   r   r   r   ÚgetComponentType‚  s    z,AbstractConstructedAsn1Item.getComponentType)T)r   r   r   ZstrictConstraintsr‰   rŠ   r   rB   ro   rp   rq   rr   rs   rt   rf   rˆ   rv   rw   r�   r‘   r|   r…   r’   r”   r•   r˜   r™   rš   r›   r   r   r   r   r
   Ä  s2   
$A
)rf   Zpyasn1r   Zpyasn1.compatr   Zpyasn1.typer   r   r   Ú__all__r`   r   r   r:   r-   r	   r
   r   r   r   r   Ú<module>   s   
}J ^