o
    C©ÌhÌû  ã                   @  sZ  d Z ddlmZ ddlZddlmZmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZmZ erTd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„ dƒ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$dudd „Z%dvd%d&„Z&dwd)d*„Z'dxd/d0„Z(G d1d2„ d2ƒZ)G d3d4„ d4e)ƒZ*G d5d6„ d6e)ƒZ+G d7d8„ d8e)ƒZ,G d9d:„ d:ƒZ-G d;d<„ d<e-ƒZ.G d=d>„ d>e-ƒZ/G d?d@„ d@e-ƒZ0G dAdB„ dBe-ƒZ1G dCdD„ dDƒZ2G dEdF„ dFƒZ3G dGdH„ dHƒZ4G dIdJ„ dJe4ƒZ5G dKdL„ dLe5ƒZ6G dMdN„ dNe5ƒZ7G dOdP„ dPe6ƒZ8G dQdR„ dRe5ƒZ9G dSdT„ dTe4ƒZ:G dUdV„ dVe6ƒZ;G dWdX„ dXe6ƒZ<G dYdZ„ dZe5ƒZ=G d[d\„ d\ƒZ>G d]d^„ d^e>ƒZ?G d_d`„ d`e>ƒZ@G dadb„ dbe>ƒZAG dcdd„ ddƒZBG dedf„ dfeBƒZCG dgdh„ dheBƒZDG didj„ djeBƒZEG dkdl„ dlƒZFG dmdn„ dneFƒZGG dodp„ dpeFƒZHG dqdr„ dreFƒZIG dsdt„ dtƒZJdS )ya  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.

.. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs.


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_ready(self, event):
            logging.info("[pool {0.address}] pool is ready".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}][connection #{0.connection_id}] "
                         "connection created".format(event))

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

        def connection_closed(self, event):
            logging.info("[pool {0.address}][connection #{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}][connection #{0.connection_id}] "
                         "connection checked out of pool".format(event))

        def connection_checked_in(self, event):
            logging.info("[pool {0.address}][connection #{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.
é    )ÚannotationsN)ÚabcÚ
namedtuple)ÚTYPE_CHECKINGÚAnyÚMappingÚOptionalÚSequence)ÚObjectId)ÚHelloÚHelloCompat)Ú_SENSITIVE_COMMANDSÚ_handle_exception)Ú_AddressÚ_DocumentOut)Ú	timedelta)ÚServerDescription)ÚTopologyDescriptionÚ
_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   úa/var/www/html/Moveonwheels/move_on_wheels/venv/lib/python3.10/site-packages/pymongo/monitoring.pyr   Ý   s    r   c                   @  ó.   e Zd ZdZddd„Zdd	d
„Zddd„ZdS )ÚCommandListenerzŠAbstract base class for command listeners.

    Handles `CommandStartedEvent`, `CommandSucceededEvent`,
    and `CommandFailedEvent`.
    ÚeventÚCommandStartedEventÚreturnÚNonec                 C  ó   t ‚)zAbstract method to handle a `CommandStartedEvent`.

        :param event: An instance of :class:`CommandStartedEvent`.
        ©ÚNotImplementedError©Úselfr#   r   r   r    Ústartedè   ó   zCommandListener.startedÚCommandSucceededEventc                 C  r'   )zƒAbstract method to handle a `CommandSucceededEvent`.

        :param event: An instance of :class:`CommandSucceededEvent`.
        r(   r*   r   r   r    Ú	succeededï   r-   zCommandListener.succeededÚCommandFailedEventc                 C  r'   )z}Abstract method to handle a `CommandFailedEvent`.

        :param event: An instance of :class:`CommandFailedEvent`.
        r(   r*   r   r   r    Úfailedö   r-   zCommandListener.failedN)r#   r$   r%   r&   )r#   r.   r%   r&   )r#   r0   r%   r&   ©r   r   r   r   r,   r/   r1   r   r   r   r    r"   á   s
    

r"   c                   @  s~   e Zd ZdZd'dd„Zd(d	d
„Zd)dd„Zd*dd„Zd+dd„Zd,dd„Z	d-dd„Z
d.dd„Zd/dd„Zd0d!d"„Zd1d$d%„Zd&S )2Ú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
    r#   ÚPoolCreatedEventr%   r&   c                 C  r'   )z´Abstract method to handle a :class:`PoolCreatedEvent`.

        Emitted when a connection Pool is created.

        :param event: An instance of :class:`PoolCreatedEvent`.
        r(   r*   r   r   r    Úpool_created  ó   z#ConnectionPoolListener.pool_createdÚPoolReadyEventc                 C  r'   )zÔAbstract method to handle a :class:`PoolReadyEvent`.

        Emitted when a connection Pool is marked ready.

        :param event: An instance of :class:`PoolReadyEvent`.

        .. versionadded:: 4.0
        r(   r*   r   r   r    Ú
pool_ready  s   	z!ConnectionPoolListener.pool_readyÚPoolClearedEventc                 C  r'   )z­Abstract method to handle a `PoolClearedEvent`.

        Emitted when a connection Pool is cleared.

        :param event: An instance of :class:`PoolClearedEvent`.
        r(   r*   r   r   r    Úpool_cleared"  r6   z#ConnectionPoolListener.pool_clearedÚPoolClosedEventc                 C  r'   )zªAbstract method to handle a `PoolClosedEvent`.

        Emitted when a connection Pool is closed.

        :param event: An instance of :class:`PoolClosedEvent`.
        r(   r*   r   r   r    Úpool_closed+  r6   z"ConnectionPoolListener.pool_closedÚConnectionCreatedEventc                 C  r'   )zÑAbstract method to handle a :class:`ConnectionCreatedEvent`.

        Emitted when a connection Pool creates a Connection object.

        :param event: An instance of :class:`ConnectionCreatedEvent`.
        r(   r*   r   r   r    Úconnection_created4  r6   z)ConnectionPoolListener.connection_createdÚConnectionReadyEventc                 C  r'   )zäAbstract method to handle a :class:`ConnectionReadyEvent`.

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

        :param event: An instance of :class:`ConnectionReadyEvent`.
        r(   r*   r   r   r    Úconnection_ready=  ó   z'ConnectionPoolListener.connection_readyÚConnectionClosedEventc                 C  r'   )zÇAbstract method to handle a :class:`ConnectionClosedEvent`.

        Emitted when a connection Pool closes a connection.

        :param event: An instance of :class:`ConnectionClosedEvent`.
        r(   r*   r   r   r    Úconnection_closedG  r6   z(ConnectionPoolListener.connection_closedÚConnectionCheckOutStartedEventc                 C  r'   )zêAbstract method to handle a :class:`ConnectionCheckOutStartedEvent`.

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

        :param event: An instance of :class:`ConnectionCheckOutStartedEvent`.
        r(   r*   r   r   r    Úconnection_check_out_startedP  r6   z3ConnectionPoolListener.connection_check_out_startedÚConnectionCheckOutFailedEventc                 C  r'   )zæAbstract method to handle a :class:`ConnectionCheckOutFailedEvent`.

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

        :param event: An instance of :class:`ConnectionCheckOutFailedEvent`.
        r(   r*   r   r   r    Úconnection_check_out_failedY  r6   z2ConnectionPoolListener.connection_check_out_failedÚConnectionCheckedOutEventc                 C  r'   )zÙAbstract method to handle a :class:`ConnectionCheckedOutEvent`.

        Emitted when the driver successfully checks out a connection.

        :param event: An instance of :class:`ConnectionCheckedOutEvent`.
        r(   r*   r   r   r    Úconnection_checked_outb  r6   z-ConnectionPoolListener.connection_checked_outÚConnectionCheckedInEventc                 C  r'   )zíAbstract method to handle a :class:`ConnectionCheckedInEvent`.

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

        :param event: An instance of :class:`ConnectionCheckedInEvent`.
        r(   r*   r   r   r    Úconnection_checked_ink  rA   z,ConnectionPoolListener.connection_checked_inN)r#   r4   r%   r&   )r#   r7   r%   r&   )r#   r9   r%   r&   )r#   r;   r%   r&   )r#   r=   r%   r&   )r#   r?   r%   r&   )r#   rB   r%   r&   )r#   rD   r%   r&   )r#   rF   r%   r&   )r#   rH   r%   r&   )r#   rJ   r%   r&   )r   r   r   r   r5   r8   r:   r<   r>   r@   rC   rE   rG   rI   rK   r   r   r   r    r3   þ   s    

	

	
	
	


	
	
		r3   c                   @  r!   )ÚServerHeartbeatListenerzÆAbstract base class for server heartbeat listeners.

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

    .. versionadded:: 3.3
    r#   ÚServerHeartbeatStartedEventr%   r&   c                 C  r'   )z�Abstract method to handle a `ServerHeartbeatStartedEvent`.

        :param event: An instance of :class:`ServerHeartbeatStartedEvent`.
        r(   r*   r   r   r    r,     r-   zServerHeartbeatListener.startedÚServerHeartbeatSucceededEventc                 C  r'   )z“Abstract method to handle a `ServerHeartbeatSucceededEvent`.

        :param event: An instance of :class:`ServerHeartbeatSucceededEvent`.
        r(   r*   r   r   r    r/   †  r-   z!ServerHeartbeatListener.succeededÚServerHeartbeatFailedEventc                 C  r'   )z�Abstract method to handle a `ServerHeartbeatFailedEvent`.

        :param event: An instance of :class:`ServerHeartbeatFailedEvent`.
        r(   r*   r   r   r    r1   �  r-   zServerHeartbeatListener.failedN)r#   rM   r%   r&   )r#   rN   r%   r&   )r#   rO   r%   r&   r2   r   r   r   r    rL   v  s
    

rL   c                   @  r!   )ÚTopologyListenerz»Abstract base class for topology monitoring listeners.
    Handles `TopologyOpenedEvent`, `TopologyDescriptionChangedEvent`, and
    `TopologyClosedEvent`.

    .. versionadded:: 3.3
    r#   ÚTopologyOpenedEventr%   r&   c                 C  r'   )zAbstract method to handle a `TopologyOpenedEvent`.

        :param event: An instance of :class:`TopologyOpenedEvent`.
        r(   r*   r   r   r    Úopened�  r-   zTopologyListener.openedÚTopologyDescriptionChangedEventc                 C  r'   )z—Abstract method to handle a `TopologyDescriptionChangedEvent`.

        :param event: An instance of :class:`TopologyDescriptionChangedEvent`.
        r(   r*   r   r   r    Údescription_changed¤  r-   z$TopologyListener.description_changedÚTopologyClosedEventc                 C  r'   )zAbstract method to handle a `TopologyClosedEvent`.

        :param event: An instance of :class:`TopologyClosedEvent`.
        r(   r*   r   r   r    Úclosed«  r-   zTopologyListener.closedN)r#   rQ   r%   r&   )r#   rS   r%   r&   )r#   rU   r%   r&   ©r   r   r   r   rR   rT   rV   r   r   r   r    rP   •  ó
    

rP   c                   @  r!   )ÚServerListenerz©Abstract base class for server listeners.
    Handles `ServerOpeningEvent`, `ServerDescriptionChangedEvent`, and
    `ServerClosedEvent`.

    .. versionadded:: 3.3
    r#   ÚServerOpeningEventr%   r&   c                 C  r'   )z}Abstract method to handle a `ServerOpeningEvent`.

        :param event: An instance of :class:`ServerOpeningEvent`.
        r(   r*   r   r   r    rR   »  r-   zServerListener.openedÚServerDescriptionChangedEventc                 C  r'   )z“Abstract method to handle a `ServerDescriptionChangedEvent`.

        :param event: An instance of :class:`ServerDescriptionChangedEvent`.
        r(   r*   r   r   r    rT   Â  r-   z"ServerListener.description_changedÚServerClosedEventc                 C  r'   )z{Abstract method to handle a `ServerClosedEvent`.

        :param event: An instance of :class:`ServerClosedEvent`.
        r(   r*   r   r   r    rV   É  r-   zServerListener.closedN)r#   rZ   r%   r&   )r#   r[   r%   r&   )r#   r\   r%   r&   rW   r   r   r   r    rY   ³  rX   rY   Údurr   r%   Úintc                 C  s   t |  ¡ d ƒS )z'Convert duration 'dur' to microseconds.g    €„.A)r^   Útotal_seconds)r]   r   r   r    Ú
_to_microsÑ  s   r`   ÚoptionÚstrÚ	listenersúSequence[_EventListeners]c                 C  sR   t |tjƒst| › dt|ƒ› �ƒ‚|D ]}t |tƒs&td| › dt|ƒ› �ƒ‚q|S )zValidate event listenersz must be a list or tuple, not úListeners for ú| must be either a CommandListener, ServerHeartbeatListener, ServerListener, TopologyListener, or ConnectionPoolListener,not )Ú
isinstancer   r	   Ú	TypeErrorÚtyper   )ra   rc   Úlistenerr   r   r    Ú_validate_event_listenersÖ  s   
üÿÿrk   rj   r&   c                 C  s˜   t | tƒstd| › dt| ƒ› �ƒ‚t | tƒrtj | ¡ t | tƒr'tj	 | ¡ t | t
ƒr2tj | ¡ t | tƒr=tj | ¡ t | tƒrJtj | ¡ dS dS )zðRegister a global event listener.

    :param listener: A subclasses of :class:`CommandListener`,
        :class:`ServerHeartbeatListener`, :class:`ServerListener`,
        :class:`TopologyListener`, or :class:`ConnectionPoolListener`.
    re   rf   N)rg   r   rh   ri   r"   Ú
_LISTENERSr   ÚappendrL   r   rY   r   rP   r   r3   r   )rj   r   r   r    Úregisterè  s"   
üÿ




ÿrn   Úcommand_nameÚdocúMapping[str, Any]Úboolc                 C  s"   |   ¡ dtjfv rd|v rdS dS )NÚhelloÚspeculativeAuthenticateTF)Úlowerr   Ú
LEGACY_CMD)ro   rp   r   r   r    Ú_is_speculative_authenticate  s   rw   c                   @  sˆ   e Zd ZdZdZ			d#d$dd„Zed%dd„ƒZed&dd„ƒZed'dd„ƒZ	ed(dd„ƒZ
ed)dd„ƒZed%dd „ƒZed)d!d"„ƒZdS )*Ú_CommandEventzBase class for command events.)Ú
__cmd_nameÚ	__rqst_idÚ	__conn_idÚ__op_idÚ__service_idÚ__dbÚ__server_conn_idNÚ ro   rb   Ú
request_idr^   Úconnection_idr   Úoperation_idúOptional[int]Ú
service_idúOptional[ObjectId]Údatabase_nameÚserver_connection_idr%   r&   c                 C  s.   || _ || _|| _|| _|| _|| _|| _d S ©N)Ú_CommandEvent__cmd_nameÚ_CommandEvent__rqst_idÚ_CommandEvent__conn_idÚ_CommandEvent__op_idÚ_CommandEvent__service_idÚ_CommandEvent__dbÚ_CommandEvent__server_conn_id)r+   ro   r�   r‚   rƒ   r…   r‡   rˆ   r   r   r    Ú__init__  s   

z_CommandEvent.__init__c                 C  ó   | j S )zThe command name.)rŠ   ©r+   r   r   r    ro   -  ó   z_CommandEvent.command_namec                 C  r’   )z"The request id for this operation.)r‹   r“   r   r   r    r�   2  r”   z_CommandEvent.request_idc                 C  r’   )z@The address (host, port) of the server this command was sent to.)rŒ   r“   r   r   r    r‚   7  r”   z_CommandEvent.connection_idc                 C  r’   )z^The service_id this command was sent to, or ``None``.

        .. versionadded:: 3.12
        )rŽ   r“   r   r   r    r…   <  ó   z_CommandEvent.service_idc                 C  r’   )z(An id for this series of events or None.)r�   r“   r   r   r    rƒ   D  r”   z_CommandEvent.operation_idc                 C  r’   )z^The database_name this command was sent to, or ``""``.

        .. versionadded:: 4.6
        )r�   r“   r   r   r    r‡   I  r•   z_CommandEvent.database_namec                 C  r’   )zThe server-side connection id for the connection this command was sent on, or ``None``.

        .. versionadded:: 4.7
        )r�   r“   r   r   r    rˆ   Q  r•   z"_CommandEvent.server_connection_id©Nr€   N)ro   rb   r�   r^   r‚   r   rƒ   r„   r…   r†   r‡   rb   rˆ   r„   r%   r&   ©r%   rb   ©r%   r^   ©r%   r   ©r%   r†   )r%   r„   )r   r   r   r   Ú	__slots__r‘   Úpropertyro   r�   r‚   r…   rƒ   r‡   rˆ   r   r   r   r    rx     s*    ørx   c                      sV   e Zd ZdZdZ		dd‡ fdd„Zeddd„ƒZed‡ fdd„ƒZddd„Z	‡  Z
S )r$   aá  Event published when a command starts.

    :param command: The command document.
    :param database_name: The name of the database this command was run against.
    :param request_id: The request id for this operation.
    :param connection_id: The address (host, port) of the server this command
        was sent to.
    :param operation_id: An optional identifier for a series of related events.
    :param service_id: The service_id this command was sent to, or ``None``.
    )Ú__cmdNÚcommandr   r‡   rb   r�   r^   r‚   r   rƒ   r„   r…   r†   rˆ   r%   r&   c           
   	     sf   |s	t |›d�ƒ‚tt|ƒƒ}tƒ j|||||||d� | ¡ }	|	tv s)t|	|ƒr.i | _d S || _d S )Nz is not a valid command©r…   r‡   rˆ   )	Ú
ValueErrorÚnextÚiterÚsuperr‘   ru   r   rw   Ú_CommandStartedEvent__cmd)
r+   rž   r‡   r�   r‚   rƒ   r…   rˆ   ro   Úcmd_name©Ú	__class__r   r    r‘   h  s    
ù	

zCommandStartedEvent.__init__c                 C  r’   )zThe command document.)r¤   r“   r   r   r    rž   …  r”   zCommandStartedEvent.commandc                   ó   t ƒ jS )z6The name of the database this command was run against.)r£   r‡   r“   r¦   r   r    r‡   Š  s   z!CommandStartedEvent.database_namec              	   C  s&   d  | jj| j| j| j| j| j| j¡S )Nz[<{} {} db: {!r}, command: {!r}, operation_id: {}, service_id: {}, server_connection_id: {}>)	Úformatr§   r   r‚   r‡   ro   rƒ   r…   rˆ   r“   r   r   r    Ú__repr__�  s   ùþzCommandStartedEvent.__repr__©NN)rž   r   r‡   rb   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ª   Ú__classcell__r   r   r¦   r    r$   Z  s    	ør$   c                      óT   e Zd ZdZdZ			dd ‡ fdd„Zed!dd„ƒZed"dd„ƒZd#dd„Z	‡  Z
S )$r.   aO  Event published when a command succeeds.

    :param duration: The command duration as a datetime.timedelta.
    :param reply: The server reply document.
    :param command_name: The command name.
    :param request_id: The request id for this operation.
    :param connection_id: The address (host, port) of the server this command
        was sent to.
    :param operation_id: An optional identifier for a series of related events.
    :param service_id: The service_id this command was sent to, or ``None``.
    :param database_name: The database this command was sent to, or ``""``.
    )Ú__duration_microsÚ__replyNr€   Údurationúdatetime.timedeltaÚreplyr   ro   rb   r�   r^   r‚   r   rƒ   r„   r…   r†   r‡   rˆ   r%   r&   c
              	     sR   t ƒ j|||||||	d� t|ƒ| _| ¡ }
|
tv st|
|ƒr$i | _d S || _d S ©NrŸ   )r£   r‘   r`   Ú'_CommandSucceededEvent__duration_microsru   r   rw   Ú_CommandSucceededEvent__reply)r+   r±   r³   ro   r�   r‚   rƒ   r…   r‡   rˆ   r¥   r¦   r   r    r‘   ­  s   ù
	

zCommandSucceededEvent.__init__c                 C  r’   ©z/The duration of this operation in microseconds.)rµ   r“   r   r   r    Úduration_microsÉ  r”   z%CommandSucceededEvent.duration_microsc                 C  r’   ©z/The server failure document for this operation.)r¶   r“   r   r   r    r³   Î  r”   zCommandSucceededEvent.replyc              
   C  s*   d  | jj| j| j| j| j| j| j| j	¡S )Nzp<{} {} db: {!r}, command: {!r}, operation_id: {}, duration_micros: {}, service_id: {}, server_connection_id: {}>)
r©   r§   r   r‚   r‡   ro   rƒ   r¸   r…   rˆ   r“   r   r   r    rª   Ó  s   øþzCommandSucceededEvent.__repr__r–   )r±   r²   r³   r   ro   rb   r�   r^   r‚   r   rƒ   r„   r…   r†   r‡   rb   rˆ   r„   r%   r&   r˜   r¬   r—   )r   r   r   r   r›   r‘   rœ   r¸   r³   rª   r­   r   r   r¦   r    r.   �  s    
ör.   c                      r®   )$r0   aN  Event published when a command fails.

    :param duration: The command duration as a datetime.timedelta.
    :param failure: The server reply document.
    :param command_name: The command name.
    :param request_id: The request id for this operation.
    :param connection_id: The address (host, port) of the server this command
        was sent to.
    :param operation_id: An optional identifier for a series of related events.
    :param service_id: The service_id this command was sent to, or ``None``.
    :param database_name: The database this command was sent to, or ``""``.
    )r¯   Ú	__failureNr€   r±   r²   Úfailurer   ro   rb   r�   r^   r‚   r   rƒ   r„   r…   r†   r‡   rˆ   r%   r&   c
           
   	     s.   t ƒ j|||||||	d� t|ƒ| _|| _d S r´   )r£   r‘   r`   Ú$_CommandFailedEvent__duration_microsÚ_CommandFailedEvent__failure)
r+   r±   r»   ro   r�   r‚   rƒ   r…   r‡   rˆ   r¦   r   r    r‘   ò  s   ù
	
zCommandFailedEvent.__init__c                 C  r’   r·   )r¼   r“   r   r   r    r¸   
  r”   z"CommandFailedEvent.duration_microsc                 C  r’   r¹   )r½   r“   r   r   r    r»     r”   zCommandFailedEvent.failurec                 C  s.   d  | jj| j| j| j| j| j| j| j	| j
¡	S )Nz<{} {} db: {!r}, command: {!r}, operation_id: {}, duration_micros: {}, failure: {!r}, service_id: {}, server_connection_id: {}>)r©   r§   r   r‚   r‡   ro   rƒ   r¸   r»   r…   rˆ   r“   r   r   r    rª     s   ÷ýzCommandFailedEvent.__repr__r–   )r±   r²   r»   r   ro   rb   r�   r^   r‚   r   rƒ   r„   r…   r†   r‡   rb   rˆ   r„   r%   r&   r˜   r¬   r—   )r   r   r   r   r›   r‘   rœ   r¸   r»   rª   r­   r   r   r¦   r    r0   â  s    
ör0   c                   @  ó6   e Zd ZdZdZddd„Zedd	d
„ƒZddd„ZdS )Ú
_PoolEventzBase class for pool events.©Ú	__addressÚaddressr   r%   r&   c                 C  ó
   || _ d S r‰   ©Ú_PoolEvent__address©r+   rÂ   r   r   r    r‘   *  ó   
z_PoolEvent.__init__c                 C  r’   )zbThe address (host, port) pair of the server the pool is attempting
        to connect to.
        rÄ   r“   r   r   r    rÂ   -  ó   z_PoolEvent.addressrb   c                 C  ó   | j j› d| j›d�S ©Nú(ú))r§   r   rÅ   r“   r   r   r    rª   4  ó   z_PoolEvent.__repr__N©rÂ   r   r%   r&   r™   r—   ©	r   r   r   r   r›   r‘   rœ   rÂ   rª   r   r   r   r    r¿   %  ó    
r¿   c                      ó>   e Zd ZdZdZd‡ fd	d
„Zeddd„ƒZddd„Z‡  Z	S )r4   z»Published when a Connection Pool is created.

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

    .. versionadded:: 3.9
    )Ú	__optionsrÂ   r   Úoptionsúdict[str, Any]r%   r&   c                   ó   t ƒ  |¡ || _d S r‰   )r£   r‘   Ú_PoolCreatedEvent__options)r+   rÂ   rÓ   r¦   r   r    r‘   C  ó   
zPoolCreatedEvent.__init__c                 C  r’   )zCAny non-default pool options that were set on this Connection Pool.)rÖ   r“   r   r   r    rÓ   G  r”   zPoolCreatedEvent.optionsrb   c                 C  ó   | j j› d| j›d| j›d�S ©NrË   z, rÌ   )r§   r   rÂ   rÖ   r“   r   r   r    rª   L  ó   zPoolCreatedEvent.__repr__©rÂ   r   rÓ   rÔ   r%   r&   )r%   rÔ   r—   )
r   r   r   r   r›   r‘   rœ   rÓ   rª   r­   r   r   r¦   r    r4   8  s    r4   c                   @  ó   e Zd ZdZdZdS )r7   zÀPublished when a Connection Pool is marked ready.

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

    .. versionadded:: 4.0
    r   N©r   r   r   r   r›   r   r   r   r    r7   P  ó    r7   c                      sR   e Zd ZdZdZ		dd‡ fdd„Zeddd„ƒZeddd„ƒZddd„Z	‡  Z
S )r9   aw  Published when a Connection Pool is cleared.

    :param address: The address (host, port) pair of the server this Pool is
       attempting to connect to.
    :param service_id: The service_id this command was sent to, or ``None``.
    :param interrupt_connections: True if all active connections were interrupted by the Pool during clearing.

    .. versionadded:: 3.9
    )r}   Ú__interrupt_connectionsNFrÂ   r   r…   r†   Úinterrupt_connectionsrr   r%   r&   c                   s   t ƒ  |¡ || _|| _d S r‰   )r£   r‘   Ú_PoolClearedEvent__service_idÚ(_PoolClearedEvent__interrupt_connections)r+   rÂ   r…   rà   r¦   r   r    r‘   i  ó   
zPoolClearedEvent.__init__c                 C  r’   )z¥Connections with this service_id are cleared.

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

        .. versionadded:: 3.12
        )rá   r“   r   r   r    r…   s  s   zPoolClearedEvent.service_idc                 C  r’   )zdIf True, active connections are interrupted during clearing.

        .. versionadded:: 4.7
        )râ   r“   r   r   r    rà   }  r•   z&PoolClearedEvent.interrupt_connectionsrb   c                 C  ó&   | j j› d| j›d| j›d| j›d�S rÙ   )r§   r   rÂ   rá   râ   r“   r   r   r    rª   …  ó   &zPoolClearedEvent.__repr__)NF©rÂ   r   r…   r†   rà   rr   r%   r&   rš   ©r%   rr   r—   )r   r   r   r   r›   r‘   rœ   r…   rà   rª   r­   r   r   r¦   r    r9   \  s    
ü
	r9   c                   @  rÜ   )r;   zºPublished when a Connection Pool is closed.

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

    .. versionadded:: 3.9
    r   NrÝ   r   r   r   r    r;   ‰  rÞ   r;   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
    ÚstaleÚidleÚerrorÚ
poolClosedN)r   r   r   r   ÚSTALEÚIDLEÚERRORÚPOOL_CLOSEDr   r   r   r    rè   •  s    rè   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
    Útimeoutrì   ÚconnectionErrorN)r   r   r   r   ÚTIMEOUTrð   Ú
CONN_ERRORr   r   r   r    rñ   ª  s    rñ   c                   @  r¾   )Ú_ConnectionEventz)Private base class for connection events.rÀ   rÂ   r   r%   r&   c                 C  rÃ   r‰   ©Ú_ConnectionEvent__addressrÆ   r   r   r    r‘   Â  rÇ   z_ConnectionEvent.__init__c                 C  r’   )ziThe address (host, port) pair of the server this connection is
        attempting to connect to.
        r÷   r“   r   r   r    rÂ   Å  rÈ   z_ConnectionEvent.addressrb   c                 C  rÉ   rÊ   )r§   r   rø   r“   r   r   r    rª   Ì  rÍ   z_ConnectionEvent.__repr__NrÎ   r™   r—   rÏ   r   r   r   r    rö   ½  rÐ   rö   c                      rÑ   )Ú_ConnectionIdEventz4Private base class for connection events with an id.)Ú__connection_idrÂ   r   r‚   r^   r%   r&   c                   rÕ   r‰   )r£   r‘   Ú!_ConnectionIdEvent__connection_id)r+   rÂ   r‚   r¦   r   r    r‘   Õ  r×   z_ConnectionIdEvent.__init__c                 C  r’   )zThe ID of the connection.)rû   r“   r   r   r    r‚   Ù  r”   z _ConnectionIdEvent.connection_idrb   c                 C  rØ   rÙ   )r§   r   rÂ   rû   r“   r   r   r    rª   Þ  rÚ   z_ConnectionIdEvent.__repr__©rÂ   r   r‚   r^   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Zd‡ fdd„Zeddd„ƒZddd„Z‡  Z	S )Ú_ConnectionDurationEventz9Private base class for connection events with a duration.)Ú
__durationrÂ   r   r‚   r^   r±   úOptional[float]r%   r&   c                   ó   t ƒ  ||¡ || _d S r‰   )r£   r‘   Ú"_ConnectionDurationEvent__duration)r+   rÂ   r‚   r±   r¦   r   r    r‘   ç  ó   
z!_ConnectionDurationEvent.__init__c                 C  r’   )zMThe duration of the connection event.

        .. versionadded:: 4.7
        )r  r“   r   r   r    r±   ë  r•   z!_ConnectionDurationEvent.durationrb   c                 C  rä   rÙ   )r§   r   rÂ   r‚   r  r“   r   r   r    rª   ó  rå   z!_ConnectionDurationEvent.__repr__)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    rý   c                   @  rÜ   )r=   a…  Published when a Connection Pool creates a Connection object.

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

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

    .. versionadded:: 3.9
    r   NrÝ   r   r   r   r    r=   ÷  s    r=   c                   @  rÜ   )r?   a&  Published when a Connection has finished its setup, and is ready to use.

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

    .. versionadded:: 3.9
    r   NrÝ   r   r   r   r    r?     ó    	r?   c                      s>   e Zd ZdZdZd‡ fd	d
„Zeddd„ƒZddd„Z‡  Z	S )rB   aK  Published when a Connection is closed.

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

    .. versionadded:: 3.9
    ©Ú__reasonrÂ   r   r‚   r^   Úreasonrb   c                   r   r‰   )r£   r‘   Ú_ConnectionClosedEvent__reason)r+   rÂ   r‚   r  r¦   r   r    r‘   !  r  zConnectionClosedEvent.__init__r%   c                 C  r’   )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  %  ó   zConnectionClosedEvent.reasonc                 C  ó   d  | jj| j| j| j¡S )Nz{}({!r}, {!r}, {!r}))r©   r§   r   rÂ   r‚   r  r“   r   r   r    rª   .  ó   üzConnectionClosedEvent.__repr__)rÂ   r   r‚   r^   r  rb   r—   ©
r   r   r   r   r›   r‘   rœ   r  rª   r­   r   r   r¦   r    rB     s    
rB   c                   @  rÜ   )rD   zÛPublished when the driver starts attempting to check out a connection.

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

    .. versionadded:: 3.9
    r   NrÝ   r   r   r   r    rD   7  rÞ   rD   c                      s>   e Zd ZdZdZd‡ fdd„Zeddd„ƒZddd„Z‡  Z	S )rF   a!  Published when the driver's attempt to check out a connection fails.

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

    .. versionadded:: 3.9
    r  rÂ   r   r  rb   r±   rÿ   r%   r&   c                   s   t ƒ j|d|d� || _d S )Nr   )rÂ   r‚   r±   )r£   r‘   Ú&_ConnectionCheckOutFailedEvent__reason)r+   rÂ   r  r±   r¦   r   r    r‘   O  s   
z&ConnectionCheckOutFailedEvent.__init__c                 C  r’   )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  S  r  z$ConnectionCheckOutFailedEvent.reasonc                 C  rä   rÙ   )r§   r   rÂ   r  r±   r“   r   r   r    rª   \  rå   z&ConnectionCheckOutFailedEvent.__repr__)rÂ   r   r  rb   r±   rÿ   r%   r&   r—   r  r   r   r¦   r    rF   C  s    	rF   c                   @  rÜ   )rH   a  Published when the driver successfully checks out a connection.

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

    .. versionadded:: 3.9
    r   NrÝ   r   r   r   r    rH   `  r  rH   c                   @  rÜ   )rJ   a  Published when the driver checks in a Connection into the Pool.

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

    .. versionadded:: 3.9
    r   NrÝ   r   r   r   r    rJ   m  r  rJ   c                   @  sD   e Zd ZdZdZdd	d
„Zeddd„ƒZeddd„ƒZddd„Z	dS )Ú_ServerEventzBase class for server events.)Ú__server_addressÚ__topology_idÚserver_addressr   Útopology_idr
   r%   r&   c                 C  ó   || _ || _d S r‰   )Ú_ServerEvent__server_addressÚ_ServerEvent__topology_id)r+   r  r  r   r   r    r‘     ó   
