+
    8i                    J   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIHt ^ RIHtHtHtHtHtHt ^ RIHtHtHtHt ^ RIHtHt ^ RIHtHt ^ RI H!t! ^ R	I"H#t# ^ R
I$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t- ^ RI.H/t/ ^ RI0H1t1H2t2H3t3 ^ RI4H5t5H6t6H7t7H8t8H9t9 ^ RI:H;t; ^ RI<H=t= ^ RI>H?t?H@t@HAtAHBtBHCtC ^ RIDHEtEHFtFHGtGHHtHHItI ]'       d   ^ RIJHKtK ^ RILHMtM ^ RINHOtOHPtP RtQ]R! ]! ]S4      P                  4      tUR R ltV ! R R4      tW ! R R4      tXR R ltYR R ltZR# ) z<Internal class to monitor a topology of one or more servers.)annotationsN)Path)TYPE_CHECKINGAnyCallableMappingOptionalcast)_csotcommonhelpers_sharedperiodic_executor)_ServerSession_ServerSessionPool)MonitorBase
SrvMonitor)Pool)Server)	ConnectionFailureInvalidOperationNetworkTimeoutNotPrimaryErrorOperationFailurePyMongoErrorServerSelectionTimeoutErrorWaitQueueTimeoutError
WriteError)Hello)_async_cond_wait_async_create_condition_async_create_lock)_SDAM_LOGGER_SERVER_SELECTION_LOGGER
_debug_log_SDAMStatusMessage_ServerSelectionStatusMessage)PoolOptions)ServerDescription)	Selectionany_server_selectorarbiter_server_selectorsecondary_server_selectorwritable_server_selector)SRV_POLLING_TOPOLOGIESTOPOLOGY_TYPETopologyDescription)_updated_topology_description_srv_pollingupdated_topology_description)ObjectId)TopologySettings)ClusterTime_AddressFc                    V ^8  d   QhRRRR/# )   	queue_refz"weakref.ReferenceType[queue.Queue]returnbool )formats   "[/var/www/html/photoedit/myenv/lib/python3.14/site-packages/pymongo/asynchronous/topology.py__annotate__r>   W   s      $F 4     c                    V ! 4       pV'       g   R #   VP                  4       pVw  r4V! V!   K    \        P                   d     R# i ; i)FT)
get_nowaitqueueEmpty)r8   qeventfnargss   &    r=   process_events_queuerH   W   sO    A
	LLNE HBI	 {{ 	
 	s   0 A	A	c                  T   ] tR t^htRtR R ltR R ltR R ltR\R	 R
 lltR]R R llt	R\R R llt
