
    Ki|X                        S r SSKrSSKJr  SSKJrJrJrJrJ	r	J
r
JrJrJrJr  SSKJr  SSKJr  SSKJrJr  SS	KJrJr  SS
KJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$  SSK%J&r&J'r'J(r(  \
\)\\\)\*\+\,\\)   4      4   r-\\\
\)\\   4   \
\)\\)\\   4   4   \
\)\\)\\   \)4   4   \
\)\\)\\   \)\
\)\)4   4   4   4      r. " S S5      r/ " S S\/5      r0\\/   r1g)z{
gspread.http_client
~~~~~~~~~~~~~~

This module contains HTTPClient class responsible for communicating with
Google API.

    N)
HTTPStatus)
IOAnyDictListMappingMutableMappingOptionalTupleTypeUnion)Credentials)AuthorizedSession)ResponseSession   )APIErrorUnSupportedExportFormat)DRIVE_FILES_API_V3_URLDRIVE_FILES_UPLOAD_API_V2_URLSPREADSHEET_BATCH_UPDATE_URLSPREADSHEET_SHEETS_COPY_TO_URLSPREADSHEET_URLSPREADSHEET_VALUES_APPEND_URL"SPREADSHEET_VALUES_BATCH_CLEAR_URL#SPREADSHEET_VALUES_BATCH_UPDATE_URLSPREADSHEET_VALUES_BATCH_URLSPREADSHEET_VALUES_CLEAR_URLSPREADSHEET_VALUES_URL)ExportFormatconvert_credentialsquotec                      \ rS rSrSrS4S\S\\   SS4S jjrS5S jr	S	\\
\\\\4   4      SS4S
 jr     S6S\S\S\\   S\\   S\\\\4      S\S\\\\4      S\4S jjrS\S\\\\4      S\4S jr  S7S\S\S\\   S\\\\4      S\4
S jjrS\S\S\S\\\\4      S\4
S jrS\S\S\4S jr  S7S\S\\   S\\\\4      S\4S jjr S4S\S\S\\   S\4S jjr S4S\S\\   S\\   S\4S jjr S4S\S\\\\4      S\4S jjrS4S\S\\   S\4S jjr S\S \!S!\S\4S" jr" S4S\S\\   S\\\4   4S# jjr#S\S\4S$ jr$\%RL                  4S%\S&\S\4S' jjr'   S8S%\S(\\   S)\\   S*\\   S+\(S,\\   S-\(S\4S. jjr)S%\S\\*\\
\\(4   4      4S/ jr+S%\S0\SS4S1 jr,S%\S\
\\4   S\4S2 jr-S3r.g)9
HTTPClient9   a  An instance of this class communicates with Google API.

:param Credentials auth: An instance of google.auth.Credentials used to authenticate requests
    created by either:

    * gspread.auth.oauth()
    * gspread.auth.oauth_from_dict()
    * gspread.auth.service_account()
    * gspread.auth.service_account_from_dict()

:param Session session: (Optional) An OAuth2 credential object. Credential objects
    created by `google-auth <https://github.com/googleapis/google-auth-library-python>`_.

    You can pass you own Session object, simply pass ``auth=None`` and ``session=my_custom_session``.

This class is not intended to be created manually.
It will be created by the gspread.Client class.
Nauthsessionreturnc                 z    Ub  X l         O*[        U5      U l        [        U R                  5      U l         S U l        g N)r'   r!   r&   r   timeout)selfr&   r'   s      fC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\gspread/http_client.py__init__HTTPClient.__init__M   s0    "L%8%>DI,TYY7DLDH    c                     SSK Jn  U R                  R                  U" U R                  5      5        U R                  R
                  R                  SSU R                  R                  -  05        g )Nr   )RequestAuthorizationz	Bearer %s)google.auth.transport.requestsr2   r&   refreshr'   headersupdatetoken)r,   r2   s     r-   loginHTTPClient.loginV   sJ    :		'$,,/0##_kDIIOO6S$TUr0   r+   c                     Xl         g)zHow long to wait for the server to send
data before giving up, as a float, or a ``(connect timeout,
read timeout)`` tuple.

Use value ``None`` to restore default timeout

