
    
!i                    F    S r SSKJr  SSKrSSKJr  SS jrSS jrS	S jrg)
z Utilities for working with URLs.    )annotationsN)parsec                p    [         R                  " SU 5      (       d  [        SR                  U 5      5      eg )Nz[a-zA-Z0-9_-]*z,"{}" is outside the restricted character set)re	fullmatch
ValueErrorformat)parts    j/home/james-whalen/.local/lib/python3.13/site-packages/google/generativeai/notebook/sheets_sanitize_url.py_validate_url_partr      s0    <<($//GNNtTUU 0    c                    [         R                  " U 5      R                  5        H$  u  p[        U5        U H  n[        U5        M     M&     g )N)r   parse_qsitemsr   )r
   keyvaluesvalues       r   _validate_url_query_or_fragmentr      s:    ~~d+1133Eu%  4r   c                j   [         R                  " U 5      nUR                  S:w  a$  [        SR	                  UR                  5      5      eUR
                  S;  a$  [        SR	                  UR
                  5      5      e UR                  R                  S5       H  n[        U5        M     UR                  (       a$  [        SR	                  UR                  5      5      e [        UR                  5         [        UR                  5        U $ ! [         a*  n[        SR	                  UR                  5      5      UeSnAff = f! [         a*  n[        S	R	                  UR                  5      5      UeSnAff = f! [         a*  n[        S
R	                  UR                  5      5      UeSnAff = f)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 #E 9E> 
E%D??E
E;%E66E;>
F2%F--F2)r
   strreturnNone)r    r$   r%   r$   )	__doc__
__future__r   r   urllibr   r   r   r#    r   r   <module>r+      s#    ' " 	 V
&7r   