+\h{^dZddlmZddlZddlmZmZddlmZm Z m Z m Z m Z ddl mZddlmZmZddlmZmZdd lmZmZerdd lmZdd lmZdd lmZed dZegggggZGddZGddeZ GddeZ!GddeZ"GddeZ#GddeZ$dcdZ% dddZ&dedZ'dfdZ(Gdd Z)Gd!d"e)Z*Gd#d$e)Z+Gd%d&e)Z,Gd'd(Z-Gd)d*e-Z.Gd+d,e-Z/Gd-d.e-Z0Gd/d0e-Z1Gd1d2Z2Gd3d4Z3Gd5d6Z4Gd7d8e4Z5Gd9d:e5Z6Gd;de6Z8Gd?d@e5Z9GdAdBe4Z:GdCdDe6Z;GdEdFe6Z<GdGdHe5Z=GdIdJZ>GdKdLe>Z?GdMdNe>Z@GdOdPe>ZAGdQdRZBGdSdTeBZCGdUdVeBZDGdWdXeBZEGdYdZZFGd[d\eFZGGd]d^eFZHGd_d`eFZIGdadbZJy)gaTools 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_CHECKINGAnyMappingOptionalSequence)ObjectId)Hello HelloCompat)_SENSITIVE_COMMANDS_handle_exception)_Address _DocumentOut) timedelta)ServerDescription)TopologyDescription _Listeners)command_listenersserver_listenersserver_heartbeat_listenerstopology_listenerscmap_listenersceZdZdZy)_EventListenerz,Abstract base class for all event listeners.N)__name__ __module__ __qualname____doc__U/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/monitoring.pyrrs6r"rc(eZdZdZddZddZddZy) CommandListenerzAbstract base class for command listeners. Handles `CommandStartedEvent`, `CommandSucceededEvent`, and `CommandFailedEvent`. ct)zAbstract method to handle a `CommandStartedEvent`. :param event: An instance of :class:`CommandStartedEvent`. NotImplementedErrorselfevents r#startedzCommandListener.started "!r"ct)zAbstract method to handle a `CommandSucceededEvent`. :param event: An instance of :class:`CommandSucceededEvent`. r'r)s r# succeededzCommandListener.succeededr-r"ct)z}Abstract method to handle a `CommandFailedEvent`. :param event: An instance of :class:`CommandFailedEvent`. r'r)s r#failedzCommandListener.failedr-r"N)r+CommandStartedEventreturnNone)r+CommandSucceededEventr3r4)r+CommandFailedEventr3r4rrrr r,r/r1r!r"r#r%r%s """r"r%cheZdZdZddZddZddZddZddZddZ ddZ dd Z dd Z dd Z dd Zy )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 ct)zAbstract method to handle a :class:`PoolCreatedEvent`. Emitted when a connection Pool is created. :param event: An instance of :class:`PoolCreatedEvent`. r'r)s r# pool_createdz#ConnectionPoolListener.pool_created "!r"ct)zAbstract 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)s r# pool_readyz!ConnectionPoolListener.pool_readys "!r"ct)zAbstract method to handle a `PoolClearedEvent`. Emitted when a connection Pool is cleared. :param event: An instance of :class:`PoolClearedEvent`. r'r)s r# pool_clearedz#ConnectionPoolListener.pool_cleared"r<r"ct)zAbstract method to handle a `PoolClosedEvent`. Emitted when a connection Pool is closed. :param event: An instance of :class:`PoolClosedEvent`. r'r)s r# pool_closedz"ConnectionPoolListener.pool_closed+r<r"ct)zAbstract method to handle a :class:`ConnectionCreatedEvent`. Emitted when a connection Pool creates a Connection object. :param event: An instance of :class:`ConnectionCreatedEvent`. r'r)s r#connection_createdz)ConnectionPoolListener.connection_created4r<r"ct)zAbstract 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)s r#connection_readyz'ConnectionPoolListener.connection_ready= "!r"ct)zAbstract method to handle a :class:`ConnectionClosedEvent`. Emitted when a connection Pool closes a connection. :param event: An instance of :class:`ConnectionClosedEvent`. r'r)s r#connection_closedz(ConnectionPoolListener.connection_closedGr<r"ct)zAbstract 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)s r#connection_check_out_startedz3ConnectionPoolListener.connection_check_out_startedPr<r"ct)zAbstract 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)s r#connection_check_out_failedz2ConnectionPoolListener.connection_check_out_failedYr<r"ct)zAbstract method to handle a :class:`ConnectionCheckedOutEvent`. Emitted when the driver successfully checks out a connection. :param event: An instance of :class:`ConnectionCheckedOutEvent`. r'r)s r#connection_checked_outz-ConnectionPoolListener.connection_checked_outbr<r"ct)zAbstract 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)s r#connection_checked_inz,ConnectionPoolListener.connection_checked_inkrGr"N)r+PoolCreatedEventr3r4)r+PoolReadyEventr3r4)r+PoolClearedEventr3r4)r+PoolClosedEventr3r4)r+ConnectionCreatedEventr3r4)r+ConnectionReadyEventr3r4)r+ConnectionClosedEventr3r4)r+ConnectionCheckOutStartedEventr3r4)r+ConnectionCheckOutFailedEventr3r4)r+ConnectionCheckedOutEventr3r4)r+ConnectionCheckedInEventr3r4)rrrr r;r>r@rBrDrFrIrKrMrOrQr!r"r#r9r9s> " """"""""""r"r9c(eZdZdZddZddZddZy) ServerHeartbeatListenerzAbstract base class for server heartbeat listeners. Handles `ServerHeartbeatStartedEvent`, `ServerHeartbeatSucceededEvent`, and `ServerHeartbeatFailedEvent`. .. versionadded:: 3.3 ct)zAbstract method to handle a `ServerHeartbeatStartedEvent`. :param event: An instance of :class:`ServerHeartbeatStartedEvent`. r'r)s r#r,zServerHeartbeatListener.startedr-r"ct)zAbstract method to handle a `ServerHeartbeatSucceededEvent`. :param event: An instance of :class:`ServerHeartbeatSucceededEvent`. r'r)s r#r/z!ServerHeartbeatListener.succeededr-r"ct)zAbstract method to handle a `ServerHeartbeatFailedEvent`. :param event: An instance of :class:`ServerHeartbeatFailedEvent`. r'r)s r#r1zServerHeartbeatListener.failedr-r"N)r+ServerHeartbeatStartedEventr3r4)r+ServerHeartbeatSucceededEventr3r4)r+ServerHeartbeatFailedEventr3r4r7r!r"r#r^r^vs"""r"r^c(eZdZdZddZddZddZy) TopologyListenerzAbstract base class for topology monitoring listeners. Handles `TopologyOpenedEvent`, `TopologyDescriptionChangedEvent`, and `TopologyClosedEvent`. .. versionadded:: 3.3 ct)zAbstract method to handle a `TopologyOpenedEvent`. :param event: An instance of :class:`TopologyOpenedEvent`. r'r)s r#openedzTopologyListener.openedr-r"ct)zAbstract method to handle a `TopologyDescriptionChangedEvent`. :param event: An instance of :class:`TopologyDescriptionChangedEvent`. r'r)s r#description_changedz$TopologyListener.description_changedr-r"ct)zAbstract method to handle a `TopologyClosedEvent`. :param event: An instance of :class:`TopologyClosedEvent`. r'r)s r#closedzTopologyListener.closedr-r"N)r+TopologyOpenedEventr3r4)r+TopologyDescriptionChangedEventr3r4)r+TopologyClosedEventr3r4rrrr rhrjrlr!r"r#rfrf"""r"rfc(eZdZdZddZddZddZy) ServerListenerzAbstract base class for server listeners. Handles `ServerOpeningEvent`, `ServerDescriptionChangedEvent`, and `ServerClosedEvent`. .. versionadded:: 3.3 ct)z}Abstract method to handle a `ServerOpeningEvent`. :param event: An instance of :class:`ServerOpeningEvent`. r'r)s r#rhzServerListener.openedr-r"ct)zAbstract method to handle a `ServerDescriptionChangedEvent`. :param event: An instance of :class:`ServerDescriptionChangedEvent`. r'r)s r#rjz"ServerListener.description_changedr-r"ct)z{Abstract method to handle a `ServerClosedEvent`. :param event: An instance of :class:`ServerClosedEvent`. r'r)s r#rlzServerListener.closedr-r"N)r+ServerOpeningEventr3r4)r+ServerDescriptionChangedEventr3r4)r+ServerClosedEventr3r4rpr!r"r#rsrsrqr"rsc:t|jdzS)z'Convert duration 'dur' to microseconds.g.A)int total_seconds)durs r# _to_microsr~s s  "T) **r"c t|tjst|dt ||D],}t|t rtd|dt ||S)zValidate event listenersz must be a list or tuple, not Listeners for | must be either a CommandListener, ServerHeartbeatListener, ServerListener, TopologyListener, or ConnectionPoolListener,not ) isinstancerr TypeErrortyper)option listenerslisteners r#_validate_event_listenersrsy i .6("@i@QRSS(N3 )H~& (  r"c0t|tstd|dt|t|trt j j|t|trt jj|t|trt jj|t|trt jj|t|tr t jj|yy)zRegister a global event listener. :param listener: A subclasses of :class:`CommandListener`, :class:`ServerHeartbeatListener`, :class:`ServerListener`, :class:`TopologyListener`, or :class:`ConnectionPoolListener`. rrN)rrrrr% _LISTENERSrappendr^rrsrrfrr9r)rs r#registerrs h /XJ'>"  $  (O,$$++H5(34--44X>(N+##**84(,-%%,,X6(23!!((24r"cR|jdtjfvrd|vryy)NhellospeculativeAuthenticateTF)lowerr LEGACY_CMD) command_namedocs r#_is_speculative_authenticaters,+*@*@ AA % , r"ceZdZdZdZ d d dZeddZeddZeddZ eddZ edd Z edd Z edd Z y) _CommandEventzBase class for command events.) __cmd_name __rqst_id __conn_id__op_id __service_id__db__server_conn_idNcf||_||_||_||_||_||_||_yN)_CommandEvent__cmd_name_CommandEvent__rqst_id_CommandEvent__conn_id_CommandEvent__op_id_CommandEvent__service_id_CommandEvent__db_CommandEvent__server_conn_id)r*r request_id connection_id operation_id service_id database_nameserver_connection_ids r#__init__z_CommandEvent.__init__s7'#&# &! 4r"c|jS)zThe command name.)rr*s r#rz_CommandEvent.command_name-r"c|jS)z"The request id for this operation.)rrs r#rz_CommandEvent.request_id2~~r"c|jS)z@The address (host, port) of the server this command was sent to.)rrs r#rz_CommandEvent.connection_id7rr"c|jS)z^The service_id this command was sent to, or ``None``. .. versionadded:: 3.12 )rrs r#rz_CommandEvent.service_id<s    r"c|jS)z(An id for this series of events or None.)rrs r#rz_CommandEvent.operation_idD||r"c|jS)z^The database_name this command was sent to, or ``""``. .. versionadded:: 4.6 )rrs r#rz_CommandEvent.database_nameIs yyr"c|jS)zThe server-side connection id for the connection this command was sent on, or ``None``. .. versionadded:: 4.7 )rrs r#rz"_CommandEvent.server_connection_idQs $$$r"NN)rstrrr{rrr Optional[int]rOptional[ObjectId]rrrrr3r4r3rr3r{r3rr3r)r3r)rrrr __slots__rpropertyrrrrrrrr!r"r#rrs(I *..2555 5 $ 5 ' 55,5 5$!!%%r"rc|eZdZdZdZ d dfd Zed dZed fd Zd dZ xZ S) r2aEvent 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``. )__cmdc |st|dtt|}t |||||||||j } | t vs t| |ri|_y||_y)Nz is not a valid commandrrr) ValueErrornextitersuperrrrr_CommandStartedEvent__cmd) r*commandrrrrrrrcmd_name __class__s r#rzCommandStartedEvent.__init__hs{*ABC CDM*      !'!5   %%' * *.J8U\.]')DJ DJr"c|jS)zThe command document.)rrs r#rzCommandStartedEvent.commandszzr"ct|S)z6The name of the database this command was run against.)rrr*rs r#rz!CommandStartedEvent.database_namesw$$r"c dj|jj|j|j|j |j |j|jS)Nz[<{} {} db: {!r}, command: {!r}, operation_id: {}, service_id: {}, server_connection_id: {}>) formatrrrrrrrrrs r#__repr__zCommandStartedEvent.__repr__sU i & NN # #             OO  % %  r"NN)rrrrrr{rrrrrrrrr3r4r3rr) rrrr rrrrrr __classcell__rs@r#r2r2Zs I*..2!!! !  ! $ !'!,! !:%%  r"r2ceZdZdZdZ d dfd Zed dZed dZd dZ xZ S) r5aOEvent 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__replyc t |||||||| t||_|j } | t vs t | |ri|_y||_yNr)rrr~'_CommandSucceededEvent__duration_microsrrr_CommandSucceededEvent__reply) r*durationreplyrrrrrrrrrs r#rzCommandSucceededEvent.__init__sk     !'!5  ",H!5%%' * *.J8UZ.[)+DL DLr"c|jSz/The duration of this operation in microseconds.)rrs r#duration_microsz%CommandSucceededEvent.duration_micros%%%r"c|jSz/The server failure document for this operation.)rrs r#rzCommandSucceededEvent.replyrr"c dj|jj|j|j|j |j |j|j|jS)Nzp<{} {} db: {!r}, command: {!r}, operation_id: {}, duration_micros: {}, service_id: {}, server_connection_id: {}>) rrrrrrrrrrrs r#rzCommandSucceededEvent.__repr__s^ ~ & NN # #              OO  % %  r"r)rdatetime.timedeltarrrrrr{rrrrrrrrrrr3r4rrr) rrrr rrrrrrrrs@r#r5r5s 1I*..2!$!! !  !  !$!'!!,! !8&&  r"r5ceZdZdZdZ d dfd Zed dZed dZd dZ xZ S) r6aNEvent 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 __failurec `t |||||||| t||_||_yr)rrr~$_CommandFailedEvent__duration_micros_CommandFailedEvent__failure) r*rfailurerrrrrrrrs r#rzCommandFailedEvent.__init__sB     !'!5  ",H!5 r"c|jSr)rrs r#rz"CommandFailedEvent.duration_micros rr"c|jSr)rrs r#rzCommandFailedEvent.failurerr"c dj|jj|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: {}>) rrrrrrrrrrrrs r#rzCommandFailedEvent.__repr__sh G & NN # #              LL OO  % %  r"r)rrrrrrrr{rrrrrrrrrrr3r4rrr) rrrr rrrrrrrrs@r#r6r6s 3I*..2!$!! !  !  !$!'!!,! !0&& r"r6c6eZdZdZdZddZeddZd dZy) _PoolEventzBase class for pool events. __addressc||_yr_PoolEvent__addressr*addresss r#rz_PoolEvent.__init__*  r"c|jS)zbThe address (host, port) pair of the server the pool is attempting to connect to. rrs r#rz_PoolEvent.address- ~~r"cN|jjd|jdSN())rrrrs r#rz_PoolEvent.__repr__4%..))*!DNN+=Q??r"Nrrr3r4rr rrrr rrrrrr!r"r#rr%s)%I! @r"rcBeZdZdZdZdfd ZeddZddZxZ S) rRzPublished 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 ) __optionsc2t||||_yr)rr_PoolCreatedEvent__options)r*roptionsrs r#rzPoolCreatedEvent.__init__Cs ! r"c|jS)zCAny non-default pool options that were set on this Connection Pool.)r rs r#r zPoolCreatedEvent.optionsGrr"ch|jjd|jd|jdSNrz, r)rrrr rs r#rzPoolCreatedEvent.__repr__Ls0..))*!DLL+;2dnn=OqQQr"rrr dict[str, Any]r3r4)r3rr) rrrr rrrr rrrs@r#rRrR8s.I!Rr"rRceZdZdZdZy)rSzPublished 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!Nrrrr rr!r"r#rSrSPIr"rScheZdZdZdZ d dfd Zed dZed dZd dZ xZ S) rTawPublished 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_connectionsc@t||||_||_yr)rr_PoolClearedEvent__service_id(_PoolClearedEvent__interrupt_connections)r*rrinterrupt_connectionsrs r#rzPoolClearedEvent.__init__is" !&'<$r"c|jS)zConnections with this service_id are cleared. When service_id is ``None``, all connections in the pool are cleared. .. versionadded:: 3.12 )rrs r#rzPoolClearedEvent.service_idss   r"c|jS)zdIf True, active connections are interrupted during clearing. .. versionadded:: 4.7 )rrs r#rz&PoolClearedEvent.interrupt_connections}s +++r"c|jjd|jd|jd|jdSr)rrrrrrs r#rzPoolClearedEvent.__repr__sB..))*!DLL+;2d>O>O=RRTUYUqUqTttuvvr")NFrrrrrboolr3r4rr3rr) rrrr rrrrrrrrs@r#rTrT\spR>R=UUVWWr"rrrr{r3r4rr) rrrr rrrrrrrs@r#r9r9s*>$I-$$Xr"r9cBeZdZdZdZdfd ZeddZddZxZ S) _ConnectionDurationEventz9Private base class for connection events with a duration.) __durationc4t|||||_yr)rr"_ConnectionDurationEvent__duration)r*rrrrs r#rz!_ConnectionDurationEvent.__init__s -0"r"c|jS)zMThe duration of the connection event. .. versionadded:: 4.7 )rDrs r#rz!_ConnectionDurationEvent.durations r"c|jjd|jd|jd|jdSr)rrrrrDrs r#rz!_ConnectionDurationEvent.__repr__sB..))*!DLL+;2d>P>P=SSUVZVeVeUhhijjr")rrrr{rOptional[float]r3r4)r3rGr) rrrr rrrrrrrs@r#rArAs*CI#kr"rAceZdZdZdZy)rVaPublished 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!Nrr!r"r#rVrVs Ir"rVceZdZdZdZy)rWa&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!Nrr!r"r#rWrWIr"rWcBeZdZdZdZdfd ZeddZddZxZ S)rXaKPublished 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 __reasonc4t|||||_yr)rr_ConnectionClosedEvent__reason)r*rrreasonrs r#rzConnectionClosedEvent.__init__!s -0 r"c|jS)zA reason explaining why this connection was closed. The reason must be one of the strings from the :class:`ConnectionClosedReason` enum. )rOrs r#rPzConnectionClosedEvent.reason%}}r"cdj|jj|j|j|j S)Nz{}({!r}, {!r}, {!r}))rrrrrrOrs r#rzConnectionClosedEvent.__repr__.s9%,, NN # # LL    MM   r")rrrr{rPrr rrrr rrrrPrrrs@r#rXrXs-I r"rXceZdZdZdZy)rYzPublished 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!Nrr!r"r#rYrY7rr"rYcBeZdZdZdZdfd ZeddZddZxZ S)rZa!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 rLc8t||d|||_y)Nr)rrr)rr&_ConnectionCheckOutFailedEvent__reason)r*rrPrrs r#rz&ConnectionCheckOutFailedEvent.__init__Os HM r"c|jS)zA reason explaining why connection check out failed. The reason must be one of the strings from the :class:`ConnectionCheckOutFailedReason` enum. )rXrs r#rPz$ConnectionCheckOutFailedEvent.reasonSrRr"c|jjd|jd|jd|jdSr)rrrrXrrs r#rz&ConnectionCheckOutFailedEvent.__repr__\s?..))*!DLL+;2dmm=NbQUQ^Q^Paabccr")rrrPrrrGr3r4rrTrs@r#rZrZCs.Idr"rZceZdZdZdZy)r[aPublished 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!Nrr!r"r#r[r[`rJr"r[ceZdZdZdZy)r\aPublished 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!Nrr!r"r#r\r\mrJr"r\cHeZdZdZdZddZed dZed dZd dZ y) _ServerEventzBase class for server events.)__server_address __topology_idc ||_||_yr)_ServerEvent__server_address_ServerEvent__topology_id)r*server_address topology_ids r#rz_ServerEvent.__init__s .(r"c|jS)z+The address (host, port) pair of the server)rbrs r#rdz_ServerEvent.server_addresss$$$r"c|jSz>A unique identifier for the topology this server is a part of.)rcrs r#rez_ServerEvent.topology_id!!!r"cjd|jjd|jd|jdS)N<  topology_id: >)rrrdrers r#rz_ServerEvent.__repr__s84>>**+1T-@-@,APTP`P`Oaabccr"Nrdrrer r3r4rr3r r) rrrr rrrrdrerr!r"r#r^r^zs='5I)%%""dr"r^cdeZdZdZdZ dfd ZeddZeddZd dZ xZ S) rxzJPublished when server description changes. .. versionadded:: 3.3 __previous_description__new_descriptionc:t||||_||_yr)rr4_ServerDescriptionChangedEvent__previous_description/_ServerDescriptionChangedEvent__new_descriptionr*previous_descriptionnew_descriptionargsrs r#rz&ServerDescriptionChangedEvent.__init__" $&:#!0r"c|jS)zUThe previous :class:`~pymongo.server_description.ServerDescription`. )rvrs r#ryz2ServerDescriptionChangedEvent.previous_description ***r"c|jS)zPThe new :class:`~pymongo.server_description.ServerDescription`. )rwrs r#rzz-ServerDescriptionChangedEvent.new_description %%%r"cdj|jj|j|j|j S)Nz <{} {} changed from: {}, to: {}>)rrrrdryrzrs r#rz&ServerDescriptionChangedEvent.__repr__s=188 NN # #     % %    r")ryrrzrr{rr3r4)r3rr rrrr rrrryrzrrrs@r#rxrxsh @I1/1+1 1  1++ &&  r"rxceZdZdZdZy)rwzEPublished when server is initialized. .. versionadded:: 3.3 r!Nrr!r"r#rwrw Ir"rwceZdZdZdZy)ryz@Published when server is closed. .. versionadded:: 3.3 r!Nrr!r"r#ryryrr"ryc6eZdZdZdZddZeddZd dZy) TopologyEventz+Base class for topology description events.)r`c||_yr_TopologyEvent__topology_id)r*res r#rzTopologyEvent.__init__s (r"c|jSrhrrs r#rezTopologyEvent.topology_idrir"cPd|jjd|jdS)Nrkrmrn)rrrers r#rzTopologyEvent.__repr__s)4>>**+>$:J:J9K1MMr"Nrer r3r4rpr) rrrr rrrrerr!r"r#rrs)5"I)""Nr"rcdeZdZdZdZ dfd ZeddZeddZd dZ xZ S) rnzPPublished when the topology description changes. .. versionadded:: 3.3 rrc:t||||_||_yr)rr6_TopologyDescriptionChangedEvent__previous_description1_TopologyDescriptionChangedEvent__new_descriptionrxs r#rz(TopologyDescriptionChangedEvent.__init__r|r"c|jS)zYThe previous :class:`~pymongo.topology_description.TopologyDescription`. )rrs r#ryz4TopologyDescriptionChangedEvent.previous_descriptionr~r"c|jS)zTThe new :class:`~pymongo.topology_description.TopologyDescription`. )rrs r#rzz/TopologyDescriptionChangedEvent.new_descriptionrr"cdj|jj|j|j|j S)Nz-<{} topology_id: {} changed from: {}, to: {}>)rrrreryrzrs r#rz(TopologyDescriptionChangedEvent.__repr__s=>EE NN # #     % %    r")ryrrzrr{rr3r4)r3rrrrs@r#rnrnsh @I111-1 1  1++ &&  r"rnceZdZdZdZy)rmzKPublished when the topology is initialized. .. versionadded:: 3.3 r!Nrr!r"r#rmrmrr"rmceZdZdZdZy)rozFPublished when the topology is closed. .. versionadded:: 3.3 r!Nrr!r"r#rororr"rocJeZdZdZdZdd dZed dZed dZd dZ y) _ServerHeartbeatEventz'Base class for server heartbeat events.)r: __awaitedc ||_||_yr)$_ServerHeartbeatEvent__connection_id_ServerHeartbeatEvent__awaited)r*rawaiteds r#rz_ServerHeartbeatEvent.__init__s, r"c|jS)zSThe address (host, port) of the server this heartbeat was sent to. )rrs r#rz#_ServerHeartbeatEvent.connection_id!s ###r"c|jS)zgWhether the heartbeat was issued as an awaitable hello command. .. versionadded:: 4.6 )rrs r#rz_ServerHeartbeatEvent.awaited(s ~~r"cjd|jjd|jd|jdS)Nrkrlz awaited: rn)rrrrrs r#rz_ServerHeartbeatEvent.__repr__0s44>>**+1T-?-?,@ 4<<.XYZZr"NFrrrrr3r4rrr) rrrr rrrrrrr!r"r#rrs=10I!$$ [r"rceZdZdZdZy)rbzFPublished when a heartbeat is started. .. versionadded:: 3.3 r!Nrr!r"r#rbrb4rr"rbceZdZdZdZ d d fd Zed dZed dZed fd Z d dZ xZ S)rczIFired when the server heartbeat succeeds. .. versionadded:: 3.3 rBrcBt|||||_||_yr)rr(_ServerHeartbeatSucceededEvent__duration%_ServerHeartbeatSucceededEvent__replyr*rrrrrs r#rz&ServerHeartbeatSucceededEvent.__init__E" 0" r"c|jSz/The duration of this heartbeat in microseconds.)rrs r#rz&ServerHeartbeatSucceededEvent.durationLrr"c|jS)z-An instance of :class:`~pymongo.hello.Hello`.)rrs r#rz#ServerHeartbeatSucceededEvent.replyQrr"ct|SzWhether 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 rrrs r#rz%ServerHeartbeatSucceededEvent.awaitedVwr"cdj|jj|j|j|j |j S)Nz,<{} {} duration: {}, awaited: {}, reply: {}>rrrrrrrrs r#rz&ServerHeartbeatSucceededEvent.__repr__bs@=DD NN # #    MM LL JJ   r"r) rfloatrr rrrrr3r4r3r)r3r rr rrrr rrrrrrrrrs@r#rcrc=s *IW\&+rrs r#rz#ServerHeartbeatFailedEvent.__repr__s@?FF NN # #    MM LL JJ   r"r) rrr Exceptionrrrrr3r4r)r3rrrrrs@r#rdrdls *I[`&/@HSW    r"rdcFeZdZdZd!dZed"dZed"dZed"dZed"dZ ed"dZ d#dZ d$ d%d Z d& d'd Z d( d)d Zd*d Z d+dZ d,dZd-dZd-dZ d.dZd/dZd/dZ d0dZd1dZd2dZ d3 d4dZd2dZd5dZ d6dZd7dZd2dZ d8dZ d6dZ!d5d Z"y )9_EventListenerszConfigure event listeners for a client instance. Any event listeners registered globally are included by default. :param listeners: A list of event listeners. ctjdd|_tjdd|_tj }|dd|_tjdd|_tjdd|_ ||D]}t|tr|jj|t|tr|jj|t|tr|j j|t|t r|jj|t|t"s|jj|t%|j|_t%|j|_t%|j |_t%|j|_t%|j|_yr)rr"_EventListeners__command_listenersr!_EventListeners__server_listenersr+_EventListeners__server_heartbeat_listenersr#_EventListeners__topology_listenersr_EventListeners__cmap_listenersrr%rrsr^rfr9r%_EventListeners__enabled_for_commands#_EventListeners__enabled_for_server-_EventListeners__enabled_for_server_heartbeat%_EventListeners__enabled_for_topology!_EventListeners__enabled_for_cmap)r*rlsts r#rz_EventListeners.__init__st#-#?#?#B ","="=a"@33,/F)$.$A$A!$D! * 9 9! <   6c?3,,33C8c>2++2237c#:;55<;?11 $J $!!%( $ $!# $rct||}|jD]} |j|y#t$r t Y-wxYw)zPublish 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)ryrrlrrrs r#publish_server_closedz%_EventListeners.publish_server_closedsO".+>11 $J $!!%( $ $!# $rct||||}|jD]} |j|y#t$r t Y-wxYw)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)rxrrjrr)r*ryrzrdrer+rs r#"publish_server_description_changedz2_EventListeners.publish_server_description_changedsX. />; 11 $J $..u5 $ $!# $rct|}|jD]} |j|y#t$r t Y-wxYw)zPublish a TopologyOpenedEvent to all topology listeners. :param topology_id: A unique identifier for the topology this server is a part of. N)rmrrhrrr*rer+rs r#publish_topology_openedz'_EventListeners.publish_topology_openedM $K033 $J $!!%( $ $!# $0AAct|}|jD]} |j|y#t$r t Y-wxYw)zPublish a TopologyClosedEvent to all topology listeners. :param topology_id: A unique identifier for the topology this server is a part of. N)rorrlrrrs r#publish_topology_closedz'_EventListeners.publish_topology_closedrrct|||}|jD]} |j|y#t$r t Y-wxYw)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)rnrrjrr)r*ryrzrer+rs r#$publish_topology_description_changedz4_EventListeners.publish_topology_description_changedsS00DoWbc33 $J $..u5 $ $!# $2AAct||}|jD]} |j|y#t$r t Y-wxYw)z:Publish a :class:`PoolCreatedEvent` to all pool listeners.N)rRrr;rr)r*rr r+rs r#publish_pool_createdz$_EventListeners.publish_pool_createdsM '2// $J $''. $ $!# $rct|}|jD]} |j|y#t$r t Y-wxYw)z8Publish a :class:`PoolReadyEvent` to all pool listeners.N)rSrr>rrr*rr+rs r#publish_pool_readyz"_EventListeners.publish_pool_readysKw'// $J $%%e, $ $!# $rct|||}|jD]} |j|y#t$r t Y-wxYw)z:Publish a :class:`PoolClearedEvent` to all pool listeners.N)rTrr@rr)r*rrrr+rs r#publish_pool_clearedz$_EventListeners.publish_pool_cleared sR!*6KL// $J $''. $ $!# $rct|}|jD]} |j|y#t$r t Y-wxYw)z9Publish a :class:`PoolClosedEvent` to all pool listeners.N)rUrrBrrrs r#publish_pool_closedz#_EventListeners.publish_pool_closedsK(// $J $&&u- $ $!# $rct||}|jD]} |j|y#t$r t Y-wxYw)zWPublish a :class:`ConnectionCreatedEvent` to all connection listeners. N)rVrrDrrr*rrr+rs r#publish_connection_createdz*_EventListeners.publish_connection_created"sO'w >// $J $--e4 $ $!# $rct|||}|jD]} |j|y#t$r t Y-wxYw)zDPublish a :class:`ConnectionReadyEvent` to all connection listeners.N)rWrrFrrr*rrrr+rs r#publish_connection_readyz(_EventListeners.publish_connection_ready-sQ%WmXF// $J $++E2 $ $!# $rct|||}|jD]} |j|y#t$r t Y-wxYw)zVPublish a :class:`ConnectionClosedEvent` to all connection listeners. N)rXrrIrr)r*rrrPr+rs r#publish_connection_closedz)_EventListeners.publish_connection_closed8sQ&g}fE// $J $,,U3 $ $!# $rct|}|jD]} |j|y#t$r t Y-wxYw)z_Publish a :class:`ConnectionCheckOutStartedEvent` to all connection listeners. N)rYrrKrrrs r#$publish_connection_check_out_startedz4_EventListeners.publish_connection_check_out_startedCsM/w7// $J $77> $ $!# $rct|||}|jD]} |j|y#t$r t Y-wxYw)z^Publish a :class:`ConnectionCheckOutFailedEvent` to all connection listeners. N)rZrrMrr)r*rrPrr+rs r##publish_connection_check_out_failedz3_EventListeners.publish_connection_check_out_failedNsQ .gvxH// $J $66u= $ $!# $rct|||}|jD]} |j|y#t$r t Y-wxYw)zZPublish a :class:`ConnectionCheckedOutEvent` to all connection listeners. N)r[rrOrrr s r#publish_connection_checked_outz._EventListeners.publish_connection_checked_out[sQ *'=(K// $J $11%8 $ $!# $rct||}|jD]} |j|y#t$r t Y-wxYw)zYPublish a :class:`ConnectionCheckedInEvent` to all connection listeners. N)r\rrQrrrs r#publish_connection_checked_inz-_EventListeners.publish_connection_checked_inhsO)-@// $J $007 $ $!# $r)rz"Optional[Sequence[_EventListener]]r)r3zlist[_EventListeners]r)rrrrrr{rrrrrrrrr3r4)NNFr)rrrrrrrr{rrrrrrrrrrrrr3r4)NNr)rrrrrrrr{rrrrrrrrrrr3r4r) rrrrrr rrr3r4) rrrrrrrrr3r4ro) ryrrzrrdrrer r3r4r)ryrrzrrer r3r4rrrrr?)rrrr{rrr3r4)rrrr{rPrr3r4)rrrPrrrr3r4)#rrrr rrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrr!r"r#rrsY>2++))33++'' " $)-$$$$$$ $$  $$ , $$$$'$$ $$\ $)-"'/$/$/$ /$  /$  /$,/$/$'/$ /$/$ /$r $)-*$*$*$ *$  *$  *$,*$*$'*$*$ *$X $$%$16$?D$OS$ $&$%$16$?H$SW$ $& $ $$/$+$! $  $  $0 $ $$1$-$ $  $($$', $ $' $ $ $  $$ $ $ $03 $?D $  $ $ $ $ $), $8= $  $ $ $03 $?D $  $ $r"r)r}rr3r{)rrrSequence[_EventListeners]r3r)rrr3r4)rrrzMapping[str, Any]r3r)Kr __future__rdatetime collectionsrrtypingrrrr r bson.objectidr pymongo.hellor r pymongo.helpers_sharedrrpymongo.typingsrrrpymongo.server_descriptionrpymongo.topology_descriptionrrrrr%r9r^rfrsr~rrrrr2r5r6rrRrSrTrUr"r,r2r9rArVrWrXrYrZr[r\r^rxrwryrrnrmrorrbrcrdrr!r"r#r"sl\#'BB",I2"<@  BB + 77"n":u"^u"p"n">"~"<"^"<+  5$3:I%I%X@ -@ FB MB J@ @ F@@&RzR0 Z *wz*wZ j FF*&@@&X)X$k1k* /  3   .  F %5 d$<d:  8  1 dd.& L& R NN"& m& R--[[8"7, $9, ^- !6- `U$U$r"