a
    db#                    @   s2  d dl Z 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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l
mZ ejZe Zg dZG dd dejZG dd deZejd  dk reZneZG dd deZG dd dejZze W n ey(   dd ZY n0 G dd dejZG dd deZ ejd  dkrfeefZ!nefZ!e!e"f Z#G dd dejZ$G d d! d!ejZ%G d"d# d#eZ&G d$d% d%ej'Z(G d&d' d'e(Z)G d(d) d)e(Z*G d*d+ d+ej'Z+G d,d- d-e+Z,G d.d/ d/e+Z-G d0d1 d1e-Z.G d2d3 d3eZ/dS )4    N)error)eoo)binary)integer)octets)base)
constraint)	namedtype)namedval)tag)tagmap)IntegerBoolean	BitStringOctetStringNullObjectIdentifierReal
EnumeratedSequenceOfAndSetOfBase
SequenceOfSetOfSequenceAndSetBaseSequenceSetChoiceAnyNoValuenoValuec                   @   s  e Zd ZdZeeejejdZ	e
 Ze Zej 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d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%dfd&d'Z&d(d) Z'd*d+ Z(d,d- Z)e*j+d. dkrd/d0 Z,d1d2 Z-n(d3d4 Z.d5d6 Z/d7d8 Z0d9d: Z1ejj2Z2d;d< Z3e*j+d. dkrVd=d> Z4d?d@ Z5dAdB Z6dCdD Z7dEdF Z8dGdH Z9dIdJ Z:dgdKdLZ;dMdN Z<dOdP Z=e*j+d.d dQkrdRdS Z>dTdU Z?dVdW Z@dXdY ZAdZd[ ZBd\d] ZCd^d_ ZDd`da ZEdbdc ZFddde ZGd%S )hr   a  Create |ASN.1| type or object.

    |ASN.1| objects are immutable and duck-type Python :class:`int` objects.

    Keyword Args
    ------------
    value: :class:`int`, :class:`str` or |ASN.1| object
        Python integer or string literal or |ASN.1| class instance.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    namedValues: :py:class:`~pyasn1.type.namedval.NamedValues`
        Object representing non-default symbolic aliases for numbers

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------

    .. code-block:: python

        class ErrorCode(Integer):
            '''
            ASN.1 specification:

            ErrorCode ::=
                INTEGER { disk-full(1), no-disk(-1),
                          disk-not-formatted(2) }

            error ErrorCode ::= disk-full
            '''
            namedValues = NamedValues(
                ('disk-full', 1), ('no-disk', -1),
                ('disk-not-formatted', 2)
            )

        error = ErrorCode('disk-full')
       c                 K   s,   d|vr| j |d< tjj| |fi | d S )NnamedValues)r    r   AbstractSimpleAsn1Item__init__selfvaluekwargs r'   a/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/pyasn1/type/univ.pyr"   c   s    
zInteger.__init__c                 C   s   |  | j|@ S Nclone_valuer$   r%   r'   r'   r(   __and__i   s    zInteger.__and__c                 C   s   |  || j@ S r)   r*   r-   r'   r'   r(   __rand__l   s    zInteger.__rand__c                 C   s   |  | j|B S r)   r*   r-   r'   r'   r(   __or__o   s    zInteger.__or__c                 C   s   |  || jB S r)   r*   r-   r'   r'   r(   __ror__r   s    zInteger.__ror__c                 C   s   |  | j|A S r)   r*   r-   r'   r'   r(   __xor__u   s    zInteger.__xor__c                 C   s   |  || jA S r)   r*   r-   r'   r'   r(   __rxor__x   s    zInteger.__rxor__c                 C   s   |  | j|> S r)   r*   r-   r'   r'   r(   
__lshift__{   s    zInteger.__lshift__c                 C   s   |  | j|? S r)   r*   r-   r'   r'   r(   
__rshift__~   s    zInteger.__rshift__c                 C   s   |  | j| S r)   r*   r-   r'   r'   r(   __add__   s    zInteger.__add__c                 C   s   |  || j S r)   r*   r-   r'   r'   r(   __radd__   s    zInteger.__radd__c                 C   s   |  | j| S r)   r*   r-   r'   r'   r(   __sub__   s    zInteger.__sub__c                 C   s   |  || j S r)   r*   r-   r'   r'   r(   __rsub__   s    zInteger.__rsub__c                 C   s   |  | j| S r)   r*   r-   r'   r'   r(   __mul__   s    zInteger.__mul__c                 C   s   |  || j S r)   r*   r-   r'   r'   r(   __rmul__   s    zInteger.__rmul__c                 C   s   |  | j| S r)   r*   r-   r'   r'   r(   __mod__   s    zInteger.__mod__c                 C   s   |  || j S r)   r*   r-   r'   r'   r(   __rmod__   s    zInteger.__rmod__Nc                 C   s   |  t| j||S r)   r+   powr,   r$   r%   modulor'   r'   r(   __pow__   s    zInteger.__pow__c                 C   s   |  t|| jS r)   r>   r-   r'   r'   r(   __rpow__   s    zInteger.__rpow__c                 C   s   |  | j| S r)   r*   r-   r'   r'   r(   __floordiv__   s    zInteger.__floordiv__c                 C   s   |  || j S r)   r*   r-   r'   r'   r(   __rfloordiv__   s    zInteger.__rfloordiv__r   c                 C   s,   t |trt| j| S | | j| S d S r)   
isinstancefloatr   r,   r+   r-   r'   r'   r(   __div__   s    
zInteger.__div__c                 C   s,   t |trt|| j S | || j S d S r)   rF   r-   r'   r'   r(   __rdiv__   s    
zInteger.__rdiv__c                 C   s   t | j| S r)   r   r,   r-   r'   r'   r(   __truediv__   s    zInteger.__truediv__c                 C   s   t || j S r)   rK   r-   r'   r'   r(   __rtruediv__   s    zInteger.__rtruediv__c                 C   s   |  t| j|S r)   r+   divmodr,   r-   r'   r'   r(   
__divmod__   s    zInteger.__divmod__c                 C   s   |  t|| jS r)   rN   r-   r'   r'   r(   __rdivmod__   s    zInteger.__rdivmod__c                 C   s
   t | jS r)   intr,   r$   r'   r'   r(   __int__   s    zInteger.__int__c                 C   s
   t | jS r)   )longr,   rT   r'   r'   r(   __long__   s    zInteger.__long__c                 C   s
   t | jS r)   rH   r,   rT   r'   r'   r(   	__float__   s    zInteger.__float__c                 C   s   |  t| jS r)   )r+   absr,   rT   r'   r'   r(   __abs__   s    zInteger.__abs__c                 C   s
   t | jS r)   rR   rT   r'   r'   r(   	__index__   s    zInteger.__index__c                 C   s   |  | j
 S r)   r*   rT   r'   r'   r(   __pos__   s    zInteger.__pos__c                 C   s   |  | j S r)   r*   rT   r'   r'   r(   __neg__   s    zInteger.__neg__c                 C   s   |  | j S r)   r*   rT   r'   r'   r(   
__invert__   s    zInteger.__invert__c                 C   s"   t | j|}|r| |S |S d S r)   )roundr,   r+   r$   nrr'   r'   r(   	__round__   s    
zInteger.__round__c                 C   s   t | jS r)   )mathfloorr,   rT   r'   r'   r(   	__floor__   s    zInteger.__floor__c                 C   s   t | jS r)   )re   ceilr,   rT   r'   r'   r(   __ceil__   s    zInteger.__ceil__r      c                 C   s   |  t| jS r)   )r+   re   truncr,   rT   r'   r'   r(   	__trunc__   s    zInteger.__trunc__c                 C   s
   | j |k S r)   r,   r-   r'   r'   r(   __lt__   s    zInteger.__lt__c                 C   s
   | j |kS r)   rn   r-   r'   r'   r(   __le__   s    zInteger.__le__c                 C   s
   | j |kS r)   rn   r-   r'   r'   r(   __eq__   s    zInteger.__eq__c                 C   s
   | j |kS r)   rn   r-   r'   r'   r(   __ne__   s    zInteger.__ne__c                 C   s
   | j |kS r)   rn   r-   r'   r'   r(   __gt__   s    zInteger.__gt__c                 C   s
   | j |kS r)   rn   r-   r'   r'   r(   __ge__   s    zInteger.__ge__c                 C   s`   z
t |W S  tyZ   z| j| W  Y S  tyT   td|t d f Y n0 Y n0 d S )Nz Can't coerce %r into integer: %s   )rS   
ValueErrorr    KeyErrorr   PyAsn1Errorsysexc_infor-   r'   r'   r(   prettyIn   s    
zInteger.prettyInc                 C   s0   zt | j| W S  ty*   t | Y S 0 d S r)   )strr    rw   r-   r'   r'   r(   	prettyOut	  s    zInteger.prettyOutc                 C   s   | j S r)   r    rT   r'   r'   r(   getNamedValues  s    zInteger.getNamedValues)N)r   )H__name__
__module____qualname____doc__r   
initTagSetTagtagClassUniversaltagFormatSimpletagSetr   ConstraintsIntersectionsubtypeSpecr
   NamedValuesr    r   r!   	getTypeIdtypeIdr   r"   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   rB   rC   rD   rE   ry   version_inforI   rJ   rL   rM   rP   rQ   __hash__rU   rW   rY   r[   r\   r]   r^   r_   rd   rg   ri   rm   ro   rp   rq   rr   rs   rt   r{   r}   r   r'   r'   r'   r(   r   "   sv   0



	r   c                   @   sN   e Zd ZdZeeejejdZ	e
