o
    B]                     @   s   d dl Z d dlT d dlT d dlT d dlT d dlT d dlT d dlmZ zd dl	Z	W n e
y5   d dlZ	Y nw dgZe Ze Ze	jdd ZdS )    N)*)ntforgsendNotificationc                 K   s~   dd }t | ||||j}t }	t | ||j|jt	
| |||dd|	f |dkr=dd }
t }||
|	 |	S )a  Creates a generator to send SNMP notification.

    When iterator gets advanced by :py:mod:`asyncio` main loop,
    SNMP TRAP or INFORM notification is send (:RFC:`1905#section-4.2.6`).
    The iterator yields :py:class:`asyncio.Future` which gets done whenever
    response arrives or error occurs.

    Parameters
    ----------
    snmpEngine : :py:class:`~pysnmp.hlapi.SnmpEngine`
        Class instance representing SNMP engine.

    authData : :py:class:`~pysnmp.hlapi.CommunityData` or :py:class:`~pysnmp.hlapi.UsmUserData`
        Class instance representing SNMP credentials.

    transportTarget : :py:class:`~pysnmp.hlapi.asyncio.UdpTransportTarget` or :py:class:`~pysnmp.hlapi.asyncio.Udp6TransportTarget`
        Class instance representing transport type along with SNMP peer address.

    contextData : :py:class:`~pysnmp.hlapi.ContextData`
        Class instance representing SNMP ContextEngineId and ContextName values.

    notifyType : str
        Indicates type of notification to be sent. Recognized literal
        values are *trap* or *inform*.

    varBinds: tuple
        Single :py:class:`~pysnmp.smi.rfc1902.NotificationType` class instance
        representing a minimum sequence of MIB variables required for
        particular notification type.
        Alternatively, a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType`
        objects could be passed instead. In the latter case it is up to
        the user to ensure proper Notification PDU contents.

    Other Parameters
    ----------------
    \*\*options :
        Request options:

            * `lookupMib` - load MIB and resolve response MIB variables at
              the cost of slightly reduced performance. Default is `True`.

    Yields
    ------
    errorIndication : str
        True value indicates SNMP engine error.
    errorStatus : str
        True value indicates SNMP PDU error.
    errorIndex : int
        Non-zero value refers to `varBinds[errorIndex-1]`
    varBinds : tuple
        A sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` class
        instances representing MIB variables returned in SNMP response.

    Raises
    ------
    PySnmpError
        Or its derivative indicating that an error occurred while
        performing SNMP operation.

    Notes
    -----
    The `sendNotification` generator will be exhausted immidiately unless
    an instance of :py:class:`~pysnmp.smi.rfc1902.NotificationType` class
    or a sequence of :py:class:`~pysnmp.smi.rfc1902.ObjectType` `varBinds`
    are send back into running generator (supported since Python 2.6).

    Examples
    --------
    >>> import asyncio
    >>> from pysnmp.hlapi.asyncio import *
    >>>
    >>> @asyncio.coroutine
    ... def run():
    ...     errorIndication, errorStatus, errorIndex, varBinds = yield from sendNotification(
    ...         SnmpEngine(),
    ...         CommunityData('public'),
    ...         UdpTransportTarget(('demo.snmplabs.com', 162)),
    ...         ContextData(),
    ...         'trap',
    ...         NotificationType(ObjectIdentity('IF-MIB', 'linkDown')))
    ...     print(errorIndication, errorStatus, errorIndex, varBinds)
    ...
    >>> asyncio.get_event_loop().run_until_complete(run())
    (None, 0, 0, [])
    >>>

    c                 S   sh   |\}}|  r
d S z	t| ||}	W n ty(   t d }
||
 Y d S w |||||	f d S )N   )	cancelledvbProcessorZunmakeVarBinds	Exceptionsysexc_infoZset_exception
set_result)
snmpEngineZsendRequestHandleZerrorIndicationZerrorStatusZ
errorIndexvarBindsZcbCtx	lookupMibfutureZvarBindsUnmadeex r   =/usr/lib/python3/dist-packages/pysnmp/hlapi/asyncio/ntforg.py__cbFun|   s   
z!sendNotification.<locals>.__cbFunr   TZtrapc                 S   s"   |   rd S | d ddg f d S )Nr   )r   r   )r   r   r   r   	__trapFun   s   z#sendNotification.<locals>.__trapFun)lcdZ	configureZcontextNameasyncioZFuturer   ZNotificationOriginatorZsendVarBindsZcontextEngineIdr   ZmakeVarBindsgetZget_event_loopZ	call_soon)r   ZauthDataZtransportTargetZcontextDataZ
notifyTyper   optionsr   Z
notifyNamer   r   Zloopr   r   r   r   !   s(   [

)r	   Zpysnmp.smi.rfc1902Zpysnmp.hlapi.authZpysnmp.hlapi.contextZpysnmp.hlapi.lcdZpysnmp.hlapi.varbindsZpysnmp.hlapi.asyncio.transportZpysnmp.entity.rfc3413r   r   ImportErrorZtrollius__all__ZNotificationOriginatorVarBindsr   Z%NotificationOriginatorLcdConfiguratorr   	coroutiner   r   r   r   r   <module>   s$   
