
    i)i                       d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 ddlmZ erddlmZ ddlmZ  e	d          Zeeef         Zee         Z G d d	          ZddZddZddZddZddZddZddZddZddZddZdS )zFCriteria to select some ServerDescriptions from a TopologyDescription.    )annotations)TYPE_CHECKINGAnyMappingOptionalSequenceTypeVarcast)SERVER_TYPE)ServerDescription)TopologyDescriptionTc                      e Zd ZdZedd            ZddZddZddZe	dd            Z
e	dd            Ze	dd            ZddZd dZdS )!	Selectionz.Input or output of a server selector function.topology_descriptionr   returnc                    |j         }d }|D ]}|j        t          j        k    r|} nt	          ||j         |j        |          S N)known_serversserver_typer   	RSPrimaryr   common_wire_version)clsr   r   primarysds        j/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/pymongo/server_selectors.pyfrom_topology_descriptionz#Selection.from_topology_description#   sc    ,: 	 	B~!666 7   . 4	
 
 	
    server_descriptionslist[ServerDescription]r   Optional[int]r   Optional[ServerDescription]c                >    || _         || _        || _        || _        d S r   )r   r   r   r   )selfr   r   r   r   s        r   __init__zSelection.__init__3   s)     %9!#6 #6   r   c                D    t          | j        || j        | j                  S r   )r   r   r   r   )r$   r   s     r   with_server_descriptionsz"Selection.with_server_descriptions?   s(    %':D<TVZVb
 
 	
r   c                `    t          |           }|j        rt          |j        d           S d S )Nc                6    t          t          | j                  S r   )r
   floatlast_write_date)r   s    r   <lambda>z>Selection.secondary_with_max_last_write_date.<locals>.<lambda>H   s    UBL^@_@_ r   )key)secondary_server_selectorr   max)r$   secondariess     r   "secondary_with_max_last_write_datez,Selection.secondary_with_max_last_write_dateD   sD    /55* 	/5_5_    tr   c                N    | j         r| j         gng }|                     |          S r   )r   r'   )r$   	primariess     r   primary_selectionzSelection.primary_selectionL   s*    &*l:T\NN	,,Y777r   intc                    | j         j        S r   )r   heartbeat_frequencyr$   s    r   r7   zSelection.heartbeat_frequencyQ   s    (<<r   c                    | j         j        S r   )r   topology_typer8   s    r   r:   zSelection.topology_typeU   s    (66r   boolc                *    t          | j                  S r   )r;   r   r8   s    r   __bool__zSelection.__bool__Y   s    D,---r   itemr   c                    | j         |         S r   )r   )r$   r>   s     r   __getitem__zSelection.__getitem__\   s    '--r   N)r   r   r   r   )r   r   r   r    r   r!   r   r"   )r   r    r   r   )r   r"   )r   r   )r   r5   )r   r;   )r>   r5   r   r   )__name__
__module____qualname____doc__classmethodr   r%   r'   r1   propertyr4   r7   r:   r=   r@    r   r   r   r       s        88
 
 
 [

7 
7 
7 
7
 
 
 

    8 8 8 X8 = = = X= 7 7 7 X7. . . .. . . . . .r   r   	selectionr   c                    | S r   rG   rH   s    r   any_server_selectorrK   `   s    r   c                J    |                      d | j        D                       S )Nc                     g | ]}|j         	|S rG   )is_readable.0ss     r   
<listcomp>z,readable_server_selector.<locals>.<listcomp>f       CCCqQ]CCCCr   r'   r   rJ   s    r   readable_server_selectorrU   d   .    --CCI1CCC  r   c                J    |                      d | j        D                       S )Nc                     g | ]}|j         	|S rG   )is_writablerO   s     r   rR   z,writable_server_selector.<locals>.<listcomp>l   rS   r   rT   rJ   s    r   writable_server_selectorrZ   j   rV   r   c                J    |                      d | j        D                       S )Nc                <    g | ]}|j         t          j        k    |S rG   )r   r   RSSecondaryrO   s     r   rR   z-secondary_server_selector.<locals>.<listcomp>r   s'    ^^^qQ]kF]5]5]5]5]5]r   rT   rJ   s    r   r.   r.   p   s.    --^^I1^^^  r   c                J    |                      d | j        D                       S )Nc                <    g | ]}|j         t          j        k    |S rG   )r   r   	RSArbiterrO   s     r   rR   z+arbiter_server_selector.<locals>.<listcomp>x   s'    \\\qQ]kF[5[5[5[5[5[r   rT   rJ   s    r   arbiter_server_selectorra   v   s.    --\\I1\\\  r   c                >    t          |           pt          |           S )z6Like PrimaryPreferred but doesn't use tags or latency.)rZ   r.   rJ   s    r   "writable_preferred_server_selectorrc   |   s    #I..V2KI2V2VVr   tag_setTagSetc                ^     d fd|                     fd|j        D                       S )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.
    server_tagsMapping[str, Any]r   r;   c                b                                     D ]\  }}|| vs| |         |k    r dS dS )NFT)items)rg   r-   valuerd   s      r   
tags_matchz(apply_single_tag_set.<locals>.tags_match   sL    !--// 	 	JC+%%S)9U)B)Buu *C tr   c                4    g | ]} |j                   |S rG   )tags)rP   rQ   rl   s     r   rR   z(apply_single_tag_set.<locals>.<listcomp>   s*    HHHqZZ5G5GHHHHr   )rg   rh   r   r;   rT   )rd   rH   rl   s   ` @r   apply_single_tag_setro      sV          --HHHHI1HHH  r   tag_setsTagSetsc                b    | D ]}t          ||          }|r|c S |                    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.
    )ro   r'   )rp   rH   rd   with_tag_sets       r   apply_tag_setsrt      sQ         +GY?? 	 	  --b111r   c                <    t          | t          |                    S )z2All near-enough secondaries matching the tag sets.)rt   r.   rp   rH   s     r   #secondary_with_tags_server_selectorrw      s    ($=i$H$HIIIr   c                <    t          | t          |                    S )z.All near-enough members matching the tag sets.)rt   rU   rv   s     r    member_with_tags_server_selectorry      s    ($<Y$G$GHHHr   N)rH   r   r   r   )rH   r   r   r   )rd   re   rH   r   r   r   )rp   rq   rH   r   r   r   ) rD   
__future__r   typingr   r   r   r   r   r	   r
   pymongo.server_typer   pymongo.server_descriptionr   pymongo.topology_descriptionr   r   strre   rq   r   rK   rU   rZ   r.   ra   rc   ro   rt   rw   ry   rG   r   r   <module>r      s   M L " " " " " " Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q + + + + + + A<<<<<<@@@@@@ GCLL	c	
6
=. =. =. =. =. =. =. =.@               W W W W
   *2 2 2 2"J J J J
I I I I I Ir   