jedd ZeddZe
 ZdS )r   aW  Create |ASN.1| type or object.

    |ASN.1| objects are immutable and duck-type Python :class:`int` objects.

    Keyword Args
    ------------
    value: :class:`int`, :class:`str` or |ASN.1| object
        Python integer or boolean or string literal or |ASN.1| class instance.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    namedValues: :py:class:`~pyasn1.type.namedval.NamedValues`
        Object representing non-default symbolic aliases for numbers

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class RoundResult(Boolean):
            '''
            ASN.1 specification:

            RoundResult ::= BOOLEAN

            ok RoundResult ::= TRUE
            ko RoundResult ::= FALSE
            '''
        ok = RoundResult(True)
        ko = RoundResult(False)
    ru   r   )Falser   )Trueru   N)r   r   r   r   r   r   r   r   r   r   r   r   r   SingleValueConstraintr
   r   r    r   r   r'   r'   r'   r(   r     s   *r      c                   @   s$   e Zd Zd ZZdd Zdd ZdS )SizedIntegerNc                 C   s    || _ t|t |  d| _| S Nr   )	bitLengthmaxr   leadingZeroBits)r$   r   r'   r'   r(   setBitLengthZ  s    zSizedInteger.setBitLengthc                 C   s    | j d u r| t |  | j S r)   )r   r   r   rT   r'   r'   r(   __len___  s    
zSizedInteger.__len__)r   r   r   r   r   r   r   r'   r'   r'   r(   r   W  s   r   c                   @   sX  e Zd ZdZeeejejdZ	e
 Ze Zej Ze Z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d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'd%d& Z(d'd( Z)d)d* Z*e+j,d+ dk rd,d- Z-d.d/ Z.d0d1 Z/d2d3 Z0d4d5 Z1e2d@d8d9Z3e2dAd:d;Z4e2dBd<d=Z5d>d? Z6d7S )Cr   a  Create |ASN.1| schema or value object.

    |ASN.1| objects are immutable and duck-type both Python :class:`tuple` (as a tuple
    of bits) and :class:`int` objects.

    Keyword Args
    ------------
    value: :class:`int`, :class:`str` or |ASN.1| object
        Python integer or string literal representing binary or hexadecimal
        number or sequence of integer bits or |ASN.1| object.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    namedValues: :py:class:`~pyasn1.type.namedval.NamedValues`
        Object representing non-default symbolic aliases for numbers

    binValue: :py:class:`str`
        Binary string initializer to use instead of the *value*.
        Example: '10110011'.

    hexValue: :py:class:`str`
        Hexadecimal string initializer to use instead of the *value*.
        Example: 'DEADBEEF'.

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class Rights(BitString):
            '''
            ASN.1 specification:

            Rights ::= BIT STRING { user-read(0), user-write(1),
                                    group-read(2), group-write(3),
                                    other-read(4), other-write(5) }

            group1 Rights ::= { group-read, group-write }
            group2 Rights ::= '0011'B
            group3 Rights ::= '3'H
            '''
            namedValues = NamedValues(
                ('user-read', 0), ('user-write', 1),
                ('group-read', 2), ('group-write', 3),
                ('other-read', 4), ('other-write', 5)
            )

        group1 = Rights(('group-read', 'group-write'))
        group2 = Rights('0011')
        group3 = Rights(0x3)
    r   c                 K   s   |t u rd|rdz| j|ddd}W n ty6   Y n0 z| j|ddd}W n tyb   Y n0 |t u r| jt ur| j| jdd}n| jt ur| j| jdd}d|vr| j|d< tj	j
| |fi | d S )NbinValueTinternalFormathexValuer    )r   fromBinaryStringpoprw   fromHexStringdefaultBinValuedefaultHexValuer    r   r!   r"   r#   r'   r'   r(   r"     s$    


zBitString.__init__c                 C   s   |   S r)   )asBinaryrT   r'   r'   r(   __str__  s    zBitString.__str__c                 C   s.   |  |}| |u p,| j|ko,t| jt|kS r)   r{   r,   lenr$   otherr'   r'   r(   rq     s    
zBitString.__eq__c                 C   s&   |  |}| j|kp$t| jt|kS r)   r   r   r'   r'   r(   rr     s    
zBitString.__ne__c                 C   s8   |  |}t| jt|k p6t| jt|ko6| j|k S r)   r{   r   r,   r   r'   r'   r(   ro     s    
zBitString.__lt__c                 C   s8   |  |}t| jt|kp6t| jt|ko6| j|kS r)   r   r   r'   r'   r(   rp     s    
zBitString.__le__c                 C   s8   |  |}t| jt|kp6t| jt|ko6| j|kS r)   r   r   r'   r'   r(   rs     s    
zBitString.__gt__c                 C   s8   |  |}t| jt|kp6t| jt|ko6| j|kS r)   r   r   r'   r'   r(   rt     s    
zBitString.__ge__c                 C   s
   t | jS r)   r   r,   rT   r'   r'   r(   r     s    zBitString.__len__c                    sl   |j tu r0  fddt|t  D S t jd }||ksN|dk rVtd j|| ? d@ S d S )Nc                    s   g | ]} | qS r'   r'   .0xrT   r'   r(   
<listcomp>      z)BitString.__getitem__.<locals>.<listcomp>ru   r   zbit index out of range)	__class__slicer+   rangeindicesr   r,   
IndexError)r$   ilengthr'   rT   r(   __getitem__  s    
&zBitString.__getitem__c                 c   s,   t | j}|r(|d8 }| j|? d@ V  q
d S Nru   r   )r$   r   r'   r'   r(   __iter__  s    
zBitString.__iter__c                 C   s   t t| S r)   )reversedtuplerT   r'   r'   r(   __reversed__  s    zBitString.__reversed__c                 C   s:   |  |}| t| jt|> |B t| jt| S r)   )r{   r+   r   r,   r   r   r-   r'   r'   r(   r6     s    
zBitString.__add__c                 C   s<   |  |}| t|t| j> | jB t| jt| S r)   )r{   r+   r   r   r,   r   r-   r'   r'   r(   r7   
  s    
zBitString.__radd__c                 C   s:   | j }|dkr0|t| j K }|| j O }|d8 }q| |S r   )r,   r   r+   )r$   r%   Z	bitStringr'   r'   r(   r:     s    

zBitString.__mul__c                 C   s   | | S r)   r'   r-   r'   r'   r(   r;     s    zBitString.__rmul__c                 C   s$   |  t| j|> t| j| S r)   )r+   r   r,   r   r   r$   countr'   r'   r(   r4     s    zBitString.__lshift__c                 C   s*   |  t| j|? tdt| j| S r   )r+   r   r,   r   r   r   r   r'   r'   r(   r5     s    zBitString.__rshift__c                 C   s   | j S r)   rn   rT   r'   r'   r(   rU     s    zBitString.__int__c                 C   s
   t | jS r)   rX   rT   r'   r'   r(   rY   "  s    zBitString.__float__r   c                 C   s   | j S r)   rn   rT   r'   r'   r(   rW   &  s    zBitString.__long__c                 C   s   t t|  S )zGet |ASN.1| value as a sequence of 8-bit integers.

        If |ASN.1| object length is not a multiple of 8, result
        will be left-padded with zeros.
        )r   r   Z	octs2intsasOctetsrT   r'   r'   r(   	asNumbers)  s    zBitString.asNumbersc                 C   s   t j| jt| dS )zGet |ASN.1| value as a sequence of octets.

        If |ASN.1| object length is not a multiple of 8, result
        will be left-padded with zeros.
        )r   )r   to_bytesr,   r   rT   r'   r'   r(   r   1  s    zBitString.asOctetsc                 C   s   | j S )z5Get |ASN.1| value as a single integer value.
        rn   rT   r'   r'   r(   	asInteger9  s    zBitString.asIntegerc                 C   s.   t | jdd }dt| jt|  | S )z4Get |ASN.1| value as a text string of bits.
        r   N0)r   binr,   r   )r$   Z	binStringr'   r'   r(   r   >  s    zBitString.asBinaryFNc              	   C   s   zt |dt|d }W n. tyJ   td| jt d f Y n0 |dur~t t |t|> |B t|t| }|s| |}|S )Create a |ASN.1| object initialized from the hex string.

        Parameters
        ----------
        value: :class:`str`
            Text string like 'DEADBEEF'
              z%s.fromHexString() error: %sru   N	r   r   r   rv   r   rx   r   ry   rz   clsr%   r   prependr'   r'   r(   r   D  s    	"zBitString.fromHexStringc              	   C   s   zt |p
ddt|}W n. tyJ   td| jt d f Y n0 |dur~t t |t|> |B t|t| }|s| |}|S )Create a |ASN.1| object initialized from a string of '0' and '1'.

        Parameters
        ----------
        value: :class:`str`
            Text string like '1010111'
        r   r   z%s.fromBinaryString() error: %sru   Nr   r   r'   r'   r(   r   ]  s    	"zBitString.fromBinaryStringc                 C   sf   t t||? t|d | }|durVt t |t|> |B t|t| }|sb| |}|S )zCreate a |ASN.1| object initialized from a string.

        Parameters
        ----------
        value: :class:`str` (Py2) or :class:`bytes` (Py3)
            Text string like '\\x01\\xff' (Py2) or b'\\x01\\xff' (Py3)
           N)r   r   
