o
    B]O                     @   s   d dl Z d dlmZ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mZmZ d dlmZmZ d d	lmZ G d
d deZG dd deZdS )    N)decodereoo)univ)null)PyAsn1Error)AbstractMessageProcessingModel)rfc3411errinderror)v1v2c)debugc                   @   s4   e Zd ZedZejZdd Z	dd Z
dd ZdS )	SnmpV1MessageProcessingModelr   c                 C   s  |j jj}|dd\}|j}|jtjv r.| j	 }|
d}tjtj@ o-td||f  |s2|}|	s6t}	tjtj@ oDtd||	f  ||	|f}| j}|d| j |d |
dj|j|dddd |f}t|}||jv ry|j| }ntjtjd	|dd
\}|jtjv r|d| ||| j||j|||||	\}}|jtjv r|d| |jtjv r| jjt|||||||||	||d |
d}|j|dt||||||||	||d
 |j|d |||fS )N__SNMP-FRAMEWORK-MIBsnmpEngineIDr   zDprepareOutgoingMessage: PDU request-id %s replaced with unique ID %sz?prepareOutgoingMessage: using contextEngineId %r contextName %r   FZverifyConstraintsZ	matchTagsZmatchConstraintsZerrorIndicationsnmpEngineMaxMessageSize)
sendPduHandlereqIDsnmpEngineIdsecurityModelsecurityNamesecurityLevelcontextEngineIdcontextNametransportDomaintransportAddress   zrfc2576.prepareOutgoingMessage)
r   r   wholeMsgr   r   r   r   r   communityNamepdu)msgAndPduDspmibInstrumController
mibBuilderimportSymbolssyntaxtagSetr   confirmedClassPDUs_cachenewMsgIDgetComponentByPositionr   loggerflagMPr   _snmpMsgSpecsetComponentByPositionmessageProcessingModelIDsetComponentByTypeintsecurityModelsr
   StatusInformationr	   unsupportedSecurityModelZgenerateRequestMsgZpushByMsgIdobserverstoreExecutionContextdictclearExecutionContext)self
snmpEnginer   r   messageProcessingModelr   r   r   r   r   
pduVersionr"   ZexpectResponser   r%   r   msgIDr   	scopedPDUmsg
globalDatak	smHandlerr   securityParametersr    r!    rF   </usr/lib/python3/dist-packages/pysnmp/proto/mpmod/rfc2576.pyprepareOutgoingMessage   s   











z3SnmpV1MessageProcessingModel.prepareOutgoingMessagec                 C   s  |j jj}|dd\}|j}|d u rtjtjd| j	
|}|d }|d }|d }|d }|d }|d	 }|d
 }|d }|d }|d }|d }tjtj@ o\td||||f  |rftjtjd|sj|}|snt}|||	f}tjtj@ otd||f  | j}|d| |d |dj|	j|	dddd |f}t|}||jv r|j| }ntjtjd|	d| ||| j||||||||
\}}|	d| |j|dt|||||||||d|	d
 |j|d |||fS )Nr   r   r   r?   r   r   r   r   r   r   securityStateReference
msgMaxSizer   r   zgprepareResponseMessage: cache read msgID %s transportDomain %s transportAddress %s by stateReference %sz?prepareResponseMessage: using contextEngineId %r contextName %rr   r   Fr   zrfc2576.prepareResponseMessager   
r   r   r   r   r   r   r   securityEngineIdr!   r"   )r#   r$   r%   r&   r'   r
   r5   r	   ZnonReportabler*   ZpopByStateRefr   r-   r.   r   r/   r0   r,   r2   r(   r3   r4   r6   ZgenerateResponseMsgr1   r7   r8   r9   r:   )r;   r<   r=   r   r   r   r   r   r>   r"   maxSizeResponseScopedPDUstateReferencestatusInformationr%   r   ZcachedParamsr?   r   rI   ZmaxMessageSizer   r   r@   rA   rB   rC   rD   rE   r    rF   rF   rG   prepareResponseMessage   s   






z3SnmpV1MessageProcessingModel.prepareResponseMessagec           !      C   s  |j jj}tj|| jd\}}tjtj@ otd|	 f  t
j|r,tjtjd|d}|dd\}	|d}
|
||ff}t|d}|d }d}z9z|j| }W n tyf   tjtjdw ||||	j|||||\}}}}}tjtj@ otd||f  W n& tjy   t d }|j|d	t||||||d
 |j|d	  w |\}}}|}|j}|t j!v r|d}z
| j"#t|}W n tj$y   |%| tjtj&dw |'d|d  tjtj@ otd||d f  |d }nd }d }|t j!v rl||d ks/||d ks/||d ks/||d ks/||d kr;|%| tjtj&dd }|j|dt|||||||||
|d
 |j|d |%| |||||||||||||fS |t j(v r|d}| j") }|'d| tjtj@ otd||f  |dd\} || jkr|%| tjtj*d| j"+ }| j"j,|||||||||||	j|||d |j|dt|||||||||
|d
 |j|d tjtj@ otd|  |||||||||||||fS  |||||||||||||fS |t j-v rG| j"+ }|j|dt|||||||||
|d
 |j|d |%| |||||||||||||fS |%| tjtj.d)N)Zasn1SpeczprepareDataElements: %sr   r   r   r   r   zDprepareDataElements: SM returned securityEngineId %r securityName %rz&rfc2576.prepareDataElements:sm-failure)r   r   r   r   rE   rO   r   zJprepareDataElements: unique PDU request-id %s replaced with original ID %sr   r   r   r   r   r   z$rfc2576.prepareDataElements:responserK   zJprepareDataElements: received PDU request-id %s replaced with unique ID %sr   )
msgVersionr?   r   r   r   r   r   r   rI   rJ   rM   r   r   z%rfc2576.prepareDataElements:confirmedz4prepareDataElements: cached by new stateReference %sz'rfc2576.prepareDataElements:unconfirmed)/r#   r$   r%   r   decoder/   r   r-   r.   ZprettyPrintr   ZendOfOctetsZisSameTypeWithr
   r5   r	   Z
parseErrorr,   r&   r3   r4   KeyErrorr6   ZprocessIncomingMsgr'   sysexc_infor7   r8   r9   r:   r(   r   ZresponseClassPDUsr*   Z
popByMsgIdZProtocolErrorZreleaseStateInformationZdataMismatchr0   r)   r+   ZengineIDMismatchZnewStateReferenceZpushByStateRefZunconfirmedClassPDUsZunsupportedPDUtype)!r;   r<   r   r   r    r%   rA   ZrestOfWholeMsgrQ   r   r!   rE   r=   r   r   rD   rL   r   r@   rM   rI   rO   r   r   r"   r>   ZpduTyper?   ZcachedReqParamsr   rN   r   r   rF   rF   rG   prepareDataElements   s  




	


















z0SnmpV1MessageProcessingModel.prepareDataElementsN)__name__
__module____qualname__r   Integerr1   r   MessagesnmpMsgSpecrH   rP   rV   rF   rF   rF   rG   r      s    
nlr   c                   @   s   e Zd ZedZejZdS )SnmpV2cMessageProcessingModelr   N)	rW   rX   rY   r   rZ   r1   r   r[   r\   rF   rF   rF   rG   r]     s    

r]   )rT   Zpyasn1.codec.berr   r   Zpyasn1.typer   Zpyasn1.compat.octetsr   Zpyasn1.errorr   Zpysnmp.proto.mpmod.baser   Zpysnmp.protor   r	   r
   Zpysnmp.proto.apir   r   Zpysnmpr   r   r]   rF   rF   rF   rG   <module>   s      U