Value for ``timeout`` is in seconds (s).
N)r+   )r,   r+   s     r-   set_timeoutHTTPClient.set_timeout]   s	     r0   methodendpointparamsdatajsonfilesr6   c                     U R                   R                  UUUUUUUU R                  S9nUR                  (       a  U$ [	        U5      e)N)r>   urlrB   r@   rA   rC   r6   r+   )r'   requestr+   okr   )	r,   r>   r?   r@   rA   rB   rC   r6   responses	            r-   rF   HTTPClient.requesth   sR     <<''LL ( 	
 ;;O8$$r0   idbodyc                 R    U R                  S[        U-  US9nUR                  5       $ )a  Lower-level method that directly calls `spreadsheets/<ID>:batchUpdate <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate>`_.

:param dict body: `Batch Update Request body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate#request-body>`_.
:returns: `Batch Update Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate#response-body>`_.
:rtype: dict

.. versionadded:: 3.0
postrB   )rF   r   rB   )r,   rJ   rK   rs       r-   batch_updateHTTPClient.batch_update   s)     LL!=!BLNvvxr0   rangec                 l    [         U[        U5      4-  nU R                  SXSUS9nUR                  5       $ )a  Lower-level method that directly calls `PUT spreadsheets/<ID>/values/<range> <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update>`_.

:param str range: The `A1 notation <https://developers.google.com/sheets/api/guides/concepts#a1_notation>`_ of the values to update.
:param dict params: (optional) `Values Update Query parameters <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update#query-parameters>`_.
:param dict body: (optional) `Values Update Request body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update#request-body>`_.
:returns: `Values Update Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update#response-body>`_.
:rtype: dict

Example::

    sh.values_update(
        'Sheet1!A2',
        params={
            'valueInputOption': 'USER_ENTERED'
        },
        body={
            'values': [[1, 2, 3]]
        }
    )

.. versionadded:: 3.0
putr@   rB   r   r"   rF   rB   r,   rJ   rR   r@   rK   rE   rO   s          r-   values_updateHTTPClient.values_update   s6    : %E%L'99LLL>vvxr0   c                 l    [         U[        U5      4-  nU R                  SXSUS9nUR                  5       $ )aw  Lower-level method that directly calls `spreadsheets/<ID>/values:append <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append>`_.

:param str range: The `A1 notation <https://developers.google.com/sheets/api/guides/concepts#a1_notation>`_
                  of a range to search for a logical table of data. Values will be appended after the last row of the table.
:param dict params: `Values Append Query parameters <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#query-parameters>`_.
:param dict body: `Values Append Request body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#request-body>`_.
:returns: `Values Append Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#response-body>`_.
:rtype: dict

.. versionadded:: 3.0
rM   rU   )r   r"   rF   rB   rW   s          r-   values_appendHTTPClient.values_append   s6     ,r5<.@@LL$L?vvxr0   c                 n    [         U[        U5      4-  nU R                  SU5      nUR                  5       $ )a  Lower-level method that directly calls `spreadsheets/<ID>/values:clear <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear>`_.

:param str range: The `A1 notation <https://developers.google.com/sheets/api/guides/concepts#a1_notation>`_ of the values to clear.
:returns: `Values Clear Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/clear#response-body>`_.
:rtype: dict

.. versionadded:: 3.0
rM   )r   r"   rF   rB   )r,   rJ   rR   rE   rO   s        r-   values_clearHTTPClient.values_clear   s2     +b%,-??LL%vvxr0   c                 V    [         U-  nU R                  SXBUS9nUR                  5       $ )a  Lower-level method that directly calls `spreadsheets/<ID>/values:batchClear`

:param dict params: (optional) `Values Batch Clear Query parameters <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchClear#path-parameters>`_.
:param dict body: (optional) `Values Batch Clear request body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchClear#request-body>`_.
:rtype: dict
rM   rU   )r   rF   rB   )r,   rJ   r@   rK   rE   rO   s         r-   values_batch_clearHTTPClient.values_batch_clear   s-     125LL$L?vvxr0   c                 j    [         U[        U5      4-  nU R                  SXCS9nUR                  5       $ )a  Lower-level method that directly calls `GET spreadsheets/<ID>/values/<range> <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get>`_.

:param str range: The `A1 notation <https://developers.google.com/sheets/api/guides/concepts#a1_notation>`_ of the values to retrieve.
:param dict params: (optional) `Values Get Query parameters <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get#query-parameters>`_.
:returns: `Values Get Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get#response-body>`_.
:rtype: dict

.. versionadded:: 3.0
getr@   rV   )r,   rJ   rR   r@   rE   rO   s         r-   
values_getHTTPClient.values_get   s4     %E%L'99LLL3vvxr0   rangesc                 f    Uc  0 nX#S'   [         U-  nU R                  SXCS9nUR                  5       $ )a  Lower-level method that directly calls `spreadsheets/<ID>/values:batchGet <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet>`_.