z_ServerEvent.__init__c                 C  r’   )z+The address (host, port) pair of the server)r  r“   r   r   r    r  ƒ  r”   z_ServerEvent.server_addressc                 C  r’   ©z>A unique identifier for the topology this server is a part of.)r  r“   r   r   r    r  ˆ  r”   z_ServerEvent.topology_idrb   c                 C  ó    d| j j› d| j› d| j› d�S )Nú<ú ú topology_id: ú>)r§   r   r  r  r“   r   r   r    rª   �  ó    z_ServerEvent.__repr__N©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  z  s    
r  c                      óL   e Zd ZdZdZd‡ fd
d„Zeddd„ƒZeddd„ƒZddd„Z	‡  Z
S )r[   zJPublished when server description changes.

    .. versionadded:: 3.3
    ©Ú__previous_descriptionÚ__new_descriptionÚprevious_descriptionr   Únew_descriptionÚargsr   r%   r&   c                   ó   t ƒ j|Ž  || _|| _d S r‰   )r£   r‘   Ú4_ServerDescriptionChangedEvent__previous_descriptionÚ/_ServerDescriptionChangedEvent__new_description©r+   r#  r$  r%  r¦   r   r    r‘   ™  rã   z&ServerDescriptionChangedEvent.__init__c                 C  r’   )zUThe previous
        :class:`~pymongo.server_description.ServerDescription`.
        )r'  r“   r   r   r    r#  £  rÈ   z2ServerDescriptionChangedEvent.previous_descriptionc                 C  r’   )zPThe new
        :class:`~pymongo.server_description.ServerDescription`.
        )r(  r“   r   r   r    r$  ª  rÈ   z-ServerDescriptionChangedEvent.new_descriptionrb   c                 C  r	  )Nz <{} {} changed from: {}, to: {}>)r©   r§   r   r  r#  r$  r“   r   r   r    rª   ±  r
  z&ServerDescriptionChangedEvent.__repr__)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[   c                   @  rÜ   )rZ   zEPublished when server is initialized.

    .. versionadded:: 3.3
    r   NrÝ   r   r   r   r    rZ   º  ó    rZ   c                   @  rÜ   )r\   z@Published when server is closed.

    .. versionadded:: 3.3
    r   NrÝ   r   r   r   r    r\   Ã  r,  r\   c                   @  r¾   )ÚTopologyEventz+Base class for topology description events.)r  r  r
   r%   r&   c                 C  rÃ   r‰   ©Ú_TopologyEvent__topology_id)r+   r  r   r   r    r‘   Ñ  rÇ   zTopologyEvent.__init__c                 C  r’   r  r.  r“   r   r   r    r  Ô  r”   zTopologyEvent.topology_idrb   c                 C  s   d| j j› d| j› d�S )Nr  r  r  )r§   r   r  r“   r   r   r    rª   Ù  s   zTopologyEvent.__repr__N©r  r
   r%   r&   r  r—   )	r   r   r   r   r›   r‘   rœ   r  rª   r   r   r   r    r-  Ì  s    
