3
]ð]·Å  ã            
   @   sÈ  d Z ddlmZ ddlmZ ddlmZ eddeƒZeg g g g g ƒZG dd„ de	ƒZ
G dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ de
ƒZdd„ Zdd„ Zdd„ Zedddd d!d"d#d$d%g	ƒZG d&d'„ d'e	ƒZG d(d)„ d)eƒZG d*d+„ d+eƒZG d,d-„ d-eƒZG d.d/„ d/e	ƒZG d0d1„ d1eƒZG d2d3„ d3eƒZG d4d5„ d5eƒZG d6d7„ d7e	ƒZG d8d9„ d9e	ƒZG d:d;„ d;e	ƒZG d<d=„ d=eƒZ G d>d?„ d?eƒZ!G d@dA„ dAeƒZ"G dBdC„ dCe	ƒZ#G dDdE„ dEe	ƒZ$G dFdG„ dGeƒZ%G dHdI„ dIeƒZ&G dJdK„ dKe	ƒZ'G dLdM„ dMe'ƒZ(G dNdO„ dOe'ƒZ)G dPdQ„ dQe'ƒZ*G dRdS„ dSe	ƒZ+G dTdU„ dUe+ƒZ,G dVdW„ dWe+ƒZ-G dXdY„ dYe+ƒZ.G dZd[„ d[e	ƒZ/G d\d]„ d]e/ƒZ0G d^d_„ d_e/ƒZ1G d`da„ dae/ƒZ2G dbdc„ dce	ƒZ3ddS )fa\  Tools to monitor driver events.

.. versionadded:: 3.1

Use :func:`register` to register global listeners for specific events.
Listeners must inherit from one of the abstract classes below and implement
the correct functions for that class.

For example, a simple command logger might be implemented like this::

    import logging

    from pymongo import monitoring

    class CommandLogger(monitoring.CommandListener):

        def started(self, event):
            logging.info("Command {0.command_name} with request id "
                         "{0.request_id} started on server "
                         "{0.connection_id}".format(event))

        def succeeded(self, event):
            logging.info("Command {0.command_name} with request id "
                         "{0.request_id} on server {0.connection_id} "
                         "succeeded in {0.duration_micros} "
                         "microseconds".format(event))

        def failed(self, event):
            logging.info("Command {0.command_name} with request id "
                         "{0.request_id} on server {0.connection_id} "
                         "failed in {0.duration_micros} "
                         "microseconds".format(event))

    monitoring.register(CommandLogger())

Server discovery and monitoring events are also available. For example::

    class ServerLogger(monitoring.ServerListener):

        def opened(self, event):
            logging.info("Server {0.server_address} added to topology "
                         "{0.topology_id}".format(event))

        def description_changed(self, event):
            previous_server_type = event.previous_description.server_type
            new_server_type = event.new_description.server_type
            if new_server_type != previous_server_type:
                # server_type_name was added in PyMongo 3.4
                logging.info(
                    "Server {0.server_address} changed type from "
                    "{0.previous_description.server_type_name} to "
                    "{0.new_description.server_type_name}".format(event))

        def closed(self, event):
            logging.warning("Server {0.server_address} removed from topology "
                            "{0.topology_id}".format(event))


    class HeartbeatLogger(monitoring.ServerHeartbeatListener):

        def started(self, event):
            logging.info("Heartbeat sent to server "
                         "{0.connection_id}".format(event))

        def succeeded(self, event):
            # The reply.document attribute was added in PyMongo 3.4.
            logging.info("Heartbeat to server {0.connection_id} "
                         "succeeded with reply "
                         "{0.reply.document}".format(event))

        def failed(self, event):
            logging.warning("Heartbeat to server {0.connection_id} "
                            "failed with error {0.reply}".format(event))

    class TopologyLogger(monitoring.TopologyListener):

        def opened(self, event):
            logging.info("Topology with id {0.topology_id} "
                         "opened".format(event))

        def description_changed(self, event):
            logging.info("Topology description updated for "
                         "topology id {0.topology_id}".format(event))
            previous_topology_type = event.previous_description.topology_type
            new_topology_type = event.new_description.topology_type
            if new_topology_type != previous_topology_type:
                # topology_type_name was added in PyMongo 3.4
                logging.info(
                    "Topology {0.topology_id} changed type from "
                    "{0.previous_description.topology_type_name} to "
                    "{0.new_description.topology_type_name}".format(event))
            # The has_writable_server and has_readable_server methods
            # were added in PyMongo 3.4.
            if not event.new_description.has_writable_server():
                logging.warning("No writable servers available.")
            if not event.new_description.has_readable_server():
                logging.warning("No readable servers available.")

        def closed(self, event):
            logging.info("Topology with id {0.topology_id} "
                         "closed".format(event))

Connection monitoring and pooling events are also available. For example::

    class ConnectionPoolLogger(ConnectionPoolListener):

        def pool_created(self, event):
            logging.info("[pool {0.address}] pool created".format(event))

        def pool_cleared(self, event):
            logging.info("[pool {0.address}] pool cleared".format(event))

        def pool_closed(self, event):
            logging.info("[pool {0.address}] pool closed".format(event))

        def connection_created(self, event):
            logging.info("[pool {0.address}][conn #{0.connection_id}] "
                         "connection created".format(event))

        def connection_ready(self, event):
            logging.info("[pool {0.address}][conn #{0.connection_id}] "
                         "connection setup succeeded".format(event))

        def connection_closed(self, event):
            logging.info("[pool {0.address}][conn #{0.connection_id}] "
                         "connection closed, reason: "
                         "{0.reason}".format(event))

        def connection_check_out_started(self, event):
            logging.info("[pool {0.address}] connection check out "
                         "started".format(event))

        def connection_check_out_failed(self, event):
            logging.info("[pool {0.address}] connection check out "
                         "failed, reason: {0.reason}".format(event))

        def connection_checked_out(self, event):
            logging.info("[pool {0.address}][conn #{0.connection_id}] "
                         "connection checked out of pool".format(event))

        def connection_checked_in(self, event):
            logging.info("[pool {0.address}][conn #{0.connection_id}] "
                         "connection checked into pool".format(event))


Event listeners can also be registered per instance of
:class:`~pymongo.mongo_client.MongoClient`::

    client = MongoClient(event_listeners=[CommandLogger()])

Note that previously registered global listeners are automatically included
when configuring per client event listeners. Registering a new global listener
will not add that listener to existing client instances.

.. note:: Events are delivered **synchronously**. Application threads block
  waiting for event handlers (e.g. :meth:`~CommandListener.started`) to
  return. Care must be taken to ensure that your event handlers are efficient
  enough to not adversely affect overall application performance.

