
    h:                     L   d Z ddlZddlZddlZddlZddlZddlmZmZ erddl	Z
nddl
Z
ddlmZmZmZ ddlmZ ddlmZmZmZmZmZ ddlmZmZmZmZmZmZ ddlmZ dd	l m!Z" dd
l#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ d Z0 G d de1      Z2 G d de1      Z3d Z4d Z5y)z<Internal class to monitor a topology of one or more servers.    N)
itervaluesPY3)commonhelpersperiodic_executor)PoolOptions)updated_topology_description)_updated_topology_description_srv_pollingTopologyDescriptionSRV_POLLING_TOPOLOGIESTOPOLOGY_TYPE)ConnectionFailureConfigurationErrorNetworkTimeoutNotMasterErrorOperationFailureServerSelectionTimeoutError)
SrvMonitor)time)Server)ServerDescription)any_server_selectorarbiter_server_selectorsecondary_server_selectorreadable_server_selectorwritable_server_selector	Selection)_ServerSessionPoolc                      |        }|sy	 	 |j                         }|\  }} ||  # t        j                  $ r Y yw xY w)NFT)
get_nowaitQueueEmpty)	queue_refqeventfnargss        S/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/topology.pyprocess_events_queuer)   8   sV    A
	LLNE HBI  {{ 	
 	s   ( >>c                      e Zd ZdZd Zd Z	 	 d*dZd Z	 	 d*dZ	 d+dZ	d,d	Z
d,d
Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd-dZd Zd Zd Zd Zed        Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+y).Topologyz*Monitor a topology of one or more servers.c                    |j                   | _         |j                  j                  | _        | j                  d u}|xr | j                  j                  | _        |xr | j                  j                  | _        d | _        d | _	        | j
                  s| j                  rt        j                  d      | _        | j                  r<| j                  j                  | j                  j                  | j                   ff       || _        t        |j                         |j!                         |j"                  d d |      }|| _        | j                  rpt        t&        j(                  i d d d | j                        }| j                  j                  | j                  j*                  || j$                  | j                   ff       |j,                  D ]L  }| j
                  s| j                  j                  | j                  j.                  || j                   ff       N t1        |j3                               | _        d| _        t9        j:                         | _        | j                  j?                  | j<                        | _         i | _!        d | _"        d | _#        tI               | _%        | j
                  s| j                  rmfd}tM        jN                  tP        jR                  d|d      }tU        jV                  | j                  |jX                        || _	        |j[                          d | _.        | j                  j^                  ta        | | j                        | _.        y y )Nd   )maxsizeFc                      t               S N)r)   )weaks   r(   targetz!Topology.__init__.<locals>.target}   s    +D11    g      ?pymongo_events_thread)intervalmin_intervalr2   name)1_topology_id_pool_optionsevent_listeners
