o
    B]OS                     @   sx  d dl mZ d dlmZmZmZmZmZ d dlm	Z	m
Z
 g d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jZG dd deZG dd dejZG dd dejZG dd dejZG dd dej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	jejZG d#d$ d$e	jejZG d%d& d&ejZd'S )(    )version_info)univtag
constraint	namedtypenamedval)rfc1155error)Opaque	TimeTicksBitsIntegerOctetString	IpAddress	Counter64
Unsigned32Gauge32	Integer32ObjectIdentifier	Counter32Nullc                   @      e Zd ZdZdS )r   a  Creates an instance of SNMP Null class.

    :py:class:`~pysnmp.proto.rfc1902.Null` type represents the absence
    of value.

    Parameters
    ----------
    initializer: str
        Python string object. Must be an empty string.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Null('')
        Null('')
        >>>
    N__name__
__module____qualname____doc__ r   r   6/usr/lib/python3/dist-packages/pysnmp/proto/rfc1902.pyr          r   c                   @   s<   e Zd ZdZejjedd Ze	dd Z
e	dd ZdS )	r   a  Creates an instance of SNMP Integer32 class.

    :py:class:`~pysnmp.proto.rfc1902.Integer32` type represents
    integer-valued information between -2147483648 to 2147483647
    inclusive (:RFC:`1902#section-7.1.1`). This type is indistinguishable
    from the :py:class:`~pysnmp.proto.rfc1902.Integer` type.
    The :py:class:`~pysnmp.proto.rfc1902.Integer32` type may be sub-typed
    to be more constrained than the base
    :py:class:`~pysnmp.proto.rfc1902.Integer32` type.

    Parameters
    ----------
    initializer : int
        Python integer in range between -2147483648 to 2147483647 inclusive
        or :py:class:`~pysnmp.proto.rfc1902.Integer32`.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Integer32(1234)
        Integer32(1234)
        >>> Integer32(1) > 2
        True
        >>> Integer32(1) + 1
        Integer32(2)
        >>> int(Integer32(321))
        321
        >>> SmallInteger = Integer32.withRange(1,3)
        >>> SmallInteger(1)
        Integer32(1)
        >>> DiscreetInteger = Integer32.withValues(4, 8, 1)
        >>> DiscreetInteger(4)
        Integer32(4)
        >>>

    i   ic                    s"   G  fddd } j |_ |S )z<Creates a subclass with discreet values constraint.
        c                       s   e Zd Z jej  ZdS )zInteger32.withValues.<locals>.XN)r   r   r   subtypeSpecr   SingleValueConstraintr   clsvaluesr   r   X\   s    r%   r   r#   r$   r%   r   r"   r   
withValuesW   s   zInteger32.withValuesc                    $   G  fddd } j |_ |S )z8Creates a subclass with value range constraint.
        c                          e Zd Z je ZdS )zInteger32.withRange.<locals>.XN)r   r   r   r    r   ValueRangeConstraintr   r#   maximumminimumr   r   r%   g       r%   r&   r#   r.   r-   r%   r   r,   r   	withRangeb      zInteger32.withRangeN)r   r   r   r   r   r   r    r   r+   classmethodr(   r1   r   r   r   r   r   )   s    
)

r   c                   @   s   e Zd ZdZedd ZdS )r   a&  Creates an instance of SNMP INTEGER class.

    The :py:class:`~pysnmp.proto.rfc1902.Integer` type represents
    integer-valued information as named-number enumerations
    (:RFC:`1902#section-7.1.1`). This type inherits and is indistinguishable
    from :py:class:`~pysnmp.proto.rfc1902.Integer32` class.
    The :py:class:`~pysnmp.proto.rfc1902.Integer` type may be sub-typed
    to be more constrained than the base
    :py:class:`~pysnmp.proto.rfc1902.Integer` type.

    Parameters
    ----------
    initializer : int
        Python integer in range between -2147483648 to 2147483647 inclusive
        or :py:class:`~pysnmp.proto.rfc1902.Integer`  class instance.
        In case of named-numbered enumerations, initialization is also
        possible by enumerated literal.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Integer(1234)
        Integer(1234)
        >>> Integer(1) > 2
        True
        >>> Integer(1) + 1
        Integer(2)
        >>> int(Integer(321))
        321
        >>> SomeState = Integer.withNamedValues(enable=1, disable=0)
        >>> SomeState(1)
        Integer('enable')
        >>> int(SomeState('disable'))
        0
        >>>

    c                    s@   t  j   G  fddd } j|_|S )z}Create a subclass with discreet named values constraint.

        Reduce fully duplicate enumerations along the way.
        c                       s*   e Zd Zej Z jej	   ZdS )z"Integer.withNamedValues.<locals>.XN)
