
    ci"V                         d dl 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e      Z	 G d	 d
e	      Z
e
Z G d de      Z e       Z G d de
      ZeZ G d de
      ZeZy)    N)error)
constraint)tag)tagmap)Asn1ItemAsn1TypeSimpleAsn1TypeConstructedAsn1Typec                       e Zd Zedd       Zy)r   c                     	 t         xj                  |z  c_        t         j                  S # t        $ r |t         _        Y t         j                  S w xY wN)r   _typeCounterAttributeError)cls	increments     7/tmp/pip-target-z3e9_cxr/lib/python/pyasn1/type/base.py	getTypeIdzAsn1Item.getTypeId   sK    	.!!Y.! $$$  	.$-H!$$$	.s   + AAN)   )__name__
__module____qualname__classmethodr        r   r   r      s    % %r   r   c                       e Zd ZdZ ej
                         Z ej                         Z	dZ
d Zd Zd Zed        Zed        Zed        Zdd	Zdd
Zed        ZddZd Zd Zd Zd Zd Zy)r   a>  Base class for all classes representing ASN.1 types.

    In the user code, |ASN.1| class is normally used only for telling
    ASN.1 objects from others.

    Note
    ----
    For as long as ASN.1 is concerned, a way to compare ASN.1 types
    is to use :meth:`isSameTypeWith` and :meth:`isSuperTypeOf` methods.
    Nc                     | j                   | j                  d}|j                  |       | j                  j                  |       || _        y )NtagSetsubtypeSpec)r   r   update__dict__	_readOnlyselfkwargsreadOnlys      r   __init__zAsn1Type.__init__2   s@    kk++

 	X&!r   c                 ~    |d   dk7  r&|| j                   v rt        j                  d|z        || j                  |<   y )Nr   _z!read-only instance attribute "%s")r"   r   PyAsn1Errorr!   )r$   namevalues      r   __setattr__zAsn1Type.__setattr__>   s=    7c>ddnn4##$G$$NOO#dr   c                 "    | j                         S r   )prettyPrintr$   s    r   __str__zAsn1Type.__str__D   s    !!r   c                     | j                   S r   )r"   r0   s    r   r&   zAsn1Type.readOnlyG   s    ~~r   c                     | j                   S )z3For |ASN.1| type is equivalent to *tagSet*
        r   r0   s    r   effectiveTagSetzAsn1Type.effectiveTagSetK   s     {{r   c                 D    t        j                  | j                  | i      S )zvReturn a :class:`~pyasn1.type.tagmap.TagMap` object mapping ASN.1 tags to ASN.1 objects within callee object.
        )r   TagMapr   r0   s    r   tagMapzAsn1Type.tagMapQ   s     }}dkk4011r   c                     | |u xs> | xs | j                   |j                   k(  xr | xs | j                  |j                  k(  S )a?  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`
            :obj:`True` if *other* is |ASN.1| type,
            :obj:`False` otherwise.
        r   r$   other	matchTagsmatchConstraintss       r   isSameTypeWithzAsn1Type.isSameTypeWithW   sP    (  P=$++"= P%%N)9)9U=N=N)N	Qr   c                     | xsQ | j                   j                  |j                         xr* | xs% | j                  j                  |j                        S )al  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`
                :obj:`True` if *other* is a subtype of |ASN.1| type,
                :obj:`False` otherwise.
        )r   isSuperTagSetOfr   isSuperTypeOfr:   s       r   rA   zAsn1Type.isSuperTypeOfo   sS    (  ],,U\\: ]&&[$*:*:*H*HIZIZ*[	^r   c                  &    | D ]  }|t         us y y)NFT)noValue)valuesr,   s     r   	isNoValuezAsn1Type.isNoValue   s!     	EG#	 r   c                     t         r   )NotImplementedErrorr$   scopes     r   r/   zAsn1Type.prettyPrint   s    !!r   c                     | j                   S r   r4   r0   s    r   	getTagSetzAsn1Type.getTagSet       {{r   c                     | j                   S r   )r5   r0   s    r   getEffectiveTagSetzAsn1Type.getEffectiveTagSet   s    ###r   c                     | j                   S r   )r8   r0   s    r   	getTagMapzAsn1Type.getTagMap   rL   r   c                     | j                   S r   r   r0   s    r   getSubtypeSpeczAsn1Type.getSubtypeSpec   s    r   c                     | j                   S r   )isValuer0   s    r   hasValuezAsn1Type.hasValue   s    ||r   )TTr   )r   r   r   __doc__r   TagSetr   r   ConstraintsIntersectionr   typeIdr'   r-   r1   propertyr&   r5   r8   r>   rA   staticmethodrE   r/   rK   rN   rP   rS   rV   r   r   r   r   r      s    	 SZZ\F 5*446K F