_listenersenabled_for_server_publish_serverenabled_for_topology_publish_tp_events_Topology__events_executorr!   putpublish_topology_opened	_settingsr   get_topology_typeget_server_descriptionsreplica_set_name_descriptionr   Unknown$publish_topology_description_changedseedspublish_server_openedlistserver_descriptions_seed_addresses_opened	threadingLock_lockcondition_class
_condition_servers_pid_max_cluster_timer   _session_poolr   PeriodicExecutorr   EVENTS_QUEUE_FREQUENCYweakrefrefcloseopen_srv_monitorfqdnr   )	selftopology_settingspubtopology_description
initial_tdseedr2   executorr1   s	           @r(   __init__zTopology.__init__K   s   -::+99IIooT)"It'I'IG4??#G#G !%4#3#3 ;;s3DLLLdooEE"//13 4*2//1557..  1,]-B-BB-14IJLLDDT..0A0ABD E &++ 	=D##  $//"G"G"&(9(9!:"< =	=  $$8$L$L$NO^^%
..88D	!%/14#3#32 )9966 ,	.H ;;t||X^^<D%-D"MMO >>* *4 @D +r3   c                    | j                   t        j                         | _         net        j                         | j                   k7  rDt        j                  d       | j
                  5  | j                  j                          ddd       | j
                  5  | j                          ddd       y# 1 sw Y   /xY w# 1 sw Y   yxY w)a  Start monitoring, or restart after a fork.

        No effect if called multiple times.

        .. warning:: Topology is shared among multiple threads and is protected
          by mutual exclusion. Using Topology from a process other than the one
          that initialized it will emit a warning and may result in deadlock. To
          prevent this from happening, MongoClient must be created after any
          forking.

        NzMongoClient opened before fork. Create MongoClient only after forking. See PyMongo's documentation for details: https://pymongo.readthedocs.io/en/stable/faq.html#is-pymongo-fork-safe)	rW   osgetpidwarningswarnrS   rY   reset_ensure_openedrb   s    r(   r_   zTopology.open   s     99		DIyy{dii'+,
 ZZ / &&,,./
 ZZ 	"!	" 	"/ /
	" 	"s   )B2B>2B;>CNc                     || j                   j                  }n|}| j                  5  | j                  |||      }|D cg c]  }| j	                  |j
                         c}cddd       S c c}w # 1 sw Y   yxY w)aL  Return a list of Servers matching selector, or time out.

        :Parameters:
          - `selector`: function that takes a list of Servers and returns
            a subset of them.
          - `server_selection_timeout` (optional): maximum seconds to wait.
            If not provided, the default value common.SERVER_SELECTION_TIMEOUT
            is used.
          - `address`: optional server address to select.

        Calls self.open() if needed.

        Raises exc:`ServerSelectionTimeoutError` after
        `server_selection_timeout` if no matching servers are found.
        N)rD   server_selection_timeoutrS   _select_servers_loopget_server_by_addressaddress)rb   selectorrs   rv   server_timeoutrN   sds          r(   select_serverszTopology.select_servers   s    & $+!^^DDN5NZZ 	3"&";";.'#3 23 ..rzz: 3		3 	33		3 	3s   A3 "A."A3.A33A<c                 p   t               }||z   }| j                  j                  ||| j                  j                        }|s|dk(  s||kD  r,t        | j                  |      d|d| j                        | j                          | j                          | j                  j                  t        j                         | j                  j                          t               }| j                  j                  ||| j                  j                        }|s| j                  j                          |S )z7select_servers() guts. Hold the lock when calling this.)custom_selectorr   z, Timeout: zs, Topology Description: )_timerH   apply_selectorrD   server_selectorr   _error_messagedescriptionrp   _request_check_allrU   waitr   MIN_HEARTBEAT_INTERVALcheck_compatible)rb   rw   timeoutrv   nowend_timerN   s          r(   rt   zTopology._select_servers_loop   s   g="//>>gt~~/M/M ? O &!|sX~1((2GT=M=MOP P !##% OO  !>!>?..0'C"&"3"3"B"B' $ > > #C #@# &* 	**,""r3   c                 N    t        j                  | j                  |||            S )zALike select_servers, but choose a random server if several match.)randomchoicerz   )rb   rw   rs   rv   s       r(   select_serverzTopology.select_server   s*    
 }}T001I18: ; 	;r3   c                 0    | j                  t        ||      S )a  Return a Server for "address", reconnecting if necessary.

        If the server's type is not known, request an immediate check of all
        servers. Time out after "server_selection_timeout" if the server
        cannot be reached.

        :Parameters:
          - `address`: A (host, port) pair.
          - `server_selection_timeout` (optional): maximum seconds to wait.
            If not provided, the default value
            common.SERVER_SELECTION_TIMEOUT is used.

        Calls self.open() if needed.

        Raises exc:`ServerSelectionTimeoutError` after
        `server_selection_timeout` if no matching servers are found.
        )r   r   )rb   rv   rs   s      r(   select_server_by_addressz!Topology.select_server_by_address   s     & !!"5":")+ 	+r3   c                    | j                   }|j                  |j                     }t        ||      ry| j                  xs | j
                  xr ||k(  }| j                  rK|sI| j                  j                  | j                  j                  |||j                  | j                  ff       t        | j                   |      | _         | j                          | j                  |j                         | j
                  rJ|sH| j                  j                  | j                  j                  || j                   | j                  ff       | j                   rS|j"                  t$        j&                  k(  r6| j                   j"                  t(        vr| j                   j+                          |rA| j,                  j/                  |j                        }|r|j0                  j3                          | j4                  j7                          y)ziProcess a new ServerDescription on an opened topology.

        Hold the lock when calling this.
        N)rH   _server_descriptionsrv   _is_stale_server_descriptionr=   r?   r@   rB   r;   "publish_server_description_changedr8   r	   _update_servers_receive_cluster_time_no_lockcluster_timerJ   r`   topology_typer   rI   r   r^   rV   getpoolro   rU   