r   r   r   r   NamedValuesnamedValuesr    r   r!   r$   r   r#   enumsr$   r   r   r%      s
    

r%   setr5   itemsupdater   r'   r   r6   r   withNamedValues   s
   zInteger.withNamedValuesN)r   r   r   r   r3   r<   r   r   r   r   r   n   s    +r   c                   @   s\   e Zd ZdZejjedd ZdZ	dd Z
dd Zd	d
 Zdd Zdd Zedd ZdS )r   uA  Creates an instance of SNMP OCTET STRING class.

    The :py:class:`~pysnmp.proto.rfc1902.OctetString` type represents
    arbitrary binary or text data (:RFC:`1902#section-7.1.2`).
    It may be sub-typed to be constrained in size.

    Parameters
    ----------
    strValue : str
        Python string or :py:class:`~pysnmp.proto.rfc1902.OctetString`
        class instance.

    Other parameters
    ----------------
    hexValue : str
        Python string representing octets in a hexadecimal notation
        (e.g. DEADBEEF).

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> OctetString('some apples')
        OctetString('some apples')
        >>> OctetString('some apples') + ' and oranges'
        OctetString('some apples and oranges')
        >>> str(OctetString('some apples'))
        'some apples'
        >>> SomeString = OctetString.withSize(3, 12)
        >>> str(SomeString(hexValue='deadbeef'))
        'Þ­¾ï'
        >>>

    r   i  Nc                 C   s
   || _ | S NfixedLengthselfvaluer   r   r   setFixedLength   s   zOctetString.setFixedLengthc                 C   s
   | j d uS r=   r>   rA   r   r   r   isFixedLength   s   
zOctetString.isFixedLengthc                 C   s   | j S r=   r>   rD   r   r   r   getFixedLength   s   zOctetString.getFixedLengthc                 O   $   t jj| g|R i ||  S r=   )r   r   clonerC   rF   rA   argskwargsr   r   r   rH         $zOctetString.clonec                 O   rG   r=   )r   r   subtyperC   rF   rI   r   r   r   rM      rL   zOctetString.subtypec                    r)   )z7Creates a subclass with value size constraint.
        c                       r*   )zOctetString.withSize.<locals>.XN)r   r   r   r    r   ValueSizeConstraintr   r,   r   r   r%      r/   r%   r&   r0   r   r,   r   withSize   r2   zOctetString.withSize)r   r   r   r   r   r   r    r   rN   r?   rC   rE   rF   rH   rM   r3   rO   r   r   r   r   r      s    
&r   c                   @   r   )r   a  Creates an instance of SNMP OBJECT IDENTIFIER class.

    The :py:class:`~pysnmp.proto.rfc1902.ObjectIdentifier` type represents
    administratively assigned names (:RFC:`1902#section-7.1.3`).
    Supports sequence protocol where elements are integer sub-identifiers.

    Parameters
    ----------
    initializer: tuple, str
        Python tuple of up to 128 integers in range between 0 to 4294967295
        inclusive or Python string containing OID in "dotted" form or
        :py:class:`~pysnmp.proto.rfc1902.ObjectIdentifier`.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> ObjectIdentifier((1, 3, 6))
        ObjectIdentifier('1.3.6')
        >>> ObjectIdentifier('1.3.6')
        ObjectIdentifier('1.3.6')
        >>> tuple(ObjectIdentifier('1.3.6'))
        (1, 3, 6)
        >>> str(ObjectIdentifier('1.3.6'))
        '1.3.6'
        >>>

    Nr   r   r   r   r   r      r   r   c                   @   sP   e Zd ZdZejeej	ej
dZejedd ZdZdd Zdd ZdS )	r   a/  Creates an instance of SNMP IpAddress class.

    The :py:class:`~pysnmp.proto.rfc1902.IpAddress` class represents
    a 32-bit internet address as an OCTET STRING of length 4, in network
    byte-order (:RFC:`1902#section-7.1.5`).

    Parameters
    ----------
    strValue : str
        The same as :py:class:`~pysnmp.proto.rfc1902.OctetString`,
        additionally IPv4 address in dotted notation ('127.0.0.1').

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> IpAddress('127.0.0.1')
        IpAddress(hexValue='7f000001')
        >>> str(IpAddress(hexValue='7f000001'))
        '  '
        >>> IpAddress('  ')
        IpAddress(hexValue='7f000001')
        >>>

    r      c                 C   sj   t |tr"t|dkr"zdd |dD }W n
   td| t| |}t|dkr3td|S )NrP   c                 S      g | ]}t |qS r   )int.0xr   r   r   