.. warning:: The command documents published through this API are *not* copies.
  If you intend to modify them in any way you must copy them in your event
  handler first.
é    )Ú
namedtuple)Úabc)Ú_handle_exceptionZ	ListenersÚcommand_listenersÚserver_listenersÚserver_heartbeat_listenersÚtopology_listenersÚcmap_listenersc               @   s   e Zd ZdZdS )Ú_EventListenerz,Abstract base class for all event listeners.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú5/tmp/pip-build-20mum3z4/pymongo/pymongo/monitoring.pyr
   À   s   r
   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCommandListenerzŠAbstract base class for command listeners.

    Handles `CommandStartedEvent`, `CommandSucceededEvent`,
    and `CommandFailedEvent`.
    c             C   s   t ‚dS )z“Abstract method to handle a `CommandStartedEvent`.

        :Parameters:
          - `event`: An instance of :class:`CommandStartedEvent`.
        N)ÚNotImplementedError)ÚselfÚeventr   r   r   ÚstartedË   s    zCommandListener.startedc             C   s   t ‚dS )z—Abstract method to handle a `CommandSucceededEvent`.

        :Parameters:
          - `event`: An instance of :class:`CommandSucceededEvent`.
        N)r   )r   r   r   r   r   Ú	succeededÓ   s    zCommandListener.succeededc             C   s   t ‚dS )z‘Abstract method to handle a `CommandFailedEvent`.

        :Parameters:
          - `event`: An instance of :class:`CommandFailedEvent`.
        N)r   )r   r   r   r   r   ÚfailedÛ   s    zCommandListener.failedN)r   r   r   r   r   r   r   r   r   r   r   r   Ä   s   r   c               @   s`   e Zd Zd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d„ Zdd„ ZdS )ÚConnectionPoolListenera-  Abstract base class for connection pool listeners.

    Handles all of the connection pool events defined in the Connection
    Monitoring and Pooling Specification:
    :class:`PoolCreatedEvent`, :class:`PoolClearedEvent`,
    :class:`PoolClosedEvent`, :class:`ConnectionCreatedEvent`,
    :class:`ConnectionReadyEvent`, :class:`ConnectionClosedEvent`,
    :class:`ConnectionCheckOutStartedEvent`,
    :class:`ConnectionCheckOutFailedEvent`,
    :class:`ConnectionCheckedOutEvent`,
    and :class:`ConnectionCheckedInEvent`.

    .. versionadded:: 3.9
    c             C   s   t ‚dS )zÈAbstract method to handle a :class:`PoolCreatedEvent`.

        Emitted when a Connection Pool is created.

        :Parameters:
          - `event`: An instance of :class:`PoolCreatedEvent`.
        N)r   )r   r   r   r   r   Úpool_createdô   s    z#ConnectionPoolListener.pool_createdc             C   s   t ‚dS )zÁAbstract method to handle a `PoolClearedEvent`.

        Emitted when a Connection Pool is cleared.

        :Parameters:
          - `event`: An instance of :class:`PoolClearedEvent`.
        N)r   )r   r   r   r   r   Úpool_clearedþ   s    z#ConnectionPoolListener.pool_clearedc             C   s   t ‚dS )z¾Abstract method to handle a `PoolClosedEvent`.

        Emitted when a Connection Pool is closed.

        :Parameters:
          - `event`: An instance of :class:`PoolClosedEvent`.
        N)r   )r   r   r   r   r   Úpool_closed  s    z"ConnectionPoolListener.pool_closedc             C   s   t ‚dS )zåAbstract method to handle a :class:`ConnectionCreatedEvent`.

        Emitted when a Connection Pool creates a Connection object.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCreatedEvent`.
        N)r   )r   r   r   r   r   Úconnection_created  s    z)ConnectionPoolListener.connection_createdc             C   s   t ‚dS )zøAbstract method to handle a :class:`ConnectionReadyEvent`.

        Emitted when a Connection has finished its setup, and is now ready to
        use.

        :Parameters:
          - `event`: An instance of :class:`ConnectionReadyEvent`.
        N)r   )r   r   r   r   r   Úconnection_ready  s    	z'ConnectionPoolListener.connection_readyc             C   s   t ‚dS )zÛAbstract method to handle a :class:`ConnectionClosedEvent`.

        Emitted when a Connection Pool closes a Connection.

        :Parameters:
          - `event`: An instance of :class:`ConnectionClosedEvent`.
        N)r   )r   r   r   r   r   Úconnection_closed'  s    z(ConnectionPoolListener.connection_closedc             C   s   t ‚dS )zþAbstract method to handle a :class:`ConnectionCheckOutStartedEvent`.

        Emitted when the driver starts attempting to check out a connection.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCheckOutStartedEvent`.
        N)r   )r   r   r   r   r   Úconnection_check_out_started1  s    z3ConnectionPoolListener.connection_check_out_startedc             C   s   t ‚dS )zúAbstract method to handle a :class:`ConnectionCheckOutFailedEvent`.

        Emitted when the driver's attempt to check out a connection fails.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCheckOutFailedEvent`.
        N)r   )r   r   r   r   r   Úconnection_check_out_failed;  s    z2ConnectionPoolListener.connection_check_out_failedc             C   s   t ‚dS )zíAbstract method to handle a :class:`ConnectionCheckedOutEvent`.

        Emitted when the driver successfully checks out a Connection.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCheckedOutEvent`.
        N)r   )r   r   r   r   r   Úconnection_checked_outE  s    z-ConnectionPoolListener.connection_checked_outc             C   s   t ‚dS )a  Abstract method to handle a :class:`ConnectionCheckedInEvent`.

        Emitted when the driver checks in a Connection back to the Connection
        Pool.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCheckedInEvent`.
        N)r   )r   r   r   r   r   Úconnection_checked_inO  s    	z,ConnectionPoolListener.connection_checked_inN)r   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dZdd„ Zdd„ Zdd„ ZdS )	ÚServerHeartbeatListenerzÆAbstract base class for server heartbeat listeners.

    Handles `ServerHeartbeatStartedEvent`, `ServerHeartbeatSucceededEvent`,
    and `ServerHeartbeatFailedEvent`.

    .. versionadded:: 3.3
    c             C   s   t ‚dS )z£Abstract method to handle a `ServerHeartbeatStartedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerHeartbeatStartedEvent`.
        N)r   )r   r   r   r   r   r   d  s    zServerHeartbeatListener.startedc             C   s   t ‚dS )z§Abstract method to handle a `ServerHeartbeatSucceededEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerHeartbeatSucceededEvent`.
        N)r   )r   r   r   r   r   r   l  s    z!ServerHeartbeatListener.succeededc             C   s   t ‚dS )z¡Abstract method to handle a `ServerHeartbeatFailedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerHeartbeatFailedEvent`.
        N)r   )r   r   r   r   r   r   t  s    zServerHeartbeatListener.failedN)r   r   r   r   r   r   r   r   r   r   r   r#   [  s   r#   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚTopologyListenerz»Abstract base class for topology monitoring listeners.
    Handles `TopologyOpenedEvent`, `TopologyDescriptionChangedEvent`, and
    `TopologyClosedEvent`.

    .. versionadded:: 3.3
    c             C   s   t ‚dS )z“Abstract method to handle a `TopologyOpenedEvent`.

        :Parameters:
          - `event`: An instance of :class:`TopologyOpenedEvent`.
        N)r   )r   r   r   r   r   Úopened…  s    zTopologyListener.openedc             C   s   t ‚dS )z«Abstract method to handle a `TopologyDescriptionChangedEvent`.

        :Parameters:
          - `event`: An instance of :class:`TopologyDescriptionChangedEvent`.
        N)r   )r   r   r   r   r   Údescription_changed�  s    z$TopologyListener.description_changedc             C   s   t ‚dS )z“Abstract method to handle a `TopologyClosedEvent`.

        :Parameters:
          - `event`: An instance of :class:`TopologyClosedEvent`.
        N)r   )r   r   r   r   r   Úclosed•  s    zTopologyListener.closedN)r   r   r   r   r%   r&   r'   r   r   r   r   r$   }  s   r$   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚServerListenerz©Abstract base class for server listeners.
    Handles `ServerOpeningEvent`, `ServerDescriptionChangedEvent`, and
    `ServerClosedEvent`.

    .. versionadded:: 3.3
    c             C   s   t ‚dS )z‘Abstract method to handle a `ServerOpeningEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerOpeningEvent`.
        N)r   )r   r   r   r   r   r%   ¦  s    zServerListener.openedc             C   s   t ‚dS )z§Abstract method to handle a `ServerDescriptionChangedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerDescriptionChangedEvent`.
        N)r   )r   r   r   r   r   r&   ®  s    z"ServerListener.description_changedc             C   s   t ‚dS )z�Abstract method to handle a `ServerClosedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerClosedEvent`.
        N)r   )r   r   r   r   r   r'   ¶  s    zServerListener.closedN)r   r   r   r   r%   r&   r'   r   r   r   r   r(   ž  s   r(   c             C   s   t | jƒ d ƒS )z'Convert duration 'dur' to microseconds.g    €„.A)ÚintÚtotal_seconds)Zdurr   r   r   Ú
_to_micros¿  s    r+   c             C   sD   t |tjƒstd| f ƒ‚x$|D ]}t |tƒs td| f ƒ‚q W |S )zValidate event listenersz%s must be a list or tuplezˆListeners for %s must be either a CommandListener, ServerHeartbeatListener, ServerListener, TopologyListener, or ConnectionPoolListener.)Ú
isinstancer   ÚSequenceÚ	TypeErrorr
   )ÚoptionÚ	listenersÚlistenerr   r   r   Ú_validate_event_listenersÄ  s    