notify_all)rb   server_description
reset_pooltd_oldsd_oldsuppress_eventservers          r(   _process_changezTopology._process_change  s   
 "",,-?-G-GH'0BC//C43C3C ;$(:: 	LLBB+#++T->->@A B
 913 	**+=+J+JKNLLDD**D,=,=>@ A &"6"6-:O:O"O&*&7&7&E&E"8'9##% ]]&&'9'A'ABF!!# 	""$r3   c                     | j                   5  | j                  r7| j                  j                  |j                        r| j                  ||       ddd       y# 1 sw Y   yxY w)zAProcess a new ServerDescription after an ismaster call completes.N)rS   rP   rH   
has_serverrv   r   )rb   r   r   s      r(   	on_changezTopology.on_change;  sY     ZZ 	E %%001C1K1KL$$%7D	E 	E 	Es   AAA#c                    | j                   }t        | j                   |      | _         | j                          | j                  rI| j                  j                  | j                  j                  || j                   | j                  ff       yy)z_Process a new seedlist on an opened topology.
        Hold the lock when calling this.
        N)	rH   r
   r   r?   r@   rB   r;   rJ   r8   )rb   seedlistr   s      r(   _process_srv_updatezTopology._process_srv_updateK  s     ""Ex) 	LLDD**D,=,=>@ A r3   c                     | j                   5  | j                  r| j                  |       ddd       y# 1 sw Y   yxY w)z?Process a new list of nodes obtained from scanning SRV records.N)rS   rP   r   )rb   r   s     r(   on_srv_updatezTopology.on_srv_updateZ  s5     ZZ 	3||((2	3 	3 	3s   4=c                 8    | j                   j                  |      S )aJ  Get a Server or None.

        Returns the current version of the server immediately, even if it's
        Unknown or absent from the topology. Only use this in unittests.
        In driver code, use select_server_by_address, since then you're
        assured a recent view of the server's type and wire protocol version.
        )rV   r   rb   rv   s     r(   ru   zTopology.get_server_by_addressa  s     }}  ))r3   c                     || j                   v S r0   )rV   r   s     r(   r   zTopology.has_serverk  s    $--''r3   c                     | j                   5  | j                  j                  }|t        j                  k7  r
	 ddd       yt        | j                               d   j                  cddd       S # 1 sw Y   yxY w)z!Return primary's address or None.Nr   )rS   rH   r   r   ReplicaSetWithPrimaryr   _new_selectionrv   )rb   r   s     r(   get_primaryzTopology.get_primaryn  sp     ZZ 	N --;;M C CC	N 	N
 ,D,?,?,AB1EMM	N 	N 	Ns   +A0%A00A9c                 T   | j                   5  | j                  j                  }|t        j                  t        j
                  fvrt               cddd       S t         || j                               D cg c]  }|j                   c}      cddd       S c c}w # 1 sw Y   yxY w)z+Return set of replica set member addresses.N)	rS   rH   r   r   r   ReplicaSetNoPrimarysetr   rv   )rb   rw   r   ry   s       r(   _get_replica_set_membersz!Topology._get_replica_set_membersx  s     ZZ 	O --;;M]%H%H%2%F%F%H Hu		O 	O Xd6I6I6K-LMr