<listcomp>E      z&IpAddress.prettyIn.<locals>.<listcomp>.zBad IP address syntax %szBad IP address syntax)
isinstancestrlensplitr	   ProtocolErrorr   prettyInr@   r   r   r   r^   B  s   
zIpAddress.prettyInc                 C   s&   |rd dd | | D S dS )NrX   c                 S   s   g | ]}d | qS )z%dr   rS   r   r   r   rV   P  rW   z'IpAddress.prettyOut.<locals>.<listcomp> )join	__class__	asNumbersr@   r   r   r   	prettyOutM  s
   zIpAddress.prettyOutN)r   r   r   r   r   tagSettagImplicitlyr   TagtagClassApplicationtagFormatSimpler    r   rN   r?   r^   rc   r   r   r   r   r     s    r   c                   @   @   e Zd ZdZejje	ej
ejdZejjedd ZdS )r   aF  Creates an instance of SNMP Counter32 class.

    :py:class:`~pysnmp.proto.rfc1902.Counter32` type represents
    a non-negative integer which monotonically increases until it
    reaches a maximum value of 4294967295, when it wraps around and
    starts increasing again from zero (:RFC:`1902#section-7.1.6`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Counter32(1234)
        Counter32(1234)
        >>> Counter32(1) + 1
        Counter32(2)
        >>> int(Counter32(321))
        321
        >>>

       r       Nr   r   r   r   r   r   rd   re   r   rf   rg   rh   r    r   r+   r   r   r   r   r   V      

r   c                   @   ri   )r   a-  Creates an instance of SNMP Gauge32 class.

    :py:class:`~pysnmp.proto.rfc1902.Gauge32` type represents
    a non-negative integer, which may increase or decrease, but shall
    never exceed a maximum value. The maximum value can not be greater
    than 4294967295 (:RFC:`1902#section-7.1.7`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Gauge32(1234)
        Gauge32(1234)
        >>> Gauge32(1) + 1
        Gauge32(2)
        >>> int(Gauge32(321))
        321
        >>>

       r   rk   Nrl   r   r   r   r   r   }  rm   r   c                   @   ri   )r   a  Creates an instance of SNMP Unsigned32 class.

    :py:class:`~pysnmp.proto.rfc1902.Unsigned32` type represents
    integer-valued information between 0 and 4294967295
    (:RFC:`1902#section-7.1.11`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Unsigned32(1234)
        Unsigned32(1234)
        >>> Unsigned32(1) + 1
        Unsigned32(2)
        >>> int(Unsigned32(321))
        321
        >>>

    rn   r   rk   Nrl   r   r   r   r   r         

r   c                   @   ri   )r   a  Creates an instance of SNMP TimeTicks class.

    :py:class:`~pysnmp.proto.rfc1902.TimeTicks` type represents
    a non-negative integer which represents the time, modulo 4294967296,
    in hundredths of a second between two epochs (:RFC:`1902#section-7.1.8`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> TimeTicks(1234)
        TimeTicks(1234)
        >>> TimeTicks(1) + 1
        TimeTicks(2)
        >>> int(TimeTicks(321))
        321
        >>>

       r   rk   Nrl   r   r   r   r   r     ro   r   c                   @   s,   e Zd ZdZejje	ej
ejdZdS )r
   uw  Creates an instance of SNMP Opaque class.

    The :py:class:`~pysnmp.proto.rfc1902.Opaque` type supports the
    capability to pass arbitrary ASN.1 syntax.  A value is encoded
    using the ASN.1 BER into a string of octets.  This, in turn, is
    encoded as an OCTET STRING, in effect "double-wrapping" the original
    ASN.1 value (:RFC:`1902#section-7.1.9`).

    Parameters
    ----------
    strValue : str
        Python string or :py:class:`~pysnmp.proto.rfc1902.OctetString`-based
        class instance.

    Other parameters
    ----------------
    hexValue : str
        Python string representing octets in a hexadecimal notation
        (e.g. DEADBEEF).

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Opaque('some apples')
        Opaque('some apples')
        >>> Opaque('some apples') + ' and oranges'
        Opaque('some apples and oranges')
        >>> str(Opaque('some apples'))
        'some apples'
        >>> str(Opaque(hexValue='deadbeef'))
        'Þ­¾ï'
        >>>

    rP   N)r   r   r   r   r   r   rd   re   r   rf   rg   rh   r   r   r   r   r
     s
    'r
   c                   @   ri   )r   aQ  Creates an instance of SNMP Counter64 class.

    :py:class:`~pysnmp.proto.rfc1902.Counter64` type represents
    a non-negative integer which monotonically increases until it reaches
    a maximum value of 18446744073709551615, when it wraps around and starts
    increasing again from zero (:RFC:`1902#section-7.1.10`).

    Parameters
    ----------
    initializer : int
        Python integer in range between 0 to 4294967295 inclusive
        or any :py:class:`~pysnmp.proto.rfc1902.Integer`-based class.

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> Counter64(1234)
        Counter64(1234)
        >>> Counter64(1) + 1
        Counter64(2)
        >>> int(Counter64(321))
        321
        >>>

       r   l    Nrl   r   r   r   r   r     rm   r   c                   @   s<   e Zd ZdZe Zdd Zdd Zdd Z	e