"$"    
 2 2
Q0^0  "
$ r   r   c                   .    e Zd ZdZh dZdZd Zd Zd Zy)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.
    >   __del____new__r'   __repr__im_class	__class__	__slots__
__reduce__
__sizeof____delattr____getattr__r-   __getstate____objclass__r   __setstate____reduce_ex____getnewargs____getinitargs____getattribute__Nc                    | j                   d }t        t        t        t        fD cg c]Y  }t        |      D ]I  }|| j                  vr9|j                  d      r(|j                  d      rt        t        ||            r|K [ }}}t        |      D ]  }t        | | ||              t        j                  |       | _         | j                   S c c}}w )Nc                       fd}|S )Nc                 4    t        j                  dz        )N/Attempted "%s" operation on ASN.1 schema objectr   r*   )r$   argskwr+   s      r   plugz.NoValue.__new__.<locals>.getPlug.<locals>.plug   s    ++,]`d,deer   r   )r+   rx   s   ` r   getPlugz NoValue.__new__.<locals>.getPlug   s    fr   __)	_instancestrintlistdictdirskipMethods
startswithendswithcallablegetattrsetsetattrobjectra   )r   ry   typr+   op_namess        r   ra   zNoValue.__new__   s    ==  %(dD#9;$'H;  7 OOD1 MM$/$WS$%78  ; ;H ; H 2T74=12 #NN3/CM}};s   ACc                 j    || j                   v rt        d|z        t        j                  d|z        )NzAttribute %s not presentrt   )r   r   r   r*   )r$   attrs     r   ri   zNoValue.__getattr__   s9    4### !;d!BCC QTX XYYr   c                 4    d| j                   j                  z  S )Nz<%s object>)rd   r   r0   s    r   rb   zNoValue.__repr__   s    t~~6666r   )	r   r   r   rX   r   r{   ra   ri   rb   r   r   r   r_   r_      s%    K4 I,Z7r   r_   c                       e Zd ZdZeZefdZd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zed        ZefdZefdZd Zd ZddZddZy)r	   a  Base class for all simple classes representing ASN.1 types.

    ASN.1 distinguishes types by their ability to hold other objects.
    Scalar types are known as *simple* in ASN.1.

    In the user code, |ASN.1| class is normally used only for telling
    ASN.1 objects from others.

    Note
    ----
    For as long as ASN.1 is concerned, a way to compare ASN.1 types
    is to use :meth:`isSameTypeWith` and :meth:`isSuperTypeOf` methods.
    c                 F   t        j                  | fi | |t        u r| j                  }|| _        y | j	                  |      }	 | j                  |       || _        y # t        j                  $ r/} t        |      |d| j                  j                        d }~ww xY w)Nz at )r   r'   rC   defaultValueprettyInr   r   r*   typerd   r   _value)r$   r,   r%   exValues       r   r'   zSimpleAsn1Type.__init__  s    $)&)G%%E  MM%(EU  '
  $$ U#d7m'4>>;R;R$STTUs   A B 1*BB c                 H   | j                   j                  d| j                  xr dxs dd}| j                  j	                         D ]  \  }}|s	|d|d|z  } | j                  r4| j                         }t        |      dkD  r|d d dz   |d	d  z   }|d
