+\hdZddlmZddlmZmZmZmZmZm Z m Z ddl m Z er ddl mZddlmZe dZeeefZeeZGdd Zdd Zdd Zdd Zdd ZddZddZddZddZddZddZy)zFCriteria to select some ServerDescriptions from a TopologyDescription.) annotations) TYPE_CHECKINGAnyMappingOptionalSequenceTypeVarcast) SERVER_TYPE)ServerDescription)TopologyDescriptionTceZdZdZed dZ d dZddZddZe ddZ e ddZ e ddZ dd Z dd Zy ) Selectionz.Input or output of a server selector function.c|j}d}|D]#}|jtjk(s!|}nt ||j|j |SN) known_servers server_typer RSPrimaryrcommon_wire_version)clstopology_descriptionrprimarysds [/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/server_selectors.pyfrom_topology_descriptionz#Selection.from_topology_description#sb,::  B~~!6!66   . . 4 4    c<||_||_||_||_yr)rserver_descriptionsrr)selfrrrrs r__init__zSelection.__init__3s#%9!#6  #6 rcZt|j||j|jSr)rrrr)r rs rwith_server_descriptionsz"Selection.with_server_descriptions?s,  % %':Dz>Selection.secondary_with_max_last_write_date..HsUBL^L^@_r)key)secondary_server_selectorrmax)r secondariess r"secondary_with_max_last_write_datez,Selection.secondary_with_max_last_write_dateDs3/5  * *//5_ rcZ|jr |jgng}|j|Sr)rr#)r primariess rprimary_selectionzSelection.primary_selectionLs&&*llT\\N ,,Y77rc.|jjSr)rheartbeat_frequencyr s rr2zSelection.heartbeat_frequencyQs((<<)r<r)r<int)r<r7)r:r?r<r )__name__ __module__ __qualname____doc__ classmethodrr!r#r-propertyr0r2r5r8r;rrrr s8     71 75 7+ 7 - 7 88==77..rrc|SrrF selections rany_server_selectorrJ`s rcx|j|jDcgc]}|js|c}Scc}wr)r#r is_readablerIss rreadable_server_selectorrOd2  - -11CqQ]]C C77cx|j|jDcgc]}|js|c}Scc}wr)r#r is_writablerMs rwritable_server_selectorrTjrPrQc|j|jDcgc]"}|jtjk(s!|$c}Scc}wr)r#rrr RSSecondaryrMs rr*r*ps=  - -11^qQ]]kF]F]5]^ ^ "AAc|j|jDcgc]"}|jtjk(s!|$c}Scc}wr)r#rrr RSArbiterrMs rarbiter_server_selectorrZvs=  - -11\qQ]]kF[F[5[\ \rWc2t|xs t|S)z6Like PrimaryPreferred but doesn't use tags or latency.)rTr*rHs r"writable_preferred_server_selectorr\|s #I . V2KI2VVrcdfd }|j|jDcgc]}||js|c}Scc}w)zAll servers matching one tag set. A tag set is a dict. A server matches if its tags are a superset: A server tagged {'a': '1', 'b': '2'} matches the tag set {'a': '1'}. The empty tag set {} matches any server. cRjD]\}}||vs |||k7syy)NFT)items) server_tagsr)valuetag_sets r tags_matchz(apply_single_tag_set..tags_matchs8!--/ JC+%S)9U)B r)r`zMapping[str, Any]r<r7)r#rtags)rbrIrcrNs` rapply_single_tag_setres?  - -11HqZ5GH Hs AAcV|D]}t||}|s|cS|jgS)aNAll servers match a list of tag sets. tag_sets is a list of dicts. The empty tag set {} matches any server, and may be provided at the end of the list as a fallback. So [{'a': 'value'}, {}] expresses a preference for servers tagged {'a': 'value'}, but accepts any server if none matches the first preference. )rer#)tag_setsrIrb with_tag_sets rapply_tag_setsris; +GY?    - -b 11rc,t|t|S)z2All near-enough secondaries matching the tag sets.)rir*rgrIs r#secondary_with_tags_server_selectorrls ($=i$H IIrc,t|t|S)z.All near-enough members matching the tag sets.)rirOrks r member_with_tags_server_selectorrns ($rwsM"QQQ+<@ CL c  6 =.=.@    W *2"J Ir