r-  c                      r  )rS   zPPublished when the topology description changes.

    .. versionadded:: 3.3
    r   r#  r   r$  r%  r   r%   r&   c                   r&  r‰   )r£   r‘   Ú6_TopologyDescriptionChangedEvent__previous_descriptionÚ1_TopologyDescriptionChangedEvent__new_descriptionr)  r¦   r   r    r‘   å  rã   z(TopologyDescriptionChangedEvent.__init__c                 C  r’   )zYThe previous
        :class:`~pymongo.topology_description.TopologyDescription`.
        )r1  r“   r   r   r    r#  ï  rÈ   z4TopologyDescriptionChangedEvent.previous_descriptionc                 C  r’   )zTThe new
        :class:`~pymongo.topology_description.TopologyDescription`.
        )r2  r“   r   r   r    r$  ö  rÈ   z/TopologyDescriptionChangedEvent.new_descriptionrb   c                 C  r	  )Nz-<{} topology_id: {} changed from: {}, to: {}>)r©   r§   r   r  r#  r$  r“   r   r   r    rª   ý  r
  z(TopologyDescriptionChangedEvent.__repr__)r#  r   r$  r   r%  r   r%   r&   )r%   r   r—   r*  r   r   r¦   r    rS   Ý  r+  rS   c                   @  rÜ   )rQ   zKPublished when the topology is initialized.

    .. versionadded:: 3.3
    r   NrÝ   r   r   r   r    rQ     r,  rQ   c                   @  rÜ   )rU   zFPublished when the topology is closed.

    .. versionadded:: 3.3
    r   NrÝ   r   r   r   r    rU     r,  rU   c                   @  sF   e Zd ZdZdZddd