from_bytesr   r   )r   r%   r   r   paddingr'   r'   r(   fromOctetStringv  s    	$zBitString.fromOctetStringc                    s  t |tr|S t|r|s,tddS |d dkr|dd  dkr^ j|dd ddS |dd  dkr j|dd ddS td	|f n j	r2|
 s2d
d |dD }z fdd|D }W n$ t y   td|f Y n0 t|}d}|D ]}|d|| > O }qt||d S |drT j|dd  ddS |drv j|dd  ddS  j|ddS npt |ttfr jddd |D ddS t |trt|t|S t |trt|S td|f d S )Nr   'z'Bru   Tr   z'Hz Bad BIT STRING value notation %sc                 S   s   g | ]}|  qS r'   )stripr   r'   r'   r(   r     r   z&BitString.prettyIn.<locals>.<listcomp>,c                    s   g | ]} j | qS r'   r~   )r   namerT   r'   r(   r     r   zunknown bit name(s) in %r0xr   0b c                 S   s   g | ]}|rd pdqS )1r   r'   )r   br'   r'   r(   r     r   z#Bad BitString initializer type '%s')rG   r   r   isStringTyper   r   r   r   rx   r    isdigitsplitrw   r   
startswithr   listjoinr   r   intTypes)r$   r%   namesZbitPositionsZrightmostPositionnumberZbitPositionr'   rT   r(   r{     sL    
zBitString.prettyIn)FN)FN)FNr   )7r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r    r   r!   r   r   r   r   r   r"   r   rq   rr   ro   rp   rs   rt   r   r   r   r   r6   r7   r:   r;   r4   r5   rU   rY   ry   r   rW   r   r   r   r   classmethodr   r   r   r{   r'   r'   r'   r(   r   f  sR   >
	r   c                 C   s   | D ]}|s dS qdS )NFTr'   )iterableelementr'   r'   r(   all  s    r   c                   @   s4  e Zd ZdZeeejejdZ	e
 Zej Ze ZZdZefddZejd dkrdd	 Zd
d Zdd Zdd Zdd Zn(dd	 Zdd Zdd Zdd Zdd Zdd Zd7ddZe dd Z!e d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*d0d1 Z+d2d3 Z,d4d5 Z-d6S )8r   a  Create |ASN.1| schema or value object.

    |ASN.1| objects are immutable and duck-type Python 2 :class:`str` or Python 3 :class:`bytes`.
    When used in Unicode context, |ASN.1| type assumes "|encoding|" serialisation.

    Keyword Args
    ------------
    value: :class:`str`, :class:`bytes` or |ASN.1| object
        string (Python 2) or bytes (Python 3), alternatively unicode object
        (Python 2) or string (Python 3) representing character string to be
        serialised into octets (note `encoding` parameter) or |ASN.1| object.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    encoding: :py:class:`str`
        Unicode codec ID to encode/decode :class:`unicode` (Python 2) or
        :class:`str` (Python 3) the payload when |ASN.1| object is used
        in text string context.

    binValue: :py:class:`str`
        Binary string initializer to use instead of the *value*.
        Example: '10110011'.

    hexValue: :py:class:`str`
        Hexadecimal string initializer to use instead of the *value*.
        Example: 'DEADBEEF'.

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class Icon(OctetString):
            '''
            ASN.1 specification:

            Icon ::= OCTET STRING

            icon1 Icon ::= '001100010011001000110011'B
            icon2 Icon ::= '313233'H
            '''
        icon1 = Icon.fromBinaryString('001100010011001000110011')
        icon2 = Icon.fromHexString('313233')
    r   z
iso-8859-1c                 K   s   |r\|t u r\z| |d}W n ty2   Y n0 z| |d}W n tyZ   Y n0 |t u r| jt ur|| | j}n| jt ur| | j}d|vr| j|d< tj	j
| |fi | d S )Nr   r   encoding)r   r   r   rw   r   r   r   r   r   r!   r"   r#   r'   r'   r(   r"     s$    


zOctetString.__init__r   r   c              	   C   s   t |tr|S t |trTz|| jW S  ttfyP   td|| jf Y q0 nXt |t	t
frzddd |D W S  ty   td| jj|f Y q0 nt|S d S )Nz&Can't encode string '%s' with codec %sr   c                 S   s   g | ]}t |qS r'   )chrr   r'   r'   r(   r   B  r   z(OctetString.prettyIn.<locals>.<listcomp>zBad %s initializer '%s')rG   r|   unicodeencoder   LookupErrorUnicodeEncodeErrorr   rx   r   r   r   rv   r   r   r-   r'   r'   r(   r{   6  s"    

zOctetString.prettyInc                 C   s
   t | jS r)   r|   r,   rT   r'   r'   r(   r   J  s    zOctetString.__str__c                 C   s>   z| j | jW S  ty8   td| j | jf Y n0 d S )Nz&Can't decode string '%s' with codec %s)r,   decoder   UnicodeDecodeErrorr   rx   rT   r'   r'   r(   __unicode__M  s    zOctetString.__unicode__c                 C   s
   t | jS r)   r   rT   r'   r'   r(   r   V  s    zOctetString.asOctetsc                 C   s   t dd | jD S )Nc                 S   s   g | ]}t |qS r'   )ordr   r'   r'   r(   r   Z  r   z)OctetString.asNumbers.<locals>.<listcomp>r   r,   rT   r'   r'   r(   r   Y  s    zOctetString.asNumbersc                 C   s   t |tr|S t |trPz|| jW S  tyL   td|| jf Y q0 nPt |trb|	 S t |t
jr|| t|S t |ttfr| t|S t|S d S )Nz(Can't encode string '%s' with '%s' codec)rG   bytesr|   r   r   r   r   rx   r   r   r   r!   r{   r   r   r-   r'   r'   r(   r{   ]  s     


c              	   C   sD   z| j | jW S  ty>   td| j | j| jjf Y n0 d S )Nz0Can't decode string '%s' with '%s' codec at '%s')r,   r   r   r   r   rx   r   r   rT   r'   r'   r(   r   p  s    c                 C   s
   t | jS r)   r   r,   rT   r'   r'   r(   	__bytes__y  s    zOctetString.__bytes__c                 C   s
   t | jS r)   r   rT   r'   r'   r(   r   |  s    c                 C   s
   t | jS r)   r   rT   r'   r'   r(   r     s    c                 C   s   |S r)   r'   r-   r'   r'   r(   r}     s    zOctetString.prettyOutc                 C   sb   |  | j}|| jur|S |  }|D ]0}|dk s:|dkr&dddd |D    S q&t| S )N    ~   r   r   c                 s   s   | ]}d | V  qdS )z%.2xNr'   r   r'   r'   r(   	<genexpr>  r   z*OctetString.prettyPrint.<locals>.<genexpr>)r}   r,   r   r   r   r   )r$   scoper%   numbersr   r'   r'   r(   prettyPrint  s    
zOctetString.prettyPrintc                 C   sx   d}d}g }| D ]R}|r"|d8 }nd}| | d}|dv rFt|}ntd|f |||> O }q| | t|S )r   r   r   ru      )r   r   z&Non-binary OCTET STRING initializer %s)appendrS   r   rx   r   	ints2octs)r%   ZbitNobyterc   vr'   r'   r(   r     s"    	



zOctetString.fromBinaryStringc                 C   sV   g }g }| D ]&}|r.| t|| d d}q|}q|rL| t|d d t|S )r   r   Nr   )r   rS   r   r   )r%   rc   pr  r'   r'   r(   r     s    	zOctetString.fromHexStringc                 C   s
   t | jS r)   r   rT   r'   r'   r(   r     s    zOctetString.__len__c                 C   s(   |j tu r| | j| S | j| S d S r)   r   r   r+   r,   r$   r   r'   r'   r(   r     s    
zOctetString.__getitem__c                 C   s
   t | jS r)   iterr,   rT   r'   r'   r(   r     s    zOctetString.__iter__c                 C   s
   || j v S r)   rn   r-   r'   r'   r(   __contains__  s    zOctetString.__contains__c                 C   s   |  | j| | S r)   )r+   r,   r{   r-   r'   r'   r(   r6     s    zOctetString.__add__c                 C   s   |  | || j S r)   )r+   r{   r,   r-   r'   r'   r(   r7     s    zOctetString.__radd__c                 C   s   |  | j| S r)   r*   r-   r'   r'   r(   r:     s    zOctetString.__mul__c                 C   s   | | S r)   r'   r-   r'   r'   r(   r;     s    zOctetString.__rmul__c                 C   s
   t | jS r)   rR   rT   r'   r'   r(   rU     s    zOctetString.__int__c                 C   s
   t | jS r)   rX   rT   r'   r'   r(   rY     s    zOctetString.__float__c                 C   s
   t | jS r)   )r   r,   rT   r'   r'   r(   r      s    zOctetString.__reversed__N)r   ).r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   r   r   r"   ry   r   r{   r   r   r   r   r   r}   r   staticmethodr   r   r   r   r   r  r6   r7   r:   r;   rU   rY   r   r'   r'   r'   r(   r     sJ   7
	
	


