o
    €j6h¡  ã                   @  sF   d Z ddlmZ ddlZddlmZ dd	d
„Zddd„Zddd„ZdS )z Utilities for working with URLs.é    )ÚannotationsN)ÚparseÚpartÚstrÚreturnÚNonec                 C  s   t  d| ¡std | ¡ƒ‚d S )Nz[a-zA-Z0-9_-]*z,"{}" is outside the restricted character set)ÚreÚ	fullmatchÚ
ValueErrorÚformat)r   © r   ú/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/google/generativeai/notebook/sheets_sanitize_url.pyÚ_validate_url_part   s   ÿr   c                 C  s6   t  | ¡ ¡ D ]\}}t|ƒ |D ]}t|ƒ qqd S )N)r   Úparse_qsÚitemsr   )r   ÚkeyÚvaluesÚvaluer   r   r   Ú_validate_url_query_or_fragment   s   
ÿþr   Úurlc              
   C  s  t  | ¡}|jdkrtd |j¡ƒ‚|jdvrtd |j¡ƒ‚z|j d¡D ]}t|ƒ q&W n tyC } z	td |j¡ƒ|‚d}~ww |j	rOtd |j	¡ƒ‚zt
|jƒ W n tyk } z	td	 |j¡ƒ|‚d}~ww zt
|jƒ W | S  ty‰ } z	td
 |j¡ƒ|‚d}~w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)r   Úparse_resultr   Úexcr   r   r   Úsanitize_sheets_url"   sP   


ÿ

ÿ
ÿ€ÿ
ÿþ€ÿû
ÿþ€ÿr"   )r   r   r   r   )r   r   r   r   )	Ú__doc__Ú
__future__r   r   Úurllibr   r   r   r"   r   r   r   r   Ú<module>   s   