d„Zeddd„ƒZeddd„ƒZddd„Z	dS )Ú_ServerHeartbeatEventz'Base class for server heartbeat events.)rú   Ú	__awaitedFr‚   r   Úawaitedrr   r%   r&   c                 C  r  r‰   )Ú$_ServerHeartbeatEvent__connection_idÚ_ServerHeartbeatEvent__awaited)r+   r‚   r5  r   r   r    r‘     r  z_ServerHeartbeatEvent.__init__c                 C  r’   )zSThe address (host, port) of the server this heartbeat was sent
        to.
        )r6  r“   r   r   r    r‚   !  rÈ   z#_ServerHeartbeatEvent.connection_idc                 C  r’   )zgWhether the heartbeat was issued as an awaitable hello command.

        .. versionadded:: 4.6
        )r7  r“   r   r   r    r5  (  r•   z_ServerHeartbeatEvent.awaitedrb   c                 C  r  )Nr  r  z
 awaited: r  )r§   r   r‚   r5  r“   r   r   r    rª   0  r  z_ServerHeartbeatEvent.__repr__N©F©r‚   r   r5  rr   r%   r&   r™   rç   r—   )
r   r   r   r   r›   r‘   rœ   r‚   r5  rª   r   r   r   r    r3    s    r3  c                   @  rÜ   )rM   zFPublished when a heartbeat is started.

    .. versionadded:: 3.3
    r   NrÝ   r   r   r   r    rM   4  r,  rM   c                      ób   e Zd ZdZdZ	dd‡ fdd„Zeddd„ƒZeddd„ƒZed‡ fdd„ƒZ	ddd„Z