dd	 Zd
S )r   u  Creates an instance of SNMP BITS class.

    The :py:class:`~pysnmp.proto.rfc1902.Bits` type represents
    an enumeration of named bits. This collection is assigned non-negative,
    contiguous values, starting at zero. Only those named-bits so enumerated
    may be present in a value (:RFC:`1902#section-7.1.4`).

    The bits are named and identified by their position in the octet string.
    Position zero is the high order (or left-most) bit in the first octet of
    the string. Position 7 is the low order (or right-most) bit of the first
    octet of the string. Position 8 is the high order bit in the second octet
    of the string, and so on
    (`BITS Pseudotype <https://tools.ietf.org/html/draft-perkins-bits-00>`_).

    Parameters
    ----------
    strValue : str, tuple
        Sequence of bit names or a Python string (as a raw data) or
        :py:class:`~pysnmp.proto.rfc1902.OctetString` class instance.

    Other parameters
    ----------------
    hexValue : str
        Python string representing octets in a hexadecimal notation
        (e.g. DEADBEEF).

    Raises
    ------
        PyAsn1Error :
            On constraint violation or bad initializer.

    Examples
    --------
        >>> from pysnmp.proto.rfc1902 import *
        >>> SomeBits = Bits.withNamedBits(apple=0, orange=1, peach=2)
        >>> SomeBits(('apple', 'orange')).prettyPrint()
        'apple, orange'
        >>> SomeBits(('apple', 'orange'))
        Bits(hexValue='c0')
        >>> SomeBits('')
        Bits(hexValue='80')
        >>> SomeBits(hexValue='80')
        Bits(hexValue='80')
        >>> SomeBits(hexValue='80').prettyPrint()
        'apple'
        >>>

    c                 O   s:   d|v r| j di t|d}||i |S t| S )Nr5   r   )withNamedBitsdictpopr   __new__)r#   rJ   rK   r   r   r   r   ru   w  s   
zBits.__new__c                 C   s   t |ttfst| |S g }|D ]:}| j|}|d u r$td| t	|d\}}|t
|kr?|dg|t
| d   ||  dd| > O  < qt| |S )NzUnknown named bit %s   r   rj      )rY   tuplelistr   r^   r5   ZgetValuer	   r]   divmodr[   extend)rA   bitsZoctetsbitvdmr   r   r   r^   ~  s   zBits.prettyInc                 C   s   g }|  | }t|D ]<\}}|| }d}|dkrI|d|> @ rA| j|d d | }|d u r<d|d d | f }|| |d8 }|dksqddd |D S )	Nrw   r   rj   rv   zUnknownBit-%sz, c                 S   rQ   r   )rZ   rS   r   r   r   rV     rW   z"Bits.prettyOut.<locals>.<listcomp>)ra   rb   	enumerater5   ZgetNameappendr`   )rA   rB   namesZintsir~   jnamer   r   r   rc     s   
zBits.prettyOutc                    s<   t | j   |  G  fddd| }| j|_|S )z|Creates a subclass with discreet named bits constraint.

        Reduce fully duplicate enumerations along the way.
        c                       s   e Zd Zej  ZdS )zBits.withNamedBits.<locals>.XN)r   r   r   r   r4   r5   r   r7   r   r   r%     s    r%   r8   r'   r   r   r   rr     s
   zBits.withNamedBitsN)r   r   r   r   r   r4   r5   ru   r^   rc   r3   rr   r   r   r   r   r   D  s    0r   c                   @   s   e Zd ZdS )
ObjectNameN)r   r   r   r   r   r   r   r     s    r   c                	   @   s:   e Zd Zeede ede ede	 Z
dS )SimpleSyntaxzinteger-valuezstring-valuezobjectID-valueN)r   r   r   r   
NamedTypes	NamedTyper   r   r   r   componentTyper   r   r   r   r     s    r   c                   @   s\   e Zd Zeede ede ede ede	 ede
 ede ZdS )ApplicationSyntaxzipAddress-valuezcounter-valueztimeticks-valuezarbitrary-valuezbig-counter-valuezgauge32-valueN)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eede ede ZdS )ObjectSyntaxsimplezapplication-wideN)	r   r   r   r   r   r   r   r   r   r   r   r   r   r     s
    r   N)sysr   Zpyasn1.typer   r   r   r   r   Zpysnmp.protor   r	   __all__r   r   r   r   r   r   r   r   r   r   r
   r   r   r   ZTypeCoercionHackMixInZChoicer   r   r   r   r   r   r   <module>   s*   E>M#:''&&-'g