r   c                   @   sN   e Zd ZdZeeejejdZ	e
jeed Ze
 Zdd ZdS )r   a  Create |ASN.1| schema or value object.

    |ASN.1| objects are immutable and duck-type Python :class:`str` objects (always empty).

    Keyword Args
    ------------
    value: :class:`str` or :py:class:`~pyasn1.type.univ.Null` object
        Python empty string literal or any object that evaluates to `False`

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class Ack(Null):
            '''
            ASN.1 specification:

            Ack ::= NULL
            '''
        ack = Ack('')
    rk   r   c                 C   s   |r|S t dS )Nr   )r   str2octsr-   r'   r'   r(   r{   .  s    zNull.prettyInN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r   r   r{   r'   r'   r'   r(   r     s   !r   r   c                   @   s   e Zd ZdZeeejejdZ	e
 Zej 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dd Zdd Zdd ZdS )r   a%  Create |ASN.1| schema or value object.

    |ASN.1| objects are immutable and duck-type Python :class:`tuple` objects (tuple of non-negative integers).

    Keyword Args
    ------------
    value: :class:`tuple`, :class:`str` or |ASN.1| object
        Python sequence of :class:`int` or string literal or |ASN.1| object.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class ID(ObjectIdentifier):
            '''
            ASN.1 specification:

            ID ::= OBJECT IDENTIFIER

            id-edims ID ::= { joint-iso-itu-t mhs-motif(6) edims(7) }
            id-bp ID ::= { id-edims 11 }
            '''
        id_edims = ID('2.6.7')
        id_bp = id_edims + (11,)
       c                 C   s   |  | j| S r)   r*   r   r'   r'   r(   r6   p  s    zObjectIdentifier.__add__c                 C   s   |  || j S r)   r*   r   r'   r'   r(   r7   s  s    zObjectIdentifier.__radd__c                 C   s   | j S r)   rn   rT   r'   r'   r(   asTuplev  s    zObjectIdentifier.asTuplec                 C   s
   t | jS r)   r   rT   r'   r'   r(   r   {  s    zObjectIdentifier.__len__c                 C   s(   |j tu r| | j| S | j| S d S r)   r  r  r'   r'   r(   r   ~  s    
zObjectIdentifier.__getitem__c                 C   s
   t | jS r)   r  rT   r'   r'   r(   r     s    zObjectIdentifier.__iter__c                 C   s
   || j v S r)   rn   r-   r'   r'   r(   r    s    zObjectIdentifier.__contains__c                 C   s   | j |S r)   )r,   index)r$   Zsuboidr'   r'   r(   r    s    zObjectIdentifier.indexc                 C   s6   t | }|t |kr2| jd| |d| kr2dS dS )av  Indicate if this |ASN.1| object is a prefix of other |ASN.1| object.

        Parameters
        ----------
        other: |ASN.1| object
            |ASN.1| object

        Returns
        -------
        : :class:`bool`
            :class:`True` if this |ASN.1| object is a parent (e.g. prefix) of the other |ASN.1| object
            or :class:`False` otherwise.
        NTFr   )r$   r   lr'   r'   r(   
isPrefixOf  s
    zObjectIdentifier.isPrefixOfc              
   C   s  t |trt|S t|rd|v rDtd|| jjt	
 d f ztdd |dD W S  ty   td|| jjt	
 d f Y n0 ztdd |D }W n6 ttfy   td|| jjt	
 d f Y n0 t|t|kr|S td|| jjf d S )	N-z Malformed Object ID %s at %s: %sru   c                 S   s   g | ]}|rt |qS r'   rS   r   ZsubOidr'   r'   r(   r     r   z-ObjectIdentifier.prettyIn.<locals>.<listcomp>.c                 S   s   g | ]}|d krt |qS )r   r  r  r'   r'   r(   r     r   zMalformed Object ID %s at %s)rG   r   r   r   r   r   rx   r   r   ry   rz   r   rv   	TypeErrorr   )r$   r%   ZtupleOfIntsr'   r'   r(   r{     s,    



zObjectIdentifier.prettyInc                 C   s   d dd |D S )Nr  c                 S   s   g | ]}t |qS r'   )r|   r   r'   r'   r(   r     r   z.ObjectIdentifier.prettyOut.<locals>.<listcomp>)r   r-   r'   r'   r(   r}     s    zObjectIdentifier.prettyOutN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r   r6   r7   r  r   r   r   r  r  r  r{   r}   r'   r'   r'   r(   r   <  s"   '
r   c                   @   s@  e Zd ZdZdZzedZedZeefZW n e	yJ   d ZZdZY n0 e
e
e
je
jdZe Zej Zedd Zd	d
 ZdbddZedd Zedd Zed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&dcd$d%Z'd&d' Z(e)j*d d(kr,d)d* Z+d+d, Z,n d-d. Z-d/d0 Z.d1d2 Z/d3d4 Z0d5d6 Z1e)j*d d(krld7d8 Z2d9d: Z3d;d< Z4d=d> Z5d?d@ Z6dddAdBZ7dCdD Z8dEdF Z9e)j*dd( dGkrdHdI Z:dJdK Z;dLdM Z<dNdO Z=dPdQ Z>dRdS Z?dTdU Z@e)j*d d(krdVdW ZAndXdY ZBejjCZCdZd[ ZDd\d] ZEd^d_ ZFd`da ZGdS )er   aZ  Create |ASN.1| schema or value object.

    |ASN.1| objects are immutable and duck-type Python :class:`float` objects.
    Additionally, |ASN.1| objects behave like a :class:`tuple` in which case its
    elements are mantissa, base and exponent.

    Keyword Args
    ------------
    value: :class:`tuple`, :class:`float` or |ASN.1| object
        Python sequence of :class:`int` (representing mantissa, base and
        exponent) or float instance or *Real* class instance.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class Pi(Real):
            '''
            ASN.1 specification:

            Pi ::= REAL

            pi Pi ::= { mantissa 314159, base 10, exponent -5 }

            '''
        pi = Pi((314159, 10, -5))
    Ninfz-infr'   	   c                 C   s6   | \}}}|r,|d dkr,|d }|d7 }q
|||fS )N
   r   ru   r'   )r%   mr   er'   r'   r(   Z__normalizeBase10  s
    

zReal.__normalizeBase10c                 C   s  t |trt|dkrt |d tr@t |d tr@t |d tsPtd|f t |d trz| jrz|d | jv rz|d S |d dvrtd|d f |d dkr| 	|}|S t |tr| 	|ddfS t |tst
|rvt
|r"zt|}W n$ ty    td	|f Y n0 | jr:|| jv r:|S d}t||kr`|d9 }|d8 }q>| 	t|d|fS nt |trt|S td	|f d S )
Nr   r   ru   r   zLame Real value syntax: %s)r   r  z"Prohibited base for Real value: %sr  zBad real value syntax: %s)rG   r   r   numericTypesr   r   rx   rH   _inf_Real__normalizeBase10r   r   rv   rS   r   )r$   r%   r  r'   r'   r(   r{     sT    


