U
    “öhU  ã                   @  sb   d Z ddlmZ ddlZddlmZ dddœdd„ZG d	d
„ d
ƒZG dd„ dƒZG dd„ dƒZ	dS )z<Module for classes related to identifying a Sheets document.é    )ÚannotationsN)Úsheets_sanitize_urlÚstr)ÚkeyÚreturnc                 C  s   t  d| ¡std | ¡ƒ‚| S )Nz[a-zA-Z0-9_-]+z"{}" is not a valid Sheets key)ÚreÚ	fullmatchÚ
ValueErrorÚformat©r   © r   úJ/tmp/pip-unpacked-wheel-doshhd5e/google/generativeai/notebook/sheets_id.pyÚ_sanitize_key   s    r   c                   @  s,   e Zd ZdZddœdd„Zddœdd„Zd	S )
Ú	SheetsURLz?Class that enforces safety by ensuring that URLs are sanitized.r   )Úurlc                 C  s   t  |¡| _d S ©N)r   Zsanitize_sheets_urlÚ_url)Úselfr   r   r   r   Ú__init__   s    zSheetsURL.__init__©r   c                 C  s   | j S r   ©r   ©r   r   r   r   Ú__str__"   s    zSheetsURL.__str__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   c                   @  s,   e Zd ZdZddœdd„Zddœdd„Zd	S )
Ú	SheetsKeyz?Class that enforces safety by ensuring that keys are sanitized.r   r   c                 C  s   t |ƒ| _d S r   )r   Ú_key)r   r   r   r   r   r   )   s    zSheetsKey.__init__r   c                 C  s   | j S r   ©r   r   r   r   r   r   ,   s    zSheetsKey.__str__Nr   r   r   r   r   r   &   s   r   c                   @  sV   e Zd ZdZdddddœdd„Zdd	œd
d„Zdd	œdd„Zdd	œdd„Zdd„ ZdS )ÚSheetsIdentifierzàEncapsulates a means to identify a Sheets document.

  The gspread library provides three ways to look up a Sheets document: by name,
  by url and by key. An instance of this class represents exactly one of the
  methods.
  Nz
str | NonezSheetsKey | NonezSheetsURL | None)Únamer   r   c                 C  sP   || _ || _|| _tt| j ƒƒtt| jƒƒ tt| jƒƒ }|dkrLtdƒ‚dS )aÀ  Constructor.

    Exactly one of the arguments should be provided.

    Args:
      name: The name of the Sheets document. More-than-one Sheets documents can
        have the same name, so this is the least precise method of identifying
        the document.
      key: The key of the Sheets document
      url: The url to the Sheets document

    Raises:
      ValueError: If the caller does not specify exactly one of name, url or
      key.
    é   z(Must set exactly one of name, key or urlN)Ú_namer   r   ÚintÚboolr	   )r   r"   r   r   Z
num_inputsr   r   r   r   8   s    (ÿzSheetsIdentifier.__init__r   c                 C  s   | j S r   )r$   r   r   r   r   r"   X   s    zSheetsIdentifier.namec                 C  s   | j S r   r    r   r   r   r   r   [   s    zSheetsIdentifier.keyc                 C  s   | j S r   r   r   r   r   r   r   ^   s    zSheetsIdentifier.urlc                 C  s4   | j rd | j ¡S | jr$d | j¡S d | j¡S d S )Nzname={}zkey={}zurl={})r$   r
   r   r   r   r   r   r   r   a   s
    zSheetsIdentifier.__str__)NNN)	r   r   r   r   r   r"   r   r   r   r   r   r   r   r!   0   s   	   ü r!   )
r   Ú
__future__r   r   Zgoogle.generativeai.notebookr   r   r   r   r!   r   r   r   r   Ú<module>   s   