:param list ranges: List of ranges in the `A1 notation <https://developers.google.com/sheets/api/guides/concepts#a1_notation>`_ of the values to retrieve.
:param dict params: (optional) `Values Batch Get Query parameters <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet#query-parameters>`_.
:returns: `Values Batch Get Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet#response-body>`_.
:rtype: dict
rh   rd   re   )r   rF   rB   )r,   rJ   rh   r@   rE   rO   s         r-   values_batch_getHTTPClient.values_batch_get   s=     >F!x*R/LLL3vvxr0   c                 T    [         U-  nU R                  SX2S9nUR                  5       $ )a  Lower-level method that directly calls `spreadsheets/<ID>/values:batchUpdate <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate>`_.

:param dict body: (optional) `Values Batch Update Request body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate#request-body>`_.
:returns: `Values Batch Update Response body <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate#response-body>`_.
:rtype: dict
rM   rN   )r   rF   rB   )r,   rJ   rK   rE   rO   s        r-   values_batch_updateHTTPClient.values_batch_update  s+     2B6LLL0vvxr0   c                 T    [         U-  nU R                  SX2S9nUR                  5       $ )zA method stub that directly calls `spreadsheets.get <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/get>`_.rd   re   r   rF   rB   r,   rJ   r@   rE   rO   s        r-   spreadsheets_getHTTPClient.spreadsheets_get  s)    "LLL3vvxr0   sheet_iddestination_spreadsheet_idc                 ^    [         X4-  nSU0nU R                  SXES9nUR                  5       $ )zLower-level method that directly calls `spreadsheets.sheets.copyTo <https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.sheets/copyTo>`_.destinationSpreadsheetIdrM   rN   )r   rF   rB   )r,   rJ   rt   ru   rE   rK   rO   s          r-   spreadsheets_sheets_copy_to&HTTPClient.spreadsheets_sheets_copy_to  s8     -~=*,FGLLL0vvxr0   c                 b    Uc  SS0n[         U-  nU R                  SX2S9nUR                  5       $ )a  Similar to :method spreadsheets_get:`gspread.http_client.spreadsheets_get`,
get the spreadsheet form the API but by default **does not get the cells data**.
It only retrieve the the metadata from the spreadsheet.

:param str id: the spreadsheet ID key
:param dict params: (optional) the HTTP params for the GET request.
    By default sets the parameter ``includeGridData`` to ``false``.
:returns: The raw spreadsheet
:rtype: dict
includeGridDatafalserd   re   rp   rq   s        r-   fetch_sheet_metadataHTTPClient.fetch_sheet_metadata  s:     >'1F"LLL3vvxr0   c                 ~    [         SR                  U5      -   nSSSS.nU R                  SX#S9nUR                  5       $ )zGet the metadata from the Drive API for a specific file
This method is mainly here to retrieve the create/update time
of a file (these metadata are only accessible from the Drive API).
z/{}Tz id,name,createdTime,modifiedTime)supportsAllDrivesincludeItemsFromAllDrivesfieldsrd   re   )r   formatrF   rB   )r,   rJ   rE   r@   ress        r-   get_file_drive_metadata"HTTPClient.get_file_drive_metadata5  sI     %u||B'77 "&)-8
 ll5#l5xxzr0   file_idr   c                     U[         ;  a  [        eSR                  [        U5      nSU0nU R	                  SX4S9nUR
                  $ )ao  Export the spreadsheet in the given format.

:param str file_id: The key of the spreadsheet to export

:param str format: The format of the resulting file.
    Possible values are:

        * ``ExportFormat.PDF``
        * ``ExportFormat.EXCEL``
        * ``ExportFormat.CSV``
        * ``ExportFormat.OPEN_OFFICE_SHEET``
        * ``ExportFormat.TSV``
        * ``ExportFormat.ZIPPED_HTML``

    See `ExportFormat`_ in the Drive API.