R\R R lltR^R R lltR_R R lltR_R R lltR R ltR R ltR R ltR R ltR R  ltR! R" ltR# R$ ltR% R& ltR' R( ltR) R* ltR+ R, ltR`R- R. lltR/ R0 ltR1 R2 ltR3 R4 lt]R5 R6 l4       tR7 R8 lt R9 R: lt!R; R< lt"R= R> lt#R? R@ lt$RA RB lt%RC RD lt&RE RF lt'RG RH lt(RI RJ lt)RK RL lt*RM RN lt+RO RP lt,RQ RR lt-RS RT lt.RU RV lt/RW RX lt0RY RZ lt1R[t2R# )aTopologyz*Monitor a topology of one or more servers.c                   V ^8  d   QhRR/# )r7   topology_settingsr3   r;   )r<   s   "r=   r>   Topology.__annotate__k   s     m4 m4*: m4r?   c           	     	  a VP                   V n         VP                  P                  V n        V P                  R J;'       d    V P                  P                  V n        V P                  R J;'       d    V P                  P                  V n        R V n        R V n	        V P
                  '       g   V P                  '       d   \        P                  ! ^dR7      V n        \        P                  ! \        P                  4      '       d+   \!        \        \"        P$                  V P                   R7       V P                  '       d]   V P                  f   Q hV P                  f   Q hV P                  P'                  V P                  P(                  V P                   334       Wn        \-        VP/                  4       VP1                  4       VP2                  R R V4      pW n        \-        \6        P8                  / R R R V P*                  4      pV P                  '       dh   V P                  f   Q hV P                  f   Q hV P                  P'                  V P                  P:                  W0P4                  V P                   334       \        P                  ! \        P                  4      '       dI   \!        \        \"        P<                  V P                   \?        V4      \?        V P4                  4      R7       VP@                   F  pV P
                  '       d]   V P                  f   Q hV P                  f   Q hV P                  P'                  V P                  PB                  W@P                   334       \        P                  ! \        P                  4      '       g   K  \!        \        \"        PD                  V P                   V^ ,          V^,          R7       K  	  \G        VPI                  4       4      V n%        RV n&        RV n'        \Q        4       V n)        \U        V PR                  \V        '       d   V P*                  PX                  MR 4      V n-        / V n.        R V n/        R V n0        \c        4       V n2        V P
                  '       g   V P                  '       d   V P                  f   Q hR V3R llp\f        Ph                  ! \j        Pl                  \j        Pn                  VRR	7      p\p        Pr                  ! V P                  VPt                  4      oW`n	        VPw                  4        R V n<        V P*                  Pz                  e7   V P*                  P|                  '       g   \        W P*                  4      V n<        . V n@        R # )
N)maxsizemessage
topologyIdrQ   rR   previousDescriptionnewDescription)rQ   rR   
serverHost
serverPortFc                   V ^8  d   QhRR/# )r7   r9   r:   r;   )r<   s   "r=   r>   'Topology.__init__.<locals>.__annotate__   s     2 2$ 2r?   c                 "   <"   \        S 4      # 5iN)rH   )weaks   r=   target!Topology.__init__.<locals>.target   s     +D11s   pymongo_events_thread)intervalmin_intervalr]   name)A_topology_id_pool_options_event_listeners
_listenersenabled_for_server_publish_serverenabled_for_topology_publish_tp_events_Topology__events_executorrB   Queuer!   isEnabledForloggingDEBUGr#   r$   START_TOPOLOGYputpublish_topology_opened	_settingsr/   get_topology_typeget_server_descriptionsreplica_set_name_descriptionr.   Unknown$publish_topology_description_changedTOPOLOGY_CHANGEreprseedspublish_server_openedSTART_SERVERlistserver_descriptions_seed_addresses_opened_closedr    _lockr   _IS_SYNCcondition_class
_condition_servers_pid_max_cluster_timer   _session_poolr   AsyncPeriodicExecutorr   EVENTS_QUEUE_FREQUENCYMIN_HEARTBEAT_INTERVALweakrefrefcloseopen_srv_monitorfqdnload_balancedr   _monitor_tasks)selfrL   topology_description
initial_tdseedr]   executorr\   s   &&     @r=   __init__Topology.__init__k   s&   -::+99JJ#d:aat?a?a??$6__4??;_;_ 15&*4#3#3#3 ;;s3DL$$W]]33*99,, <<+++??...LLdooEEHYHYG[\]*2//1557.. 
 1(!!2tT4

 <<+++??...LLOOHH!2!2D4E4EF $$W]]33*::,,$($4#D$5$56 &++D###||///222  $//"G"G$PaPaIb!cd((77 .;;#00#Aw#Aw ,  $$8$L$L$NO')
1JJ((66
 13#'	8</14#3#3#3<<+++2 2 )>>66#::,	H ;;t||X^^<D%-"MMO >>*4>>3O3O3O *4 @D 24r?   c                   V ^8  d   QhRR/# r7   r9   Noner;   )r<   s   "r=   r>   rM      s     %( %(D %(r?   c                "  "   \         P                  ! 4       pV P                  f   Wn        MWP                  8w  d   Wn        \        P                  R,          R8  d   R\
        3/pMR^/p\        P                  ! R/ VB  V P                  ;_uu_4       GRj  xL
  V P                  P                  4        F  pVP                  4       G Rj  xL
  K  	  V P                  P                  4        RRR4      GRj  xL
  V P                  ;_uu_4       GRj  xL
  V P                  4       G Rj  xL
  RRR4      GRj  xL
  R#  L L{ LO  + GRj  xL 
 '       g   i     Lf; i LP L: L,  + GRj  xL 
 '       g   i     R# ; i5i)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, AsyncMongoClient must be created after any
  forking.

N:Nr7   Nskip_file_prefixes
stacklevel)      )zAsyncMongoClient opened before fork. May not be entirely fork-safe, proceed with caution. See PyMongo's documentation for details: https://dochub.mongodb.org/core/pymongo-fork-deadlock)osgetpidr   sysversion_info_pymongo_dirwarningswarnr   r   valuesr   r   reset_ensure_opened)r   pidkwargsservers   &   r=   r   Topology.open   s     iik99IIII#w..@&*MM  	 zzzz"mm224F ,,.(( 5 ""((* "z ::::%%''' :: " ) "zzz ' :::s   BFE
F1EE
"E3F>E?FE,FE23E.4E28FE0FEFE)	E
E)	"E)	$	F.E20F2F	8E;9
F	F		Fc                   V ^8  d   QhRR/# )r7   r9   floatr;   )r<   s   "r=   r>   rM     s      e r?   c                	d    \         P                  ! 4       pVf   V P                  P                  # V# r[   )r
   	remainingrt   server_selection_timeout)r   timeouts   & r=   get_server_selection_timeout%Topology.get_server_selection_timeout  s(    //#?>>:::r?   Nc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r7   selector Callable[[Selection], Selection]	operationstrr   Optional[float]addressOptional[_Address]operation_idOptional[int]deprioritized_serversOptional[list[Server]]r9   zlist[Server]r;   )r<   s   "r=   r>   rM     sP     - -2- - #2	-
 $- $-  6- 
-r?   c                  "   Vf   V P                  4       pMTp\        '       g+   V P                  '       d   V P                  4       G Rj  xL
  V P                  ;_uu_4       GRj  xL
  V P                  VVVVVVR7      G Rj  xL
 pV U	u. uF,  p	\        \        V P                  V	P                  4      4      NK.  	  up	uuRRR4      GRj  xL
  #  L Lp LSu up	i  L  + GRj  xL 
 '       g   i     R# ; i5i)a2  Return a list of Servers matching selector, or time out.

:param selector: function that takes a list of Servers and returns
    a subset of them.
:param operation: The name of the operation that the server is being selected for.
:param server_selection_timeout: maximum seconds to wait.
    If not provided, the default value common.SERVER_SELECTION_TIMEOUT
    is used.
:param 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)r   )
r   r   r   cleanup_monitorsr   _select_servers_loopr	   r   get_server_by_addressr   )
r   r   r   r   r   r   r   server_timeoutr   sds
   &&&&&&&   r=   select_serversTopology.select_servers  s     0 $+!>>@N5N xD///'')))::::(,(A(A&; )B ) # PcObVT77

CDOb :: *# :::s   #DDDCD(C)D,C$CC$2CC$DC"DDC$C$"D$C>	*C-+
C>	6C>	8	Dc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r7   r   r   r   r   r   r   r   r   r   r   r   r   r9   list[ServerDescription]r;   )r<   s   "r=   r>   rM   7  sY     P# P#2P# P# 	P#
 $P# $P#  6P# 
!P#r?   c                ,  "   \         P                  ! 4       pWr,           pRp	\        P                  ! \        P
                  4      '       dM   \        \        \        P                  VVVV P                  V P                  P                  P                  R7       V P                  P                  TTV P                  P                  V'       d   V U
u. uF  qP                  NK  	  up
MRR7      pV'       Eg   V^ 8X  g   Wx8  d   \        P                  ! \        P
                  4      '       d]   \        \        \        P                   VVVV P                  V P                  P                  P                  V P#                  V4      R7       \%        V P#                  V4       RV RV P                  : 24      hV	'       gz   \        \        \        P&                  VVVV P                  V P                  P                  P                  \)        RV\         P                  ! 4       ,
          ,          4      R	7       R
p	V P+                  4       G Rj  xL
  V P-                  4        \/        V P0                  \2        P4                  4      G Rj  xL
  V P                  P7                  4        \         P                  ! 4       pV P                  P                  WV P                  P                  R7      pEK  V P                  P7                  4        V# u up
i  L L5i)z7select_servers() guts. Hold the lock when calling this.F)rQ   r   r   operationIdtopologyDescriptionclientIdN)custom_selectorr   )rQ   r   r   r   r   r   failurez, Timeout: zs, Topology Description: i  )rQ   r   r   r   r   r   remainingTimeMST)r   )time	monotonicr"   rn   ro   rp   r#   r%   STARTEDdescription_topology_settingsrc   rx   apply_selectorrt   server_selectorFAILED_error_messager   WAITINGintr   _request_check_allr   r   r   r   check_compatible)r   r   r   r   r   r   r   nowend_timelogged_waitingr   r   s   &&&&&&&     r=   r   Topology._select_servers_loop7  s|     nn=#00??(5==!#($($4$4))<<II #//>> NN::$ EZ"ZDY&#5#5DY"Z ? 
 &%!|s~+88GG0 = D D!)"+$0,0,<,<!%!1!1!D!D!Q!Q $ 3 3H =	 2**845[	Ibcgcscsbvw  ",9AA%' ,(,(8(8!--@@MM$'4>>;K0K(L$M	 "&%%'''##% #4??F4Q4QRRR..0.."C"&"3"3"B"B4>>3Q3Q #C # 	**,""g #[H ( SsK   C	LLL$L76L.BL?BLL;LLB	LLc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# r7   r   r   r   r   r   r   r   r   r   r   r   r   r9   r   r;   )r<   s   "r=   r>   rM     sP      2  #2	
 $  6 $ 
r?   c                	  "   V P                  VVVVVV4      G R j  xL
 p\        V4      ^8X  d
   V^ ,          # \        P                  ! V^4      w  rVP                  P
                  V	P                  P
                  8:  d   V# V	#  Li5ir[   )r   lenrandomsamplepooloperation_count)
r   r   r   r   r   r   r   serversserver1server2s
   &&&&&&&   r=   _select_serverTopology._select_server  s      ++$!
 
 w<11:!==!4<<''7<<+G+GGNN
s   BBA*Bc               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# r   r;   )r<   s   "r=   r>   rM     sP        2    #2	 
 $   6  $  
 r?   c                6  "   V P                  VVVVVVR7      G Rj  xL
 p\        P                  ! 4       '       d+   \        P                  ! VP                  P
                  4       \        P                  ! \        P                  4      '       d   \        \        \        P                  VVVV P                  V P                  P                  P                  VP                  P                  ^ ,          VP                  P                  ^,          R7	       V#  L5i)zALike select_servers, but choose a random server if several match.r   N)rQ   r   r   r   r   r   rV   rW   )r   r
   get_timeoutset_rttr   min_round_trip_timer"   rn   ro   rp   r#   r%   	SUCCEEDEDr   rc   r   )r   r   r   r   r   r   r   r   s   &&&&&&& r=   select_serverTopology.select_server  s      **$!% + 
 
 MM&,,@@A#00??(5??!#($($4$4))<<II!--55a8!--55a8
 -
s   DDDADBDc          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r7   r   r5   r   r   r   r   r   r9   r   r;   )r<   s   "r=   r>   rM     s<     
 

 
 #0	

 $
 

r?   c                R   "   V P                  \        VVVVR7      G Rj  xL
 #  L5i)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.

:param address: A (host, port) pair.
:param operation: The name of the operation that the server is being selected for.
:param server_selection_timeout: maximum seconds to wait.
    If not provided, the default value
    common.SERVER_SELECTION_TIMEOUT is used.
:param operation_id: The unique id of the current operation being performed. Defaults to None if not provided.

Calls self.open() if needed.

Raises exc:`ServerSelectionTimeoutError` after
`server_selection_timeout` if no matching servers are found.
r   N)r   r)   )r   r   r   r   r   s   &&&&&r=   select_server_by_address!Topology.select_server_by_address  s8     2 ''$% ( 
 
 	
 
s   '%'c               (    V ^8  d   QhRRRRRRRR/# r7   server_descriptionr'   
reset_poolr:   interrupt_connectionsr9   r   r;   )r<   s   "r=   r>   rM     s8     E% E%-E% E%  $	E%
 
E%r?   c           	       "   V P                   pVP                  VP                  ,          p\        WQ4      '       d   R# \	        V P                   V4      pVP
                  '       g2   VP                  '       do   VP                  \        P                  8X  dP   V P                  P                  VP                  4      pV'       d#   VP                  P                  4       G Rj  xL
  WQ8H  pV P                  '       dq   V'       gi   V P                  f   Q hV P                   f   Q hV P                  P#                  V P                   P$                  WQVP                  V P&                  334       W`n         V P)                  4       G Rj  xL
  V P*                  '       dp   V'       gh   V P                  f   Q hV P                   f   Q hV P                  P#                  V P                   P,                  W@P                   V P&                  334       \.        P0                  ! \2        P4                  4      '       dQ   V'       gI   \7        \.        \8        P:                  V P&                  \=        V4      \=        V P                   4      R7       V P>                  '       d   VP                  \        P@                  8X  ds   V P                   P                  \B        9  dT   V P>                  PE                  4       G Rj  xL
  \F        '       g&   V PH                  PK                  V P>                  4       V PL                  PO                  4        R#  ELc EL LW5i)zYProcess a new ServerDescription on an opened topology.