zReal.prettyInr   c                 C   s*   z|  t| W S  ty$   Y dS 0 d S )Nz
<overflow>)r}   rH   OverflowError)r$   r   r'   r'   r(   r   3  s    zReal.prettyPrintc                 C   s   | j | jkS )zIndicate PLUS-INFINITY object value

        Returns
        -------
        : :class:`bool`
            :class:`True` if calling object represents plus infinity
            or :class:`False` otherwise.

        )r,   _plusInfrT   r'   r'   r(   	isPlusInf:  s    zReal.isPlusInfc                 C   s   | j | jkS )zIndicate MINUS-INFINITY object value

        Returns
        -------
        : :class:`bool`
            :class:`True` if calling object represents minus infinity
            or :class:`False` otherwise.
        )r,   	_minusInfrT   r'   r'   r(   
isMinusInfG  s    
zReal.isMinusInfc                 C   s   | j | jv S r)   )r,   r  rT   r'   r'   r(   isInfS  s    z
Real.isInfc                 C   s   |  t| | S r)   r+   rH   r-   r'   r'   r(   r6   W  s    zReal.__add__c                 C   s   | | S r)   r'   r-   r'   r'   r(   r7   Z  s    zReal.__radd__c                 C   s   |  t| | S r)   r#  r-   r'   r'   r(   r:   ]  s    zReal.__mul__c                 C   s   | | S r)   r'   r-   r'   r'   r(   r;   `  s    zReal.__rmul__c                 C   s   |  t| | S r)   r#  r-   r'   r'   r(   r8   c  s    zReal.__sub__c                 C   s   |  |t|  S r)   r#  r-   r'   r'   r(   r9   f  s    zReal.__rsub__c                 C   s   |  t| | S r)   r#  r-   r'   r'   r(   r<   i  s    zReal.__mod__c                 C   s   |  |t|  S r)   r#  r-   r'   r'   r(   r=   l  s    zReal.__rmod__c                 C   s   |  tt| ||S r)   r+   r?   rH   r@   r'   r'   r(   rB   o  s    zReal.__pow__c                 C   s   |  t|t| S r)   r$  r-   r'   r'   r(   rC   r  s    zReal.__rpow__r   c                 C   s   |  t| | S r)   r#  r-   r'   r'   r(   rI   v  s    zReal.__div__c                 C   s   |  |t|  S r)   r#  r-   r'   r'   r(   rJ   y  s    zReal.__rdiv__c                 C   s   |  t| | S r)   r#  r-   r'   r'   r(   rL   |  s    zReal.__truediv__c                 C   s   |  |t|  S r)   r#  r-   r'   r'   r(   rM     s    zReal.__rtruediv__c                 C   s   |  t| | S r)   r#  r-   r'   r'   r(   rP     s    zReal.__divmod__c                 C   s   |  |t|  S r)   r#  r-   r'   r'   r(   rQ     s    zReal.__rdivmod__c                 C   s   t t| S r)   )rS   rH   rT   r'   r'   r(   rU     s    zReal.__int__c                 C   s   t t| S r)   )rV   rH   rT   r'   r'   r(   rW     s    zReal.__long__c                 C   s:   | j | jv r| j S t| j d t| j d | j d  S d S )Nr   ru   r   )r,   r  rH   r?   rT   r'   r'   r(   rY     s
    zReal.__float__c                 C   s   |  tt| S r)   )r+   rZ   rH   rT   r'   r'   r(   r[     s    zReal.__abs__c                 C   s   |  t| 
 S r)   r#  rT   r'   r'   r(   r]     s    zReal.__pos__c                 C   s   |  t|  S r)   r#  rT   r'   r'   r(   r^     s    zReal.__neg__c                 C   s$   t t| |}|r| |S |S d S r)   )r`   rH   r+   ra   r'   r'   r(   rd     s    
zReal.__round__c                 C   s   |  tt| S r)   )r+   re   rf   rH   rT   r'   r'   r(   rg     s    zReal.__floor__c                 C   s   |  tt| S r)   )r+   re   rh   rH   rT   r'   r'   r(   ri     s    zReal.__ceil__rj   c                 C   s   |  tt| S r)   )r+   re   rl   rH   rT   r'   r'   r(   rm     s    zReal.__trunc__c                 C   s   t | |k S r)   rH   r-   r'   r'   r(   ro     s    zReal.__lt__c                 C   s   t | |kS r)   r%  r-   r'   r'   r(   rp     s    zReal.__le__c                 C   s   t | |kS r)   r%  r-   r'   r'   r(   rq     s    zReal.__eq__c                 C   s   t | |kS r)   r%  r-   r'   r'   r(   rr     s    zReal.__ne__c                 C   s   t | |kS r)   r%  r-   r'   r'   r(   rs     s    zReal.__gt__c                 C   s   t | |kS r)   r%  r-   r'   r'   r(   rt     s    zReal.__ge__c                 C   s   t t| S r)   boolrH   rT   r'   r'   r(   __nonzero__  s    zReal.__nonzero__c                 C   s   t t| S r)   r&  rT   r'   r'   r(   __bool__  s    zReal.__bool__c                 C   s&   | j | jv rtdn
| j | S d S )Nz Invalid infinite value operation)r,   r  r   rx   r$   idxr'   r'   r(   r     s    zReal.__getitem__c                 C   s   | j S r)   )r  rT   r'   r'   r(   isPlusInfinity  s    zReal.isPlusInfinityc                 C   s   | j S r)   )r!  rT   r'   r'   r(   isMinusInfinity  s    zReal.isMinusInfinityc                 C   s   | j S r)   )r"  rT   r'   r'   r(   
isInfinity  s    zReal.isInfinity)r   )N)r   )Hr   r   r   r   Z
binEncBaserH   r  r   r  rv   r   r   r   r   r   r   r   r   r   r   r!   r   r   r	  r  r{   r   propertyr  r!  r"  r6   r7   r:   r;   r8   r9   r<   r=   rB   rC   ry   r   rI   rJ   rL   rM   rP   rQ   rU   rW   rY   r[   r]   r^   rd   rg   ri   rm   ro   rp   rq   rr   rs   rt   r(  r)  r   r   r,  r-  r.  r'   r'   r'   r(   r     s   &


(







r   c                   @   s@   e Zd ZdZeeejejdZ	e
 Ze Ze ZdS )r   a  Create |ASN.1| type or object.

    |ASN.1| objects are immutable and duck-type Python :class:`int` objects.

    Keyword Args
    ------------
    value: :class:`int`, :class:`str` or |ASN.1| object
        Python integer or string literal or |ASN.1| class instance.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    namedValues: :py:class:`~pyasn1.type.namedval.NamedValues`
        Object representing non-default symbolic aliases for numbers

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------

    .. code-block:: python

        class RadioButton(Enumerated):
            '''
            ASN.1 specification:

            RadioButton ::= ENUMERATED { button1(0), button2(1),
                                         button3(2) }

            selected-by-default RadioButton ::= button1
            '''
            namedValues = NamedValues(
                ('button1', 0), ('button2', 1),
                ('button3', 2)
            )

        selected_by_default = RadioButton('button1')
    r  N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r    r'   r'   r'   r(   r     s   /r   c                   @   s   e 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dZdd Zd+ddZdd Zdd ZedfddZedddfd d!Zed"d# Zd,d$d%Zd-d&d'Zed(d) ZdS ).r   a  Create |ASN.1| type.

    |ASN.1| objects are mutable and duck-type Python :class:`list` objects.

    Keyword Args
    ------------
    componentType : :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
        A pyasn1 object representing ASN.1 type allowed within |ASN.1| type

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    sizeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing collection size constraint

    Examples
    --------

    .. code-block:: python

        class LotteryDraw(SequenceOf):  #  SetOf is similar
            '''
            ASN.1 specification:

            LotteryDraw ::= SEQUENCE OF INTEGER
            '''
            componentType = Integer()

        lotteryDraw = LotteryDraw()
        lotteryDraw.extend([123, 456, 789])
    c                 O   sJ   |r2t d|D ]"\}}||v r(td||d< qtjj| fi | d S )N)componentTyper   r   sizeSpecz*Conflicting positional and keyword params!r0  )zipr   rx   r   AbstractConstructedAsn1Itemr"   )r$   argsr&   keyr%   r'   r'   r(   r"   D  s    

zSequenceOfAndSetOfBase.__init__c                 C   s6   z|  |W S  tjy0   tt d Y n0 d S r   )getComponentByPositionr   rx   r   ry   rz   r*  r'   r'   r(   r   Q  s    z"SequenceOfAndSetOfBase.__getitem__c                 C   s:   z|  || W n$ tjy4   tt d Y n0 d S r   )setComponentByPositionr   rx   r   ry   rz   r$   r+  r%   r'   r'   r(   __setitem__X  s    z"SequenceOfAndSetOfBase.__setitem__c                 C   s
   g | _ d S r)   _componentValuesrT   r'   r'   r(   clear_  s    zSequenceOfAndSetOfBase.clearc                 C   s   || t | < d S r)   )r   r-   r'   r'   r(   r   b  s    zSequenceOfAndSetOfBase.appendc                 C   s   | j |S r)   )r;  r   r-   r'   r'   r(   r   e  s    zSequenceOfAndSetOfBase.countc                 C   s   |D ]}|  | qd S r)   )r   )r$   valuesr%   r'   r'   r(   extendh  s    zSequenceOfAndSetOfBase.extendr   Nc                 C   sL   |d u rt | }z| j|||W S  tjyF   tt d Y n0 d S r   )r   r;  r  r   rx   rv   ry   rz   )r$   r%   startstopr'   r'   r(   r  l  s    zSequenceOfAndSetOfBase.indexc                 C   s   | j   d S r)   )r;  reverserT   r'   r'   r(   rA  u  s    zSequenceOfAndSetOfBase.reverseFc                 C   s   | j j||d d S )N)r5  rA  )r;  sort)r$   r5  rA  r'   r'   r(   rB  x  s    zSequenceOfAndSetOfBase.sortc                 C   s
   t | jS r)   )r  r;  rT   r'   r'   r(   r   {  s    zSequenceOfAndSetOfBase.__iter__c                 C   sR   t | jD ]B\}}|tur
t|tjr<|||j|d q
|||  q
d S N)cloneValueFlag	enumerater;  r   rG   r   r3  r7  r+   r$   myClonerD  r+  componentValuer'   r'   r(   _cloneComponentValues~  s    z,SequenceOfAndSetOfBase._cloneComponentValuesTc                 C   s\   z| j | }W n2 ty@   |s(| Y S | | | j | }Y n0 |tu sP|jrT|S |S dS )a!  Return |ASN.1| type component value by position.

        Equivalent to Python sequence subscription operation (e.g. `[]`).

        Parameters
        ----------
        idx : :class:`int`
            Component index (zero-based). Must either refer to an existing
            component or to N+1 component (if *componentType* is set). In the latter
            case a new component type gets instantiated and appended to the |ASN.1|
            sequence.

        Keyword Args
        ------------
        default: :class:`object`
            If set and requested component is a schema object, return the `default`
            object instead of the requested component.

        instantiate: :class:`bool`
            If `True` (default), inner component will be automatically instantiated.
            If 'False' either existing component or the `noValue` object will be
            returned.

        Returns
        -------
        : :py:class:`~pyasn1.type.base.PyAsn1Item`
            Instantiate |ASN.1| component type or return existing component value

        Examples
        --------

        .. code-block:: python

            # can also be SetOf
            class MySequenceOf(SequenceOf):
                componentType = OctetString()

            s = MySequenceOf()

            # returns component #0 with `.isValue` property False
            s.getComponentByPosition(0)

            # returns None
            s.getComponentByPosition(0, default=None)

            s.clear()

            # returns noValue
            s.getComponentByPosition(0, instantiate=False)

            # sets component #0 to OctetString() ASN.1 schema
            # object and returns it
            s.getComponentByPosition(0, instantiate=True)

            # sets component #0 to ASN.1 value object
            s.setComponentByPosition(0, 'ABCD')

            # returns OctetString('ABCD') value object
            s.getComponentByPosition(0, instantiate=False)

            s.clear()

            # returns noValue
            s.getComponentByPosition(0, instantiate=False)
        N)r;  r   r7  r   isValuer$   r+  defaultinstantiaterI  r'   r'   r(   r6    s    B
z-SequenceOfAndSetOfBase.getComponentByPositionc                 C   s  | j }z| j| }W n. tyB   t}t| j|k r>tdY n0 |tu rr|dur^| }n|tu rptdnt|t	j
s|durt|t	jr|j|d}n4|turt|t	jr|j|d}ntd|| f nX|dur.| jr||||s.td||f n"||||s.td||f |r|jrz| || W n8 tjy   t \}}	}
|d|	| jjf Y n0 |tu r| j| n
|| j|< | S )a  Assign |ASN.1| type component by position.

        Equivalent to Python sequence item assignment operation (e.g. `[]`)
        or list.append() (when idx == len(self)).

        Parameters
        ----------
        idx: :class:`int`
            Component index (zero-based). Must either refer to existing
            component or to N+1 component. In the latter case a new component
            type gets instantiated (if *componentType* is set, or given ASN.1
            object is taken otherwise) and appended to the |ASN.1| sequence.

        Keyword Args
        ------------
        value: :class:`object` or :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
            A Python value to initialize |ASN.1| component with (if *componentType* is set)
            or ASN.1 value object to assign to |ASN.1| component.

        verifyConstraints: :class:`bool`
             If `False`, skip constraints validation

        matchTags: :class:`bool`
             If `False`, skip component tags matching

        matchConstraints: :class:`bool`
             If `False`, skip component constraints matching

        Returns
        -------
        self

        Raises
        ------
        IndexError:
            When idx > len(self)
        Component index out of rangeNComponent type not definedr%   z5Non-ASN.1 value %r and undefined component type at %r-Component value is tag-incompatible: %r vs %r%s at %s)r0  r;  r   r   r   r   rx   r+   rG   r   Asn1Itemr!   strictConstraintsisSameTypeWithisSuperTypeOfrK  r   ry   rz   r   r   r   )r$   r+  r%   verifyConstraints	matchTagsmatchConstraintsr0  currentValueexTypeexValueexTbr'   r'   r(   r7    sD    )



