
    h                     f    d Z ddlmZ  G d de      Zd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zy)zFCriteria to select some ServerDescriptions from a TopologyDescription.    )SERVER_TYPEc                   r    e Zd ZdZed        Zd Zd Zd Ze	d        Z
e	d        Ze	d        Zd	 ZeZd
 Zy)	Selectionz.Input or output of a server selector function.c                     |j                   }d }|D ]#  }|j                  t        j                  k(  s!|} n t	        ||j                   |j
                  |      S N)known_serversserver_typer   	RSPrimaryr   common_wire_version)clstopology_descriptionr   primarysds        [/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/server_selectors.pyfrom_topology_descriptionz#Selection.from_topology_description   sb    ,:: 	B~~!6!66	
 --;;-AA " 	"    c                 <    || _         || _        || _        || _        y r   )r   server_descriptionsr   r   )selfr   r   r   r   s        r   __init__zSelection.__init__%   s#    
 %9!#6 #6 r   c                 Z    t        | j                  || j                  | j                        S r   )r   r   r   r   )r   r   s     r   with_server_descriptionsz"Selection.with_server_descriptions/   s*    22,11' 	'r   c                 b    t        |       }|j                  rt        |j                  d       S y )Nc                     | j                   S r   )last_write_date)r   s    r   <lambda>z>Selection.secondary_with_max_last_write_date.<locals>.<lambda>9   s    b&8&8 r   )key)secondary_server_selectorr   max)r   secondariess     r   "secondary_with_max_last_write_datez,Selection.secondary_with_max_last_write_date5   s2    /5**{668: : +r   c                 Z    | j                   r| j                   gng }| j                  |      S r   )r   r   )r   	primariess     r   primary_selectionzSelection.primary_selection;   s&    &*llT\\N	,,Y77r   c                 .    | j                   j                  S r   )r   heartbeat_frequencyr   s    r   r&   zSelection.heartbeat_frequency@   s    ((<<<r   c                 .    | j                   j                  S r   )r   topology_typer'   s    r   r)   zSelection.topology_typeD   s    ((666r   c                 ,    t        | j                        S r   )boolr   r'   s    r   __bool__zSelection.__bool__H   s    D,,--r   c                      | j                   |   S r   )r   )r   items     r   __getitem__zSelection.__getitem__M   s    ''--r   N)__name__
__module____qualname____doc__classmethodr   r   r   r!   propertyr$   r&   r)   r,   __nonzero__r/    r   r   r   r      ss    8" "7': 8 8 = = 7 7. K.r   r   c                     | S r   r7   	selections    r   any_server_selectorr;   Q   s    r   c                 x    | j                  | j                  D cg c]  }|j                  s| c}      S c c}w r   )r   r   is_readabler:   ss     r   readable_server_selectorr@   U   4    --11CqQ]]CE EC   77c                 x    | j                  | j                  D cg c]  }|j                  s| c}      S c c}w r   )r   r   is_writabler>   s     r   writable_server_selectorrE   Z   rA   rB   c                     | j                  | j                  D cg c]!  }|j                  t        j                  k(  r|# c}      S c c}w r   )r   r   r	   r   RSSecondaryr>   s     r   r   r   _   sG    --11 	6qMM[444 
 	67 7	6   &Ac                     | j                  | j                  D cg c]!  }|j                  t        j                  k(  r|# c}      S c c}w r   )r   r   r	   r   	RSArbiterr>   s     r   arbiter_server_selectorrK   e   sG    --11 	4qMM[222 
 	45 5	4rH   c                 2    t        |       xs t        |       S )z6Like PrimaryPreferred but doesn't use tags or latency.)rE   r   r9   s    r   "writable_preferred_server_selectorrM   k   s    $Y/ 1%i02r   c                       fd}|j                  |j                  D cg c]  } ||j                        s| c}      S c c}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.
    c                 R    j                         D ]  \  }}|| vs	| |   |k7  s y y)NFT)items)server_tagsr   valuetag_sets      r   
tags_matchz(apply_single_tag_set.<locals>.tags_matchy   s8    !--/ 	JC+%S)9U)B	 r   )r   r   tags)rS   r:   rT   r?   s   `   r   apply_single_tag_setrV   q   sA     --11HqZ5GHJ JHs
   AAc                 V    | D ]  }t        ||      }|s|c S  |j                  g       S )aN  All 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.
    )rV   r   )tag_setsr:   rS   with_tag_sets       r   apply_tag_setsrZ      s;       +GY? 
 --b11r   c                 ,    t        | t        |            S )z2All near-enough secondaries matching the tag sets.)rZ   r   rX   r:   s     r   #secondary_with_tags_server_selectorr]      s    ($=i$HIIr   c                 ,    t        | t        |            S )z.All near-enough members matching the tag sets.)rZ   r@   r\   s     r    member_with_tags_server_selectorr_      s    ($<Y$GHHr   N)r3   pymongo.server_typer   objectr   r;   r@   rE   r   rK   rM   rV   rZ   r]   r_   r7   r   r   <module>rb      sR    M +:. :.zE
E
752J&2"J
Ir   