o
    B]5q                     @   sT  d dl Z d dlZd dlZd dlT d dlmZ d dlmZ d dlm	Z	 d dl
mZ eddd	d
\ZZZedd\Zedddddd\ZZZZZeddddd\ZZZZG dd deZG dd deeZG dd deeZG dd deeZG d d! d!eeZ G d"d# d#eeZ!G d$d% d%eeZ"G d&d' d'eeZ#G d(d) d)eeZ$G d*d+ d+eeZ%G d,d- d-eeZ&G d.d/ d/eeZ'G d0d1 d1eeZ(G d2d3 d3eeZ)G d4d5 d5eeZ*G d6d7 d7eeZ+G d8d9 d9eeZ,ej-	:d;i dedededed!e d#e!d%e"d'e#d)e$d+e%d-e&d/e'd1e(d3e)d5e*d7e+d9e, dS )<    N)*)debug)univ)octets)Asn1ItemZASN1OctetStringIntegerObjectIdentifierzASN1-ENUMERATIONNamedValueszASN1-REFINEMENTConstraintsIntersectionConstraintsUnionSingleValueConstraintValueRangeConstraintValueSizeConstraintz
SNMPv2-SMI	Counter32
Unsigned32	TimeTicks	Counter64c                   @   sx   e Zd ZdZdZdZdZdZe Z	e
 Ze Z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S )TextualConvention current c                 C      | j S N)displayHintselfr   r   ;/usr/lib/python3/dist-packages/pysnmp/smi/mibs/SNMPv2-TC.pygetDisplayHint!      z TextualConvention.getDisplayHintc                 C   r   r   )statusr   r   r   r   	getStatus$   r   zTextualConvention.getStatusc                 C   r   r   )descriptionr   r   r   r   getDescription'   r   z TextualConvention.getDescriptionc                 C   r   r   )	referencer   r   r   r   getReference*   r   zTextualConvention.getReferencec                 C   s   |   S r   )cloner   r   r   r   getValue-   s   zTextualConvention.getValuec                 C   s   |d u rt j}| |S r   )r   noValuer&   r   valuer   r   r   setValue0   s   
zTextualConvention.setValuec                 C   s^  | j r| jj| ddr|  r| jj| dds| jj| ddrd%dd}|| j d \}}|dkr6d| S |d	kr^zd
t|t|t	dt| f W S  t
y]   tdt d  w |dkrfd| S |dkr|}dg}|r|dd|d@   |dL }|sqd|S td|| jjf | j r| jj| ddrd}t| }| j }|r|r|d dkrt|d  }}	|dd }|dd }nd}	d}d}
|r|d tjv r|
|d 7 }
|dd }|r|d tjv s|
st|}
zt|
}
W n t
y   td|
 w |std| j  |d }|dd }|r:|d tjvr:|d dkr:|d }|dd }nd}|rT|rT|durT|d }d}|dd }nd}|	r|	d8 }	|dkro||d|
 dd7 }nt|dkr||d|
 dd7 }nb|dv rd}|d|
 }|r|dK }z|t|d O }|dd }W n t
y   td |t d f w |s|dkr|d!| 7 }n|dkr|d"| 7 }n|d| 7 }ntd#| |r|r||7 }||
d }|	sY|r |r ||7 }|s| j }|r|s|S t| jD ]}t|ts)t|tr)| | |  S qtd$)&z"Implements DISPLAY-HINT evaluationFZmatchConstraintsr   c                 S      | |fS r   r   tfr   r   r   <lambda>:       z-TextualConvention.prettyOut.<locals>.<lambda>-xz0x%xdz%.*f
   float evaluation error: %s   oz0%obBz%dr   (Unsupported numeric type spec "%s" at %sr   NBad octet length: %sShort octet length: %saasciiignorer/   zutf-8r4   r5   r9      #Display format eval failure: %s: %sz%02xz%03o#Unsupported display format char: %s3TEXTUAL-CONVENTION has no underlying SNMP base typer   )!r   _TextualConvention__integerisSuperTypeOfgetNamedValues_TextualConvention__unsigned32_TextualConvention__timetickssplitintfloatpow	ExceptionSmiErrorsysexc_infoinsertjoin	__class____name___TextualConvention__octetStringr   ZasOctetsr   Zoct2intstringdigitslendecodeinspectgetmro
issubclassr   r   	prettyOut)r   r*   _displayHintTypedecimalPrecisionrunningValueoutputValuer   ZrepeatIndicatorZrepeatCountoctetLengthdisplayFormat
displaySepZrepeatTerminatorZnumberZnumberStringbaser   r   r   ra   5   s   
$
$