z-SequenceOfAndSetOfBase.setComponentByPositionc                 C   s   | j d ur| j jS d S r)   )r0  tagMaprT   r'   r'   r(   componentTagMap0  s    
z&SequenceOfAndSetOfBase.componentTagMapc                 C   sb   |d7 }| j jd }t| jD ]>\}}|d| 7 }|tu rN| jd urN|d7 }q|||7 }q|S )Nru   :
 z<empty>)r   r   rF  r;  r   r0  r   r$   r   representationr+  rI  r'   r'   r(   r   5  s    
z"SequenceOfAndSetOfBase.prettyPrintc                 C   sX   |d7 }d| j | jjf }| jd ur@|d| 7 }|| j|7 }|d d|d   d S )Nru   %s -> %s {
rb  
})r   r   r   r0  prettyPrintType)r$   r   rd  r'   r'   r(   rh  A  s    
z&SequenceOfAndSetOfBase.prettyPrintTypec                 C   s$   | j D ]}|tu s|js dS qdS W  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).
        FT)r;  r   rK  r$   rI  r'   r'   r(   rK  J  s    
zSequenceOfAndSetOfBase.isValue)r   N)NF)r   )r   )r   r   r   r   r"   r   r9  r<  r   r   r>  r  rA  rB  r   rJ  r   r6  r7  r/  r`  r   rh  rK  r'   r'   r'   r(   r   !  s2   "
	

R
V


	r   c                   @   sF   e Zd ZejZeeejej	dZ
dZe Ze Ze ZdS )r   r   Nr   r   r   r   r   r   r   r   r   tagFormatConstructedr   r0  r   r   r   r1  r   r   r'   r'   r'   r(   r   l  s   r   c                   @   sF   e Zd ZejZeeejej	dZ
dZe Ze Ze ZdS )r      Nrl  r'   r'   r'   r(   r     s   r   c                   @   s   e Zd ZdZe ZG dd de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dd Zdd Zdd ZedfddZedddfddZedfdd Zedddfd!d"Zed#d$ Zd1d&d'Zd2d(d)Zd*d+ Zd,d- Zd.d/ Zd0S )3r   a:  Create |ASN.1| type.

    |ASN.1| objects are mutable and duck-type Python :class:`dict` objects.

    Keyword Args
    ------------
    componentType: :py:class:`~pyasn1.type.namedtype.NamedType`
        Object holding named ASN.1 types allowed within this collection

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    sizeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing collection size constraint

    Examples
    --------

    .. code-block:: python

        class Description(Sequence):  #  Set is similar
            '''
            ASN.1 specification:

            Description ::= SEQUENCE {
                surname    IA5String,
                first-name IA5String OPTIONAL,
                age        INTEGER DEFAULT 40
            }
            '''
            componentType = NamedTypes(
                NamedType('surname', IA5String()),
                OptionalNamedType('first-name', IA5String()),
                DefaultedNamedType('age', Integer(40))
            )

        descr = Description()
        descr['surname'] = 'Smith'
        descr['first-name'] = 'John'
    c                   @   sP   e 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dS )zSequenceAndSetBase.DynamicNamesz9Fields names/positions mapping for component-less objectsc                 C   s   i | _ i | _d S r)   _keyToIdxMap_idxToKeyMaprT   r'   r'   r(   r"     s    z(SequenceAndSetBase.DynamicNames.__init__c                 C   s
   t | jS r)   )r   rp  rT   r'   r'   r(   r     s    z'SequenceAndSetBase.DynamicNames.__len__c                 C   s   || j v p|| jv S r)   ro  r$   itemr'   r'   r(   r    s    z,SequenceAndSetBase.DynamicNames.__contains__c                    s    fddt t jD S )Nc                 3   s   | ]} j | V  qd S r)   )rq  )r   r+  rT   r'   r(   r     r   z;SequenceAndSetBase.DynamicNames.__iter__.<locals>.<genexpr>)r   r   rq  rT   r'   rT   r(   r     s    z(SequenceAndSetBase.DynamicNames.__iter__c                 C   s.   z| j | W S  ty(   | j|  Y S 0 d S r)   )rp  rw   rq  rr  r'   r'   r(   r     s    z+SequenceAndSetBase.DynamicNames.__getitem__c                 C   s.   z| j | W S  ty(   tdY n0 d S )NzType position out of range)rq  rw   r   rx   r*  r'   r'   r(   getNameByPosition  s    z1SequenceAndSetBase.DynamicNames.getNameByPositionc                 C   s4   z| j | W S  ty.   td|f Y n0 d S )NName %s not found)rp  rw   r   rx   )r$   r   r'   r'   r(   getPositionByName  s    z1SequenceAndSetBase.DynamicNames.getPositionByNamec                 C   s    || j d| < d| | j|< d S )Nzfield-%dro  r*  r'   r'   r(   addField  s    z(SequenceAndSetBase.DynamicNames.addFieldN)r   r   r   r   r"   r   r  r   r   rt  rv  rw  r'   r'   r'   r(   DynamicNames  s   rx  c                 K   s4   t jj| fi | t| j| _| jp,|  | _d S r)   )r   r3  r"   r   r0  _componentTypeLenrx  _dynamicNames)r$   r&   r'   r'   r(   r"     s    zSequenceAndSetBase.__init__c                 C   st   t |r>z| |W S  tjy:   tt d Y qp0 n2z| |W S  tjyn   t	t d Y n0 d S r   )
