
    nh                        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y)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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/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/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__3   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,    %%':D<T<TVZVbVb
 	
r   c                b    t        |       }|j                  rt        |j                  d       S y )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^L^@_ r   )key)secondary_server_selectorr   max)r    secondariess     r   "secondary_with_max_last_write_datez,Selection.secondary_with_max_last_write_dateD   s3    /5**//5_  r   c                Z    | j                   r| j                   gng }| j                  |      S r   )r   r#   )r    	primariess     r   primary_selectionzSelection.primary_selectionL   s&    &*llT\\N	,,Y77r   c                .    | j                   j                  S r   )r   heartbeat_frequencyr    s    r   r2   zSelection.heartbeat_frequencyQ   s    ((<<<r   c                .    | j                   j                  S r   )r   topology_typer3   s    r   r5   zSelection.topology_typeU   s    ((666r   c                ,    t        | j                        S r   )boolr   r3   s    r   __bool__zSelection.__bool__Y   s    D,,--r   c                     | j                   |   S r   )r   )r    items     r   __getitem__zSelection.__getitem__\   s    ''--r   N)r   r   returnr   )r   r   r   list[ServerDescription]r   zOptional[int]r   Optional[ServerDescription])r   r=   r<   r   )r<   r>   )r<   r   )r<   int)r<   r7   )r:   r?   r<   r   )__name__
__module____qualname____doc__classmethodr   r!   r#   r-   propertyr0   r2   r5   r8   r;    r   r   r   r       s    8
 

71
7 5
7 +	
7
 -
7

 8 8 = = 7 7..r   r   c                    | S r   rF   	selections    r   any_server_selectorrJ   `   s    r   c                x    | j                  | j                  D cg c]  }|j                  s| c}      S c c}w r   )r#   r   is_readablerI   ss     r   readable_server_selectorrO   d   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_writablerM   s     r   writable_server_selectorrT   j   rP   rQ   c                    | j                  | j                  D cg c]"  }|j                  t        j                  k(  s!|$ c}      S c c}w r   )r#   r   r   r   RSSecondaryrM   s     r   r*   r*   p   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   	RSArbiterrM   s     r   arbiter_server_selectorrZ   v   s=    --11\qQ]]kF[F[5[\ \rW   c                2    t        |       xs t        |       S )z6Like PrimaryPreferred but doesn't use tags or latency.)rT   r*   rH   s    r   "writable_preferred_server_selectorr\   |   s    #I.V2KI2VVr   c                     d 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_match   s8    !--/ 	JC+%S)9U)B	 r   )r`   zMapping[str, Any]r<   r7   )r#   r   tags)rb   rI   rc   rN   s   `   r   apply_single_tag_setre      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.
    )re   r#   )tag_setsrI   rb   with_tag_sets       r   apply_tag_setsri      s;       +GY? 
 --b11r   c                ,    t        | t        |            S )z2All near-enough secondaries matching the tag sets.)ri   r*   rg   rI   s     r   #secondary_with_tags_server_selectorrl      s    ($=i$HIIr   c                ,    t        | t        |            S )z.All near-enough members matching the tag sets.)ri   rO   rk   s     r    member_with_tags_server_selectorrn      s    ($<Y$GHHr   N)rI   r   r<   r   )rI   r   r<   r   )rb   TagSetrI   r   r<   r   )rg   TagSetsrI   r   r<   r   ) rC   
__future__r   typingr   r   r   r   r   r	   r
   pymongo.server_typer   pymongo.server_descriptionr   pymongo.topology_descriptionr   r   strro   rp   r   rJ   rO   rT   r*   rZ   r\   re   ri   rl   rn   rF   r   r   <module>rw      s    M " Q Q Q +<@ CL	c	
6
=. =.@W
*2"J
Ir   