
    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        V/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pymongo/server_selectors.pyfrom_topology_descriptionz#Selection.from_topology_description   sb    ,:: 	B~~!6!66	
   .. 44	
 	
    c                 <    || _         || _        || _        || _        y r   )r   server_descriptionsr   r   )selfr   r   r   r   s        r   __init__zSelection.__init__'   s!    $8!#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,    %%':D<T<TVZVbVb
 	
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>5   s    rGYGY r   )key)secondary_server_selectorr   max)r   secondariess     r   "secondary_with_max_last_write_datez,Selection.secondary_with_max_last_write_date2   s.    /5**{66<YZZ +r   c                 Z    | j                   r| j                   gng }| j                  |      S r   )r   r   )r   	primariess     r   primary_selectionzSelection.primary_selection7   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_type@   s    ((666r   c                 ,    t        | j                        S r   )boolr   r'   s    r   __bool__zSelection.__bool__D   s    D,,--r   c                      | j                   |   S r   )r   )r   items     r   __getitem__zSelection.__getitem__I   s    ''--r   N)__name__
__module____qualname____doc__classmethodr   r   r   r!   propertyr$   r&   r)   r,   __nonzero__r/    r   r   r   r      st    8
 
7

[
 8 8 = = 7 7. K.r   r   c                     | S r   r7   	selections    r   any_server_selectorr;   M   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@   Q   2    --11CqQ]]C 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   W   rA   rB   c                     | j                  | j                  D cg c]"  }|j                  t        j                  k(  s!|$ c}      S c c}w r   )r   r   r	   r   RSSecondaryr>   s     r   r   r   ]   s=    --11^qQ]]kF]F]5]^ ^
   "AAc                     | j                  | j                  D cg c]"  }|j                  t        j                  k(  s!|$ c}      S c c}w r   )r   r   r	   r   	RSArbiterr>   s     r   arbiter_server_selectorrK   c   s=    --11\qQ]]kF[F[5[\ \rH   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   i   s    #I.V2KI2VVr   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_matchw   s8    !--/ 	JC+%S)9U)B	 r   )r   r   tags)rS   r:   rT   r?   s   `   r   apply_single_tag_setrV   n   s?     --11HqZ5GH 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      sP    M +6. 6.rW
*2"J
Ir   