r   r   getComponentByNamer   rx   rw   ry   rz   r6  r   r*  r'   r'   r(   r     s    
zSequenceAndSetBase.__getitem__c                 C   s|   t |rBz| || W qx tjy>   tt d Y qx0 n6z| || W n$ tjyv   t	t d Y n0 d S r   )
r   r   setComponentByNamer   rx   rw   ry   rz   r7  r   r8  r'   r'   r(   r9    s    
zSequenceAndSetBase.__setitem__c                 C   s   | j r|| jv S || jv S d S r)   )ry  r0  rz  r$   r5  r'   r'   r(   r  #  s    
zSequenceAndSetBase.__contains__c                 C   s   t | jp| jS r)   )r  r0  rz  rT   r'   r'   r(   r   )  s    zSequenceAndSetBase.__iter__c                 c   s(   t | jpt| jD ]}| | V  qd S r)   )r   ry  r   rz  r*  r'   r'   r(   r=  .  s    zSequenceAndSetBase.valuesc                 C   s   t | S r)   )r  rT   r'   r'   r(   keys2  s    zSequenceAndSetBase.keysc                 c   sP   t | jpt| jD ]6}| jr6| j| j| | fV  q| j| | | fV  qd S r)   )r   ry  r   rz  r0  r   r*  r'   r'   r(   items5  s    zSequenceAndSetBase.itemsc                 O   s0   |D ]\}}|| |< q|D ]}|| | |< qd S r)   r'   )r$   Z	iterValueZmappingValuekr  r'   r'   r(   update<  s    
zSequenceAndSetBase.updatec                 C   s   g | _ |  | _d S r)   )r;  rx  rz  rT   r'   r'   r(   r<  B  s    zSequenceAndSetBase.clearc                 C   sR   t | jD ]B\}}|tur
t|tjr<|||j|d q
|||  q
d S rC  rE  rG  r'   r'   r(   rJ  F  s    z(SequenceAndSetBase._cloneComponentValuesTc                 C   sX   | j r| j|}n4z| j|}W n" tyF   td|f Y n0 | j|||dS )aG  Returns |ASN.1| type component by name.

        Equivalent to Python :class:`dict` subscription operation (e.g. `[]`).

        Parameters
        ----------
        name: :class:`str`
            |ASN.1| type component name

        Keyword Args
        ------------
        default: :class:`object`
            If set and requested component is a schema object, return the `default`
            object instead of the requested component.

        instantiate: :class:`bool`
            If `True` (default), inner component will be automatically instantiated.
            If 'False' either existing component or the `noValue` object will be
            returned.

        Returns
        -------
        : :py:class:`~pyasn1.type.base.PyAsn1Item`
            Instantiate |ASN.1| component type or return existing component value
        ru  rM  rN  )ry  r0  rv  rz  rw   r   rx   r6  )r$   r   rM  rN  r+  r'   r'   r(   r{  P  s    z%SequenceAndSetBase.getComponentByNamec                 C   sZ   | j r| j|}n4z| j|}W n" tyF   td|f Y n0 | |||||S )aV  Assign |ASN.1| type component by name.

        Equivalent to Python :class:`dict` item assignment operation (e.g. `[]`).

        Parameters
        ----------
        name: :class:`str`
            |ASN.1| type component name

        Keyword Args
        ------------
        value: :class:`object` or :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
            A Python value to initialize |ASN.1| component with (if *componentType* is set)
            or ASN.1 value object to assign to |ASN.1| component.

        verifyConstraints: :class:`bool`
             If `False`, skip constraints validation

        matchTags: :class:`bool`
             If `False`, skip component tags matching

        matchConstraints: :class:`bool`
             If `False`, skip component constraints matching

        Returns
        -------
        self
        ru  )ry  r0  rv  rz  rw   r   rx   r7  )r$   r   r%   rX  rY  rZ  r+  r'   r'   r(   r|  u  s     
z%SequenceAndSetBase.setComponentByNamec                 C   sv   z| j | }W n ty$   t}Y n0 |s@|tu s8|js<|S |S |tu rR| | | j | }|tu sj|jrn|S |S dS )a  Returns |ASN.1| type component by index.

        Equivalent to Python sequence subscription operation (e.g. `[]`).

        Parameters
        ----------
        idx: :class:`int`
            Component index (zero-based). Must either refer to an existing
            component or (if *componentType* is set) new ASN.1 schema object gets
            instantiated.

        Keyword Args
        ------------
        default: :class:`object`
            If set and requested component is a schema object, return the `default`
            object instead of the requested component.

        instantiate: :class:`bool`
            If `True` (default), inner component will be automatically instantiated.
            If 'False' either existing component or the `noValue` object will be
            returned.

        Returns
        -------
        : :py:class:`~pyasn1.type.base.PyAsn1Item`
            a PyASN1 object

        Examples
        --------

        .. code-block:: python

            # can also be Set
            class MySequence(Sequence):
                componentType = NamedTypes(
                    NamedType('id', OctetString())
                )

            s = MySequence()

            # returns component #0 with `.isValue` property False
            s.getComponentByPosition(0)

            # returns None
            s.getComponentByPosition(0, default=None)

            s.clear()

            # returns noValue
            s.getComponentByPosition(0, instantiate=False)

            # sets component #0 to OctetString() ASN.1 schema
            # object and returns it
            s.getComponentByPosition(0, instantiate=True)

            # sets component #0 to ASN.1 value object
            s.setComponentByPosition(0, 'ABCD')

            # returns OctetString('ABCD') value object
            s.getComponentByPosition(0, instantiate=False)

            s.clear()

            # returns noValue
            s.getComponentByPosition(0, instantiate=False)
        N)r;  r   r   rK  r7  rL  r'   r'   r(   r6    s    C


z)SequenceAndSetBase.getComponentByPositionc                 C   s  | j }| j}z| j| }W n8 tyR   t}|rN||k rBtdtg| | _Y n0 |tu r|rp|| }n|tu rtdnt	|t
js|r||}	t	|	t
jr|	j|d}ntd|jj n4|turt	|t
jr|j|d}ntd|jj nh|s|rl|rl||}	|	turl| jr:|	jp>|	j}
|
|||sl|| jsltd||f |r|jrz| || W n8 tjy   t \}}}|d|| jjf Y n0 |s|| jv r|| j|< n4t| j|kr| j| | j| n
td| S )	aJ  Assign |ASN.1| type component by position.

        Equivalent to Python sequence item assignment operation (e.g. `[]`).

        Parameters
        ----------
        idx : :class:`int`
            Component index (zero-based). Must either refer to existing
            component (if *componentType* is set) or to N+1 component
            otherwise. In the latter case a new component of given ASN.1
            type gets instantiated and appended to |ASN.1| sequence.

        Keyword Args
        ------------
        value: :class:`object` or :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
            A Python value to initialize |ASN.1| component with (if *componentType* is set)
            or ASN.1 value object to assign to |ASN.1| component.

        verifyConstraints : :class:`bool`
             If `False`, skip constraints validation

        matchTags: :class:`bool`
             If `False`, skip component tags matching

        matchConstraints: :class:`bool`
             If `False`, skip component constraints matching

        Returns
        -------
        self
        zcomponent index out of rangerP  rQ  z%s can cast only scalar valuesz%s undefined component typerR  rS  rO  )r0  ry  r;  r   r   r   rx   getTypeByPositionr+   rG   r   rT  r!   r   r   rU  rV  rW  ZopenTyperK  r   ry   rz   rz  r   r   rw  )r$   r+  r%   rX  rY  rZ  r0  ZcomponentTypeLenr[  subComponentTypeZsubtypeCheckerr\  r]  r^  r'   r'   r(   r7    s`    #




z)SequenceAndSetBase.setComponentByPositionc                 C   s|   | j }|rXt|jD ]@\}}|js|jr*q| js6 dS | j| }|tu sN|js dS qn | jD ]}|tu sp|js^ dS q^dS ri  )r0  rF  Z
namedTypesZisDefaultedZ
isOptionalr;  r   rK  )r$   r0  r+  r  rI  r'   r'   r(   rK  a	  s    


zSequenceAndSetBase.isValuer   c                 C   sz   |d7 }| j jd }t| jD ]V\}}|tur|d| 7 }| jrR|| j|7 }n|| j|7 }d|||f }q|S )zReturn an object representation string.

        Returns
        -------
        : :class:`str`
            Human-friendly object representation.
        ru   ra  rb  z%s=%s
)	r   r   rF  r;  r   r0  rt  rz  r   rc  r'   r'   r(   r   	  s    
zSequenceAndSetBase.prettyPrintc                 C   s   |d7 }d| j | jjf }t| j p*| jD ]V\}}|d| 7 }| jr^|d| j| 7 }n|d| j| 7 }d||	|f }q.|d d|d   d S )Nru   re  rb  z"%s"z%s = %s
rf  rg  )
r   r   r   rF  r0  r=  r;  rt  rz  rh  )r$   r   rd  r+  r0  r'   r'   r(   rh  	  s    
z"SequenceAndSetBase.prettyPrintTypec                 C   s   | S r)   r'   rT   r'   r'   r(   setDefaultComponents	  s    z'SequenceAndSetBase.setDefaultComponentsc                 C   s   | j r| jS d S r)   )ry  r0  rT   r'   r'   r(   getComponentType	  s    z#SequenceAndSetBase.getComponentTypec                 C   s   | j r| j| jS d S r)   )ry  r0  r   r*  r'   r'   r(   rt  	  s    z$SequenceAndSetBase.getNameByPositionN)r   )r   ) r   r   r   r   r	   
NamedTypesr0  objectrx  r"   r   r9  r  r   r=  r~  r  r  r<  rJ  r   r{  r|  r6  r7  r/  rK  r   rh  r  r  rt  r'   r'   r'   r(   r     sB   -)
%
-Y
f
/

r   c                   @   sZ   e Zd ZejZeeejej	dZ
e Ze Ze Ze Zdd Zdd ZdS )r   r   c                 C   s   | j r| j |S d S r)   )r0  ZgetTagMapNearPositionr*  r'   r'   r(   getComponentTagMapNearPosition	  s    z'Sequence.getComponentTagMapNearPositionc                 C   s   | j r| j ||S |S d S r)   )r0  ZgetPositionNearType)r$   r   r+  r'   r'   r(   getComponentPositionNearType	  s    z%Sequence.getComponentPositionNearTypeN)r   r   r   r   r   r   r   r   r   rm  r   r   r   r   r1  r	   r  r0  r   r   r  r  r'   r'   r'   r(   r   	  s   r   c                   @   s   e Zd ZejZeeejej	dZ
e Ze Ze Ze ZdddZeddfddZeddddfdd	Zed
d ZdS )r   rn  Fc                 C   s   | S r)   r'   )r$   	innerFlagr'   r'   r(   getComponent
  s    zSet.getComponentTc                 C   s:   | j | j|||d}|r2t|tr2|jddS |S dS )a  Returns |ASN.1| type component by ASN.1 tag.

        Parameters
        ----------
        tagSet : :py:class:`~pyasn1.type.tag.TagSet`
            Object representing ASN.1 tags to identify one of
            |ASN.1| object component

        Keyword Args
        ------------
        default: :class:`object`
            If set and requested component is a schema object, return the `default`
            object instead of the requested component.

        instantiate: :class:`bool`
            If `True` (default), inner component will be automatically instantiated.
            If 'False' either existing component or the `noValue` object will be
            returned.

        Returns
        -------
        : :py:class:`~pyasn1.type.base.PyAsn1Item`
            a pyasn1 object
        r  Tr  N)r6  r0  getPositionByTyperG   r   r  )r$   r   rM  rN  r  rI  r'   r'   r(   getComponentByType
  s    
zSet.getComponentByTypec           	      C   sl   | j |}|rV| j |}|jr4| |||||S | |}|j||||||dS n| |||||S dS )a  Assign |ASN.1| type component by ASN.1 tag.

        Parameters
        ----------
        tagSet : :py:class:`~pyasn1.type.tag.TagSet`
            Object representing ASN.1 tags to identify one of
            |ASN.1| object component

        Keyword Args
        ------------
        value: :class:`object` or :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
            A Python value to initialize |ASN.1| component with (if *componentType* is set)
            or ASN.1 value object to assign to |ASN.1| component.

        verifyConstraints : :class:`bool`
            If `False`, skip constraints validation

        matchTags: :class:`bool`
            If `False`, skip component tags matching

        matchConstraints: :class:`bool`
            If `False`, skip component constraints matching

        innerFlag: :class:`bool`
            If `True`, search for matching *tagSet* recursively.

        Returns
        -------
        self
        r  N)r0  r  r  r   r7  r6  setComponentByType)	r$   r   r%   rX  rY  rZ  r  r+  r0  r'   r'   r(   r  ,
  s    #


zSet.setComponentByTypec                 C   s   | j r| j jS d S r)   )r0  tagMapUniquerT   r'   r'   r(   r`  b
  s    zSet.componentTagMapN)F)r   r   r   r   r   r   r   r   r   rm  r   r	   r  r0  r   r   r   r1  r   r   r  r   r  r  r/  r`  r'   r'   r'   r(   r   	  s(   

%
6r   c                   @   s>  e Zd ZdZe Ze Z	e
 Ze
e
ddZe Z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rdd Znd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%d&fd'd(Z&e%d&d&d&fd)d*Z'e(d+d, Z)e(d-d. Z*d:d0d1Z+d;d2d3Z,e(d4d5 Z-d6d7 Z.d8d9 Z/dS )<r   aA  Create |ASN.1| type.

    |ASN.1| objects are mutable and duck-type Python :class:`dict` objects.

    Keyword Args
    ------------
    componentType: :py:class:`~pyasn1.type.namedtype.NamedType`
        Object holding named ASN.1 types allowed within this collection

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    sizeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing collection size constraint

    Examples
    --------

    .. code-block:: python

        class Afters(Choice):
            '''
            ASN.1 specification:

            Afters ::= CHOICE {
                cheese  [0] IA5String,
                dessert [1] IA5String
            }
            '''
            componentType = NamedTypes(
                NamedType('cheese', IA5String().subtype(
                    implicitTag=Tag(tagClassContext, tagFormatSimple, 0)
                ),
                NamedType('dessert', IA5String().subtype(
                    implicitTag=Tag(tagClassContext, tagFormatSimple, 1)
                )
            )

        afters = Afters()
        afters['cheese'] = 'Mascarpone'
    ru   Nc                 C   s   | j r| j | j |kS tS r)   r;  _currentIdxNotImplementedr   r'   r'   r(   rq   
  s    zChoice.__eq__c                 C   s   | j r| j | j |kS tS r)   r  r   r'   r'   r(   rr   
  s    zChoice.__ne__c                 C   s   | j r| j | j |k S tS r)   r  r   r'   r'   r(   ro   
  s    zChoice.__lt__c                 C   s   | j r| j | j |kS tS r)   r  r   r'   r'   r(   rp   
  s    zChoice.__le__c                 C   s   | j r| j | j |kS tS r)   r  r   r'   r'   r(   rs   
  s    zChoice.__gt__c                 C   s   | j r| j | j |kS tS r)   r  r   r'   r'   r(   rt   
  s    zChoice.__ge__r   r   c                 C   s   | j r
dpdS NTFr:  rT   r'   r'   r(   r(  
  s    zChoice.__nonzero__c                 C   s   | j r
dpdS r  r:  rT   r'   r'   r(   r)  
  s    zChoice.__bool__c                 C   s   | j d urdpdS )Nru   r   )r  rT   r'   r'   r(   r   
  s    zChoice.__len__c                 C   s"   | j d u rdS || j| j   kS )NFr  r0  getNamer}  r'   r'   r(   r  
  s    
zChoice.__contains__c                 c   s$   | j d u rt| j| j   V  d S r)   )r  StopIterationr0  r  rT   r'   r'   r(   r   
  s    
zChoice.__iter__c                 c   s   | j d ur| j| j  V  d S r)   )r  r;  rT   r'   r'   r(   r=  
  s    
zChoice.valuesc                 c   s    | j d ur| j| j   V  d S r)   r  rT   r'   r'   r(   r~  
  s    
zChoice.keysc                 c   s*   | j d ur&| j| j   | | j  fV  d S r)   r  rT   r'   r'   r(   r  
  s    
zChoice.itemsc                 C   s   | j d u rtdd S )NComponent not chosen)r  r   rx   rT   r'   r'   r(   verifySizeSpec
  s    
zChoice.verifySizeSpecc                 C   sp   z|   }W n tjy    Y nL0 t|tr4|j}n|j}t|tjr\|	||j
|d n|	||
  d S rC  )r  r   rx   rG   r   effectiveTagSetr   r   r3  r  r+   )r$   rH  rD  	componentr   r'   r'   r(   rJ  
  s    
zChoice._cloneComponentValuesTc                 C   s6   t j}| jd u s| j|kr,t j| |||dS | j| S )Nr  )r   r   r  r6  r;  )r$   r+  rM  rN  r   r'   r'   r(   r6    s    
zChoice.getComponentByPositionc                 C   s>   | j }t| ||||| || _ |dur:||kr:t| j|< | S )a  Assign |ASN.1| type component by position.

        Equivalent to Python sequence item assignment operation (e.g. `[]`).

        Parameters
        ----------
        idx: :class:`int`
            Component index (zero-based). Must either refer to existing
            component or to N+1 component. In the latter case a new component
            type gets instantiated (if *componentType* is set, or given ASN.1
            object is taken otherwise) and appended to the |ASN.1| sequence.

        Keyword Args
        ------------
        value: :class:`object` or :py:class:`~pyasn1.type.base.PyAsn1Item` derivative
            A Python value to initialize |ASN.1| component with (if *componentType* is set)
            or ASN.1 value object to assign to |ASN.1| component. Once a new value is
            set to *idx* component, previous value is dropped.

        verifyConstraints : :class:`bool`
            If `False`, skip constraints validation

        matchTags: :class:`bool`
            If `False`, skip component tags matching

        matchConstraints: :class:`bool`
            If `False`, skip component constraints matching

        Returns
        -------
        self
        N)r  r   r7  r   r;  )r$   r+  r%   rX  rY  rZ  ZoldIdxr'   r'   r(   r7    s    $
zChoice.setComponentByPositionc                 C   s   | j r| j S |  }|jS dS )zwReturn a :class:`~pyasn1.type.tag.TagSet` object of the currently initialized component or self (if |ASN.1| is tagged).N)r   r  r  )r$   r  r'   r'   r(   r  7  s    zChoice.effectiveTagSetc                 C   s   | j rtj| S | jjS dS z"Return a :class:`~pyasn1.type.tagmap.TagMap` object mapping
            ASN.1 tags to ASN.1 objects contained within callee.
        N)r   r   r_  fgetr0  r  rT   r'   r'   r(   r_  @  s    zChoice.tagMapFc                 C   sB   | j du rtdn(| j| j  }|r:t|tr:||S |S dS )zReturn currently assigned component of the |ASN.1| object.

        Returns
        -------
        : :py:class:`~pyasn1.type.base.PyAsn1Item`
            a PyASN1 object
        Nr  )r  r   rx   r;  rG   r   r  r$   r  cr'   r'   r(   r  J  s    

zChoice.getComponentc                 C   sL   | j du rtdn2|r:| j| j  }t|tr:||S | j| j S dS )zReturn the name of currently assigned component of the |ASN.1| object.

        Returns
        -------
        : :py:class:`str`
            |ASN.1| component name
        Nr  )	r  r   rx   r;  rG   r   r  r0  rt  r  r'   r'   r(   r  [  s    


zChoice.getNamec                 C   s(   | j du rdS | j| j  }|tuo&|jS )rj  NF)r  r;  r   rK  rk  r'   r'   r(   rK  l  s    
zChoice.isValuec                 C   s   d | _ t|  d S r)   )r  r   r<  rT   r'   r'   r(   r<    s    zChoice.clearc                 C   s   | j S r)   )Z	minTagSetrT   r'   r'   r(   getMinTagSet  s    zChoice.getMinTagSet)F)F)0r   r   r   r   r   TagSetr   r	   r  r0  r   r   r   ZValueSizeConstraintr1  r   r   r   r  rq   rr   ro   rp   rs   rt   ry   r   r(  r)  r   r  r   r=  r~  r  r  rJ  r   r6  r7  r/  r  r_  r  r  rK  r<  r  r'   r'   r'   r(   r   h
  sT   /

	
+

	


!r   c                   @   s4   e Zd ZdZe Ze Z	e
 Zedd ZdS )r   a
  Create |ASN.1| schema or value object.

    |ASN.1| objects are immutable and duck-type Python 2 :class:`str` or Python 3
    :class:`bytes`. When used in Unicode context, |ASN.1| type assumes "|encoding|"
    serialisation.

    Keyword Args
    ------------
    value: :class:`str`, :class:`bytes` or |ASN.1| object
        string (Python 2) or bytes (Python 3), alternatively unicode object
        (Python 2) or string (Python 3) representing character string to be
        serialised into octets (note `encoding` parameter) or |ASN.1| object.

    tagSet: :py:class:`~pyasn1.type.tag.TagSet`
        Object representing non-default ASN.1 tag(s)

    subtypeSpec: :py:class:`~pyasn1.type.constraint.ConstraintsIntersection`
        Object representing non-default ASN.1 subtype constraint(s)

    encoding: :py:class:`str`
        Unicode codec ID to encode/decode :class:`unicode` (Python 2) or
        :class:`str` (Python 3) the payload when |ASN.1| object is used
        in text string context.

    binValue: :py:class:`str`
        Binary string initializer to use instead of the *value*.
        Example: '10110011'.

    hexValue: :py:class:`str`
        Hexadecimal string initializer to use instead of the *value*.
        Example: 'DEADBEEF'.

    Raises
    ------
    :py:class:`~pyasn1.error.PyAsn1Error`
        On constraint violation or bad initializer.

    Examples
    --------
    .. code-block:: python

        class Error(Sequence):
            '''
            ASN.1 specification:

            Error ::= SEQUENCE {
                code      INTEGER,
                parameter ANY DEFINED BY code  -- Either INTEGER or REAL
            }
            '''
            componentType=NamedTypes(
                NamedType('code', Integer()),
                NamedType('parameter', Any(),
                          openType=OpenType('code', {1: Integer(),
                                                     2: Real()}))
            )

        error = Error()
        error['code'] = 1
        error['parameter'] = Integer(1234)
    c                 C   sF   z| j W S  ty@   t| j| itjjtji| | _ | j  Y S 0 dS r  )Z_tagMapAttributeErrorr   ZTagMapr   r   ZendOfOctetsrT   r'   r'   r(   r_    s    z
Any.tagMapN)r   r   r   r   r   r  r   r   r   r   r   r   r   r/  r_  r'   r'   r'   r(   r     s   @r   )0re   ry   Zpyasn1r   Zpyasn1.codec.berr   Zpyasn1.compatr   r   r   Zpyasn1.typer   r   r	   r
   r   r   r   r   __all__r!   r   r   r   rV   ZSizedIntegerBaserS   r   r   r   	NameErrorr   r   r   rH   r  r   r   r   r3  r   r   r   r   r   r   r   r   r'   r'   r'   r(   <module>   sv   	 u;  b  30

   C  M    %'~  2