
    h?                        d Z ddlmZ ddlmZ ddlmZ ddlmZ  edd      Z	 e	g g g g g       Z
 G d d	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Zd Zd Zd Z eg d      Zd Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Z  G d+ d,e      Z! G d- d.e      Z" G d/ d0e"      Z# G d1 d2e"      Z$ G d3 d4e"      Z% G d5 d6e      Z& G d7 d8e      Z' G d9 d:e"      Z( G d; d<e"      Z) G d= d>e      Z* G d? d@e*      Z+ G dA dBe*      Z, G dC dDe*      Z- G dE dFe      Z. G dG dHe.      Z/ G dI dJe.      Z0 G dK dLe.      Z1 G dM dNe      Z2 G dO dPe2      Z3 G dQ dRe2      Z4 G dS dTe2      Z5 G dU dVe      Z6yW)Xa  Tools to monitor driver events.

.. versionadded:: 3.1

.. attention:: Starting in PyMongo 3.11, the monitoring classes outlined below
    are included in the PyMongo distribution under the
    :mod:`~pymongo.event_loggers` submodule.

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)HelloCompat)_handle_exception	Listeners)command_listenersserver_listenersserver_heartbeat_listenerstopology_listenerscmap_listenersc                       e Zd ZdZy)_EventListenerz,Abstract base class for all event listeners.N)__name__
__module____qualname____doc__     P/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pymongo/monitoring.pyr   r      s    6r   r   c                   "    e Zd ZdZd Zd Zd Zy)CommandListenerzAbstract base class for command listeners.

    Handles `CommandStartedEvent`, `CommandSucceededEvent`,
    and `CommandFailedEvent`.
    c                     t         )zAbstract method to handle a `CommandStartedEvent`.

        :Parameters:
          - `event`: An instance of :class:`CommandStartedEvent`.
        NotImplementedErrorselfevents     r   startedzCommandListener.started   
     "!r   c                     t         )zAbstract method to handle a `CommandSucceededEvent`.

        :Parameters:
          - `event`: An instance of :class:`CommandSucceededEvent`.
        r   r   s     r   	succeededzCommandListener.succeeded   r   r   c                     t         )zAbstract method to handle a `CommandFailedEvent`.

        :Parameters:
          - `event`: An instance of :class:`CommandFailedEvent`.
        r   r   s     r   failedzCommandListener.failed   r   r   Nr   r   r   r   r   r!   r#   r   r   r   r   r      s    """r   r   c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)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                     t         )zAbstract method to handle a :class:`PoolCreatedEvent`.

        Emitted when a Connection Pool is created.

        :Parameters:
          - `event`: An instance of :class:`PoolCreatedEvent`.
        r   r   s     r   pool_createdz#ConnectionPoolListener.pool_created   
     "!r   c                     t         )zAbstract method to handle a `PoolClearedEvent`.

        Emitted when a Connection Pool is cleared.

        :Parameters:
          - `event`: An instance of :class:`PoolClearedEvent`.
        r   r   s     r   pool_clearedz#ConnectionPoolListener.pool_cleared	  r)   r   c                     t         )zAbstract method to handle a `PoolClosedEvent`.

        Emitted when a Connection Pool is closed.

        :Parameters:
          - `event`: An instance of :class:`PoolClosedEvent`.
        r   r   s     r   pool_closedz"ConnectionPoolListener.pool_closed  r)   r   c                     t         )zAbstract method to handle a :class:`ConnectionCreatedEvent`.

        Emitted when a Connection Pool creates a Connection object.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCreatedEvent`.
        r   r   s     r   connection_createdz)ConnectionPoolListener.connection_created  r)   r   c                     t         )zAbstract 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`.
        r   r   s     r   connection_readyz'ConnectionPoolListener.connection_ready'  
     "!r   c                     t         )zAbstract method to handle a :class:`ConnectionClosedEvent`.

        Emitted when a Connection Pool closes a Connection.

        :Parameters:
          - `event`: An instance of :class:`ConnectionClosedEvent`.
        r   r   s     r   connection_closedz(ConnectionPoolListener.connection_closed2  r)   r   c                     t         )zAbstract method to handle a :class:`ConnectionCheckOutStartedEvent`.

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

        :Parameters:
          - `event`: An instance of :class:`ConnectionCheckOutStartedEvent`.
        r   r   s     r   connection_check_out_startedz3ConnectionPoolListener.connection_check_out_started<  r)   r   c                     t         )zAbstract 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`.
        r   r   s     r   connection_check_out_failedz2ConnectionPoolListener.connection_check_out_failedF  r)   r   c                     t         )zAbstract method to handle a :class:`ConnectionCheckedOutEvent`.

        Emitted when the driver successfully checks out a Connection.

        :Parameters:
          - `event`: An instance of :class:`ConnectionCheckedOutEvent`.
        r   r   s     r   connection_checked_outz-ConnectionPoolListener.connection_checked_outP  r)   r   c                     t         )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`.
        r   r   s     r   connection_checked_inz,ConnectionPoolListener.connection_checked_inZ  r2   r   N)r   r   r   r   r(   r+   r-   r/   r1   r4   r6   r8   r:   r<   r   r   r   r&   r&      s9    """"	"""""	"r   r&   c                   "    e Zd ZdZd Zd Zd Zy)ServerHeartbeatListenerzAbstract base class for server heartbeat listeners.

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

    .. versionadded:: 3.3
    c                     t         )zAbstract method to handle a `ServerHeartbeatStartedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerHeartbeatStartedEvent`.
        r   r   s     r   r   zServerHeartbeatListener.startedo  r   r   c                     t         )zAbstract method to handle a `ServerHeartbeatSucceededEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerHeartbeatSucceededEvent`.
        r   r   s     r   r!   z!ServerHeartbeatListener.succeededw  r   r   c                     t         )zAbstract method to handle a `ServerHeartbeatFailedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerHeartbeatFailedEvent`.
        r   r   s     r   r#   zServerHeartbeatListener.failed  r   r   Nr$   r   r   r   r>   r>   f  s    """r   r>   c                   "    e Zd ZdZd Zd Zd Zy)TopologyListenerzAbstract base class for topology monitoring listeners.
    Handles `TopologyOpenedEvent`, `TopologyDescriptionChangedEvent`, and
    `TopologyClosedEvent`.

    .. versionadded:: 3.3
    c                     t         )zAbstract method to handle a `TopologyOpenedEvent`.

        :Parameters:
          - `event`: An instance of :class:`TopologyOpenedEvent`.
        r   r   s     r   openedzTopologyListener.opened  r   r   c                     t         )zAbstract method to handle a `TopologyDescriptionChangedEvent`.

        :Parameters:
          - `event`: An instance of :class:`TopologyDescriptionChangedEvent`.
        r   r   s     r   description_changedz$TopologyListener.description_changed  r   r   c                     t         )zAbstract method to handle a `TopologyClosedEvent`.

        :Parameters:
          - `event`: An instance of :class:`TopologyClosedEvent`.
        r   r   s     r   closedzTopologyListener.closed  r   r   Nr   r   r   r   rE   rG   rI   r   r   r   rC   rC         """r   rC   c                   "    e Zd ZdZd Zd Zd Zy)ServerListenerzAbstract base class for server listeners.
    Handles `ServerOpeningEvent`, `ServerDescriptionChangedEvent`, and
    `ServerClosedEvent`.

    .. versionadded:: 3.3
    c                     t         )zAbstract method to handle a `ServerOpeningEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerOpeningEvent`.
        r   r   s     r   rE   zServerListener.opened  r   r   c                     t         )zAbstract method to handle a `ServerDescriptionChangedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerDescriptionChangedEvent`.
        r   r   s     r   rG   z"ServerListener.description_changed  r   r   c                     t         )zAbstract method to handle a `ServerClosedEvent`.

        :Parameters:
          - `event`: An instance of :class:`ServerClosedEvent`.
        r   r   s     r   rI   zServerListener.closed  r   r   NrJ   r   r   r   rM   rM     rK   r   rM   c                 :    t        | j                         dz        S )z'Convert duration 'dur' to microseconds.g    .A)inttotal_seconds)durs    r   
_to_microsrU     s    s  "T)**r   c                     t        |t        j                        st        | d      |D ]!  }t        |t              rt        d| d       |S )zValidate event listenersz must be a list or tupleListeners for x must be either a CommandListener, ServerHeartbeatListener, ServerListener, TopologyListener, or ConnectionPoolListener.)
isinstancer   Sequence	TypeErrorr   )option	listenerslisteners      r   _validate_event_listenersr_     sV    i.@AA (N3 .46  r   c                    t        | t              st        d| d      t        | t              rt        j
                  j                  |        t        | t              rt        j                  j                  |        t        | t              rt        j                  j                  |        t        | t              rt        j                  j                  |        t        | t              r t        j                  j                  |        yy)a   Register a global event listener.

    :Parameters:
      - `listener`: A subclasses of :class:`CommandListener`,
        :class:`ServerHeartbeatListener`, :class:`ServerListener`,
        :class:`TopologyListener`, or :class:`ConnectionPoolListener`.
    rW   rX   N)rY   r   r[   r   
_LISTENERSr   appendr>   r
   rM   r	   rC   r   r&   r   )r^   s    r   registerrc     s     h/ *24
 	
 (O,$$++H5(34--44X>(N+##**84(,-%%,,X6(23!!((2 4r   )	authenticate	saslstartsaslcontinuegetnonce
createuser
updateusercopydbgetnoncecopydbsaslstartcopydbc                 R    | j                         dt        j                  fv rd|v ryy)NhellospeculativeAuthenticateTF)lowerr   
LEGACY_CMD)command_namedocs     r   _is_speculative_authenticatert     s,    +*@*@ AA%,r   c                   l    e Zd ZdZdZd
dZed        Zed        Zed        Z	ed        Z
ed	        Zy)_CommandEventzBase class for command events.)
__cmd_name	__rqst_id	__conn_id__op_id__service_idNc                 J    || _         || _        || _        || _        || _        y N)_CommandEvent__cmd_name_CommandEvent__rqst_id_CommandEvent__conn_id_CommandEvent__op_id_CommandEvent__service_id)r   rr   
request_idconnection_idoperation_id
service_ids         r   __init__z_CommandEvent.__init__  s&    &#&#&r   c                     | j                   S )zThe command name.)r~   r   s    r   rr   z_CommandEvent.command_name"       r   c                     | j                   S )z"The request id for this operation.)r   r   s    r   r   z_CommandEvent.request_id'       ~~r   c                     | j                   S )z@The address (host, port) of the server this command was sent to.)r   r   s    r   r   z_CommandEvent.connection_id,  r   r   c                     | j                   S )z^The service_id this command was sent to, or ``None``.

        .. versionadded:: 3.12
        )r   r   s    r   r   z_CommandEvent.service_id1  s        r   c                     | j                   S )z(An id for this series of events or None.)r   r   s    r   r   z_CommandEvent.operation_id9       ||r   r}   )r   r   r   r   	__slots__r   propertyrr   r   r   r   r   r   r   r   rv   rv     ss    (SI'       ! !  r   rv   c                   P     e Zd ZdZdZ	 d fd	Zed        Zed        Zd Z	 x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.
      - `service_id`: The service_id this command was sent to, or ``None``.
    )__cmd__dbc                 
   |st        |d      t        t        |            }t        t        |   |||||       |j                         ||   }	}|t        v st        ||      ri | _	        || _
        y || _	        || _
        y )Nz is not a valid commandr   )
ValueErrornextitersuperr   r   rp   _SENSITIVE_COMMANDSrt   _CommandStartedEvent__cmd_CommandStartedEvent__db)r   commanddatabase_namer   r   r   r   rr   cmd_namecmd_doc	__class__s             r   r   zCommandStartedEvent.__init__N  s     GEFFDM*!41*m\j 	2 	
 )..0',2G'**.J8U\.]DJ "	 !DJ!	r   c                     | j                   S )zThe command document.)r   r   s    r   r   zCommandStartedEvent.command_  s     zzr   c                     | j                   S )z6The name of the database this command was run against.)r   r   s    r   r   z!CommandStartedEvent.database_named  s     yyr   c                     d| j                   j                  d| j                  d| j                  d| j                  d| j
                  d| j                  dS )N< z db: z, command: , operation_id: , service_id: >)r   r   r   r   rr   r   r   r   s    r   __repr__zCommandStartedEvent.__repr__i  sD    NN##OO
 	
r   r}   )r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r   ?  sH    
 "I [_""    
r   r   c                   P     e Zd ZdZdZ	 d fd	Zed        Zed        Zd Z	 x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.
      - `service_id`: The service_id this command was sent to, or ``None``.
    )__duration_micros__replyc                     t         t        |   |||||       t        |      | _        |j                         }|t        v st        ||      ri | _        y || _        y Nr   )	r   r   r   rU   '_CommandSucceededEvent__duration_microsrp   r   rt   _CommandSucceededEvent__reply)
r   durationreplyrr   r   r   r   r   r   r   s
            r   r   zCommandSucceededEvent.__init__  sd     	#T3*m\j 	4 	
 ",H!5%%'**.J8UZ.[DL DLr   c                     | j                   S z/The duration of this operation in microseconds.)r   r   s    r   duration_microsz%CommandSucceededEvent.duration_micros       %%%r   c                     | j                   S z/The server failure document for this operation.)r   r   s    r   r   zCommandSucceededEvent.reply  r   r   c                     d| j                   j                  d| j                  d| j                  d| j                  d| j
                  d| j                  dS )Nr   r   
 command: r   , duration_micros: r   r   )r   r   r   rr   r   r   r   r   s    r   r   zCommandSucceededEvent.__repr__  sD    NN##  OO
 	
r   r}   )r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r   t  sF     1I !( & &  
r   r   c                   P     e Zd ZdZdZ	 d fd	Zed        Zed        Zd Z	 x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.
      - `service_id`: The service_id this command was sent to, or ``None``.
    )r   	__failurec                 d    t         t        |   |||||       t        |      | _        || _        y r   )r   r   r   rU   $_CommandFailedEvent__duration_micros_CommandFailedEvent__failure)	r   r   failurerr   r   r   r   r   r   s	           r   r   zCommandFailedEvent.__init__  s;     	 $0*m\j 	1 	
 ",H!5 r   c                     | j                   S r   )r   r   s    r   r   z"CommandFailedEvent.duration_micros  r   r   c                     | j                   S r   )r   r   s    r   r   zCommandFailedEvent.failure  r   r   c                     d| j                   j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  dS )	Nr   r   r   r   r   z, failure: r   r   )r   r   r   rr   r   r   r   r   r   s    r   r   zCommandFailedEvent.__repr__  sM    
 NN##  LLOO
 	
r   r}   )r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r     sF     3I !  & &  
r   r   c                   0    e Zd ZdZdZd Zed        Zd Zy)
_PoolEventzBase class for pool events.	__addressc                     || _         y r}   _PoolEvent__addressr   addresss     r   r   z_PoolEvent.__init__  	     r   c                     | j                   S )zbThe address (host, port) pair of the server the pool is attempting
        to connect to.
        r   r   s    r   r   z_PoolEvent.address      
 ~~r   c                 N    | j                   j                  d| j                  dS N())r   r   r   r   s    r   r   z_PoolEvent.__repr__      >>22DNNCCr   N	r   r   r   r   r   r   r   r   r   r   r   r   r   r     s)    %I!  Dr   r   c                   <     e Zd ZdZdZ fdZed        Zd Z xZ	S )PoolCreatedEventzPublished 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                 :    t         t        |   |       || _        y r}   )r   r   r   _PoolCreatedEvent__options)r   r   optionsr   s      r   r   zPoolCreatedEvent.__init__  s    .w7 r   c                     | j                   S )zCAny non-default pool options that were set on this Connection Pool.)r   r   s    r   r   zPoolCreatedEvent.options	  r   r   c                 h    | j                   j                  d| j                  d| j                  dS Nr   z, r   )r   r   r   r   r   s    r   r   zPoolCreatedEvent.__repr__  s!    #~~66dnnUUr   )
r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r     s.     I!  Vr   r   c                   >     e Zd ZdZdZd fd	Zed        Zd Z xZ	S )PoolClearedEventa  Published when a Connection Pool is cleared.

    :Parameters:
     - `address`: The address (host, port) pair of the server this Pool is
       attempting to connect to.
     - `service_id`: The service_id this command was sent to, or ``None``.

    .. versionadded:: 3.9
    )r{   c                 :    t         t        |   |       || _        y r}   )r   r   r   _PoolClearedEvent__service_id)r   r   r   r   s      r   r   zPoolClearedEvent.__init__  s    .w7&r   c                     | j                   S )zConnections with this service_id are cleared.

        When service_id is ``None``, all connections in the pool are cleared.

        .. versionadded:: 3.12
        )r   r   s    r   r   zPoolClearedEvent.service_id#  s        r   c                 h    | j                   j                  d| j                  d| j                  dS r   )r   r   r   r   r   s    r   r   zPoolClearedEvent.__repr__-  s#    #~~66dFWFWXXr   r}   )
r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r     s.     "I' ! !Yr   r   c                       e Zd ZdZdZy)PoolClosedEventzPublished 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
    r   Nr   r   r   r   r   r   r   r   r   r   1  s     Ir   r   c                   &    e Zd ZdZdZ	 dZ	 dZ	 dZy)ConnectionClosedReasonzqAn enum that defines values for `reason` on a
    :class:`ConnectionClosedEvent`.

    .. versionadded:: 3.9
    staleidleerror
poolClosedN)r   r   r   r   STALEIDLEERRORPOOL_CLOSEDr   r   r   r   r   >  s-     EFD EIKEr   r   c                        e Zd ZdZdZ	 dZ	 dZy)ConnectionCheckOutFailedReasonzyAn enum that defines values for `reason` on a
    :class:`ConnectionCheckOutFailedEvent`.

    .. versionadded:: 3.9
    timeoutr   connectionErrorN)r   r   r   r   TIMEOUTr   
CONN_ERRORr   r   r   r   r   S  s#     GJKM"Jr   r   c                   @    e Zd ZdZdZd Zed        Zed        Zd Z	y)_ConnectionEventz.Private base class for some connection events.)r   __connection_idc                      || _         || _        y r}   )_ConnectionEvent__address_ConnectionEvent__connection_id)r   r   r   s      r   r   z_ConnectionEvent.__init__k  s     ,r   c                     | j                   S ziThe address (host, port) pair of the server this connection is
        attempting to connect to.
        )r  r   s    r   r   z_ConnectionEvent.addresso  r   r   c                     | j                   S )zThe ID of the Connection.)r  r   s    r   r   z_ConnectionEvent.connection_idv  s     ###r   c                 h    | j                   j                  d| j                  d| j                  dS r   )r   r   r  r  r   s    r   r   z_ConnectionEvent.__repr__{  s#    #~~66H\H\]]r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  f  s=    80I-   $ $^r   r  c                       e Zd ZdZdZy)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
    r   Nr   r   r   r   r  r    s     Ir   r  c                       e Zd ZdZdZy)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
    r   Nr   r   r   r   r  r         Ir   r  c                   <     e Zd ZdZdZ fdZed        Zd Z x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                 <    t         t        |   ||       || _        y r}   )r   r  r   _ConnectionClosedEvent__reason)r   r   r   reasonr   s       r   r   zConnectionClosedEvent.__init__  s    #T3G]Kr   c                     | j                   S )zA reason explaining why this connection was closed.

        The reason must be one of the strings from the
        :class:`ConnectionClosedReason` enum.
        )r  r   s    r   r  zConnectionClosedEvent.reason       }}r   c                     | j                   j                  d| j                  d| j                  d| j                  dS r   )r   r   r   r   r  r   s    r   r   zConnectionClosedEvent.__repr__  s0    NN##LLMM	
 	
r   )
r   r   r   r   r   r   r   r  r   r   r   s   @r   r  r    s-    	 I  
r   r  c                   0    e Zd ZdZdZd Zed        Zd Zy)ConnectionCheckOutStartedEventzPublished 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
    r   c                     || _         y r}   (_ConnectionCheckOutStartedEvent__addressr   s     r   r   z'ConnectionCheckOutStartedEvent.__init__  r   r   c                     | j                   S r  r  r   s    r   r   z&ConnectionCheckOutStartedEvent.address  r   r   c                 N    | j                   j                  d| j                  dS r   )r   r   r  r   s    r   r   z'ConnectionCheckOutStartedEvent.__repr__  r   r   Nr   r   r   r   r  r    s-     I!  Dr   r  c                   @    e Zd ZdZdZd Zed        Zed        Zd Z	y)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
    )r   r  c                      || _         || _        y r}   )'_ConnectionCheckOutFailedEvent__address&_ConnectionCheckOutFailedEvent__reason)r   r   r  s      r   r   z&ConnectionCheckOutFailedEvent.__init__  s     r   c                     | j                   S r  )r#  r   s    r   r   z%ConnectionCheckOutFailedEvent.address  r   r   c                     | j                   S )zA reason explaining why connection check out failed.

        The reason must be one of the strings from the
        :class:`ConnectionCheckOutFailedReason` enum.
        )r$  r   s    r   r  z$ConnectionCheckOutFailedEvent.reason  r  r   c                 h    | j                   j                  d| j                  d| j                  dS r   )r   r   r#  r$  r   s    r   r   z&ConnectionCheckOutFailedEvent.__repr__  s!    #~~66VVr   N)
r   r   r   r   r   r   r   r   r  r   r   r   r   r!  r!    sA     *I    Wr   r!  c                       e Zd ZdZdZy)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
    r   Nr   r   r   r   r)  r)    r  r   r)  c                       e Zd ZdZdZy)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
    r   Nr   r   r   r   r+  r+    r  r   r+  c                   @    e Zd ZdZdZd Zed        Zed        Zd Z	y)_ServerEventzBase class for server events.)__server_address__topology_idc                      || _         || _        y r}   )_ServerEvent__server_address_ServerEvent__topology_id)r   server_addresstopology_ids      r   r   z_ServerEvent.__init__"  s     .(r   c                     | j                   S )z+The address (host, port) pair of the server)r1  r   s    r   r3  z_ServerEvent.server_address&  s     $$$r   c                     | j                   S z>A unique identifier for the topology this server is a part of.)r2  r   s    r   r4  z_ServerEvent.topology_id+       !!!r   c                 j    d| j                   j                  d| j                  d| j                  dS )Nr   r    topology_id: r   )r   r   r3  r4  r   s    r   r   z_ServerEvent.__repr__0  s+    NN##
 	
r   N)
r   r   r   r   r   r   r   r3  r4  r   r   r   r   r-  r-    s<    '5I) % % " "
r   r-  c                   L     e Zd ZdZdZ fdZed        Zed        Zd Z	 xZ
S )ServerDescriptionChangedEventzJPublished when server description changes.

    .. versionadded:: 3.3
    __previous_description__new_descriptionc                 B    t        t        | 
  |  || _        || _        y r}   )r   r<  r   4_ServerDescriptionChangedEvent__previous_description/_ServerDescriptionChangedEvent__new_descriptionr   previous_descriptionnew_descriptionargsr   s       r   r   z&ServerDescriptionChangedEvent.__init__@  s#    +T;TB&:#!0r   c                     | j                   S )zLThe previous
        :class:`~pymongo.server_description.ServerDescription`.)rA  r   s    r   rD  z2ServerDescriptionChangedEvent.previous_descriptionE       ***r   c                     | j                   S )zGThe new
        :class:`~pymongo.server_description.ServerDescription`.)rB  r   s    r   rE  z-ServerDescriptionChangedEvent.new_descriptionK       %%%r   c           	          d| j                   j                  d| j                  d| j                  d| j                  d	S )Nr   r    changed from: , to: r   )r   r   r3  rD  rE  r   s    r   r   z&ServerDescriptionChangedEvent.__repr__Q  s4    NN##%%  	
 	
r   r   r   r   r   r   r   r   rD  rE  r   r   r   s   @r   r<  r<  8  B    
 @I1
 + +
 & &

r   r<  c                       e Zd ZdZdZy)ServerOpeningEventzEPublished when server is initialized.

    .. versionadded:: 3.3
    r   Nr   r   r   r   rQ  rQ  Z      
 Ir   rQ  c                       e Zd ZdZdZy)ServerClosedEventz@Published when server is closed.

    .. versionadded:: 3.3
    r   Nr   r   r   r   rT  rT  c  rR  r   rT  c                   0    e Zd ZdZdZd Zed        Zd Zy)TopologyEventz+Base class for topology description events.r/  c                     || _         y r}   _TopologyEvent__topology_id)r   r4  s     r   r   zTopologyEvent.__init__q  s
    (r   c                     | j                   S r7  rX  r   s    r   r4  zTopologyEvent.topology_idt  r8  r   c                 P    d| j                   j                  d| j                  dS )Nr   r:  r   )r   r   r4  r   s    r   r   zTopologyEvent.__repr__y  s    )-)@)@$BRBRSSr   N)	r   r   r   r   r   r   r   r4  r   r   r   r   rV  rV  l  s)    5I) " "Tr   rV  c                   L     e Zd ZdZdZ fdZed        Zed        Zd Z	 xZ
S )TopologyDescriptionChangedEventzPPublished when the topology description changes.

    .. versionadded:: 3.3
    r=  c                 B    t        t        | 
  |  || _        || _        y r}   )r   r]  r   6_TopologyDescriptionChangedEvent__previous_description1_TopologyDescriptionChangedEvent__new_descriptionrC  s       r   r   z(TopologyDescriptionChangedEvent.__init__  s#    -t=tD&:#!0r   c                     | j                   S )zPThe previous
        :class:`~pymongo.topology_description.TopologyDescription`.)r_  r   s    r   rD  z4TopologyDescriptionChangedEvent.previous_description  rH  r   c                     | j                   S )zKThe new
        :class:`~pymongo.topology_description.TopologyDescription`.)r`  r   s    r   rE  z/TopologyDescriptionChangedEvent.new_description  rJ  r   c           	          d| j                   j                  d| j                  d| j                  d| j                  d	S )Nr   r:  rL  rM  r   )r   r   r4  rD  rE  r   s    r   r   z(TopologyDescriptionChangedEvent.__repr__  s4    NN##%%  	
 	
r   rN  r   s   @r   r]  r]  }  rO  r   r]  c                       e Zd ZdZdZy)TopologyOpenedEventzKPublished when the topology is initialized.

    .. versionadded:: 3.3
    r   Nr   r   r   r   re  re    rR  r   re  c                       e Zd ZdZdZy)TopologyClosedEventzFPublished when the topology is closed.

    .. versionadded:: 3.3
    r   Nr   r   r   r   rg  rg    rR  r   rg  c                   0    e Zd ZdZdZd Zed        Zd Zy)_ServerHeartbeatEventz'Base class for server heartbeat events.r  c                     || _         y r}   $_ServerHeartbeatEvent__connection_id)r   r   s     r   r   z_ServerHeartbeatEvent.__init__  s
    ,r   c                     | j                   S )zJThe address (host, port) of the server this heartbeat was sent
        to.rk  r   s    r   r   z#_ServerHeartbeatEvent.connection_id  s     ###r   c                 P    d| j                   j                  d| j                  dS )Nr   r   r   )r   r   r   r   s    r   r   z_ServerHeartbeatEvent.__repr__  s     NN33T5G5GHHr   N)	r   r   r   r   r   r   r   r   r   r   r   r   ri  ri    s)    1!I- $ $
Ir   ri  c                       e Zd ZdZdZy)ServerHeartbeatStartedEventzFPublished when a heartbeat is started.

    .. versionadded:: 3.3
    r   Nr   r   r   r   rp  rp    rR  r   rp  c                   ^     e Zd ZdZdZd fd	Zed        Zed        Zed        Z	d Z
 xZS )	ServerHeartbeatSucceededEventzIFired when the server heartbeat succeeds.

    .. versionadded:: 3.3
    
__durationr   	__awaitedc                 V    t         t        |   |       || _        || _        || _        y r}   )r   rr  r   (_ServerHeartbeatSucceededEvent__duration%_ServerHeartbeatSucceededEvent__reply'_ServerHeartbeatSucceededEvent__awaitedr   r   r   r   awaitedr   s        r   r   z&ServerHeartbeatSucceededEvent.__init__  s(    +T;MJ" r   c                     | j                   S z/The duration of this heartbeat in microseconds.)rw  r   s    r   r   z&ServerHeartbeatSucceededEvent.duration  r   r   c                     | j                   S )a  An instance of :class:`~pymongo.ismaster.IsMaster`.

        .. warning:: :class:`~pymongo.ismaster.IsMaster` is deprecated.
          Starting with PyMongo 4.0 this attribute will return an instance
          of :class:`~pymongo.hello.Hello`, which provides the same API.
        )rx  r   s    r   r   z#ServerHeartbeatSucceededEvent.reply  s     ||r   c                     | j                   S zWhether the heartbeat was awaited.

        If true, then :meth:`duration` reflects the sum of the round trip time
        to the server and the time that the server waited before sending a
        response.
        )ry  r   s    r   r{  z%ServerHeartbeatSucceededEvent.awaited       ~~r   c                     d| j                   j                  d| j                  d| j                  d| j                  d| j
                  dS Nr   r   z duration: z, awaited: z	, reply: r   r   r   r   r   r{  r   r   s    r   r   z&ServerHeartbeatSucceededEvent.__repr__  7    NN##MMLLJJ
 	
r   Fr   r   r   r   r   r   r   r   r   r{  r   r   r   s   @r   rr  rr    sU    
 7I!      
r   rr  c                   ^     e Zd ZdZdZd fd	Zed        Zed        Zed        Z	d Z
 xZS )	ServerHeartbeatFailedEventzxFired when the server heartbeat fails, either with an "ok: 0"
    or a socket exception.

    .. versionadded:: 3.3
    rs  c                 V    t         t        |   |       || _        || _        || _        y r}   )r   r  r   %_ServerHeartbeatFailedEvent__duration"_ServerHeartbeatFailedEvent__reply$_ServerHeartbeatFailedEvent__awaitedrz  s        r   r   z#ServerHeartbeatFailedEvent.__init__  s(    ($8G" r   c                     | j                   S r}  )r  r   s    r   r   z#ServerHeartbeatFailedEvent.duration  r   r   c                     | j                   S )zA subclass of :exc:`Exception`.)r  r   s    r   r   z ServerHeartbeatFailedEvent.reply  r   r   c                     | j                   S r  )r  r   s    r   r{  z"ServerHeartbeatFailedEvent.awaited  r  r   c                     d| j                   j                  d| j                  d| j                  d| j                  d| j
                  dS r  r  r   s    r   r   z#ServerHeartbeatFailedEvent.__repr__   r  r   r  r  r   s   @r   r  r    sU     7I!      
r   r  c                      e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
d Z	 d d
Z	 	 	 d!dZ	 	 d dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!y	)"_EventListenerszConfigure event listeners for a client instance.

    Any event listeners registered globally are included by default.

    :Parameters:
      - `listeners`: A list of event listeners.
    c                    t         j                  d d  | _        t         j                  d d  | _        t         j
                  }|d d  | _        t         j                  d d  | _        t         j                  d d  | _
        ||D ]  }t        |t              r| j                  j                  |       t        |t              r| j                  j                  |       t        |t              r| j                  j                  |       t        |t               r| j                  j                  |       t        |t"              s| j                  j                  |        t%        | j                        | _        t%        | j                        | _        t%        | j                        | _        t%        | j                        | _        t%        | j                        | _        y r}   )ra   r   "_EventListeners__command_listenersr	   !_EventListeners__server_listenersr
   +_EventListeners__server_heartbeat_listenersr   #_EventListeners__topology_listenersr   _EventListeners__cmap_listenersrY   r   rb   rM   r>   rC   r&   bool%_EventListeners__enabled_for_commands#_EventListeners__enabled_for_server-_EventListeners__enabled_for_server_heartbeat%_EventListeners__enabled_for_topology!_EventListeners__enabled_for_cmap)r   r]   lsts      r   r   z_EventListeners.__init__3  st   #-#?#?#B ","="=a"@33,/F)$.$A$A!$D! * 9 9! <   
6c?3,,33C8c>2++2237c#:;55<<SAc#34--44S9c#9:))005
6 '+4+C+C&D#$()@)@$A!.243T3T.U+&*4+D+D&E#"&t'<'<"=r   c                     | j                   S )z-Are any CommandListener instances registered?)r  r   s    r   enabled_for_commandsz$_EventListeners.enabled_for_commandsL       ***r   c                     | j                   S )z,Are any ServerListener instances registered?)r  r   s    r   enabled_for_serverz"_EventListeners.enabled_for_serverQ  s     (((r   c                     | j                   S )z5Are any ServerHeartbeatListener instances registered?)r  r   s    r   enabled_for_server_heartbeatz,_EventListeners.enabled_for_server_heartbeatV  s     222r   c                     | j                   S )z.Are any TopologyListener instances registered?)r  r   s    r   enabled_for_topologyz$_EventListeners.enabled_for_topology[  r  r   c                     | j                   S )z4Are any ConnectionPoolListener instances registered?)r  r   s    r   enabled_for_cmapz _EventListeners.enabled_for_cmap`  s     &&&r   c                 h    | j                   | j                  z   | j                  z   | j                  z   S )z#List of registered event listeners.)r  r  r  r  r   s    r   event_listenersz_EventListeners.event_listenerse  s>     $$--.##$ %%&	
r   Nc                     ||}t        ||||||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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.
          - `service_id`: The service_id this command was sent to, or ``None``.
        Nr   )r   r  r   	Exceptionr   )	r   r   r   r   r   op_idr   r   
subscribers	            r   publish_command_startz%_EventListeners.publish_command_startn  sg     =E#]JuQ[
 22 	$J$""5)	$  $!#$s   :AAc	           	          ||}|ri }t        |||||||      }	| j                  D ]  }
	 |
j                  |	        y# t        $ r t	                Y -w xY w)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.
          - `service_id`: The service_id this command was sent to, or ``None``.
          - `speculative_hello`: Was the command sent with speculative auth?
        N)r   r  r!   r  r   )r   r   r   rr   r   r   r  r   speculative_hellor   r  s              r   publish_command_successz'_EventListeners.publish_command_success  sr    0 =E E%e\:}eZ
 22 	$J$$$U+	$  $!#$s   >AAc           	          ||}t        |||||||      }| j                  D ]  }		 |	j                  |        y# t        $ r t	                Y -w xY w)ac  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.
          - `service_id`: The service_id this command was sent to, or ``None``.
        Nr   )r   r  r#   r  r   )
r   r   r   rr   r   r   r  r   r   r  s
             r   publish_command_failurez'_EventListeners.publish_command_failure  si    . =E"g|ZZd
 22 	$J$!!%(	$  $!#$s   ;AAc                     t        |      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zPublish a ServerHeartbeatStartedEvent to all server heartbeat
        listeners.

        :Parameters:
         - `connection_id`: The address (host, port) pair of the connection.
        N)rp  r  r   r  r   )r   r   r   r  s       r    publish_server_heartbeat_startedz0_EventListeners.publish_server_heartbeat_started  sM     ,M:;; 	$J$""5)	$  $!#$   0AAc                     t        ||||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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.
         - `awaited`: True if the response was awaited.
        N)rr  r  r!   r  r   r   r   r   r   r{  r   r  s          r   "publish_server_heartbeat_succeededz2_EventListeners.publish_server_heartbeat_succeeded  sS     .h}gV;; 	$J$$$U+	$  $!#$   3A	A	c                     t        ||||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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.
         - `awaited`: True if the response was awaited.
        N)r  r  r#   r  r   r  s          r   publish_server_heartbeat_failedz/_EventListeners.publish_server_heartbeat_failed  sS     +8UM7S;; 	$J$!!%(	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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)rQ  r  rE   r  r   r   r3  r4  r   r  s        r   publish_server_openedz%_EventListeners.publish_server_opened  sO     #>;?11 	$J$!!%(	$  $!#$   1AAc                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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)rT  r  rI   r  r   r  s        r   publish_server_closedz%_EventListeners.publish_server_closed  sO     ".+>11 	$J$!!%(	$  $!#$r  c                     t        ||||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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  rG   r  r   )r   rD  rE  r3  r4  r   r  s          r   "publish_server_description_changedz2_EventListeners.publish_server_description_changed!  sX     . />;
 11 	$J$..u5	$  $!#$r  c                     t        |      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zPublish a TopologyOpenedEvent to all topology listeners.

        :Parameters:
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)re  r  rE   r  r   r   r4  r   r  s       r   publish_topology_openedz'_EventListeners.publish_topology_opened6  M     $K033 	$J$!!%(	$  $!#$r  c                     t        |      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zPublish a TopologyClosedEvent to all topology listeners.

        :Parameters:
         - `topology_id`: A unique identifier for the topology this server
           is a part of.
        N)rg  r  rI   r  r   r  s       r   publish_topology_closedz'_EventListeners.publish_topology_closedD  r  r  c                     t        |||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)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  rG   r  r   )r   rD  rE  r4  r   r  s         r   $publish_topology_description_changedz4_EventListeners.publish_topology_description_changedR  sS     00DoWbc33 	$J$..u5	$  $!#$   2AAc                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)z:Publish a :class:`PoolCreatedEvent` to all pool listeners.N)r   r  r(   r  r   )r   r   r   r   r  s        r   publish_pool_createdz$_EventListeners.publish_pool_createdd  sM     '2// 	$J$''.	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)z:Publish a :class:`PoolClearedEvent` to all pool listeners.N)r   r  r+   r  r   )r   r   r   r   r  s        r   publish_pool_clearedz$_EventListeners.publish_pool_clearedm  sM     *5// 	$J$''.	$  $!#$r  c                     t        |      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)z9Publish a :class:`PoolClosedEvent` to all pool listeners.N)r   r  r-   r  r   r   r   r   r  s       r   publish_pool_closedz#_EventListeners.publish_pool_closedv  sK    (// 	$J$&&u-	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zWPublish a :class:`ConnectionCreatedEvent` to all connection
        listeners.
        N)r  r  r/   r  r   r   r   r   r   r  s        r   publish_connection_createdz*_EventListeners.publish_connection_created  sO     'w>// 	$J$--e4	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zDPublish a :class:`ConnectionReadyEvent` to all connection listeners.N)r  r  r1   r  r   r  s        r   publish_connection_readyz(_EventListeners.publish_connection_ready  sM    $Wm<// 	$J$++E2	$  $!#$r  c                     t        |||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zVPublish a :class:`ConnectionClosedEvent` to all connection
        listeners.
        N)r  r  r4   r  r   )r   r   r   r  r   r  s         r   publish_connection_closedz)_EventListeners.publish_connection_closed  sQ     &g}fE// 	$J$,,U3	$  $!#$r  c                     t        |      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)z_Publish a :class:`ConnectionCheckOutStartedEvent` to all connection
        listeners.
        N)r  r  r6   r  r   r  s       r   $publish_connection_check_out_startedz4_EventListeners.publish_connection_check_out_started  sM     /w7// 	$J$77>	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)z^Publish a :class:`ConnectionCheckOutFailedEvent` to all connection
        listeners.
        N)r!  r  r6   r  r   )r   r   r  r   r  s        r   #publish_connection_check_out_failedz3_EventListeners.publish_connection_check_out_failed  sO     .gv>// 	$J$77>	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zZPublish a :class:`ConnectionCheckedOutEvent` to all connection
        listeners.
        N)r)  r  r:   r  r   r  s        r   publish_connection_checked_outz._EventListeners.publish_connection_checked_out  sO     *'=A// 	$J$11%8	$  $!#$r  c                     t        ||      }| j                  D ]  }	 |j                  |        y# t        $ r t	                Y -w xY w)zYPublish a :class:`ConnectionCheckedInEvent` to all connection
        listeners.
        N)r+  r  r<   r  r   r  s        r   publish_connection_checked_inz-_EventListeners.publish_connection_checked_in  sO     )-@// 	$J$007	$  $!#$r  )NN)NNF)"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  r  r   r   r   r  r  *  s    >2 + + ) ) 3 3 + + ' '
 Y]$B %$\  $D$$$$$$$$*$$$$$$$	$$	$	$	$	$	$r   r  N)7r   collectionsr   bson.py3compatr   pymongo.hello_compatr   pymongo.helpersr   
_Listenersra   objectr   r   r&   r>   rC   rM   rU   r_   rc   setr   rt   rv   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r!  r)  r+  r-  r<  rQ  rT  rV  r]  re  rg  ri  rp  rr  r  r  r   r   r   <module>r     sO  fP #  , -	
 BB+
7V 7"n "@t"^ t"n"n "D"~ "B"^ "B+
3< 
 "&F &R2
- 2
j6
M 6
r6
 6
rD D&Vz V2Yz Y>
j 
FV F*V &^v ^2- "+ !
, !
HDV D4"WF "WJ 0 / 
6 
6
L 
D  TF T"
m 
D- - IF I$"7 .
$9 .
b*
!6 *
Z^$f ^$r   