MN	O 	O N	O 	Os$   ABB6B
	BBB'c                 ,    | j                  t              S )z"Return set of secondary addresses.)r   r   rq   s    r(   get_secondarieszTopology.get_secondaries  s    ,,-FGGr3   c                 ,    | j                  t              S )z Return set of arbiter addresses.)r   r   rq   s    r(   get_arbiterszTopology.get_arbiters  s    ,,-DEEr3   c                     | j                   S )z1Return a document, the highest seen $clusterTime.rX   rq   s    r(   max_cluster_timezTopology.max_cluster_time  s    %%%r3   c                 \    |r*| j                   r|d   | j                   d   kD  r|| _         y y y )NclusterTimer   rb   r   s     r(   r   z&Topology._receive_cluster_time_no_lock  s=     **.**=9:)5&: r3   c                 h    | j                   5  | j                  |       d d d        y # 1 sw Y   y xY wr0   )rS   r   r   s     r(   receive_cluster_timezTopology.receive_cluster_time  s,    ZZ 	=..|<	= 	= 	=s   (1c                     | j                   5  | j                          | j                  j                  |       ddd       y# 1 sw Y   yxY w)z=Wake all monitors, wait for at least one to check its server.N)rS   r   rU   r   )rb   	wait_times     r(   request_check_allzTopology.request_check_all  s<    ZZ 	,##%OO  +	, 	, 	,s   ,AAc                     t        |d|d      }| j                  5  | j                  j                  |      }|r-| j	                  t        ||      d       |j                          ddd       y# 1 sw Y   yxY w)z@Clear our pool for a server, mark it Unknown, and check it soon.i{'  )codeerrmsgerrorTN)r   rS   rV   r   r   r   request_check)rb   rv   	error_msgr   r   s        r(   handle_getlasterrorzTopology.handle_getlasterror  sm    y5I*NOZZ 	']]&&w/F$$%gU;TC$$&	' 	' 	's   AA00A9c                     | j                   j                  t        j                  k(  r| j                   j                  S | j                   j
                  S )z~Return a list of all data-bearing servers.

        This includes any server that might be selected for an operation.
        )rH   r   r   Singleknown_serversreadable_serversrq   s    r(   data_bearing_serverszTopology.data_bearing_servers  sB    
 **m.B.BB$$222  111r3   c                 B   g }| j                   5  | j                         D ]B  }| j                  |j                     }|j	                  ||j
                  j                  f       D 	 d d d        |D ]!  \  }}|j
                  j                  ||       # y # 1 sw Y   0xY wr0   )rS   r   rV   rv   appendr   