!
YzTextualConvention.prettyOutc                 C   s  t | jD ]}t|tst|tr nqtd| jr,| jj	| ddr)| 
 s:| jj	| dds:| jj	| ddr,t|}d+dd}|| jd \}}|dkr|d	s[|d
rz"|drp|| t|dd d W S || t|dd dW S  ty   tdt d  w |dkrz|| tt|dt|  W S  ty   tdt d  w |dkr|ds|drz
|| t|dW S  ty   tdt d  w |dkr"|ds|dr"|d}|r|dd }n|dd }dd |D }d}|r||d K }|d= |s|| |S td|| jjf | jr| jj	| ddrdddd}ttjttjttjd }	t|rdt|sd|| |}n|| |S td!}
|}| j}|r|r|d d"krtd#| jj d!}|r|d tjv r||d 7 }|dd }|r|d tjv s|st |}zt|}W n ty   td$| w |std%| j |d }|dd }|r|d tjvr|d d"kr|d }|dd }nd!}|d&v r
|
|d| 7 }
n||v r|r$|!t|}|d'kr#t |}nt"t |D ]}|| |	| vr9|} nq*t |}ztt#|d| || }W n tyg   td(|d| t d f w g }|r|r~|$|d)@  |dL }|spndg}t ||k r|$d t ||k s|%  |
t&|7 }
|r|d7 }|}ntd*| ||d }|s| j}|r|sz|| |
S || |S ),a\  Implements DISPLAY-HINT parsing into base SNMP value

        Proper parsing seems impossible due to ambiguities.
        Here we are trying to do our best, but be prepared
        for failures on complicated DISPLAY-HINTs.

        Keep in mind that this parser only works with "text"
        input meaning `unicode` (Py2) or `str` (Py3).
        rF   Fr,   r   c                 S   r-   r   r   r.   r   r   r   r1      r2   z,TextualConvention.prettyIn.<locals>.<lambda>r3   r4   0xz-0x   N      zinteger evaluation error: %sr8   r5   r6   r7   r9   0z-0rC   zoctal evaluation error: %sr:   r;   z-Bc                 S   s   g | ]
}|d kr
dpdqS )ro   r8   r   r   ).0r4   r   r   r   
<listcomp>   s    z.TextualConvention.prettyIn.<locals>.<listcomp>r<   rB   )r4   r9   r5   r   r   z$Can't parse "*" in DISPLAY-HINT (%s)r=   r>   )r?   r/   rD      rE   rG   )'r^   r_   rW   r`   r   r   rR   r   rH   rI   rJ   rK   rL   strrM   
startswithprettyInrN   rQ   rS   rT   rO   rX   rY   r   Zstr2octsrZ   Z	hexdigitsZ	octdigitsr[   ZisStringTypeZisOctetsTyper\   findrangeZocts2strappendreverseZ	ints2octs)r   r*   rj   rb   rc   rd   negativeZbinValueZnumBaseZ	numDigitsrf   re   r   rg   rh   ri   ZguessedOctetLengthidxZnumZnum_as_bytesr   r   r   rv      s,  


" 



	

$


 
_zTextualConvention.prettyInN)rX   
__module____qualname__r   r    r"   r$   bitsr   rH   r   rK   r   rL   r   rY   r   r!   r#   r%   r'   r+   ra   rv   r   r   r   r   r      s&     r   c                   @   (   e Zd ZdZdZejedd ZdZdS )DisplayString8  Represents textual information taken from the NVT ASCII character set, as defined in pages 4, 10-11 of RFC 854. To summarize RFC 854, the NVT ASCII repertoire specifies: - the use of character codes 0-127 (decimal) - the graphics characters (32-126) are interpreted as US ASCII - NUL, LF, CR, BEL, BS, HT, VT and FF have the special meanings specified in RFC 854 - the other 25 codes have no standard interpretation - the sequence 'CR LF' means newline - the sequence 'CR NUL' means carriage-return - an 'LF' not preceded by a 'CR' means moving to the same column on the next line. - the sequence 'CR x' for any x other than LF or NUL is illegal. (Note that this also means that a string may end with either 'CR LF' or 'CR NUL', but not with CR.) Any object defined using this syntax may not exceed 255 characters in length.r   r   rs   Z255aN	rX   r}   r~   r"   r    r   subtypeSpecr   r   r   r   r   r   r   u  
    r   c                   @      e Zd ZdZdZdZdS )PhysAddressr   r   1x:N)rX   r}   r~   r"   r    r   r   r   r   r   r   |      r   c                   @   s,   e Zd ZdZdZejedd ZdZdZ	dS )
MacAddressa  Represents an 802 MAC address represented in the `canonical' order defined by IEEE 802.1a, i.e., as if it were transmitted least significant bit first, even though 802.5 (in contrast to other 802.x protocols) requires MAC addresses to be transmitted most significant bit first.r      r   N)
rX   r}   r~   r"   r    r   r   r   r   ZfixedLengthr   r   r   r   r     s    r   c                   @   s.   e Zd ZdZdZejedd ZeddZ	dS )
TruthValuezRepresents a boolean value.r   r8   rn   )truer8   )Zfalsern   N
rX   r}   r~   r"   r    r   r   r   r
   namedValuesr   r   r   r   r     s
    r   c                   @   s0   e Zd ZdZdZejedd ZdZdd Z	dS )TestAndIncra  Represents integer-valued information used for atomic operations. When the management protocol is used to specify that an object instance having this syntax is to be modified, the new value supplied via the management protocol must precisely match the value presently held by the instance. If not, the management protocol set operation fails with an error of `inconsistentValue'. Otherwise, if the current value is the maximum value of 2^31-1 (2147483647 decimal), then the value held by the instance is wrapped to zero; otherwise, the value held by the instance is incremented by one. (Note that regardless of whether the management protocol set operation succeeds, the variable- binding in the request and response PDUs are identical.) The value of the ACCESS clause for objects having this syntax is either `read-write' or `read-create'. When an instance of a columnar object having this syntax is created, any value may be supplied via the management protocol. When the network management portion of the system is re- initialized, the value of every object instance having this syntax must either be incremented from its value prior to the re-initialization, or (if the value prior to the re- initialization is unknown) be set to a pseudo-randomly generated value.r   r   c                 C   sB   |d ur|| krt  |d7 }|dkrd}|d u rtj}| |S )Nr8   ir   )InconsistentValueErrorr   r(   r&   r)   r   r   r   r+     s   
