
    h-i                    @    d Z ddlmZ ddlZddlmZ ddZddZd	dZy)
z Utilities for working with URLs.    )annotationsN)parsec                d    t        j                  d|       st        dj                  |             y )Nz[a-zA-Z0-9_-]*z,"{}" is outside the restricted character set)re	fullmatch
ValueErrorformat)parts    oD:\DhanshreeandTeamAI\Github\ai_code\venv\Lib\site-packages\google/generativeai/notebook/sheets_sanitize_url.py_validate_url_partr      s-    <<($/GNNtTUU 0    c                    t        j                  |       j                         D ]"  \  }}t        |       |D ]  }t        |        $ y )N)r   parse_qsitemsr   )r
   keyvaluesvalues       r   _validate_url_query_or_fragmentr      s<    ~~d+113V3Eu%  4r   c                P   t        j                  |       }|j                  dk7  r$t        dj	                  |j                              |j
                  dvr$t        dj	                  |j
                              	 |j                  j                  d      D ]  }t        |        	 |j                  r$t        dj	                  |j                              	 t        |j                         	 t        |j                         | S # t        $ r*}t        dj	                  |j                              |d}~ww xY w# t        $ r*}t        d	j	                  |j                              |d}~ww xY w# t        $ r*}t        d
j	                  |j                              |d}~ww xY w)a  Sanitize a Sheets URL.

    Run some saftey checks to check whether `url` is a Sheets URL. This is not a
    general-purpose URL sanitizer. Rather, it makes use of the fact that we know
    the URL has to be for Sheets so we can make a few assumptions about (e.g. the
    domain).

    Args:
      url: The url to sanitize.

    Returns:
      The sanitized url.

    Raises:
      ValueError: If `url` does not match the expected restrictions for a Sheets
      URL.
    httpsz/Scheme for Sheets url must be "https", got "{}")zdocs.google.comzsheets.googleapis.comz9Domain for Sheets url must be "docs.google.com", got "{}"/z%Invalid path for Sheets url, got "{}"Nz(Params component must be empty, got "{}"z&Invalid query for Sheets url, got "{}"z)Invalid fragment for Sheets url, got "{}")r   urlparseschemer   r	   netlocpathsplitr   paramsr   queryfragment)urlparse_resultr   excs       r   sanitize_sheets_urlr#   "   s   $ >>#&Lg%=DD\EXEXY
 	
 "NNGNN|ObObc
 	

e$))//4Hx( 5 CJJ<K^K^_``'(:(:;'(=(=> J/  e@GGHYHYZ[adde  4;;L<N<NO
	  7>>|?T?TU
	sH   <+D D< /E2 	D9%D44D9<	E/%E**E/2	F%;%F  F%)r
   strreturnNone)r    r$   r%   r$   )	__doc__
__future__r   r   urllibr   r   r   r#    r   r   <module>r+      s#    ' " 	 V
&7r   