r2   c             C   sŠ   t | tƒstd| f ƒ‚t | tƒr.tjj| ƒ t | tƒrDtjj| ƒ t | t	ƒrZtj
j| ƒ t | tƒrptjj| ƒ t | tƒr†tjj| ƒ dS )a   Register a global event listener.

    :Parameters:
      - `listener`: A subclasses of :class:`CommandListener`,
        :class:`ServerHeartbeatListener`, :class:`ServerListener`,
        :class:`TopologyListener`, or :class:`ConnectionPoolListener`.
    zˆListeners for %s must be either a CommandListener, ServerHeartbeatListener, ServerListener, TopologyListener, or ConnectionPoolListener.N)r,   r
   r.   r   Ú
_LISTENERSr   Úappendr#   r   r(   r   r$   r   r   r	   )r1   r   r   r   ÚregisterÑ  s    






r5   ZauthenticateZ	saslstartZsaslcontinueZgetnonceZ
createuserZ
updateuserZcopydbgetnonceZcopydbsaslstartZcopydbc               @   sL   e Zd ZdZdZdd„ Zedd	„ ƒZed
d„ ƒZedd„ ƒZ	edd„ ƒZ
dS )Ú_CommandEventzBase class for command events.Ú
__cmd_nameÚ	__rqst_idÚ	__conn_idÚ__op_idc             C   s   || _ || _|| _|| _d S )N)Ú_CommandEvent__cmd_nameÚ_CommandEvent__rqst_idÚ_CommandEvent__conn_idÚ_CommandEvent__op_id)r   Úcommand_nameÚ
request_idÚconnection_idÚoperation_idr   r   r   Ú__init__ö  s    z_CommandEvent.__init__c             C   s   | j S )zThe command name.)r;   )r   r   r   r   r?   ü  s    z_CommandEvent.command_namec             C   s   | j S )z"The request id for this operation.)r<   )r   r   r   r   r@     s    z_CommandEvent.request_idc             C   s   | j S )z@The address (host, port) of the server this command was sent to.)r=   )r   r   r   r   rA     s    z_CommandEvent.connection_idc             C   s   | j S )z(An id for this series of events or None.)r>   )r   r   r   r   rB     s    z_CommandEvent.operation_idN)r7   r8   r9   r:   )r   r   r   r   Ú	__slots__rC   Úpropertyr?   r@   rA   rB   r   r   r   r   r6   ñ  s   r6   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚCommandStartedEventa   Event published when a command starts.

    :Parameters:
      - `command`: The command document.
      - `database_name`: The name of the database this command was run against.
      - `request_id`: The request id for this operation.
      - `connection_id`: The address (host, port) of the server this command
        was sent to.
      - `operation_id`: An optional identifier for a series of related events.
    Ú__cmdÚ__dbc                sX   |st d|f ƒ‚tt|ƒƒ}tt| ƒj|f|žŽ  |jƒ tkrHi | _n|| _|| _	d S )Nz%r is not a valid command)
Ú
ValueErrorÚnextÚiterÚsuperrF   rC   ÚlowerÚ_SENSITIVE_COMMANDSÚ_CommandStartedEvent__cmdÚ_CommandStartedEvent__db)r   ÚcommandÚdatabase_nameÚargsr?   )Ú	__class__r   r   rC     s    zCommandStartedEvent.__init__c             C   s   | j S )zThe command document.)rO   )r   r   r   r   rQ   *  s    zCommandStartedEvent.commandc             C   s   | j S )z6The name of the database this command was run against.)rP   )r   r   r   r   rR   /  s    z!CommandStartedEvent.database_name)rG   rH   )
r   r   r   r   rD   rC   rE   rQ   rR   Ú__classcell__r   r   )rT   r   rF     s
   