zTestAndIncr.setValueN)
rX   r}   r~   r"   r    r   r   r   ZdefaultValuer+   r   r   r   r   r     s    r   c                   @      e Zd ZdZdZdS )AutonomousTypezRepresents an independently extensible type identification value. It may, for example, indicate a particular sub-tree with further MIB definitions, or define a particular type of protocol or hardware.r   NrX   r}   r~   r"   r    r   r   r   r   r         r   c                   @   r   )InstancePointerac  A pointer to either a specific instance of a MIB object or a conceptual row of a MIB table in the managed device. In the latter case, by convention, it is the name of the particular instance of the first accessible columnar object in the conceptual row. The two uses of this textual convention are replaced by VariablePointer and RowPointer, respectively.ZobsoleteNr   r   r   r   r   r     r   r   c                   @   r   )VariablePointerzSA pointer to a specific object instance. For example, sysContact.0 or ifInOctets.3.r   Nr   r   r   r   r   r     r   r   c                   @   r   )
RowPointera!  Represents a pointer to a conceptual row. The value is the name of the instance of the first accessible columnar object in the conceptual row. For example, ifIndex.3 would point to the 3rd row in the ifTable (note that if ifIndex were not-accessible, then ifDescr.3 would be used instead).r   Nr   r   r   r   r   r     r   r   c                
   @   s  e Zd ZdZdZdZejedddddd	d
 Ze	dddddddZ
eed\ZZZZZZZi eefeefeefeefeefeefeefeefeefeefeefeefeefeefeefeefeefeefeefeefeefdefeefdefeefeefeefeefeefdefeefdefeefeefeefeefeefeefeefeefeefdefiZdd ZdS )	RowStatuszeA special kind of scalar MIB variable responsible for
       MIB table row creation/destruction.
    zThe RowStatus textual convention is used to manage the creation and deletion of conceptual rows, and is used as the value of the SYNTAX clause for the status column of a conceptual row (as described in Section 7.7.1 of [2].)...r   r   r8   rn   rl         r   )Z	notExistsr   )Zactiver8   )ZnotInServicern   )ZnotReadyrl   )ZcreateAndGor   )ZcreateAndWaitr   )Zdestroyr      Nc                 C   s   |d u rt j}| |}| j| r|p| j|  r| p| jftd f\}}|d u r.t j}| |}tj	tj