Hold the lock when calling this.
NrS   )(rx   _server_descriptionsr   _is_stale_server_descriptionr1   is_readableis_server_type_knowntopology_typer.   Singler   getr   readyrh   rk   rf   rr   "publish_server_description_changedrc   _update_serversrj   rz   r!   rn   ro   rp   r#   r$   r{   r|   r   ry   r-   r   r   r   appendr   
notify_all)	r   r  r  r	  td_oldsd_oldnew_tdr   suppress_events	   &&&&     r=   _process_changeTopology._process_change  sv     "",,-?-G-GH'CC-d.?.?AST)))3338L8LP]PdPd8d]]&&'9'A'ABFkk'')))5<<+++??...LLOOFF1C1K1KTM^M^_ #""$$$N<<+++??...LLOOHH..0A0AB $$W]]33N*::,,$(L#D$5$56   M$9$99!!//7MM##))+++8##**4+<+<= 	""$] * 	%6 ,sr   A6M9AMM"M#!MBMMMM%BM6M>AMAM3M4MAMMMc               (    V ^8  d   QhRRRRRRRR/# r  r;   )r<   s   "r=   r>   rM   ,  s8     U U-U U  $	U
 
Ur?   c                  "   V P                   ;_uu_4       GRj  xL
  V P                  '       dF   V P                  P                  VP                  4      '       d   V P                  WV4      G Rj  xL
  RRR4      GRj  xL
  V'       dV   V P                  P                  VP                  4      pV'       d'   VP                  P                  VR7      G Rj  xL
  R# R# R#  L Lu Lg  + GRj  xL 
 '       g   i     L~; i L,5i)z>Process a new ServerDescription after an hello call completes.N)r	  )