rF   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚCommandSucceededEventaÁ  Event published when a command succeeds.

    :Parameters:
      - `duration`: The command duration as a datetime.timedelta.
      - `reply`: The server reply document.
      - `command_name`: The command name.
      - `request_id`: The request id for this operation.
      - `connection_id`: The address (host, port) of the server this command
        was sent to.
      - `operation_id`: An optional identifier for a series of related events.
    Ú__duration_microsÚ__replyc                s>   t t| ƒj||||ƒ t|ƒ| _|jƒ tkr4i | _n|| _d S )N)rL   rV   rC   r+   Ú'_CommandSucceededEvent__duration_microsrM   rN   Ú_CommandSucceededEvent__reply)r   ÚdurationÚreplyr?   r@   rA   rB   )rT   r   r   rC   C  s    

zCommandSucceededEvent.__init__c             C   s   | j S )z/The duration of this operation in microseconds.)rY   )r   r   r   r   Úduration_microsM  s    z%CommandSucceededEvent.duration_microsc             C   s   | j S )z/The server failure document for this operation.)rZ   )r   r   r   r   r\   R  s    zCommandSucceededEvent.reply)rW   rX   )
r   r   r   r   rD   rC   rE   r]   r\   rU   r   r   )rT   r   rV   5  s
   
rV   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚCommandFailedEventaÀ  Event published when a command fails.

    :Parameters:
      - `duration`: The command duration as a datetime.timedelta.
      - `failure`: The server reply document.
      - `command_name`: The command name.
      - `request_id`: The request id for this operation.
      - `connection_id`: The address (host, port) of the server this command
        was sent to.
      - `operation_id`: An optional identifier for a series of related events.
    rW   Ú	__failurec                s$   t t| ƒj|Ž  t|ƒ| _|| _d S )N)rL   r^   rC   r+   Ú$_CommandFailedEvent__duration_microsÚ_CommandFailedEvent__failure)r   r[   ÚfailurerS   )rT   r   r   rC   f  s    