:type format: :class:`~gspread.utils.ExportFormat`

:returns bytes: The content of the exported file.

.. _ExportFormat: https://developers.google.com/drive/api/guides/ref-export-formats
z{}/{}/exportmimeTyperd   re   )r    r   r   r   rF   content)r,   r   r   rE   r@   rO   s         r-   exportHTTPClient.exportG  sK    0 %))##$:GD(&1LLL3yyr0   email_address	perm_typerolenotifyemail_message	with_linkc                     SR                  [        U5      nUUUS.n	SS0n
US:X  a  X)S'   O4US;   a  X)S'   XZS'   XjS	'   O!US
:X  a  O[        SR                  U5      5      eU R                  SXU
S9$ )a  Creates a new permission for a file.

:param str file_id: a spreadsheet ID (aka file ID).
:param email_address: user or group e-mail address, domain name
    or None for 'anyone' type.
:type email_address: str, None
:param str perm_type: (optional) The account type.
    Allowed values are: ``user``, ``group``, ``domain``, ``anyone``
:param str role: (optional) The primary role for this user.
    Allowed values are: ``owner``, ``writer``, ``reader``
:param bool notify: Whether to send an email to the target
    user/domain. Default ``True``.
:param str email_message: (optional) An email message to be sent
    if ``notify=True``.
:param bool with_link: Whether the link is required for this
    permission to be active. Default ``False``.

:returns dict: the newly created permission

Examples::

    # Give write permissions to otto@example.com

    gc.insert_permission(
        '0BmgG6nO_6dprnRRUWl1UFE',
        'otto@example.org',
        perm_type='user',
        role='writer'
    )

    # Make the spreadsheet publicly readable

    gc.insert_permission(
        '0BmgG6nO_6dprnRRUWl1UFE',
        None,
        perm_type='anyone',
        role='reader'
    )