‡  ZS )rN   zIFired when the server heartbeat succeeds.

    .. versionadded:: 3.3
    ©rþ   r°   Fr±   Úfloatr³   úHello[dict[str, Any]]r‚   r   r5  rr   r%   r&   c                   ó   t ƒ  ||¡ || _|| _d S r‰   )r£   r‘   Ú(_ServerHeartbeatSucceededEvent__durationÚ%_ServerHeartbeatSucceededEvent__reply©r+   r±   r³   r‚   r5  r¦   r   r    r‘   E  s   
z&ServerHeartbeatSucceededEvent.__init__c                 C  r’   ©z/The duration of this heartbeat in microseconds.)r?  r“   r   r   r    r±   P  r”   z&ServerHeartbeatSucceededEvent.durationc                 C  r’   )z-An instance of :class:`~pymongo.hello.Hello`.)r@  r“   r   r   r    r³   U  r”   z#ServerHeartbeatSucceededEvent.replyc                   r¨   ©zøWhether 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.

        .. versionadded:: 3.11
        ©r£   r5  r“   r¦   r   r    r5  Z  ó   
z%ServerHeartbeatSucceededEvent.awaitedrb   c                 C  ó   d  | jj| j| j| j| j¡S )Nz,<{} {} duration: {}, awaited: {}, reply: {}>©r©   r§   r   r‚   r±   r5  r³   r“   r   r   r    rª   f  ó   ûz&ServerHeartbeatSucceededEvent.__repr__r8  )
r±   r<  r³   r=  r‚   r   r5  rr   r%   r&   ©r%   r<  )r%   r=  rç   r—   ©r   r   r   r   r›   r‘   rœ   r±   r³   r5  rª   r­   r   r   r¦   r    rN   =  s    ûrN   c                      r:  )rO   zxFired when the server heartbeat fails, either with an "ok: 0"
    or a socket exception.

    .. versionadded:: 3.3
    r;  Fr±   r<  r³   Ú	Exceptionr‚   r   r5  rr   r%   r&   c                   r>  r‰   )r£   r‘   Ú%_ServerHeartbeatFailedEvent__durationÚ"_ServerHeartbeatFailedEvent__replyrA  r¦   r   r    r‘   y  s   
