
    nh                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ d	Zed	d
d	dddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZed	d
d	dddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)z*Tools to parse and validate a MongoDB URI.    )annotations)AnyOptional)unquote_plus)SRV_SERVICE_NAME_CaseInsensitiveDictionary)ConfigurationError
InvalidURI)_SrvResolver)	_ALLOWED_TXT_OPTSDEFAULT_PORTSCHEME
SCHEME_LENSRV_SCHEME_LEN_check_options_validate_urisplit_hostssplit_optionsTFNc                h    t        | |||||      }|j                  t        | |||||||             |S )a(  Parse and validate a MongoDB URI.

    Returns a dict of the form::

        {
            'nodelist': <list of (host, port) tuples>,
            'username': <username> or None,
            'password': <password> or None,
            'database': <database name> or None,
            'collection': <collection name> or None,
            'options': <dict of MongoDB URI options>,
            'fqdn': <fqdn of the MongoDB+SRV URI> or None
        }

    If the URI scheme is "mongodb+srv://" DNS SRV and TXT lookups will be done
    to build nodelist and options.

    :param uri: The MongoDB URI to parse.
    :param default_port: The port number to use when one wasn't specified
          for a host in the URI.
    :param validate: If ``True`` (the default), validate and
          normalize all options. Default: ``True``.
    :param warn: When validating, if ``True`` then will warn
          the user then ignore any invalid options or values. If ``False``,
          validation will error when options are unsupported or values are
          invalid. Default: ``False``.
    :param normalize: If ``True``, convert names of URI options
          to their internally-used names. Default: ``True``.
    :param connect_timeout: The maximum time in milliseconds to
          wait for a response from the DNS server.
    :param srv_service_name: A custom SRV service name

    .. versionchanged:: 4.6
       The delimiting slash (``/``) between hosts and connection options is now optional.
       For example, "mongodb://example.com?tls=true" is now a valid URI.

    .. versionchanged:: 4.0
       To better follow RFC 3986, unquoted percent signs ("%") are no longer
       supported.

    .. versionchanged:: 3.9
        Added the ``normalize`` parameter.

    .. versionchanged:: 3.6
        Added support for mongodb+srv:// URIs.

    .. versionchanged:: 3.5
        Return the original value of the ``readPreference`` MongoDB URI option
        instead of the validated read preference mode.

    .. versionchanged:: 3.1
        ``warn`` added so invalid options can be ignored.
    )r   update
_parse_srv)	uridefault_portvalidatewarn	normalizeconnect_timeoutsrv_service_namesrv_max_hostsresults	            /var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/pymongo/synchronous/uri_parser.py	parse_urir"   (   sL    ~ 3hiWF
MM		
 M    c                   | j                  t              rd}| t        d  }	nd}| t        d  }	t	               }
|	j                  d      \  }}}d|v r|j                  d      \  }}}n|}|r|
j                  t        ||||             ||
j                  dt              }d|v r|j                  d      \  }}}n|}t        |      }|xs |
j                  d      }|rt        |d       }|d	   \  }}|xs |
j                  d
      }t        ||||      }|j                         }|j                         }|rMt        ||||      }t!        |      t"        z
  rt%        d      |j'                         D ]  \  }}||
vs||
|<    |
j                  d      r|rt)        d      |
j                  d      r|rt)        d      d|
vrd|
vr|rdnd|
d<   nt        ||      }t+        ||
       ||
dS )NFT?/srvServiceName@srvMaxHosts)r   r   connectTimeoutMSzDOnly authSource, replicaSet, and loadBalanced are supported from DNSloadBalancedz0You cannot specify loadBalanced with srvMaxHosts
replicaSetz.You cannot specify replicaSet with srvMaxHoststlsssltrue)nodelistoptions)
startswithr   r   r   r   	partitionr   r   getr   
rpartitionr   r   r   	get_hostsget_optionssetr   r	   itemsr
   r   )r   r   r   r   r   r   r   r   is_srvscheme_freer1   host_plus_db_part_opts	host_parthostsnodesfqdnportdns_resolverdns_optionsparsed_dns_optionsoptvals                           r!   r   r   w   s$    ~~f*+&./*(*G!,!6!6s!;q$
+55c:	1a%	}T8T9EF";;'79IJ
i**3/1eE!?W[[%?ME51X
d *LW[[9K-L#D/;K][&&("..0!.{HdI!V%&)::(Z  /446 'Sg%#&GCL' ;;~&=OPP;;|$MNNE$8%-T6GENE=5'"  r#   )r   strr   Optional[int]r   boolr   rK   r   rK   r   zOptional[float]r   zOptional[str]r   rJ   returnzdict[str, Any])__doc__
__future__r   typingr   r   urllib.parser   pymongo.commonr   r   pymongo.errorsr	   r
    pymongo.synchronous.srv_resolverr   pymongo.uri_parser_sharedr   r   r   r   r   r   r   r   r   _IS_SYNCr"   r    r#   r!   <module>rW      s+    1 "   % G 9 9
 
 
 
 #/'+&*#'L	LL L 	L
 L %L $L !L Lb #/'+&*#'E	EE E 	E
 E %E $E !E Er#   