|z  z  }d|z  S )N r,   schema object,        z...i, payload [%s]<%s>)rd   r   rU   r&   itemsr/   len)r$   representationr   r,   s       r   rb   zSimpleAsn1Type.__repr__  s    NN##T\\%=g%I%IK  ==..0 	<KD%tU";;	< <<$$&E5zBcr
U*U34[8.66N&&r   c                 *    | |u ry| j                   |k(  S )NTr   r$   r;   s     r   __eq__zSimpleAsn1Type.__eq__#  s    5={{e##r   c                      | j                   |k7  S r   r   r   s     r   __ne__zSimpleAsn1Type.__ne__(      {{e##r   c                      | j                   |k  S r   r   r   s     r   __lt__zSimpleAsn1Type.__lt__+      {{U""r   c                      | j                   |k  S r   r   r   s     r   __le__zSimpleAsn1Type.__le__.  r   r   c                      | j                   |kD  S r   r   r   s     r   __gt__zSimpleAsn1Type.__gt__1  r   r   c                      | j                   |k\  S r   r   r   s     r   __ge__zSimpleAsn1Type.__ge__4  r   r   c                 ,    t        | j                        S r   )boolr   r0   s    r   __bool__zSimpleAsn1Type.__bool__7      DKK  r   c                 ,    t        | j                        S r   )hashr   r0   s    r   __hash__zSimpleAsn1Type.__hash__:  r   r   c                 &    | j                   t        uS )az  Indicate that |ASN.1| object represents ASN.1 value.

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

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

        Returns
        -------
        : :class:`bool`
            :obj:`False` if object represents just ASN.1 schema.
            :obj:`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).
        )r   rC   r0   s    r   rU   zSimpleAsn1Type.isValue=  s    8 {{'))r   c                     |t         u r|s| S | j                  }| j                  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.
        )rC   r   r&   copyr    rd   )r$   r,   r%   initializerss       r   clonezSimpleAsn1Type.clone[  sS      GKKE}}))+F#t~~e4|44r   c                    |t         u r|s| S | j                  }| j                  j                         }|j	                  dd      }|| j
                  j                  |      |d<   |j	                  dd      }|| j
                  j                  |      |d<   |j                         D ]  \  }}||xx   |z  cc<     | 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)
rC   r   r&   r   popr   tagImplicitlytagExplicitlyr   rd   )r$   r,   r%   r   r   r   argoptions           r   subtypezSimpleAsn1Type.subtypev  s    ^ GKKE}}))+jj5"%)[[%>%>{%KL"jj5"%)[[%>%>{%KL"!<<> 	(KC'	( t~~e4|44r   c                     |S r   r   r$   r,   s     r   r   zSimpleAsn1Type.prettyIn  s    r   c                     t        |      S r   )r|   r   s     r   	prettyOutzSimpleAsn1Type.prettyOut  s    5zr   c                 8    | j                  | j                        S r   )r   r   rH   s     r   r/   zSimpleAsn1Type.prettyPrint  s    ~~dkk**r   c                 L    | j                   d| j                  j                  S )Nz -> )r   rd   r   rH   s     r   prettyPrintTypezSimpleAsn1Type.prettyPrintType  s    ![[$..*A*ABBr   NrW   )r   r   r   rX   rC   r   r'   rb   r   r   r   r   r   r   r   r   r\   rU   r   r   r   r   r/   r   r   r   r   r	   r	      s     L$ ' $
$#$#$!! * *: " 56 $ B5H+Cr   r	   c                       e Zd ZdZdZdZ ej                         Zd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zed        Zd Zd Zd Zd ZddZd Zd Zd Zd Zy)r
   a  Base class for all constructed classes representing ASN.1 types.

    ASN.1 distinguishes types by their ability to hold other objects.
    Those "nesting" types are known as *constructed* in ASN.1.

    In the user code, |ASN.1| class is normally used only for telling
    ASN.1 objects from others.

    Note
    ----
    For as long as ASN.1 is concerned, a way to compare ASN.1 types
    is to use :meth:`isSameTypeWith` and :meth:`isSuperTypeOf` methods.
    FNc                     | j                   | j                  d} | j                  di |}|j                  |       t	        j
                  | fi | y )N)componentTypesizeSpecr   )r   r   _moveSizeSpecr    r   r'   r#   s      r   r'   zConstructedAsn1Type.__init__  sO    !//
 $##-f-$+(+r   c                     |j                  d| j                        }|r+|j                  d| j                        }|r|}n||z  }||d<   |S )Nr   r   )r   r   r   )r$   r%   r   r   s       r   r   z!ConstructedAsn1Type._moveSizeSpec  sR    ::j$--8 **]D4D4DEK& x'$/F=!r   c           
      ~   | j                   j                  d| j                  xr dxs dd}| j                  j	                         D ]  \  }}|t
        us|d|d|z  } | j                  rD| j                  r8|ddj                  | j                  D cg c]  }t        |       c}      z  z  }d|z  S c c}w )	Nr   r,   r   r   r   =r   r   )	rd   r   rU   r&   r   rC   
componentsjoinrepr)r$   r   r   r,   xs        r   rb   zConstructedAsn1Type.__repr__  s    NN##T\\%=g%I%I
  ==..0 	<KD%G#tU";;	< <<DOO."&//2Qa224 4 4N && 3s   B:c                 ,    | |u xs | j                   |k(  S r   r   r   s     r   r   zConstructedAsn1Type.__eq__!  s    u}85 88r   c                      | j                   |k7  S r   r   r   s     r   r   zConstructedAsn1Type.__ne__$      %''r   c                      | j                   |k  S r   r   r   s     r   r   zConstructedAsn1Type.__lt__'      &&r   c                      | j                   |k  S r   r   r   s     r   r   zConstructedAsn1Type.__le__*  r   r   c                      | j                   |kD  S r   r   r   s     r   r   zConstructedAsn1Type.__gt__-  r   r   c                      | j                   |k\  S r   r   r   s     r   r   zConstructedAsn1Type.__ge__0  r   r   c                 ,    t        | j                        S r   )r   r   r0   s    r   r   zConstructedAsn1Type.__bool__3  s    DOO$$r   c                 ,    t        j                  d      NzMethod not implementedru   r0   s    r   r   zConstructedAsn1Type.components6  s     899r   c                      y r   r   )r$   myClonecloneValueFlags      r   _cloneComponentValuesz)ConstructedAsn1Type._cloneComponentValues:      r   c                     |j                  dd      }| j                  j                         }|j                  |        | j                  di |}|r| j                  ||       |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, a new |ASN.1| object will be created and returned.
        r   Fr   )r   r&   r   r    rd   r   )r$   r%   r   r   r   s        r   r   zConstructedAsn1Type.clone=  s`    .  $4e<}}))+F#..&&un=r   c                    | j                   j                         }|j                  dd      }|j                  dd      }|| j                  j	                  |      |d<   |j                  dd      }|| j                  j                  |      |d<   |j                         D ]  \  }}||xx   |z  cc<     | j                  di |}|r| j                  ||       |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 mutable nature of the |ASN.1| object, even if no arguments
        are supplied, a new |ASN.1| object will be created and returned.
        r   Fr   Nr   r   r   )	r&   r   r   r   r   r   r   rd   r   )	r$   r%   r   r   r   r   r   r   r   s	            r   r   zConstructedAsn1Type.subtype`  s    T }}))+$4e<jj5"%)[[%>%>{%KL"jj5"%)[[%>%>{%KL"!<<> 	(KC'	( ..&&un=r   c                 ,    t        j                  d      r   ru   )r$   idxs     r   getComponentByPositionz*ConstructedAsn1Type.getComponentByPosition       899r   c                 ,    t        j                  d      r   ru   )r$   r   r,   verifyConstraintss       r   setComponentByPositionz*ConstructedAsn1Type.setComponentByPosition  r   r   c                 T    t        |      D ]
  \  }}|| |<    |D ]
  }||   | |<    | S r   )	enumerate)r$   rv   r%   r   r,   ks         r   setComponentsz!ConstructedAsn1Type.setComponents  sC    #D/ 	JCDI	 	 AQiDG	 r   c                      y r   r   r0   s    r   setDefaultComponentsz(ConstructedAsn1Type.setDefaultComponents  r   r   c                     | j                   S r   )r   r0   s    r   getComponentTypez$ConstructedAsn1Type.getComponentType  s    !!!r   c                 &    | j                  |        y r   rR   r0   s    r   verifySizeSpecz"ConstructedAsn1Type.verifySizeSpec  s    r   )T)r   r   r   rX   strictConstraintsr   r   rZ   r   r'   r   rb   r   r   r   r   r   r   r   r\   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r
     s      M 2z113H,'9('('(% : :!F>@::"r   r
   )syspyasn1r   pyasn1.typer   r   r   __all__r   r   r   Asn1ItemBaser_   rC   r	   AbstractSimpleAsn1Itemr
   AbstractConstructedAsn1Itemr   r   r   <module>r     s      "  "%v %Ex EP G7f G7T )PCX PCf ( ,Z( Z| 2 r   