o
    BŠ]
  ã                   @   s    d dl mZ G dd„ deƒZdS )é    )Úerrorc                   @   sB   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Z	dS )ÚMetaObserveraê  This is a simple facility for exposing internal SNMP Engine
       working details to pysnmp applications. These details are
       basically local scope variables at a fixed point of execution.

       Two modes of operations are offered:
       1. Consumer: app can request an execution point context by execution point ID.
       2. Provider: app can register its callback function (and context) to be invoked
          once execution reaches specified point. All local scope variables
          will be passed to the callback as in #1.

       It's important to realize that execution context is only guaranteed
       to exist to functions that are at the same or deeper level of invocation
       relative to execution point specified.
    c                 C   s   i | _ i | _i | _d S ©N)Ú_MetaObserver__observersÚ_MetaObserver__contextsÚ_MetaObserver__execpoints)Úself© r	   ú8/usr/lib/python3/dist-packages/pysnmp/entity/observer.pyÚ__init__   s   
zMetaObserver.__init__c                 O   sZ   || j v rt d| ¡‚| d¡| j |< |D ]}|| jvr"g | j|< | j|  |¡ qd S )Nzduplicate observer %sZcbCtx)r   r   ZPySnmpErrorÚgetr   Úappend)r   ÚcbFunÚ
execpointsÚkwargsÚ	execpointr	   r	   r
   ÚregisterObserver   s   


ýzMetaObserver.registerObserverNc                 C   sd   |d u r| j  ¡  | j ¡  d S t| j ƒD ]}|| j | v r&| j |  |¡ | j | s/| j |= qd S r   )r   Úclearr   ÚdictÚremove)r   r   r   r	   r	   r
   ÚunregisterObserver)   s   

€üzMetaObserver.unregisterObserverc                 C   s@   || j |< || jv r| j| D ]}||||| j| ƒ qd S d S r   )r   r   r   )r   Ú
snmpEnginer   Z	variablesr   r	   r	   r
   ÚstoreExecutionContext4   s   

þz"MetaObserver.storeExecutionContextc                 G   s(   |r|D ]}| j |= qd S | j  ¡  d S r   )r   r   )r   r   r   r   r	   r	   r
   ÚclearExecutionContext:   s
   
ÿz"MetaObserver.clearExecutionContextc                 C   s
   | j | S r   )r   )r   r   r	   r	   r
   ÚgetExecutionContextA   s   
z MetaObserver.getExecutionContextr   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r	   r	   r	   r
   r   
   s    

r   N)Zpysnmpr   Úobjectr   r	   r	   r	   r
   Ú<module>   s   