z#ServerHeartbeatFailedEvent.__init__c                 C  r’   rB  )rL  r“   r   r   r    r±   €  r”   z#ServerHeartbeatFailedEvent.durationc                 C  r’   )zA subclass of :exc:`Exception`.)rM  r“   r   r   r    r³   …  r”   z ServerHeartbeatFailedEvent.replyc                   r¨   rC  rD  r“   r¦   r   r    r5  Š  rE  z"ServerHeartbeatFailedEvent.awaitedrb   c                 C  rF  )Nz.<{} {} duration: {}, awaited: {}, reply: {!r}>rG  r“   r   r   r    rª   –  rH  z#ServerHeartbeatFailedEvent.__repr__r8  )
r±   r<  r³   rK  r‚   r   r5  rr   r%   r&   rI  )r%   rK  rç   r—   rJ  r   r   r¦   r    rO   p  s    ÿrO   c                   @  sl  e Zd ZdZdjdd„Zedkdd	„ƒZedkd
d„ƒZedkdd„ƒZedkdd„ƒZ	edkdd„ƒZ
dldd„Z		dmdnd$d%„Z			&	'dodpd-d.„Z			'dqdrd0d1„Zdsd3d4„Zdtd7d8„Zdud:d;„Zdvd?d@„ZdvdAdB„ZdwdFdG„ZdxdHdI„ZdxdJdK„ZdydMdN„ZdzdRdS„Zd{dTdU„Z	&d|d}dWdX„Zd{dYdZ„Zd~d[d\„Zdd]d^„Zd€d`da„Zd{dbdc„Zd�ddde„Z ddfdg„Z!d~dhdi„Z"dS )‚Ú_EventListenersz­Configure event listeners for a client instance.

    Any event listeners registered globally are included by default.

    :param listeners: A list of event listeners.
    rc   ú"Optional[Sequence[_EventListener]]c                 C  s  t jd d … | _t jd d … | _t j}|d d … | _t jd d … | _t j	d d … | _
|d urj|D ]9}t|tƒr=| j |¡ t|tƒrH| j |¡ t|tƒrS| j |¡ t|tƒr^| j |¡ t|tƒri| j
 |¡ q0t| jƒ| _t| jƒ| _t| jƒ| _t| jƒ| _t| j
ƒ| _d S r‰   )rl   r   Ú"_EventListeners__command_listenersr   Ú!_EventListeners__server_listenersr   Ú+_EventListeners__server_heartbeat_listenersr   Ú#_EventListeners__topology_listenersr   Ú_EventListeners__cmap_listenersrg   r"   rm   rY   rL   rP   r3   rr   Ú%_EventListeners__enabled_for_commandsÚ#_EventListeners__enabled_for_serverÚ-_EventListeners__enabled_for_server_heartbeatÚ%_EventListeners__enabled_for_topologyÚ!_EventListeners__enabled_for_cmap)r+   rc   Úlstr   r   r    r‘   ¨  s0   




€z_EventListeners.__init__r%   rr   c                 C  r’   )z-Are any CommandListener instances registered?)rU  r“   r   r   r    Úenabled_for_commandsÁ  r”   z$_EventListeners.enabled_for_commandsc                 C  r’   )z,Are any ServerListener instances registered?)rV  r“   r   r   r    Úenabled_for_serverÆ  r”   z"_EventListeners.enabled_for_serverc                 C  r’   )z5Are any ServerHeartbeatListener instances registered?)rW  r“   r   r   r    Úenabled_for_server_heartbeatË  r”   z,_EventListeners.enabled_for_server_heartbeatc                 C  r’   )z.Are any TopologyListener instances registered?)rX  r“   r   r   r    Úenabled_for_topologyÐ  r”   z$_EventListeners.enabled_for_topologyc                 C  r’   )z4Are any ConnectionPoolListener instances registered?)rY  r“   r   r   r    Úenabled_for_cmapÕ  r”   z _EventListeners.enabled_for_cmapúlist[_EventListeners]c                 C  s   | j | j | j | j | j S )z#List of registered event listeners.)rP  rR  rQ  rS  rT  r“   r   r   r    Úevent_listenersÚ  s   ÿþýüÿz_EventListeners.event_listenersNrž   r   r‡   rb   r�   r^   r‚   r   rˆ   r„   Úop_idr…   r†   r&   c           
   	   C  sX   |du r|}t |||||||d�}| jD ]}	z|	 |¡ W q ty)   tƒ  Y qw dS )a  Publish a CommandStartedEvent to all command listeners.

        :param command: The command document.
        :param database_name: The name of the database this command was run
            against.
        :param request_id: The request id for this operation.
        :param connection_id: The address (host, port) of the server this
            command was sent to.
        :param op_id: The (optional) operation id for this operation.
        :param service_id: The service_id this command was sent to, or ``None``.
        N)r…   rˆ   )r$   rP  r,   rK  r   )
r+   rž   r‡   r�   r‚   rˆ   rb  r…   r#   Ú
subscriberr   r   r    Úpublish_command_startä  s$   ù
	
ÿýz%_EventListeners.publish_command_startFr€   r±   r   r³   ro   Úspeculative_helloc                 C  sd   |du r|}|	r
i }t ||||||||
|d�	}| jD ]}z| |¡ W q ty/   tƒ  Y qw dS )aÈ  Publish a CommandSucceededEvent to all command listeners.

        :param duration: The command duration as a datetime.timedelta.
        :param reply: The server reply document.
        :param command_name: The command name.
        :param request_id: The request id for this operation.
        :param connection_id: The address (host, port) of the server this
            command was sent to.
        :param op_id: The (optional) operation id for this operation.
        :param service_id: The service_id this command was sent to, or ``None``.
        :param speculative_hello: Was the command sent with speculative auth?
        :param database_name: The database this command was sent to, or ``""``.
        N)r‡   rˆ   )r.   rP  r/   rK  r   )r+   r±   r³   ro   r�   r‚   rˆ   rb  r…   re  r‡   r#   rc  r   r   r    Úpublish_command_success
  s,   ÷

ÿýz'_EventListeners.publish_command_successr»   c
                 C  s\   |du r|}t ||||||||	|d�	}
| jD ]}z| |
¡ W q ty+   tƒ  Y qw dS )a¥  Publish a CommandFailedEvent to all command listeners.

        :param duration: The command duration as a datetime.timedelta.
        :param failure: The server reply document or failure description
            document.
        :param command_name: The command name.
        :param request_id: The request id for this operation.
        :param connection_id: The address (host, port) of the server this
            command was sent to.
        :param op_id: The (optional) operation id for this operation.
        :param service_id: The service_id this command was sent to, or ``None``.
        :param database_name: The database this command was sent to, or ``""``.
        NrŸ   )r0   rP  r1   rK  r   )r+   r±   r»   ro   r�   r‚   rˆ   rb  r…   r‡   r#   rc  r   r   r    Úpublish_command_failure;  s(   ÷

ÿýz'_EventListeners.publish_command_failurer5  c              	   C  ó@   t ||ƒ}| jD ]}z| |¡ W q ty   tƒ  Y qw dS )zÿPublish a ServerHeartbeatStartedEvent to all server heartbeat
        listeners.

        :param connection_id: The address (host, port) pair of the connection.
        :param awaited: True if this heartbeat is part of an awaitable hello command.
        N)rM   rR  r,   rK  r   )r+   r‚   r5  r#   rc  r   r   r    Ú publish_server_heartbeat_startedg  ó   


ÿýz0_EventListeners.publish_server_heartbeat_startedr<  r=  c              	   C  óD   t ||||ƒ}| jD ]}z| |¡ W q
 ty   tƒ  Y q
w dS )aˆ  Publish a ServerHeartbeatSucceededEvent to all server heartbeat
        listeners.

        :param connection_id: The address (host, port) pair of the connection.
        :param duration: The execution time of the event in the highest possible
            resolution for the platform.
        :param reply: The command reply.
        :param awaited: True if the response was awaited.
        N)rN   rR  r/   rK  r   ©r+   r‚   r±   r³   r5  r#   rc  r   r   r    Ú"publish_server_heartbeat_succeededu  ó   

ÿýz2_EventListeners.publish_server_heartbeat_succeededrK  c              	   C  rk  )a…  Publish a ServerHeartbeatFailedEvent to all server heartbeat
        listeners.

        :param connection_id: The address (host, port) pair of the connection.
        :param duration: The execution time of the event in the highest possible
            resolution for the platform.
        :param reply: The command reply.
        :param awaited: True if the response was awaited.
        N)rO   rR  r1   rK  r   rl  r   r   r    Úpublish_server_heartbeat_failedˆ  rn  z/_EventListeners.publish_server_heartbeat_failedr  r  r
   c              	   C  rh  )zñPublish a ServerOpeningEvent to all server listeners.

        :param server_address: The address (host, port) pair of the server.
        :param topology_id: A unique identifier for the topology this server
           is a part of.
        N)rZ   rQ  rR   rK  r   ©r+   r  r  r#   rc  r   r   r    Úpublish_server_opened›  rj  z%_EventListeners.publish_server_openedc              	   C  rh  )zðPublish a ServerClosedEvent to all server listeners.

        :param server_address: The address (host, port) pair of the server.
        :param topology_id: A unique identifier for the topology this server
           is a part of.
        N)r\   rQ  rV   rK  r   rp  r   r   r    Úpublish_server_closed©  rj  z%_EventListeners.publish_server_closedr#  r   r$  c              	   C  sD   t ||||ƒ}| jD ]}z| |¡ W q
 ty   tƒ  Y q
w dS )a~  Publish a ServerDescriptionChangedEvent to all server listeners.

        :param previous_description: The previous server description.
        :param server_address: The address (host, port) pair of the server.
        :param new_description: The new server description.
        :param topology_id: A unique identifier for the topology this server
           is a part of.
        N)r[   rQ  rT   rK  r   )r+   r#  r$  r  r  r#   rc  r   r   r    Ú"publish_server_description_changed·  s   ÿ

ÿýz2_EventListeners.publish_server_description_changedc              	   C  ó>   t |ƒ}| jD ]}z| |¡ W q ty   tƒ  Y qw dS )z¨Publish a TopologyOpenedEvent to all topology listeners.

        :param topology_id: A unique identifier for the topology this server
           is a part of.
        N)rQ   rS  rR   rK  r   ©r+   r  r#   rc  r   r   r    Úpublish_topology_openedÏ  ó   

ÿýz'_EventListeners.publish_topology_openedc              	   C  rt  )z¨Publish a TopologyClosedEvent to all topology listeners.

        :param topology_id: A unique identifier for the topology this server
           is a part of.
        N)rU   rS  rV   rK  r   ru  r   r   r    Úpublish_topology_closedÜ  rw  z'_EventListeners.publish_topology_closedr   c              	   C  óB   t |||ƒ}| jD ]}z| |¡ W q	 ty   tƒ  Y q	w dS )a:  Publish a TopologyDescriptionChangedEvent to all topology listeners.

        :param previous_description: The previous topology description.
        :param new_description: The new topology description.
        :param topology_id: A unique identifier for the topology this server
           is a part of.
        N)rS   rS  rT   rK  r   )r+   r#  r$  r  r#   rc  r   r   r    Ú$publish_topology_description_changedé  s   

ÿýz4_EventListeners.publish_topology_description_changedrÂ   rÓ   rÔ   c              	   C  rh  )z:Publish a :class:`PoolCreatedEvent` to all pool listeners.N)r4   rT  r5   rK  r   )r+   rÂ   rÓ   r#   rc  r   r   r    Úpublish_pool_createdý  s   


ÿýz$_EventListeners.publish_pool_createdc              	   C  rt  )z8Publish a :class:`PoolReadyEvent` to all pool listeners.N)r7   rT  r8   rK  r   ©r+   rÂ   r#   rc  r   r   r    Úpublish_pool_ready  ó   

ÿýz"_EventListeners.publish_pool_readyrà   c              	   C  ry  )z:Publish a :class:`PoolClearedEvent` to all pool listeners.N)r9   rT  r:   rK  r   )r+   rÂ   r…   rà   r#   rc  r   r   r    Úpublish_pool_cleared  s   

ÿýz$_EventListeners.publish_pool_clearedc              	   C  rt  )z9Publish a :class:`PoolClosedEvent` to all pool listeners.N)r;   rT  r<   rK  r   r|  r   r   r    Úpublish_pool_closed  r~  z#_EventListeners.publish_pool_closedc              	   C  rh  )zWPublish a :class:`ConnectionCreatedEvent` to all connection
        listeners.
        N)r=   rT  r>   rK  r   ©r+   rÂ   r‚   r#   rc  r   r   r    Úpublish_connection_created&  ó   


ÿýz*_EventListeners.publish_connection_createdc              	   C  ry  )zDPublish a :class:`ConnectionReadyEvent` to all connection listeners.N)r?   rT  r@   rK  r   ©r+   rÂ   r‚   r±   r#   rc  r   r   r    Úpublish_connection_ready1  ó   

ÿýz(_EventListeners.publish_connection_readyr  c              	   C  ry  )zVPublish a :class:`ConnectionClosedEvent` to all connection
        listeners.
        N)rB   rT  rC   rK  r   )r+   rÂ   r‚   r  r#   rc  r   r   r    Úpublish_connection_closed<  r†  z)_EventListeners.publish_connection_closedc              	   C  rt  )z_Publish a :class:`ConnectionCheckOutStartedEvent` to all connection
        listeners.
        N)rD   rT  rE   rK  r   r|  r   r   r    Ú$publish_connection_check_out_startedG  s   

ÿýz4_EventListeners.publish_connection_check_out_startedc              	   C  ry  )z^Publish a :class:`ConnectionCheckOutFailedEvent` to all connection
        listeners.
        N)rF   rT  rG   rK  r   )r+   rÂ   r  r±   r#   rc  r   r   r    Ú#publish_connection_check_out_failedR  ó   

ÿýz3_EventListeners.publish_connection_check_out_failedc              	   C  ry  )zZPublish a :class:`ConnectionCheckedOutEvent` to all connection
        listeners.
        N)rH   rT  rI   rK  r   r„  r   r   r    Úpublish_connection_checked_out_  rŠ  z._EventListeners.publish_connection_checked_outc              	   C  rh  )zYPublish a :class:`ConnectionCheckedInEvent` to all connection
        listeners.
        N)rJ   rT  rK   rK  r   r�  r   r   r    Úpublish_connection_checked_inl  rƒ  z-_EventListeners.publish_connection_checked_in)rc   rO  rç   )r%   r`  r«   )rž   r   r‡   rb   r�   r^   r‚   r   rˆ   r„   rb  r„   r…   r†   r%   r&   )NNFr€   )r±   r   r³   r   ro   rb   r�   r^   r‚   r   rˆ   r„   rb  r„   r…   r†   re  rr   r‡   rb   r%   r&   )NNr€   )r±   r   r»   r   ro   rb   r�   r^   r‚   r   rˆ   r„   rb  r„   r…   r†   r‡   rb   r%   r&   r9  )
