+\hem UdZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZddlmZmZdd lmZmZmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#Gdde Z$e$e%dZ&e&jNe&jPfZ)de*d<eeegeefZ+GddZ,e!jZe&jPe!j\e&j^e!j`e&jbe!jde&jbe!jfe&jbiZ4 ddZ5 ddZ6 ddZ7 ddZ8 d dZ9d!dZ:y)"zRepresent a deployment of MongoDB servers. .. seealso:: This module is compatible with both the synchronous and asynchronous PyMongo APIs. ) annotations)sample)AnyCallableListMappingMutableMapping NamedTupleOptionalcastMinKey)ObjectId)common)ConfigurationError PyMongoError)PrimaryReadPreference _AggWritePref _ServerMode)ServerDescription) Selection) SERVER_TYPE)_AddresscJeZdZUded<ded<ded<ded<ded<ded<y) _TopologyTypeintSingleReplicaSetNoPrimaryReplicaSetWithPrimaryShardedUnknown LoadBalancedN)__name__ __module__ __qualname____annotations___/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/topology_description.pyrr-s# K L Lr)rztuple[int, int]SRV_POLLING_TOPOLOGIESceZdZ ddZddZddZddZddZddZddZ e d dZ e d!d Z e d"d Z e d#d Ze d$d Ze d#d Ze d%dZe d&dZe d%dZe d#dZe d dZe d dZd'dZ d( d)dZej4fd*dZd&dZd!dZy)+TopologyDescriptioncN||_||_||_||_||_||_d|_|jtjk7r|j|j}|sd|_ ytd|Drd|_ ytd|D|_ y)aRepresentation of a deployment of MongoDB servers. :param topology_type: initial type :param server_descriptions: dict of (address, ServerDescription) for all seeds :param replica_set_name: replica set name or None :param max_set_version: greatest setVersion seen from a primary, or None :param max_election_id: greatest electionId seen from a primary, or None :param topology_settings: a TopologySettings Nc38K|]}|jduywNlogical_session_timeout_minutes.0ss r* z/TopologyDescription.__init__..ksUq22d:Uc34K|]}|jywr1r2r4s r*r7z/TopologyDescription.__init__..ns+6711+)_topology_type_replica_set_name_server_descriptions_max_set_version_max_election_id_topology_settings_incompatible_err TOPOLOGY_TYPEr#_init_incompatible_errreadable_servers_ls_timeout_minutesanymin)self topology_typeserver_descriptionsreplica_set_namemax_set_versionmax_election_idtopology_settingsrDs r*__init__zTopologyDescription.__init__@s&,!1$7! / /#4"&   -"<"< <  ' ' ) 00'+D $ UDTU U'+D $'*+;K+(D $r)cN|jjD]}|js|jduxr|jtj kD}|j duxr|j tjk}|rEd|jd|jdxsd|jtj fz|_ |sd|jd|jdxsd|j tjtjfz|_ yy)z>Internal compatibility check for non-load balanced topologies.Nz]Server at %s:%d requires wire version %d, but this version of PyMongo only supports up to %d.rzgServer at %s:%d reports wire version %d, but this version of PyMongo requires at least %d (MongoDB %s).) r=valuesis_server_type_knownmin_wire_versionrMAX_SUPPORTED_WIRE_VERSIONmax_wire_versionMIN_SUPPORTED_WIRE_VERSIONaddressrAMIN_SUPPORTED_SERVER_VERSION)rHr6server_too_newserver_too_olds r*rCz*TopologyDescription._init_incompatible_errrs1**113+ A)) ""$.K&&)J)JJ ""$.K&&)J)JJ  A !  ! )**99 & L !  ! )**99;; &W+ r)cF|jrt|jy)zRaise ConfigurationError if any server is incompatible. A server is incompatible if its wire protocol version range does not overlap with PyMongo's. N)rArrHs r*check_compatiblez$TopologyDescription.check_compatibles#  ! !$T%;%;< < "r)c||jvSr1)r=)rHrXs r* has_serverzTopologyDescription.has_servers$3333r)cT|j|j}t||S)z;A copy of this description, with one server marked Unknown.)r= to_unknownupdated_topology_description)rHrX unknown_sds r* reset_serverz TopologyDescription.reset_servers(..w7BBD +D*==r)c6|jtjk(rtj}n |j}|jDcic]}|t |}}t |||j|j|j|jScc}w)zr?r@)rHrIrXsdss r*resetzTopologyDescription.resets   -"E"E E)==M //MCGB[B[\ww)'22\\"    " "  ! !  ! !  # #   ]s Bc6|jjS)z[dict of (address, :class:`~pymongo.server_description.ServerDescription`). )r=copyr]s r*rJz'TopologyDescription.server_descriptionss((--//r)c|jS)zThe type of this topology.)r;r]s r*rIz!TopologyDescription.topology_types"""r)c<tj|jS)zUThe topology type as a human readable string. .. versionadded:: 3.4 )rB_fieldsr;r]s r*topology_type_namez&TopologyDescription.topology_type_names $$T%8%899r)c|jS)zThe replica set name.)r<r]s r*rKz$TopologyDescription.replica_set_names%%%r)c|jS)z1Greatest setVersion seen from a primary, or None.)r>r]s r*rLz#TopologyDescription.max_set_version$$$r)c|jS)z1Greatest electionId seen from a primary, or None.)r?r]s r*rMz#TopologyDescription.max_election_idrqr)c|jS)z)Minimum logical session timeout, or None.)rEr]s r*r3z3TopologyDescription.logical_session_timeout_minutess'''r)cv|jjDcgc]}|js|c}Scc}w)z)List of Servers of types besides Unknown.)r=rRrSrHr6s r* known_serversz!TopologyDescription.known_serverss/ 44;;=XaAWAWXXX66cVtd|jjDS)z7Whether there are any Servers of types besides Unknown.c3:K|]}|js|ywr1)rSr4s r*r7z8TopologyDescription.has_known_servers..s[ADZDZ1[s)rFr=rRr]s r*has_known_serversz%TopologyDescription.has_known_serverss$[d77>>@[[[r)cv|jjDcgc]}|js|c}Scc}w)zList of readable Servers.)r=rR is_readablerus r*rDz$TopologyDescription.readable_serverss- 44;;=OaOOOrwcX|j}|rtd|jDSy)z3Minimum of all servers' max wire versions, or None.c34K|]}|jywr1)rVr4s r*r7z:TopologyDescription.common_wire_version..sFaq))Fr:N)rvrGrHserverss r*common_wire_versionz'TopologyDescription.common_wire_versions,$$ F43E3EFF Fr)c.|jjSr1)r@heartbeat_frequencyr]s r*rz'TopologyDescription.heartbeat_frequencys&&:::r)c.|jjSr1)r@_srv_max_hostsr]s r* srv_max_hostsz!TopologyDescription.srv_max_hostss&&555r)c|sgSg}|jD]S}|j*d|jd|d|j}t||j |jUt |}|j jdz }|jDcgc]$}tt|j|z |kr|&c}Scc}w)Nzround_trip_time for server z is unexpectedly None: z , servers: g@@) rJround_trip_timerXrappendrGr@local_threshold_msr float)rH selectionround_trip_timesserverconfig_err_msgfastest thresholdr6s r*_apply_local_thresholdz*TopologyDescription._apply_local_threshold sI(*33 v~~>NNefjekkvxAxUxUwV"W(88  # #F$:$: ;  < &'++>>G 22 UA--.8YF    s)CNct|ddr8|j}|r*||jkrtd||j|fzt |t r|j ||jtjk(rgS|jtjtjfvr |jS|r&|jj|}|r|gSgS|jtjk(r`t!|t"urO|j$j'D]0}|j(t*j,k(s!|g}|r||}|cSgSt/j0|}|jtj2k7r||}|#|r!|j5||j}|j7|S)aList of servers matching the provided selector(s). :param selector: a callable that takes a Selection as input and returns a Selection as output. For example, an instance of a read preference from :mod:`~pymongo.read_preferences`. :param address: A server address to select. :param custom_selector: A callable that augments server selection rules. Accepts a list of :class:`~pymongo.server_description.ServerDescription` objects and return a list of server descriptions that should be considered suitable for the desired operation. .. versionadded:: 3.4 rTrzF%s requires min wire version %d, but topology's min wire version is %d)getattrrrTr isinstancerselection_hookrIrBr"rr#rvrJgetr typerr=rR server_typer RSPrimaryrfrom_topology_descriptionr!with_server_descriptionsr) rHselectorrXcustom_selector common_wv descriptionsdrgrs r*apply_selectorz"TopologyDescription.apply_selectors( 8/ 300IY)B)BB(*-5x7P7PR[,\] h .  # #D )   !6!6 6I   M$8$8-:T:T#U U%% % 22488AK$/K= 7R 7   !D!D Dh[bIb//668 >>[%:%::$C&-c2J  I77=   !6!6 6 +I  &9!:: = =>I**955r)cbtjd|t|j|S)aDoes this topology have any readable servers available matching the given read preference? :param read_preference: an instance of a read preference from :mod:`~pymongo.read_preferences`. Defaults to :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`. .. note:: When connected directly to a single server this method always returns ``True``. .. versionadded:: 3.4 read_preference)rvalidate_read_preferencerFr)rHrs r*has_readable_serverz'TopologyDescription.has_readable_server^s+ ''(9?K4&&788r)c@|jtjS)zDoes this topology have a writable server available? .. note:: When connected directly to a single server this method always returns ``True``. .. versionadded:: 3.4 )rrPRIMARYr]s r*has_writable_serverz'TopologyDescription.has_writable_serverns''(>(>??r)ct|jjd}dj|jj |j j|j|S)Nc|jSr1)rX)rs r*z.TopologyDescription.__repr__..zs BJJr))keyz-<{} id: {}, topology_type: {}, servers: {!r}>) sortedr=rRformat __class__r$r@ _topology_idrnrs r*__repr__zTopologyDescription.__repr__xsY2299;AVW>EE NN # #  # # 0 0  # #    r))rIrrJ!dict[_Address, ServerDescription]rK Optional[str]rL Optional[int]rMOptional[ObjectId]rNrreturnNone)rr)rXrrbool)rXrrr.)rr.)rr)rr)rstr)rr)rr)rr)rlist[ServerDescription])rr)rzOptional[Selection]rr)NN)rrrXzOptional[_Address]rzOptional[_ServerSelector]rr)rrrr)r$r%r&rOrCr^r`rerhrJpropertyrIrnrKrLrMr3rvrzrDrrrrrrrrrrr(r)r*r.r.?s00?0( 0 ' 0 , 00 0d-^=4>  &0 ##::&&%%%%((YY\\PP;;66 *'+59 >6>6$>63 >6 ! >6@BPAWAW9 @ r)r.c|j}|j}|j}|j}|j}|j }|j }|||<|tjk(rs|I||jk7r:tdj||j} |j| ||<ttj|||||jS|tjk(r|tj tj"fvrEt%|jj&dk(rtj}n=|j)|n+|tjtj*fvr t,|}|tj.k(r6|tj0tjfvr|j)|nw|tj2k(r|tj tj0fvr|j)|n/|tj4k(rt7|||||\}}}}n|tj8tj:tj<fvrt?|||\}}n|tj@k(r|tj tj0fvr|j)|tC|}nr|tj4k(rt7|||||\}}}}nJ|tj8tj:tj<fvrtE|||}n tC|}t||||||jS)anReturn an updated copy of a TopologyDescription. :param topology_description: the current TopologyDescription :param server_description: a new ServerDescription that resulted from a hello call Called after attempting (successfully or not) to call hello on the server at server_description.address. Does not modify topology_description. zeclient is configured to connect to a replica set named '{}' but this node belongs to a set named '{}')errorrQ)#rXrIrKrLrMrrJrBrrrrbr.r@r"r Standalone LoadBalancerlenseedspopRSGhost_SERVER_TYPE_TO_TOPOLOGY_TYPEr!Mongosrr_update_rs_from_primary RSSecondary RSArbiterRSOther!_update_rs_no_primary_from_memberr _check_has_primary#_update_rs_with_primary_from_member) topology_descriptionserver_descriptionrXrIset_namerLrMrrgrs r*rcrcs!((G)66M#44H*::O*::O$00K  2 2 4C&CL ,,,  H0B0S0S$S&AAG0AABE .88u8ECL"      3 3    --- ;11;3K3KL L'::@@AQF - 4 4  !4!4k6I6I J J9+FM --- {11;3F3FG G GGG  -;; ; ;11;3E3EF F GGG  K11 1JaX1?OK G]Ho[44k6K6K[M`M`a a&GX1' #M8 -== = ;11;3E3EF F GGG .s3M K11 1JaX1?OK G]Ho[44k6K6K[M`M`a a?XOabM/s3M  //  r)c |jtvsJ|j}t|j t|k(r|St |j D]}||vs|j ||jdk7rmt|t|j z }|jt|z }|dkDr)tt|t|t|}ng}|D]}||vst|||<t|j||j|j|j |j"S)zReturn an updated copy of a TopologyDescription. :param topology_description: the current TopologyDescription :param seedlist: a list of new seeds new ServerDescription that resulted from a hello call r)rIr,rJsetkeyslistrrrrrrGrr.rKrLrMr@)rseedlistrgrX new_hostsn_to_adds r*)_updated_topology_description_srv_pollingrs= - -1G GG G  2 2 4C 388:#h-'## # ( " GGG ))Q.MC O3 '55C@ a<fY/Xs9~1NOHH6 # ,W5CL6 ** --,,,,//  r)c| |j}n9||jk7r*|j|jt||||fS|j|jdkr|j |j f}||f}d|vrQd|vrA||kr<|jtd|d|||j<t||||fS|j }|j ||j |kDr|j }n|j |j f}||f}td|D}td|D}||kr<|jtd|d|||j<t||||fS|j }|j }|jD]a} | jtjus | j|jk7s:| jtd|| j<n|jD]} | |vst| || <t!||jz D]} |j| t||||fS)agUpdate topology description from a primary's hello response. Pass in a dict of ServerDescriptions, current replica set name, the ServerDescription we are processing, and the TopologyDescription's max_set_version and max_election_id if any. Returns (new topology type, new replica_set_name, new max_set_version, new max_election_id). Nz.P![1ai&(Q">![r8c38K|]}| tn|ywr1r rs r*r7z*_update_rs_from_primary..Qrr8z6primary marked stale due to discovery of newer primary)rKrrXrrV set_version election_idrbrtuplerRrrr all_hostsrr) rgrKrrLrMnew_election_tuplemax_election_tuplenew_election_safemax_election_safer new_addressaddrs r*rr"s ->> /@@ @ "**+!#&(8/?ZZ**26H6Y6Y\^6^%7%C%CEWEcEc$d%4o$F ) )--2DGY2Y2D2O2O VWiVjkABTAUV3&../ *#.0@/Sbbb0< c !0=C > C-777   s #%5 XXr)c |J||jk7r&|j|jt |S|jr4|j|jk7r|j|jt |S)zRS with known primary. Process a response from a non-primary. Pass in a dict of ServerDescriptions, current replica set name, and the ServerDescription we are processing. Returns new topology type. )rKrrXmer)rgrKrs r*rrzs  '' '->>> "**+ c ""   #5#=#=ASAVAV#V "**+ c ""r)cltj}| |j}n.||jk7r|j|j||fS|j D]}||vst |||<|jr4|j|jk7r|j|j||fS)zRS without known primary. Update from a non-primary's response. Pass in a dict of ServerDescriptions, current replica set name, and the ServerDescription we are processing. Returns (new topology type, new replica_set_name). )rBrrKrrXrrr)rgrKrrIrXs r*rrs"55M->> /@@ @ "**+...&//6 # ,W5CL6!3!;!;?Q?T?T!T "**+ * **r)c|jD]1}|jtjk(s!tj cStj S)zCurrent topology type is ReplicaSetWithPrimary. Is primary still known? Pass in a dict of ServerDescriptions. Returns new topology type. )rRrrrrBr r)rgr6s r*rrsEZZ\1 ==K11 1 66 61000r)N)rr.rrrr.)rr.rzlist[tuple[str, Any]]rr.) rg+MutableMapping[_Address, ServerDescription]rKrrrrLrrMrrzrs#    ";XX8.+$JuQx( ,9+@+@-BWBW*XXD!234d;L6MMNA A N  --=>>]>>=<<:: !e-eCTeeP(-(9N((VUY 4UY#UY*UY# UY ( UY B UYp# 4###*# #.+ 4+#+*+ +@ 1r)