{}/{}/permissions)typer   withLinkr   truedomain>   usergroupemailAddresssendNotificationEmailemailMessageanyonezInvalid permission type: {}rM   )rB   r@   )r   r   
ValueErrorrF   )r,   r   r   r   r   r   r   r   rE   payloadr@   s              r-   insert_permissionHTTPClient.insert_permissioni  s    d "(()?I!
  
   -H++&3N#.4*+%2>"(":AA)LMM||FCf|EEr0   c                     SR                  [        U5      nSSS.nSn/ nUbT  U(       a  XCS'   U R                  SX#S	9R                  5       nUR	                  US
   5        UR                  SS5      nUb  MT  U$ )z`Retrieve a list of permissions for a file.

:param str file_id: a spreadsheet ID (aka file ID).
r   TznextPageToken,permissions)r   r    N	pageTokenrd   re   permissionsnextPageToken)r   r   rF   rB   extendrd   )r,   r   rE   r@   r8   r   rO   s          r-   list_permissionsHTTPClient.list_permissions  s    
 "(()?I "&1

 &+{#UC7<<>Aq/0EE/40E  r0   permission_idc                 X    SR                  [        X5      nSS0nU R                  SX4S9  g)zDeletes a permission from a file.

:param str file_id: a spreadsheet ID (aka file ID.)
:param str permission_id: an ID for the permission.
z{}/{}/permissions/{}r   Tdeletere   N)r   r   rF   )r,   r   r   rE   r@   s        r-   remove_permissionHTTPClient.remove_permission  s5     %++"G
 248Xs2r0   c           	          [        U[        5      (       a  UR                  S5      nSS0nSR                  [        U5      nU R                  SUUSSSS.US	9nUR                  5       $ )
am  Imports data into the first page of the spreadsheet.

:param str data: A CSV string of data.

Example:

.. code::

    # Read CSV file contents
    content = open('file_to_import.csv', 'r').read()

    gc.import_csv(spreadsheet.id, content)

.. note::

   This method removes all other worksheets and then entirely
   replaces the contents of the first worksheet.

zutf-8zContent-Typeztext/csvz{}/{}rT   mediaT)
uploadTypeconvertr   )rA   r@   r6   )
isinstancestrencoder   r   rF   rB   )r,   r   rA   r6   rE   r   s         r-   
import_csvHTTPClient.import_csv  sw    * dC  ;;w'D!:.nn:GDll%%)
   

 xxzr0   )r&   r'   r+   r*   )r(   N)NNNNN)NN)TNF)/__name__
__module____qualname____firstlineno____doc__r   r
   r   r.   r9   r   floatr   r<   r   
ParamsTypebytesr   r   FileTyper	   r   rF   rP   rX   r[   r^   ra   rf   r   rj   rm   rr   intrx   r}   r   r    PDFr   boolr   r   r   r   r   __static_attributes__ r0   r-   r$   r$   9   s)   &I[ I8G3D IPT IV	8E%ue|9L2L,M#N 	SW 	 (, $,06:%% % $	%
 uo% wsCx()% % .c23% 
%4s (7383D*E # " (,,0  $	
 wsCx() 
B!+5=EgcSVhFW=X	$s 3 3   (,,0	 $ wsCx()	
 
" CG!+3J+?	" JN#Cy2::2F	( <@%gc3h&78	3 0D PS !$BE	 7;'
3	c	,# # $ 2>1A1A  c  3  e  P '+GFGF  }GF C=	GF
 smGF GF  }GF GF 
GFR T#uS$Y?O:O5P0Q 63 3S 3T 3'# 'U3:-> '3 'r0   r$   c                      ^  \ rS rSr% Sr\R                  \R                  /r\	\   \
S'   Sr\\
S'   Sr\\
S'   S\S	\S
\4U 4S jjrSrU =r$ )BackOffHTTPClienti  a  BackOffHTTPClient is a http client with exponential
backoff retries.

In case a request fails due to some API rate limits,
it will wait for some time, then retry the request.

This can help by trying the request after some time and
prevent the application from failing (by raising an APIError exception).

.. Warning::
    This HTTPClient is not production ready yet.
    Use it at your own risk !

.. note::
    To use with the `auth` module, make sure to pass this backoff
    http client using the ``http_client`` parameter of the
    method used.

.. note::
    Currently known issues are:

    * will retry exponentially even when the error should
      raise instantly. Due to the Drive API that raises
      403 (Forbidden) errors for forbidden access and
      for api rate limit exceeded._HTTP_ERROR_CODESr   _NR_BACKOFF   _MAX_BACKOFFargskwargsr(   c                   >^  S[         S[        [        [        4   S[         S[        4U 4S jjn [
        T	T ]  " U0 UD6$ ! [         a  nUR                  nUR                  nT =R                  S-  sl
        [        ST R                  -  T R                  5      nU" XVU5      SL a6  [        R                  " U5        T R                  " U0 UD6nS	T l
        Us S nA$ UeS nAff = f)
Ncodeerrorwaitr(   c                    > SU;   a$  U [         R                  :X  a  US   S   S   S:X  a  gU TR                  ;   =(       d    U [         R                  :  =(       a    UTR                  :*  $ )Nerrorsr   r   usageLimitsT)r   	FORBIDDENr   INTERNAL_SERVER_ERRORr   )r   r   r   r,   s      r-   _should_retry0BackOffHTTPClient.request.<locals>._should_retry(  ss     5  J000h*84E ... <:;;;, $+++,r0   r      Tr   )r   r   r   r   r   superrF   r   r   r   r   minr   timesleep)
r,   r   r   r   errr   r   r   rH   	__class__s
   `        r-   rF   BackOffHTTPClient.request&  s    	,	,38$	, 	, 		,2	7?D3F33 	88DIIE!q$***D,=,=>D T$/47

4   <<88 $%  I)	s$   A 
C$BCC$CC$)r   )r   r   r   r   r   r   REQUEST_TIMEOUTTOO_MANY_REQUESTSr   r   __annotations__r   r   r   r   r   rF   r   __classcell__)r   s   @r-   r   r     se    *6 	""$$+tJ'  KL#1S 1C 1H 1 1r0   r   )2r   r   httpr   typingr   r   r   r   r   r	   r
   r   r   r   google.auth.credentialsr   r4   r   requestsr   r   
exceptionsr   r   urlsr   r   r   r   r   r   r   r   r   r   r   utilsr    r!   r"   r   r   r   r   r   r   r$   r   HTTPClientTyper   r0   r-   <module>r      s"       0 < & 9    < ;C%S$tCy0P*Q!RRS
	sBsG|$sE#r#w,//0sE#r#w"3445sE#r#w^CH5M"MNNO	QH HVS
 Sl j!r0   