r   r   rx   
has_serverr   r  r   r  r   r   )r   r  r  r	  r   s   &&&& r=   	on_changeTopology.on_change,  s      :::: ||| 1 1 < <=O=W=W X X**+=K`aaa : ]]&&'9'A'ABFkk''>S'TTT    b ::: Usz   D
C&D
=C,C,2C(3C,7D
C*D
,D
<D
DD
(C,*D
,D	2C53
D	>D	 	D
c                    V ^8  d   QhRRRR/# r7   seedlistzlist[tuple[str, Any]]r9   r   r;   )r<   s   "r=   r>   rM   E  s      2G D r?   c           	       "   V P                   pVP                  \        9  d   R# \        V P                   V4      V n         V P	                  4       G Rj  xL
  V P
                  '       dh   V P                  f   Q hV P                  f   Q hV P                  P                  V P                  P                  W P                   V P                  334       \        P                  ! \        P                  4      '       dK   \        \        \         P"                  V P                  \%        V4      \%        V P                   4      R7       R# R#  L5i)zOProcess a new seedlist on an opened topology.
Hold the lock when calling this.
NrS   )rx   r  r-   r0   r  rj   rk   rf   rr   rz   rc   r!   rn   ro   rp   r#   r$   r{   r|   )r   r$  r  s   && r=   _process_srv_updateTopology._process_srv_updateE  s     ""'==EdFWFWYab""$$$<<+++??...LLOOHH..0A0AB $$W]]33*::,,$(L#D$5$56 4 	%s    AE
EE
+BE
<AE
c                    V ^8  d   QhRRRR/# r#  r;   )r<   s   "r=   r>   rM   b  s     9 9,A 9d 9r?   c                  "   V P                   ;_uu_4       GRj  xL
  V P                  '       d   V P                  V4      G Rj  xL
  RRR4      GRj  xL
  R#  LA L L
  + GRj  xL 
 '       g   i     R# ; i5i)z?Process a new list of nodes obtained from scanning SRV records.N)r   r   r&  )r   r$  s   &&r=   on_srv_updateTopology.on_srv_updateb  sF      ::::|||..x888 ::8 :::s\   B AB 'A#AA#B A!B A#!B #A=	)A,*
A=	5A=	7	B c                    V ^8  d   QhRRRR/# )r7   r   r5   r9   zOptional[Server]r;   )r<   s   "r=   r>   rM   i  s     * *X *:J *r?   c                8    V P                   P                  V4      # )a"  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.
)r   r  r   r   s   &&r=   r   Topology.get_server_by_addressi  s     }}  ))r?   c                    V ^8  d   QhRRRR/# )r7   r   r5   r9   r:   r;   )r<   s   "r=   r>   rM   s  s     ( (( (t (r?   c                	    WP                   9   # r[   )r   r.  s   &&r=   r  Topology.has_servers  s    --''r?   c                   V ^8  d   QhRR/# )r7   r9   r   r;   )r<   s   "r=   r>   rM   v  s     N N#5 Nr?   c                ~  "   V P                   ;_uu_4       GRj  xL
  V P                  P                  pV\        P                  8w  d    RRR4      GRj  xL
  R# \        V P                  4       4      ^ ,          P                  uuRRR4      GRj  xL
  #  L~ LD L	  + GRj  xL 
 '       g   i     R# ; i5i)z!Return primary's address or None.N)r   rx   r  r.   ReplicaSetWithPrimaryr,   _new_selectionr   )r   r  s   & r=   get_primaryTopology.get_primaryv  sl      :::: --;;M C CC ::
 ,D,?,?,AB1EMM ::::::sh   B=BB=-B B=BB=)B B=BB=B=B= B:	&B)'
B:	2B:	4	B=c                    V ^8  d   QhRRRR/# )r7   r   r   r9   set[_Address]r;   )r<   s   "r=   r>   rM     s      P P8P	Pr?   c                  "   V P                   ;_uu_4       GRj  xL
  V P                  P                  pV\        P                  \        P
                  39  d   \        4       uuRRR4      GRj  xL
  # \        V! V P                  4       4      4       Uu0 uF  q3P                  kK  	  upuuRRR4      GRj  xL
  #  L LQu upi  L  + GRj  xL 
 '       g   i     R# ; i5i)z+Return set of replica set member addresses.N)
r   rx   r  r.   r5  ReplicaSetNoPrimarysetiterr6  r   )r   r   r  r   s   &&  r=   _get_replica_set_members!Topology._get_replica_set_members  s     
 :::: --;;M3311%  u :: *.ht7J7J7L.M)NO)N2JJ)NO :: P :::s{   C)CC)AC$C)1C2C)7!CC,C.C);C
<C)C)C
C)C&	C
C&	C&	 	C)c                   V ^8  d   QhRR/# r7   r9   r:  r;   )r<   s   "r=   r>   rM     s     N N} Nr?   c                H   "   V P                  \        4      G Rj  xL
 #  L5i)z"Return set of secondary addresses.N)r?  r+   r   s   &r=   get_secondariesTopology.get_secondaries  s     223LMMMM   " "c                   V ^8  d   QhRR/# rB  r;   )r<   s   "r=   r>   rM     s     L LM Lr?   c                H   "   V P                  \        4      G Rj  xL
 #  L5i)z Return set of arbiter addresses.N)r?  r*   rD  s   &r=   get_arbitersTopology.get_arbiters  s     223JKKKKrG  c                   V ^8  d   QhRR/# )r7   r9   zOptional[ClusterTime]r;   )r<   s   "r=   r>   rM     s     & &"7 &r?   c                    V P                   # )z1Return a document, the highest seen $clusterTime.r   rD  s   &r=   max_cluster_timeTopology.max_cluster_time  s    %%%r?   c                    V ^8  d   QhRRRR/# r7   cluster_timeOptional[Mapping[str, Any]]r9   r   r;   )r<   s   "r=   r>   rM     s     6 6:U 6Z^ 6r?   c                	    V'       d<   V P                   '       d    VR ,          V P                   R ,          8  d	   Wn         R# R# R# )clusterTimeNrN  r   rS  s   &&r=   _receive_cluster_time_no_lock&Topology._receive_cluster_time_no_lock  s>      ***.1G1G1VV)5& W	 r?   c                    V ^8  d   QhRRRR/# rR  r;   )r<   s   "r=   r>   rM     s     = =7R =W[ =r?   c                	   "   V P                   ;_uu_4       GR j  xL
  V P                  V4       R R R 4      GR j  xL
  R #  L' L  + GR j  xL 
 '       g   i     R # ; i5ir[   )r   rX  rW  s   &&r=   receive_cluster_timeTopology.receive_cluster_time  s-     ::::..|< :::::sG   A$AA$AA$AA$A$A!	A
A!	A!		A$c                    V ^8  d   QhRRRR/# )r7   	wait_timer   r9   r   r;   )r<   s   "r=   r>   rM     s     ? ? ?T ?r?   c                
  "   V P                   ;_uu_4       GRj  xL
  V P                  4        \        V P                  V4      G Rj  xL
  RRR4      GRj  xL
  R#  LD L L
  + GRj  xL 
 '       g   i     R# ; i5i)z=Wake all monitors, wait for at least one to check its server.N)r   r   r   r   )r   r_  s   &&r=   request_check_allTopology.request_check_all  sG     ::::##%"4??I>>> ::> :::s\   BA B*A&	A"
A&BA$B"A&$B&B 	,A/-
B 	8B 	:	Bc                   V ^8  d   QhRR/# )r7   r9   r   r;   )r<   s   "r=   r>   rM     s     2 2&= 2r?   c                    V P                   P                  \        P                  8X  d   V P                   P                  # V P                   P
                  # )znReturn a list of all data-bearing servers.

This includes any server that might be selected for an operation.
)rx   r  r.   r  known_serversreadable_serversrD  s   &r=   data_bearing_serversTopology.data_bearing_servers  sB    
 **m.B.BB$$222  111r?   c                   V ^8  d   QhRR/# r   r;   )r<   s   "r=   r>   rM     s      4 r?   c           	     	  "   . pV P                   ;_uu_4       GR j  xL
  V P                  4        FT  pV P                  VP                  ,          pVP	                  W3P
                  P                  P                  4       34       KV  	  R R R 4      GR j  xL
  V F)  w  r4 VP
                  P                  V4      G R j  xL
  K+  	  R #  L L7  + GR j  xL 
 '       g   i     LN; i L*  \         dE   p\        T^ TRR 4      pT P                  TP                  P                  T4      G R j  xL 
  h R p?ii ; i5i)NF)r   rg  r   r   r  r   genget_overallremove_stale_socketsr   _ErrorContexthandle_errorr   )r   r   r   r   
generationexcctxs   &      r=   update_poolTopology.update_pool  s     :::://1rzz2(C(C(EFG 2 : #*Fkk66zBBB #* ::: C #CJtD''(:(:(B(BCHHHs   D?CD?A)C
D?CD?"C- C+C-D?D?C(	C
C(	!C(	#D?+C--D<88D70D31D77D<<D?c                   V ^8  d   QhRR/# r   r;   )r<   s   "r=   r>   rM     s     B< B<T B<r?   c           	     *  "   V P                   ;_uu_4       GRj  xL
  V P                  pV P                  P                  4        FN  pVP	                  4       G Rj  xL
  \
        '       d   K)  V P                  P                  VP                  4       KP  	  V P                  P                  4       V n        V P                  P                  4       P                  4        F.  w  r4W0P                  9   g   K  W@P                  V,          n        K0  	  V P                  '       dT   V P                  P	                  4       G Rj  xL
  \
        '       g&   V P                  P                  V P                  4       RV n        RV n        RRR4      GRj  xL
  V P                   '       Ed   V P"                  f   Q hV P$                  f   Q h\'        \(        P*                  / V P                  P,                  V P                  P.                  V P                  P0                  V P                  P2                  4      V n        V P"                  P5                  V P$                  P6                  XV P                  V P8                  334       V P"                  P5                  V P$                  P:                  V P8                  334       \<        P>                  ! \@        PB                  4      '       ds   \E        \<        \F        PH                  V P8                  \K        X4      \K        V P                  4      R7       \E        \<        \F        PL                  V P8                  R7       V PN                  '       g   V P                   '       di   V PP                  P	                  4        V PP                  PS                  ^4      G Rj  xL
  \U        \V        PX                  ! V P"                  4      4       R# R#  EL EL EL ELb  + GRj  xL 
 '       g   i     ELz; i LZ5i)zClear pools and terminate monitors. Topology does not reopen on
demand. Any further operations will raise
:exc:`~.errors.InvalidOperation`.
NFTrS   rP   )-r   rx   r   r   r   r   r   r  _monitorr   r   itemsr   r   r   r   rj   rk   rf   r/   r.   ry   rw   max_set_versionmax_election_idr   rr   rz   rc   publish_topology_closedr!   rn   ro   rp   r#   r$   r{   r|   STOP_TOPOLOGYrh   rl   joinrH   r   r   )r   old_tdr   r   r   s   &    r=   r   Topology.close  s    
 ::::&&F--..0lln$$x''..v? 1 !% 1 1 7 7 9D#00DDFLLNmm+9;MM'*6  O
    ''--///x''..t/@/@A DLDL) :. <<+++??... 3%%!!22!!11!!11!!44!D LLOOHH))))	 LLdooEEHYHYG[\]$$W]]33*::,,$(L#D$5$56 &8&F&FSWSdSd 4#3#3#3""((*((--a000 T\\!:;	 $4s  % 0 :::x 1s   PO(P=O4O+
O4/BO46,O4#O4 O.O43O4PO1P'E P(BP,P>8P6P72P+O4.O41P4P	:O=;
P	P	
Pc                   V ^8  d   QhRR/# )r7   r9   r/   r;   )r<   s   "r=   r>   rM     s     ! !0 !r?   c                	    V P                   # r[   )rx   rD  s   &r=   r   Topology.description  s       r?   c                   V ^8  d   QhRR/# )r7   r9   zlist[_ServerSession]r;   )r<   s   "r=   r>   rM     s     , ,"6 ,r?   c                6    V P                   P                  4       # )z"Pop all session ids from the pool.)r   pop_allrD  s   &r=   pop_all_sessionsTopology.pop_all_sessions  s    !!))++r?   c                    V ^8  d   QhRRRR/# )r7   session_timeout_minutesr   r9   r   r;   )r<   s   "r=   r>   rM     s     N N- NN Nr?   c                8    V P                   P                  V4      # )z>Start or resume a server session, or raise ConfigurationError.)r   get_server_session)r   r  s   &&r=   r  Topology.get_server_session  s    !!445LMMr?   c                    V ^8  d   QhRRRR/# )r7   server_sessionr   r9   r   r;   )r<   s   "r=   r>   rM     s     A AN At Ar?   c                	<    V P                   P                  V4       R # r[   )r   return_server_session)r   r  s   &&r=   r  Topology.return_server_session  s    00@r?   c                   V ^8  d   QhRR/# )r7   r9   r(   r;   )r<   s   "r=   r>   rM   !  s     F F	 Fr?   c                B    \         P                  ! V P                  4      # )z]A Selection object, initially including all known servers.

Hold the lock when calling this.
)r(   from_topology_descriptionrx   rD  s   &r=   r6  Topology._new_selection!  s    
 2243D3DEEr?   c                   V ^8  d   QhRR/# r   r;   )r<   s   "r=   r>   rM   (  s        d  r?   c                  "   V P                   '       d   \        R4      hV P                  '       Eg   RV n        V P                  4       G Rj  xL
  V P                  '       g   V P
                  '       d   V P                  P                  4        V P                  '       d:   V P                  P                  \        9   d   V P                  P                  4        V P                  P                  '       dN   V P                  \        V P                   ^ ,          \#        R^RV P$                  R^/4      4      4      G Rj  xL
  V P&                  P)                  4        F  pVP                  4       G Rj  xL
  K  	  R#  EL2 LB L5i)zKStart monitors, or restart after a fork.

Hold the lock when calling this.
z'Cannot use AsyncMongoClient after closeTNok	serviceIdmaxWireVersion)r   r   r   r  rj   rh   rl   r   r   r   r  r-   rt   r   r  r'   r   r   rc   r   r   r   r   s   & r=   r   Topology._ensure_opened(  s/    
 <<<"#LMM|||DL&&((( 4#7#7#7&&++-    d&6&6&D&DH^&^!!&&(~~+++**%,,Q/tQT5F5FHXZ\]^   mm**,F++- -) )  sT   0FFE?F$F6+F"AF7AF?F 4F4F5FFFc               $    V ^8  d   QhRRRRRR/# )r7   r   r5   err_ctxrn  r9   r:   r;   )r<   s   "r=   r>   rM   I  s&     B Bx B- BD Br?   c                	   V P                   P                  V4      pVf   R# VP                  P                  VP                  VP
                  4      '       d   R# VP                  P                  pVP                  pR pV'       dN   \        VR4      '       d<   \        VP                  \        4      '       d   VP                  P                  R4      p\        WF4      # )NTdetailstopologyVersion)r   r  _poolstale_generationsock_generation
service_idr   topology_versionerrorhasattr
isinstancer  dict _is_stale_error_topology_version)r   r   r  r   cur_tvr  error_tvs   &&&    r=   _is_stale_errorTopology._is_stale_errorI  s    ""7+><<(()@)@'BTBTUU ##44WUI..%--.. ==,,->?/AAr?   c               $    V ^8  d   QhRRRRRR/# r7   r   r5   r  rn  r9   r   r;   )r<   s   "r=   r>   rM   ]  s'     D+ D+8 D+m D+PT D+r?   c                	.  "   V P                  W4      '       d   R # V P                  V,          pVP                  pVP                  pV P                  P
                  '       d   V'       g   VP                  '       g   R # \        V\        4      '       d   VP                  '       d   R # \        V\        4      '       d   R # \        V\        \        34      '       Edo   \        VR4      '       d   VP                  pM6\        V\        4      '       d   RMR pVP                  P                  RV4      pV\         P"                  9   d   V\         P$                  9   pV P                  P
                  '       g$   V P'                  \)        WR7      4      G R j  xL
  V'       g   VP*                  ^8:  d   VP-                  V4      G R j  xL
  VP/                  4        R # VP                  '       g[   V P                  P
                  '       g$   V P'                  \)        WR7      4      G R j  xL
  VP-                  V4      G R j  xL
  R # R # \        V\0        4      '       d   \        V\2        4      '       g   VP5                  R4      '       d   R # V P                  P
                  '       g$   V P'                  \)        WR7      4      G R j  xL
  VP-                  V4      G R j  xL
  VP6                  P9                  4        R # R #  ELr ELC L L LE L.5i)Ncodei{'  r  SystemOverloadedError)r  r   r  r  rt   r   completed_handshaker  r   r   r   r   r  r  r  r  r   _NOT_PRIMARY_CODES_SHUTDOWN_CODESr  r'   max_wire_versionr   request_checkr   r   has_error_labelrw  cancel_check)	r   r   r  r   r  r  err_codedefaultis_shutting_downs	   &&&      r=   _handle_errorTopology._handle_error]  sI    11w'''
 >>'''
7C^C^C^e^,,1L1L1L
 z**1ABCC uf%% :: $.e_#E#E%4 ==,,VW=><<<#+~/M/M#M ~~333../@/VWWW#(@(@A(E ,,z222$$&000~~333../@/VWWWll:... 1 011%!677%%&=>> >>///**+<W+RSSS,,z*** OO((* 2 X 3
 X. T*s   A L#L+L=)L'CL7LLL"%LL
'L0LL*L+LLA
LL-LLL$L%#L
LLLLLc               $    V ^8  d   QhRRRRRR/# r  r;   )r<   s   "r=   r>   rM     s!     7 7( 7] 7t 7r?   c                   "   V P                   ;_uu_4       GRj  xL
  V P                  W4      G Rj  xL
  RRR4      GRj  xL
  R#  L/ L L
  + GRj  xL 
 '       g   i     R# ; i5i)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)r   r  )r   r   r  s   &&&r=   ro  Topology.handle_error  s=      ::::$$W666 ::6 :::sY   A.AA.AAAA.AA.AA.A+	A
A+	#A+	%	A.c                   V ^8  d   QhRR/# r   r;   )r<   s   "r=   r>   rM     s     # #D #r?   c                h    V P                   P                  4        F  pVP                  4        K  	  R# )z3Wake all monitors. Hold the lock when calling this.N)r   r   r  r  s   & r=   r   Topology._request_check_all  s%    mm**,F  " -r?   c                   V ^8  d   QhRR/# r   r;   )r<   s   "r=   r>   rM     s     *+ *+t *+r?   c           
       "   V P                   P                  4       P                  4        EF{  w  rWP                  9  d   V P                  P                  VV V P                  V4      V P                  R7      pRpV P                  '       d/   V P                  e!   \        P                  ! V P                  4      p\        VV P                  V4      VV P                  V P                  VR7      pWPP                  V&   VP                  4       G Rj  xL
  K  V P                  V,          P                   P"                  pW P                  V,          n        WbP"                  8w  g   EK=  V P                  V,          P$                  P'                  VP"                  4      G Rj  xL
  EK~  	  \)        V P                  P                  4       4       F  w  rV P                   P+                  V4      '       d   K(  VP-                  4       G Rj  xL
  \.        '       g&   V P0                  P3                  VP4                  4       V P                  P7                  V4       K  	  R#  ELP L L[5i)zbSync our Servers from TopologyDescription.server_descriptions.

Hold the lock while calling this.
)r  topologyr   rL   N)r  r   monitortopology_id	listenersevents)rx   r   rx  r   rt   monitor_class_create_pool_for_monitorrh   rk   r   r   r   _create_pool_for_serverrc   rf   r   r   is_writabler   update_is_writabler   r  r   r   r   r  rw  pop)r   r   r   r  r\   r   was_writables   &      r=   r  Topology._update_servers  s    
  ,,@@BHHJKGmm+..66')!66w?&*nn	 7  '''DLL,D";;t||4D')55g># $ 1 1"oo *0g&kkm##  $}}W5AAMM57g&2>>1--055HHXXX= K@  $DMM$7$7$9:OG$$//88lln$$x''..v?!!'*  ; $ Y %sR   B
I'BI'I AI'(9I'!I#"AI'6I'	I%
I'AI'#I'%I'c                    V ^8  d   QhRRRR/# r7   r   r5   r9   r   r;   )r<   s   "r=   r>   rM     s     
 
x 
D 
r?   c                	x    V P                   P                  WP                   P                  V P                  R 7      # ))	client_id)rt   
pool_classpool_optionsrc   r.  s   &&r=   r   Topology._create_pool_for_server  s3    ~~((^^00D<M<M ) 
 	
r?   c                    V ^8  d   QhRRRR/# r  r;   )r<   s   "r=   r>   rM     s     
 
 
T 
r?   c                	F   V P                   P                  p\        VP                  VP                  VP                  VP
                  VP                  VP                  VP                  R VP                  R7	      pV P                   P                  WRV P                  R7      # )F)	connect_timeoutsocket_timeoutssl_contexttls_allow_invalid_hostnamesevent_listenersappnamedriverpause_enabled
server_apiT)is_sdamr  )rt   r  r&   r  _ssl_contextr  re   r  r  r  r  rc   )r   r   optionsmonitor_pool_optionss   &&  r=   r  !Topology._create_pool_for_monitor  s    ..--
  +#33"22,,(/(K(K#44OO>>))
 
 ~~((44CTCT ) 
 	
r?   c                    V ^8  d   QhRRRR/# )r7   r   r   r9   r   r;   )r<   s   "r=   r>   rM     s     8Y 8Y'G 8YC 8Yr?   c                *  a V P                   P                  \        P                  \        P                  39   pV'       d   RpM.V P                   P                  \        P
                  8X  d   RpMRpV P                   P                  '       d'   V\        J d   V'       d   R# RV,          # RV RV R2# \        V P                   P                  4       4      p\        V P                   P                  4       P                  4       4      pV'       g8   V'       d'   R	P                  VV P                  P                  4      # R
V,          # V^ ,          P                  o\        ;QJ d&    V3R lVR,           4       F  '       d   K   RM	  RM! V3R lVR,           4       4      pV'       dT   Sf
   RV,          # V'       d4   \!        V4      P#                  V P$                  4      '       g
   RV,          # \'        S4      # RP)                  R V 4       4      # )zUFormat 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)No {} available for replica set name "{}"zNo %s availablec              3  @   <"   T F  qP                   S8H  x  K  	  R # 5ir[   r  ).0r   r  s   & r=   	<genexpr>*Topology._error_message.<locals>.<genexpr>!  s     G;||u,;s   :   NNFTzNo %s found yetz\Could not reach any servers in %s. Replica set is configured with internal hostnames or IPs?,c              3  r   "   T F-  qP                   '       g   K  \        VP                   4      x  K/  	  R # 5ir[   )r  r   )r  r   s   & r=   r  r  0  s#     Xf<< 1FLL 1 1s   77)rx   r  r.   r5  r<  Shardedre  r,   r   r   r   r<   rt   rw   r  allr=  intersectionr   r   r}  )r   r   is_replica_setserver_plural	addressesr   samer  s   &&     @r=   r   Topology._error_message  s   
 **88//--=
 

 1M,,0E0EE&M%M***33!<7-GG]O+<XJaHHT..BBDEI4,,@@BIIKLG!FMM%77 
 -}<< AJ$$E3G72;G333G72;GGD=,}<<!#i.*E*EdFZFZ*[*[FHQR
 5z!xxXXXXr?   c                   V ^8  d   QhRR/# r   r;   )r<   s   "r=   r>   rM   2  s     Q Q Qr?   c                	6  "   . p V P                   '       d,   VP                  V P                   P                  4       4       K=   \        P
                  ! V Uu. uF  q"P                  4       NK  	  upR R/ G Rj  xL
  R#   \         d     LJi ; iu upi  L5i)return_exceptionsTN)r   r  r  
IndexErrorasynciogatherr}  )r   tasksts   &  r=   r   Topology.cleanup_monitors2  s     	%%%T004467 & nn7Avvx7P4PPP  		7PsE   BB +B BB0
B:B;BBBB	Bc                   V ^8  d   QhRR/# )r7   r9   r   r;   )r<   s   "r=   r>   rM   ;  s     I I# Ir?   c                	    R pV P                   '       g   RpRV P                  P                   RV V P                  : R2# ) zCLOSED < >)r   	__class____name__rx   )r   msgs   & r=   __repr__Topology.__repr__;  s@    |||C4>>**+1SE$2C2C1FaHHr?   c                   V ^8  d   QhRR/# )r7   r9   z>tuple[tuple[_Address, ...], Optional[str], Optional[str], str]r;   )r<   s   "r=   r>   rM   A  s     \ \X \r?   c                    V P                   p\        \        VP                  4      4      VP                  VP
                  VP                  3# )zDThe properties to use for AsyncMongoClient/Topology equality checks.)rt   tuplesortedr}   rw   r   srv_service_name)r   tss   & r=   eq_propsTopology.eq_propsA  s8    ^^fRXX&')<)<bggrGZGZ[[r?   c                    V ^8  d   QhRRRR/# )r7   otherobjectr9   r:   r;   )r<   s   "r=   r>   rM   F  s      F t r?   c                	    \        WP                  4      '       d"   V P                  4       VP                  4       8H  # \        # r[   )r  r  r  NotImplemented)r   r  s   &&r=   __eq__Topology.__eq__F  s/    e^^,,==?enn&666r?   c                   V ^8  d   QhRR/# )r7   r9   r   r;   )r<   s   "r=   r>   rM   K  s     % %# %r?   c                	4    \        V P                  4       4      # r[   )hashr  rD  s   &r=   __hash__Topology.__hash__K  s    DMMO$$r?   )__events_executorr   r   rx   rk   rf   r   r   r   r   r   rh   rj   r   r   r   rt   r   rc   )NNNNr[   )NN)FF)   )3r  
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r  r  r   r&  r*  r   r  r7  r?  rE  rJ  rO  rX  r\  ra  rg  rs  r   propertyr   r  r  r  r6  r   r  r  ro  r   r  r  r  r   r   r  r  r"  r'  __static_attributes__r;   r?   r=   rJ   rJ   h   s   4m4^%(N-^P#d2 D
BE%NU2:9*(NPNL&6=?2"B<H ! !,NAF BB(D+L7#
*+X


,8YtQI\

% %r?   rJ   c                  &    ] tR tRtRtR R ltRtR# )rn  iO  z.An error with context for SDAM error handling.c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r7   r  BaseExceptionr  r   r  r  r:   r  zOptional[ObjectId]r;   )r<   s   "r=   r>   _ErrorContext.__annotate__R  s<     % %% % 	%
 "% '%r?   c                	B    Wn         W n        W0n        W@n        WPn        R # r[   )r  r  r  r  r  )r   r  r  r  r  r  s   &&&&&&r=   r   _ErrorContext.__init__R  s      
 0.#6 $r?   )r  r  r  r  r  N)r  r+  r,  r-  r.  r   r0  r;   r?   r=   rn  rn  O  s    8% %r?   rn  c               $    V ^8  d   QhRRRRRR/# )r7   
current_tvrT  r  r9   r:   r;   )r<   s   "r=   r>   r>   a  s$     8 8+87R8	8r?   c                j    V e   Vf   R# V R,          VR,          8w  d   R# V R,          VR,          8  # )z9Return True if the error's topologyVersion is <= current.F	processIdcounterr;   )r8  r  s   &&r=   r  r  a  s<     X-+(;"77i HY$777r?   c               $    V ^8  d   QhRRRRRR/# )r7   
current_sdr'   new_sdr9   r:   r;   )r<   s   "r=   r>   r>   l  s$     5 5-> 5HY 5^b 5r?   c                    V P                   VP                   r2Ve   Vf   R# VR,          VR,          8w  d   R# VR,          VR,          8  # )z4Return True if the new topologyVersion is < current.Fr:  r;  )r  )r=  r>  r8  new_tvs   &&  r=   r  r  l  sL    #44f6M6MV^+&"55i 6)#444r?   )[r.  
__future__r   r  ro   r   rB   r   r   r   r   r   pathlibr   typingr   r   r   r   r   r	   pymongor
   r   r   r   #pymongo.asynchronous.client_sessionr   r   pymongo.asynchronous.monitorr   r   pymongo.asynchronous.poolr   pymongo.asynchronous.serverr   pymongo.errorsr   r   r   r   r   r   r   r   r   pymongo.hellor   pymongo.lockr   r   r    pymongo.loggerr!   r"   r#   r$   r%   pymongo.pool_optionsr&   pymongo.server_descriptionr'   pymongo.server_selectorsr(   r)   r*   r+   r,   pymongo.topology_descriptionr-   r.   r/   r0   r1   bsonr2   pymongo.asynchronous.settingsr3   pymongo.typingsr4   r5   r   r   __file__parentr   rH   rJ   rn  r  r  r;   r?   r=   <module>rV     s    C "   	   
     H H D D R @ * .
 
 
   
  - 8   >54>(()"d% d%N% %$85r?   