generationremove_stale_sockets)rb   all_credentialsserversry   r   r   s         r(   update_poolzTopology.update_pool  s    ZZ 	A//1 Arzz2(>(>?@A	A #* 	JFJKK,,ZI	J	A 	As   ABBc                    | j                   5  | j                  j                         D ]  }|j                           | j                  j                         | _        | j                  j                         j                         D ](  \  }}|| j                  v s|| j                  |   _        * | j                  r| j                  j                          d| _
        ddd       | j                  r<| j                  j                  | j                  j                  | j                   ff       | j"                  s| j                  r| j$                  j                          yy# 1 sw Y   xY w)z?Clear pools and terminate monitors. Topology reopens on demand.FN)rS   rV   valuesr^   rH   ro   rN   itemsr   r`   rP   r?   r@   rB   r;   publish_topology_closedr8   r=   rA   )rb   r   rv   ry   s       r(   r^   zTopology.close  s*   ZZ 	!--..0  !% 1 1 7 7 9D#00DDFLLN <dmm+9;DMM'*6<
   !!'') DL	!" LLdooEE#0024 54#3#3""((* $4)	! 	!s   BE AE  E)c                     | j                   S r0   )rH   rq   s    r(   r   zTopology.description  s       r3   c                 z    | j                   5  | j                  j                         cddd       S # 1 sw Y   yxY w)z"Pop all session ids from the pool.N)rS   rY   pop_allrq   s    r(   pop_all_sessionszTopology.pop_all_sessions  s0    ZZ 	0%%--/	0 	0 	0s   1:c                 F   | j                   5  | j                  j                  }|| j                  j                  t        j
                  k(  rB| j                  j                  sm| j                  t        | j                  j                  d       nA| j                  j                  s+| j                  t        | j                  j                  d       | j                  j                  }|t        d      | j                  j                  |      cddd       S # 1 sw Y   yxY w)z>Start or resume a server session, or raise ConfigurationError.Nz5Sessions are not supported by this MongoDB deployment)rS   rH   logical_session_timeout_minutesr   r   r   has_known_serversrt   r   rD   rs   r   r   r   rY   get_server_session)rb   session_timeouts     r(   r   zTopology.get_server_session  s    ZZ 	J"//OOO&$$22m6J6JJ,,>>11/ NNCC " **;;--0??
 #//OOO&(KM M %%88I+	J 	J 	Js   D DD c                     |rJ| j                   5  | j                  j                  }|| j                  j	                  ||       d d d        y | j                  j                  |       y # 1 sw Y   y xY wr0   )rS   rH   r   rY   return_server_sessionreturn_server_session_no_lock)rb   server_sessionlockr   s       r(   r   zTopology.return_server_session  su     N%%EE  ".&&<<^=LN	N N <<^LN Ns   5A))A2c                 @    t        j                  | j                        S )zmA Selection object, initially including all known servers.

        Hold the lock when calling this.
        )r   from_topology_descriptionrH   rq   s    r(   r   zTopology._new_selection  s    
 2243D3DEEr3   c                    | j                   sd| _         | j                          | j                  s| j                  r| j                  j                          | j                  r6| j                  j                  t        v r| j                  j                          t        | j                        D ]  }|j                           y)z[Start monitors, or restart after a fork.

        Hold the lock when calling this.
        TN)rP   r   r?   r=   rA   r_   r`   r   r   r   r   rV   rb   r   s     r(   rp   zTopology._ensure_opened  s    
 ||DL  " 4#7#7&&++-   d&6&6&D&D&<'=!!&&( !/ 	FKKM	r3   c                 l   | j                   j                  |      }|y|j                  |j                  j                  k7  ry|j
                  j                  }|j                  }d }|rAt        |d      r5t        |j                  t              r|j                  j                  d      }t        ||      S )NTdetailstopologyVersion)rV   r   sock_generation_poolr   r   topology_versionr   hasattr
isinstancer   dict _is_stale_error_topology_version)rb   rv   err_ctxr   cur_tvr   error_tvs          r(   _is_stale_errorzTopology._is_stale_error*  s    ""7+>""fll&=&== ##44WUI.%--. ==,,->?/AAr3   c                 *   | j                  ||      ry | j                  |   }|j                  }t        |      }t	        |t
              r|j                  ry t	        |t              r||j                  j                  dd      }|t        j                  v }| j                  t        ||             |s|j                  dk  r|j                          |j!                          y t	        |t"              rG| j                  t        ||             |j                          |j$                  j'                          y t	        |t(              rJ|j*                  t        j,                  v r-| j                  t        ||             |j                          y y y )Nr   r      )r   rV   r   type
issubclassr   completed_handshaker   r   r   r   _SHUTDOWN_CODESr   r   max_wire_versionro   r   r   _monitorcancel_checkr   r   _NOT_MASTER_CODES)rb   rv   r   r   r   exc_typeerr_codeis_shutting_downs           r(   _handle_errorzTopology._handle_error>  sA   1w';x0++
 .1 }}((4H'7+B+BB  !27%!HIG$<$<$A  ""34   !27%!HILLN OO((*"23 zzW666$$%6we%LM 7 4r3   c                 j    | j                   5  | j                  ||       ddd       y# 1 sw Y   yxY w)zHandle an application error.

        May reset the server to Unknown, clear the pool, and request an
        immediate check depending on the error and the context.
        N)rS   r	  )rb   rv   r   s      r(   handle_errorzTopology.handle_erroro  s0     ZZ 	1w0	1 	1 	1s   )2c                 b    | j                   j                         D ]  }|j                           y)z3Wake all monitors. Hold the lock when calling this.N)rV   r   r   r   s     r(   r   zTopology._request_check_allx  s*    mm**, 	#F  "	#r3   c           	         | j                   j                         j                         D ]G  \  }}|| j                  vr| j                  j                  || | j                  |      | j                        }d}| j                  rt        j                  | j                        }t        || j                  |      || j                  | j                  |      }|| j                  |<   |j                          | j                  |   j                   j"                  }|| j                  |   _        ||j"                  k7  s| j                  |   j$                  j'                  |j"                         J t)        | j                  j                               D ]L  \  }}| j                   j+                  |      r"|j-                          | j                  j/                  |       N y)zrSync our Servers from TopologyDescription.server_descriptions.

        Hold the lock while calling this.
        )r   topologyr   rc   N)r   r   monitortopology_id	listenersevents)rH   rN   r   rV   rD   monitor_class_create_pool_for_monitorr=   r\   r]   r@   r   _create_pool_for_serverr8   r;   r_   r   is_writabler   update_is_writablerM   r   r^   pop)rb   rv   ry   r  r1   r   was_writables          r(   r   zTopology._update_servers}  s   
  ,,@@BHHJ 	(KGRdmm+..66')!66w?&*nn	 7 6 ''";;t||4D')55g># $ 1 1"oo! *0g&  $}}W5AAMM57g&22>>1MM'*//BB(9	(>  $DMM$7$7$9: 	+OGV$$//8!!'*	+r3   c                 b    | j                   j                  || j                   j                        S r0   )rD   
pool_classpool_optionsr   s     r(   r  z Topology._create_pool_for_server  s#    ~~(($..2M2MNNr3   c           	         | j                   j                  }t        |j                  |j                  |j                  |j
                  |j                  |j                  |j                        }| j                   j                  ||d      S )N)connect_timeoutsocket_timeoutssl_contextssl_match_hostnamer:   appnamedriverF)	handshake)
rD   r  r   r  r   r!  r:   r"  r#  r  )rb   rv   optionsmonitor_pool_optionss       r(   r  z!Topology._create_pool_for_monitor  s    ..--
  +#33"22++&99#33OO>> # ~~((2F38 ) : 	:r3   c                    | j                   j                  t        j                  t        j                  fv }|rd}n,| j                   j                  t        j
                  k(  rd}nd}| j                   j                  r|t        u r|ryd|z  S d|d|dS t        | j                   j                               }t        | j                   j                         j                               }|s$|rd|d	| j                  j                  dS d
|z  S |d   j                  t        fd|dd D              }|r=d|z  S |r)t        |      j!                  | j"                        sd|z  S t%              S dj'                  d |D              S )zeFormat an error message if server selection fails.

        Hold the lock when calling this.
        zreplica set membersmongosesr   zNo primary available for writeszNo %s available for writeszNo z match selector ""z! available for replica set name "zNo %s availabler   c              3   <   K   | ]  }|j                   k(    y wr0   r   ).0r   r   s     r(   	<genexpr>z*Topology._error_message.<locals>.<genexpr>  s     Gv||u,Gs      NzNo %s found yetz\Could not reach any servers in %s. Replica set is configured with internal hostnames or IPs?,c              3   ^   K   | ]%  }|j                   rt        |j                          ' y wr0   )r   str)r+  r   s     r(   r,  z*Topology._error_message.<locals>.<genexpr>  s'       1f#)<< !$FLL 1  1s   +-)rH   r   r   r   r   Shardedr   r   rM   rN   r   rD   rG   r   allr   intersectionrO   r0  join)rb   rw   is_replica_setserver_plural	addressesr   samer   s          @r(   r   zTopology._error_message  s   
 **88//--=/ / 1M,,0E0EE&M%M**33!<7-GG	 4 7DXNNT..BBDEI4,,@@BIIKLG! &t~~'F'FH H -}<< AJ$$EG712;GGD=,}<<"I33D4H4HIF!"#
 5z!xx  1  1 1 1r3   c                 t    d}| j                   sd}d| j                  j                  d|| j                  dS )N zCLOSED < >)rP   	__class____name__rH   )rb   msgs     r(   __repr__zTopology.__repr__  s1    ||C"nn55sD<M<MNNr3   )NNr0   )F)   ),r?  
__module____qualname____doc__ri   r_   rz   rt   r   r   r   r   r   r   ru   r   r   r   r   r   r   r   r   r   r   r   r   r^   propertyr   r   r   r   r   rp   r   r	  r  r   r   r  r  r   rA   r3   r(   r+   r+   I   s   4DAL"> 15#3>#B 04"; ;?+.-%^E A3*(N	OHF&6=,'2
J+2 ! !0
J2
MF,B(/b1#
'+RO:$71rOr3   r+   c                       e Zd ZdZd Zy)_ErrorContextz.An error with context for SDAM error handling.c                 <    || _         || _        || _        || _        y r0   )r   r  r   r   )rb   r   r  r   r   s        r(   ri   z_ErrorContext.__init__  s!    
 0.#6 r3   N)r?  rC  rD  rE  ri   rG  r3   r(   rI  rI    s
    87r3   rI  c                 :    | |y| d   |d   k7  ry| d   |d   k\  S )z9Return True if the error's topologyVersion is <= current.F	processIdcounterrG  )
current_tvr   s     r(   r   r     s:    X-+(;"77i HY$777r3   c                 j    | j                   |j                   }}||y|d   |d   k7  ry|d   |d   kD  S )z4Return True if the new topologyVersion is < current.FrL  rM  )r   )
current_sdnew_sdrN  new_tvs       r(   r   r     sN    #44f6M6MJV^+&"55i 6)#444r3   )6rE  rk   r   rQ   rm   r\   bson.py3compatr   r   queuer!   pymongor   r   r   pymongo.poolr   pymongo.topology_descriptionr	   r
   r   r   r   pymongo.errorsr   r   r   r   r   r   pymongo.monitorr   pymongo.monotonicr   r}   pymongo.serverr   pymongo.server_descriptionr   pymongo.server_selectorsr   r   r   r   r   r   pymongo.client_sessionr   r)   objectr+   rI  r   r   rG  r3   r(   <module>r`     s    C 	     *( ( %Q Q9 9 ' + ! 81 1 6"o
Ov o
Od7F 785r3   