@ oCt	d| |||f  |d urU|d| ||f |d}||S )NzORowStatus state change from %r to %r produced new state %r, error indication %rzMException at row state transition from %r to %r yields state %r and exception)msgZsyntax)r   r(   r&   stateMatrixgetZhasValuestNotExistsZMibOperationErrorr   loggerZflagIns)r   r*   ZexcValueZnewStater   r   r   r+     s6   

zRowStatus.setValue)rX   r}   r~   __doc__r"   r    r   r   r   r
   r   listrx   r   ZstActiveZstNotInServiceZ
stNotReadyZstCreateAndGoZstCreateAndWaitZ	stDestroyZRowCreationWantedr   ZRowDestructionWantedr   r+   r   r   r   r   r     sl    
	
r   c                   @   r   )	TimeStampa_  The value of the sysUpTime object at which a specific occurrence happened. The specific occurrence must be defined in the description of any object defined using this type. If sysUpTime is reset to zero as a result of a re- initialization of the network management (sub)system, then the values of all TimeStamp objects are also reset. However, after approximately 497 days without a re- initialization, the sysUpTime object will reach 2^^32-1 and then increment around to zero; in this case, existing values of TimeStamp objects do not change. This can lead to ambiguities in the value of TimeStamp objects.r   Nr   r   r   r   r   r     r   r   c                   @   s$   e Zd ZdZdZejedd ZdS )TimeIntervalz4A period of time, measured in units of 0.01 seconds.r   r   r   N)rX   r}   r~   r"   r    r   r   r   r   r   r   r   r     s    r   c                   @   r   )DateAndTimeag  A date-time specification. field octets contents range ----- ------ -------- ----- 1 1-2 year* 0..65536 2 3 month 1..12 3 4 day 1..31 4 5 hour 0..23 5 6 minutes 0..59 6 7 seconds 0..60 (use 60 for leap-second) 7 8 deci-seconds 0..9 8 9 direction from UTC '+' / '-' 9 10 hours from UTC* 0..13 10 11 minutes from UTC 0..59 * Notes: - the value of year is in network-byte order - daylight saving time in New Zealand is +13 For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be displayed as: 1992-5-26,13:30:15.0,-4:0 Note that if only local time is known, then timezone information (fields 8-10) is not present.r   rC      z2d-1d-1d,1d:1d:1d.1d,1a1d:1dNr   r   r   r   r   r     r   r   c                   @   s:   e Zd ZdZdZejeddddd Zedd	d
ddZ	dS )StorageTypea  Describes the memory realization of a conceptual row. A row which is volatile(2) is lost upon reboot. A row which is either nonVolatile(3), permanent(4) or readOnly(5), is backed up by stable storage. A row which is permanent(4) can be changed but not deleted. A row which is readOnly(5) cannot be changed nor deleted. If the value of an object with this syntax is either permanent(4) or readOnly(5), it cannot be written. Conversely, if the value is either other(1), volatile(2) or nonVolatile(3), it cannot be modified to be permanent(4) or readOnly(5). (All illegal modifications result in a 'wrongValue' error.) Every usage of this textual convention is required to specify the columnar objects which a permanent(4) row must at a minimum allow to be writable.r   r8   rn   rl   r   r   )otherr8   )Zvolatilern   )ZnonVolatilerl   )Z	permanentr   )ZreadOnlyr   Nr   r   r   r   r   r     s    r   c                   @   r   )TDomain0The SNMPv2-TM MIB module is defined in RFC 1906.zDenotes a kind of transport service. Some possible values, such as snmpUDPDomain, are defined in the SNMPv2-TM MIB module. Other possible values are defined in other MIB modules.r   N)rX   r}   r~   r$   r"   r    r   r   r   r   r   "  r   r   c                   @   s(   e Zd ZdZdZdZejedd ZdS )TAddressr   a  Denotes a transport service address. A TAddress value is always interpreted within the context of a TDomain value. Thus, each definition of a TDomain value must be accompanied by a definition of a textual convention for use with that TDomain. Some possible textual conventions, such as SnmpUDPAddress for snmpUDPDomain, are defined in the SNMPv2-TM MIB module. Other possible textual conventions are defined in other MIB modules.r   r8   rs   N)	rX   r}   r~   r$   r"   r    r   r   r   r   r   r   r   r   (  s
    r   	SNMPv2-TC)r   ).rS   r^   rZ   Zpysnmp.smi.errorZpysnmpr   Zpyasn1.typer   Zpyasn1.compatr   Zpyasn1.type.baser   Z
mibBuilderZimportSymbolsr   r   r	   r
   r   r   r   r   r   r   r   r   r   objectr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ZexportSymbolsr   r   r   r   <module>   s     aP