r‚   r   r±   r<  r³   r=  r5  rr   r%   r&   )
r‚   r   r±   r<  r³   rK  r5  rr   r%   r&   r  )
r#  r   r$  r   r  r   r  r
   r%   r&   r0  )r#  r   r$  r   r  r
   r%   r&   rÛ   rÎ   r8  ræ   rü   )rÂ   r   r‚   r^   r±   r<  r%   r&   )rÂ   r   r‚   r^   r  rb   r%   r&   )rÂ   r   r  rb   r±   r<  r%   r&   )#r   r   r   r   r‘   rœ   r[  r\  r]  r^  r_  ra  rd  rf  rg  ri  rm  ro  rq  rr  rs  rv  rx  rz  r{  r}  r  r€  r‚  r…  r‡  rˆ  r‰  r‹  rŒ  r   r   r   r    rN     s^    

ø.õ9ö
,









	ü

	




rN  )r]   r   r%   r^   )ra   rb   rc   rd   r%   rd   )rj   r   r%   r&   )ro   rb   rp   rq   r%   rr   )Kr   Ú
__future__r   ÚdatetimeÚcollectionsr   r   Útypingr   r   r   r   r	   Úbson.objectidr
   Úpymongo.hellor   r   Úpymongo.helpers_sharedr   r   Úpymongo.typingsr   r   r   Úpymongo.server_descriptionr   Úpymongo.topology_descriptionr   r   rl   r   r"   r3   rL   rP   rY   r`   rk   rn   rw   rx   r$   r.   r0   r¿   r4   r7   r9   r;   rè   rñ   rö   rù   rý   r=   r?   rB   rD   rF   rH   rJ   r  r[   rZ   r\   r-  rS   rQ   rU   r3  rM   rN   rO   rN  r   r   r   r    Ú<module>   s~    /þx



	LCEC-#)		)			30