zCommandFailedEvent.__init__c             C   s   | j S )z/The duration of this operation in microseconds.)r`   )r   r   r   r   r]   k  s    z"CommandFailedEvent.duration_microsc             C   s   | j S )z/The server failure document for this operation.)ra   )r   r   r   r   rb   p  s    zCommandFailedEvent.failure)rW   r_   )
r   r   r   r   rD   rC   rE   r]   rb   rU   r   r   )rT   r   r^   X  s
   r^   c               @   s0   e Zd ZdZd
Zdd„ Zedd„ ƒZdd„ Zd	S )Ú
_PoolEventzBase class for pool events.Ú	__addressc             C   s
   || _ d S )N)Ú_PoolEvent__address)r   Úaddressr   r   r   rC   z  s    z_PoolEvent.__init__c             C   s   | j S )zbThe address (host, port) pair of the server the pool is attempting
        to connect to.
        )re   )r   r   r   r   rf   }  s    z_PoolEvent.addressc             C   s   d| j j| jf S )Nz%s(%r))rT   r   re   )r   r   r   r   Ú__repr__„  s    z_PoolEvent.__repr__N)rd   )	r   r   r   r   rD   rC   rE   rf   rg   r   r   r   r   rc   v  s
   rc   c                   s8   e Zd ZdZd	Z‡ fdd„Zedd„ ƒZdd„ Z‡  Z	S )
ÚPoolCreatedEventzÊPublished when a Connection Pool is created.

    :Parameters:
     - `address`: The address (host, port) pair of the server this Pool is
       attempting to connect to.

    .. versionadded:: 3.9
    Ú	__optionsc                s   t t| ƒj|ƒ || _d S )N)rL   rh   rC   Ú_PoolCreatedEvent__options)r   rf   Úoptions)rT   r   r   rC   “  s    zPoolCreatedEvent.__init__c             C   s   | j S )zLAny non-default pool options that were set on this Connection Pool.
        )rj   )r   r   r   r   rk   —  s    zPoolCreatedEvent.optionsc             C   s   d| j j| j| jf S )Nz
%s(%r, %r))rT   r   rf   rj   )r   r   r   r   rg   �  s    zPoolCreatedEvent.__repr__)ri   )
r   r   r   r   rD   rC   rE   rk   rg   rU   r   r   )rT   r   rh   ˆ  s
   rh   c               @   s   e Zd ZdZf ZdS )ÚPoolClearedEventzÊPublished when a Connection Pool is cleared.

    :Parameters:
     - `address`: The address (host, port) pair of the server this Pool is
       attempting to connect to.

    .. versionadded:: 3.9
    N)r   r   r   r   rD   r   r   r   r   rl   ¢  s   rl   c               @   s   e Zd ZdZf ZdS )ÚPoolClosedEventzÉPublished when a Connection Pool is closed.

    :Parameters:
     - `address`: The address (host, port) pair of the server this Pool is
       attempting to connect to.

    .. versionadded:: 3.9
    N)r   r   r   r   rD   r   r   r   r   rm   ®  s   rm   c               @   s    e Zd ZdZdZdZdZdZdS )ÚConnectionClosedReasonzqAn enum that defines values for `reason` on a
    :class:`ConnectionClosedEvent`.

    .. versionadded:: 3.9
    ÚstaleZidleÚerrorÚ
poolClosedN)r   r   r   r   ZSTALEZIDLEÚERRORÚPOOL_CLOSEDr   r   r   r   rn   º  s   rn   c               @   s   e Zd ZdZdZdZdZdS )ÚConnectionCheckOutFailedReasonzyAn enum that defines values for `reason` on a
    :class:`ConnectionCheckOutFailedEvent`.

    .. versionadded:: 3.9
    Útimeoutrq   ZconnectionErrorN)r   r   r   r   ÚTIMEOUTrs   Z
CONN_ERRORr   r   r   r   rt   Ï  s
   rt   c               @   s<   e Zd ZdZdZdd„ Zedd„ ƒZedd	„ ƒZd
d„ Z	dS )Ú_ConnectionEventz.Private base class for some connection events.rd   Ú__connection_idc             C   s   || _ || _d S )N)Ú_ConnectionEvent__addressÚ_ConnectionEvent__connection_id)r   rf   rA   r   r   r   rC   æ  s    z_ConnectionEvent.__init__c             C   s   | j S )ziThe address (host, port) pair of the server this connection is
        attempting to connect to.
        )ry   )r   r   r   r   rf   ê  s    z_ConnectionEvent.addressc             C   s   | j S )zThe ID of the Connection.)rz   )r   r   r   r   rA   ñ  s    z_ConnectionEvent.connection_idc             C   s   d| j j| j| jf S )Nz
%s(%r, %r))rT   r   ry   rz   )r   r   r   r   rg   ö  s    z_ConnectionEvent.__repr__N)rd   rx   )
r   r   r   r   rD   rC   rE   rf   rA   rg   r   r   r   r   rw   â  s   rw   c               @   s   e Zd ZdZf ZdS )ÚConnectionCreatedEventa’  Published when a Connection Pool creates a Connection object.

    NOTE: This connection is not ready for use until the
    :class:`ConnectionReadyEvent` is published.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.
     - `connection_id`: The integer ID of the Connection in this Pool.

    .. versionadded:: 3.9
    N)r   r   r   r   rD   r   r   r   r   r{   û  s   r{   c               @   s   e Zd ZdZf ZdS )ÚConnectionReadyEventa3  Published when a Connection has finished its setup, and is ready to use.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.
     - `connection_id`: The integer ID of the Connection in this Pool.

    .. versionadded:: 3.9
    N)r   r   r   r   rD   r   r   r   r   r|     s   	r|   c                   s8   e Zd ZdZd	Z‡ fdd„Zedd„ ƒZdd„ Z‡  Z	S )
ÚConnectionClosedEventaV  Published when a Connection is closed.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.
     - `connection_id`: The integer ID of the Connection in this Pool.
     - `reason`: A reason explaining why this connection was closed.

    .. versionadded:: 3.9
    Ú__reasonc                s   t t| ƒj||ƒ || _d S )N)rL   r}   rC   Ú_ConnectionClosedEvent__reason)r   rf   rA   Úreason)rT   r   r   rC   %  s    zConnectionClosedEvent.__init__c             C   s   | j S )z¢A reason explaining why this connection was closed.

        The reason must be one of the strings from the
        :class:`ConnectionClosedReason` enum.
        )r   )r   r   r   r   r€   )  s    zConnectionClosedEvent.reasonc             C   s   d| j j| j| j| jf S )Nz%s(%r, %r, %r))rT   r   rf   rA   r   )r   r   r   r   rg   2  s    zConnectionClosedEvent.__repr__)r~   )
r   r   r   r   rD   rC   rE   r€   rg   rU   r   r   )rT   r   r}     s
   
	r}   c               @   s0   e Zd ZdZd
Zdd„ Zedd„ ƒZdd„ Zd	S )ÚConnectionCheckOutStartedEventzêPublished when the driver starts attempting to check out a connection.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.

    .. versionadded:: 3.9
    rd   c             C   s
   || _ d S )N)Ú(_ConnectionCheckOutStartedEvent__address)r   rf   r   r   r   rC   C  s    z'ConnectionCheckOutStartedEvent.__init__c             C   s   | j S )ziThe address (host, port) pair of the server this connection is
        attempting to connect to.
        )r‚   )r   r   r   r   rf   F  s    z&ConnectionCheckOutStartedEvent.addressc             C   s   d| j j| jf S )Nz%s(%r))rT   r   r‚   )r   r   r   r   rg   M  s    z'ConnectionCheckOutStartedEvent.__repr__N)rd   )	r   r   r   r   rD   rC   rE   rf   rg   r   r   r   r   r�   8  s
   r�   c               @   s<   e Zd ZdZdZdd„ Zedd„ ƒZedd	„ ƒZd
d„ Z	dS )ÚConnectionCheckOutFailedEventa.  Published when the driver's attempt to check out a connection fails.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.
     - `reason`: A reason explaining why connection check out failed.

    .. versionadded:: 3.9
    rd   r~   c             C   s   || _ || _d S )N)Ú'_ConnectionCheckOutFailedEvent__addressÚ&_ConnectionCheckOutFailedEvent__reason)r   rf   r€   r   r   r   rC   ]  s    z&ConnectionCheckOutFailedEvent.__init__c             C   s   | j S )ziThe address (host, port) pair of the server this connection is
        attempting to connect to.
        )r„   )r   r   r   r   rf   a  s    z%ConnectionCheckOutFailedEvent.addressc             C   s   | j S )z«A reason explaining why connection check out failed.

        The reason must be one of the strings from the
        :class:`ConnectionCheckOutFailedReason` enum.
        )r…   )r   r   r   r   r€   h  s    z$ConnectionCheckOutFailedEvent.reasonc             C   s   d| j j| j| jf S )Nz
%s(%r, %r))rT   r   r„   r…   )r   r   r   r   rg   q  s    z&ConnectionCheckOutFailedEvent.__repr__N)rd   r~   )
r   r   r   r   rD   rC   rE   rf   r€   rg   r   r   r   r   rƒ   Q  s   		rƒ   c               @   s   e Zd ZdZf ZdS )ÚConnectionCheckedOutEventa*  Published when the driver successfully checks out a Connection.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.
     - `connection_id`: The integer ID of the Connection in this Pool.

    .. versionadded:: 3.9
    N)r   r   r   r   rD   r   r   r   r   r†   v  s   	r†   c               @   s   e Zd ZdZf ZdS )ÚConnectionCheckedInEventa*  Published when the driver checks in a Connection into the Pool.

    :Parameters:
     - `address`: The address (host, port) pair of the server this
       Connection is attempting to connect to.
     - `connection_id`: The integer ID of the Connection in this Pool.

    .. versionadded:: 3.9
    N)r   r   r   r   rD   r   r   r   r   r‡   ƒ  s   	r‡   c               @   s4   e Zd ZdZdZdd„ Zedd„ ƒZedd	„ ƒZd
S )Ú_ServerEventzBase class for server events.Ú__server_addressÚ__topology_idc             C   s   || _ || _d S )N)Ú_ServerEvent__server_addressÚ_ServerEvent__topology_id)r   Úserver_addressÚtopology_idr   r   r   rC   •  s    z_ServerEvent.__init__c             C   s   | j S )z+The address (host, port) pair of the server)r‹   )r   r   r   r   r�   ™  s    z_ServerEvent.server_addressc             C   s   | j S )z>A unique identifier for the topology this server is a part of.)rŒ   )r   r   r   r   rŽ   ž  s    z_ServerEvent.topology_idN)r‰   rŠ   )	r   r   r   r   rD   rC   rE   r�   rŽ   r   r   r   r   rˆ   �  s
   rˆ   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚServerDescriptionChangedEventzJPublished when server description changes.

    .. versionadded:: 3.3
    Ú__previous_descriptionÚ__new_descriptionc                s    t t| ƒj|Ž  || _|| _d S )N)rL   r�   rC   Ú4_ServerDescriptionChangedEvent__previous_descriptionÚ/_ServerDescriptionChangedEvent__new_description)r   Úprevious_descriptionÚnew_descriptionrS   )rT   r   r   rC   ¬  s    z&ServerDescriptionChangedEvent.__init__c             C   s   | j S )zLThe previous
        :class:`~pymongo.server_description.ServerDescription`.)r’   )r   r   r   r   r”   ±  s    z2ServerDescriptionChangedEvent.previous_descriptionc             C   s   | j S )zGThe new
        :class:`~pymongo.server_description.ServerDescription`.)r“   )r   r   r   r   r•   ·  s    z-ServerDescriptionChangedEvent.new_description)r�   r‘   )
r   r   r   r   rD   rC   rE   r”   r•   rU   r   r   )rT   r   r�   ¤  s
   r�   c               @   s   e Zd ZdZf ZdS )ÚServerOpeningEventzEPublished when server is initialized.

    .. versionadded:: 3.3
    N)r   r   r   r   rD   r   r   r   r   r–   ¾  s   r–   c               @   s   e Zd ZdZf ZdS )ÚServerClosedEventz@Published when server is closed.

    .. versionadded:: 3.3
    N)r   r   r   r   rD   r   r   r   r   r—   Ç  s   r—   c               @   s(   e Zd ZdZdZdd„ Zedd„ ƒZdS )ÚTopologyEventz+Base class for topology description events.rŠ   c             C   s
   || _ d S )N)Ú_TopologyEvent__topology_id)r   rŽ   r   r   r   rC   Õ  s    zTopologyEvent.__init__c             C   s   | j S )z>A unique identifier for the topology this server is a part of.)r™   )r   r   r   r   rŽ   Ø  s    zTopologyEvent.topology_idN)r   r   r   r   rD   rC   rE   rŽ   r   r   r   r   r˜   Ð  s   r˜   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚTopologyDescriptionChangedEventzPPublished when the topology description changes.

    .. versionadded:: 3.3
    r�   r‘   c                s    t t| ƒj|Ž  || _|| _d S )N)rL   rš   rC   Ú6_TopologyDescriptionChangedEvent__previous_descriptionÚ1_TopologyDescriptionChangedEvent__new_description)r   r”   r•   rS   )rT   r   r   rC   æ  s    z(TopologyDescriptionChangedEvent.__init__c             C   s   | j S )zPThe previous
        :class:`~pymongo.topology_description.TopologyDescription`.)r›   )r   r   r   r   r”   ë  s    z4TopologyDescriptionChangedEvent.previous_descriptionc             C   s   | j S )zKThe new
        :class:`~pymongo.topology_description.TopologyDescription`.)rœ   )r   r   r   r   r•   ñ  s    z/TopologyDescriptionChangedEvent.new_description)r�   r‘   )
r   r   r   r   rD   rC   rE   r”   r•   rU   r   r   )rT   r   rš   Þ  s
   rš   c               @   s   e Zd ZdZf ZdS )ÚTopologyOpenedEventzKPublished when the topology is initialized.

    .. versionadded:: 3.3
    N)r   r   r   r   rD   r   r   r   r   r�   ø  s   r�   c               @   s   e Zd ZdZf ZdS )ÚTopologyClosedEventzFPublished when the topology is closed.

    .. versionadded:: 3.3
    N)r   r   r   r   rD   r   r   r   r   rž     s   rž   c               @   s(   e Zd ZdZdZdd„ Zedd„ ƒZdS )Ú_ServerHeartbeatEventz'Base class for server heartbeat events.rx   c             C   s
   || _ d S )N)Ú$_ServerHeartbeatEvent__connection_id)r   rA   r   r   r   rC     s    z_ServerHeartbeatEvent.__init__c             C   s   | j S )zJThe address (host, port) of the server this heartbeat was sent
        to.)r    )r   r   r   r   rA     s    z#_ServerHeartbeatEvent.connection_idN)r   r   r   r   rD   rC   rE   rA   r   r   r   r   rŸ   
  s   rŸ   c               @   s   e Zd ZdZf ZdS )ÚServerHeartbeatStartedEventzFPublished when a heartbeat is started.

    .. versionadded:: 3.3
    N)r   r   r   r   rD   r   r   r   r   r¡     s   r¡   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚServerHeartbeatSucceededEventzIFired when the server heartbeat succeeds.

    .. versionadded:: 3.3
    Ú
__durationrX   c                s    t t| ƒj|Ž  || _|| _d S )N)rL   r¢   rC   Ú(_ServerHeartbeatSucceededEvent__durationÚ%_ServerHeartbeatSucceededEvent__reply)r   r[   r\   rS   )rT   r   r   rC   *  s    z&ServerHeartbeatSucceededEvent.__init__c             C   s   | j S )z/The duration of this heartbeat in microseconds.)r¤   )r   r   r   r   r[   /  s    z&ServerHeartbeatSucceededEvent.durationc             C   s   | j S )z3An instance of :class:`~pymongo.ismaster.IsMaster`.)r¥   )r   r   r   r   r\   4  s    z#ServerHeartbeatSucceededEvent.reply)r£   rX   )
r   r   r   r   rD   rC   rE   r[   r\   rU   r   r   )rT   r   r¢   "  s
   r¢   c                   s<   e Zd ZdZd
Z‡ fdd„Zedd„ ƒZedd	„ ƒZ‡  Z	S )ÚServerHeartbeatFailedEventzxFired when the server heartbeat fails, either with an "ok: 0"
    or a socket exception.

    .. versionadded:: 3.3
    r£   rX   c                s    t t| ƒj|Ž  || _|| _d S )N)rL   r¦   rC   Ú%_ServerHeartbeatFailedEvent__durationÚ"_ServerHeartbeatFailedEvent__reply)r   r[   r\   rS   )rT   r   r   rC   C  s    z#ServerHeartbeatFailedEvent.__init__c             C   s   | j S )z/The duration of this heartbeat in microseconds.)r§   )r   r   r   r   r[   H  s    z#ServerHeartbeatFailedEvent.durationc             C   s   | j S )zA subclass of :exc:`Exception`.)r¨   )r   r   r   r   r\   M  s    z ServerHeartbeatFailedEvent.reply)r£   rX   )
r   r   r   r   rD   rC   rE   r[   r\   rU   r   r   )rT   r   r¦   :  s
   r¦   c               @   s  e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
dd„ Zd=dd„Zd>dd„Zd?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%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Z d;d<„ Z!dS )@Ú_EventListenersz½Configure event listeners for a client instance.

    Any event listeners registered globally are included by default.

    :Parameters:
      - `listeners`: A list of event listeners.
    c             C   s  t jd d … | _t jd d … | _t j}|d d … | _t jd d … | _t j	d d … | _
|d k	rØxz|D ]r}t|tƒr|| jj|ƒ t|tƒr’| jj|ƒ t|tƒr¨| jj|ƒ t|tƒr¾| jj|ƒ t|tƒrb| j
j|ƒ qbW t| jƒ| _t| jƒ| _t| jƒ| _t| jƒ| _t| j
ƒ| _d S )N)r3   r   Ú"_EventListeners__command_listenersr   Ú!_EventListeners__server_listenersr   Ú+_EventListeners__server_heartbeat_listenersr   Ú#_EventListeners__topology_listenersr	   Ú_EventListeners__cmap_listenersr,   r   r4   r(   r#   r$   r   ÚboolÚ%_EventListeners__enabled_for_commandsÚ#_EventListeners__enabled_for_serverÚ-_EventListeners__enabled_for_server_heartbeatÚ%_EventListeners__enabled_for_topologyÚ!_EventListeners__enabled_for_cmap)r   r0   Úlstr   r   r   rC   [  s0    






z_EventListeners.__init__c             C   s   | j S )z-Are any CommandListener instances registered?)r°   )r   r   r   r   Úenabled_for_commandsu  s    z$_EventListeners.enabled_for_commandsc             C   s   | j S )z,Are any ServerListener instances registered?)r±   )r   r   r   r   Úenabled_for_serverz  s    z"_EventListeners.enabled_for_serverc             C   s   | j S )z5Are any ServerHeartbeatListener instances registered?)r²   )r   r   r   r   Úenabled_for_server_heartbeat  s    z,_EventListeners.enabled_for_server_heartbeatc             C   s   | j S )z.Are any TopologyListener instances registered?)r³   )r   r   r   r   Úenabled_for_topology„  s    z$_EventListeners.enabled_for_topologyc             C   s   | j S )z4Are any ConnectionPoolListener instances registered?)r´   )r   r   r   r   Úenabled_for_cmap‰  s    z _EventListeners.enabled_for_cmapc             C   s4   | j dd… | jdd… | jdd… | jdd… fS )z#List of registered event listeners.N)rª   r¬   r«   r­   )r   r   r   r   Úevent_listenersŽ  s    z_EventListeners.event_listenersNc             C   sZ   |dkr|}t |||||ƒ}x8| jD ].}y|j|ƒ W q$ tk
rP   tƒ  Y q$X q$W dS )aÏ  Publish a CommandStartedEvent to all command listeners.

        :Parameters:
          - `command`: The command document.
          - `database_name`: The name of the database this command was run
            against.
          - `request_id`: The request id for this operation.
          - `connection_id`: The address (host, port) of the server this
            command was sent to.
          - `op_id`: The (optional) operation id for this operation.
        N)rF   rª   r   Ú	Exceptionr   )r   rQ   rR   r@   rA   Úop_idr   Ú
subscriberr   r   r   Úpublish_command_start•  s    z%_EventListeners.publish_command_startc       	      C   s\   |dkr|}t ||||||ƒ}x8| jD ].}y|j|ƒ W q& tk
rR   tƒ  Y q&X q&W dS )aè  Publish a CommandSucceededEvent to all command listeners.

        :Parameters:
          - `duration`: The command duration as a datetime.timedelta.
          - `reply`: The server reply document.
          - `command_name`: The command name.
          - `request_id`: The request id for this operation.
          - `connection_id`: The address (host, port) of the server this
            command was sent to.
          - `op_id`: The (optional) operation id for this operation.
        N)rV   rª   r   r¼   r   )	r   r[   r\   r?   r@   rA   r½   r   r¾   r   r   r   Úpublish_command_success¬  s    z'_EventListeners.publish_command_successc       	      C   s\   |dkr|}t ||||||ƒ}x8| jD ].}y|j|ƒ W q& tk
rR   tƒ  Y q&X q&W dS )a  Publish a CommandFailedEvent to all command listeners.

        :Parameters:
          - `duration`: The command duration as a datetime.timedelta.
          - `failure`: The server reply document or failure description
            document.
          - `command_name`: The command name.
          - `request_id`: The request id for this operation.
          - `connection_id`: The address (host, port) of the server this
            command was sent to.
          - `op_id`: The (optional) operation id for this operation.
        N)r^   rª   r   r¼   r   )	r   r[   rb   r?   r@   rA   r½   r   r¾   r   r   r   Úpublish_command_failureÃ  s    z'_EventListeners.publish_command_failurec             C   sF   t |ƒ}x8| jD ].}y|j|ƒ W q tk
r<   tƒ  Y qX qW dS )z¼Publish a ServerHeartbeatStartedEvent to all server heartbeat
        listeners.

        :Parameters:
         - `connection_id`: The address (host, port) pair of the connection.
        N)r¡   r¬   r   r¼   r   )r   rA   r   r¾   r   r   r   Ú publish_server_heartbeat_startedÛ  s    z0_EventListeners.publish_server_heartbeat_startedc             C   sJ   t |||ƒ}x8| jD ].}y|j|ƒ W q tk
r@   tƒ  Y qX qW dS )a^  Publish a ServerHeartbeatSucceededEvent to all server heartbeat
        listeners.

        :Parameters:
         - `connection_id`: The address (host, port) pair of the connection.
         - `duration`: The execution time of the event in the highest possible
            resolution for the platform.
         - `reply`: The command reply.
         N)r¢   r¬   r   r¼   r   )r   rA   r[   r\   r   r¾   r   r   r   Ú"publish_server_heartbeat_succeededé  s    z2_EventListeners.publish_server_heartbeat_succeededc             C   sJ   t |||ƒ}x8| jD ].}y|j|ƒ W q tk
r@   tƒ  Y qX qW dS )a[  Publish a ServerHeartbeatFailedEvent to all server heartbeat
        listeners.

        :Parameters:
         - `connection_id`: The address (host, port) pair of the connection.
         - `duration`: The execution time of the event in the highest possible
            resolution for the platform.
         - `reply`: The command reply.
         N)r¦   r¬   r   r¼   r   )r   rA   r[   r\   r   r¾   r   r   r   Úpublish_server_heartbeat_failedû  s    
z/_EventListeners.publish_server_heartbeat_failedc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )a  Publish a ServerOpeningEvent to all server listeners.

        :Parameters:
         - `server_address`: The address (host, port) pair of the server.
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)r–   r«   r%   r¼   r   )r   r�   rŽ   r   r¾   r   r   r   Úpublish_server_opened  s    
z%_EventListeners.publish_server_openedc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )a  Publish a ServerClosedEvent to all server listeners.

        :Parameters:
         - `server_address`: The address (host, port) pair of the server.
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)r—   r«   r'   r¼   r   )r   r�   rŽ   r   r¾   r   r   r   Úpublish_server_closed  s    
z%_EventListeners.publish_server_closedc             C   sL   t ||||ƒ}x8| jD ].}y|j|ƒ W q tk
rB   tƒ  Y qX qW dS )a‹  Publish a ServerDescriptionChangedEvent to all server listeners.

        :Parameters:
         - `previous_description`: The previous server description.
         - `server_address`: The address (host, port) pair of the server.
         - `new_description`: The new server description.
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)r�   r«   r&   r¼   r   )r   r”   r•   r�   rŽ   r   r¾   r   r   r   Ú"publish_server_description_changed*  s    z2_EventListeners.publish_server_description_changedc             C   sF   t |ƒ}x8| jD ].}y|j|ƒ W q tk
r<   tƒ  Y qX qW dS )z»Publish a TopologyOpenedEvent to all topology listeners.

        :Parameters:
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)r�   r­   r%   r¼   r   )r   rŽ   r   r¾   r   r   r   Úpublish_topology_opened?  s    z'_EventListeners.publish_topology_openedc             C   sF   t |ƒ}x8| jD ].}y|j|ƒ W q tk
r<   tƒ  Y qX qW dS )z»Publish a TopologyClosedEvent to all topology listeners.

        :Parameters:
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)rž   r­   r'   r¼   r   )r   rŽ   r   r¾   r   r   r   Úpublish_topology_closedM  s    z'_EventListeners.publish_topology_closedc             C   sJ   t |||ƒ}x8| jD ].}y|j|ƒ W q tk
r@   tƒ  Y qX qW dS )aI  Publish a TopologyDescriptionChangedEvent to all topology listeners.

        :Parameters:
         - `previous_description`: The previous topology description.
         - `new_description`: The new topology description.
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)rš   r­   r&   r¼   r   )r   r”   r•   rŽ   r   r¾   r   r   r   Ú$publish_topology_description_changed[  s    
z4_EventListeners.publish_topology_description_changedc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )zCPublish a :class:`PoolCreatedEvent` to all pool listeners.
        N)rh   r®   r   r¼   r   )r   rf   rk   r   r¾   r   r   r   Úpublish_pool_createdm  s    
z$_EventListeners.publish_pool_createdc             C   sF   t |ƒ}x8| jD ].}y|j|ƒ W q tk
r<   tƒ  Y qX qW dS )zCPublish a :class:`PoolClearedEvent` to all pool listeners.
        N)rl   r®   r   r¼   r   )r   rf   r   r¾   r   r   r   Úpublish_pool_clearedw  s    z$_EventListeners.publish_pool_clearedc             C   sF   t |ƒ}x8| jD ].}y|j|ƒ W q tk
r<   tƒ  Y qX qW dS )zBPublish a :class:`PoolClosedEvent` to all pool listeners.
        N)rm   r®   r   r¼   r   )r   rf   r   r¾   r   r   r   Úpublish_pool_closed�  s    z#_EventListeners.publish_pool_closedc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )zWPublish a :class:`ConnectionCreatedEvent` to all connection
        listeners.
        N)r{   r®   r   r¼   r   )r   rf   rA   r   r¾   r   r   r   Úpublish_connection_created‹  s    
z*_EventListeners.publish_connection_createdc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )zMPublish a :class:`ConnectionReadyEvent` to all connection listeners.
        N)r|   r®   r   r¼   r   )r   rf   rA   r   r¾   r   r   r   Úpublish_connection_ready–  s    
z(_EventListeners.publish_connection_readyc             C   sJ   t |||ƒ}x8| jD ].}y|j|ƒ W q tk
r@   tƒ  Y qX qW dS )zVPublish a :class:`ConnectionClosedEvent` to all connection
        listeners.
        N)r}   r®   r   r¼   r   )r   rf   rA   r€   r   r¾   r   r   r   Úpublish_connection_closed   s    z)_EventListeners.publish_connection_closedc             C   sF   t |ƒ}x8| jD ].}y|j|ƒ W q tk
r<   tƒ  Y qX qW dS )z_Publish a :class:`ConnectionCheckOutStartedEvent` to all connection
        listeners.
        N)r�   r®   r   r¼   r   )r   rf   r   r¾   r   r   r   Ú$publish_connection_check_out_started«  s    z4_EventListeners.publish_connection_check_out_startedc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )z^Publish a :class:`ConnectionCheckOutFailedEvent` to all connection
        listeners.
        N)rƒ   r®   r   r¼   r   )r   rf   r€   r   r¾   r   r   r   Ú#publish_connection_check_out_failed¶  s    
z3_EventListeners.publish_connection_check_out_failedc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )zZPublish a :class:`ConnectionCheckedOutEvent` to all connection
        listeners.
        N)r†   r®   r!   r¼   r   )r   rf   rA   r   r¾   r   r   r   Úpublish_connection_checked_outÁ  s    
z._EventListeners.publish_connection_checked_outc             C   sH   t ||ƒ}x8| jD ].}y|j|ƒ W q tk
r>   tƒ  Y qX qW dS )zYPublish a :class:`ConnectionCheckedInEvent` to all connection
        listeners.
        N)r‡   r®   r"   r¼   r   )r   rf   rA   r   r¾   r   r   r   Úpublish_connection_checked_inÌ  s    
z-_EventListeners.publish_connection_checked_in)N)N)N)"r   r   r   r   rC   rE   r¶   r·   r¸   r¹   rº   r»   r¿   rÀ   rÁ   rÂ   rÃ   rÄ   rÅ   rÆ   rÇ   rÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   rÐ   rÑ   rÒ   rÓ   rÔ   r   r   r   r   r©   S  s<   






r©   N)r   r   r   r   r	   )4r   Úcollectionsr   Zbson.py3compatr   Zpymongo.helpersr   Z
_Listenersr3   Úobjectr
   r   r   r#   r$   r(   r+   r2   r5   ÚsetrN   r6   rF   rV   r^   rc   rh   rl   rm   rn   rt   rw   r{   r|   r}   r�   rƒ   r†   r‡   rˆ   r�   r–   r—   r˜   rš   r�   rž   rŸ   r¡   r¢   r¦   r©   r   r   r   r   Ú<module>±   sf      w"!!
 $# %					