HEX
Server: LiteSpeed
System: Linux us-phx-web629.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64
User: u756937133 (756937133)
PHP: 8.2.27
Disabled: passthru,chgrp
Upload Files
File: //opt/gsutil/third_party/apitools/apitools/base/py/__pycache__/batch.cpython-39.pyc
a

�z�g�G�@s�dZddlZddlmZddlmmZddlmm	Z
ddlmZ
ddlZddlZddlZddlZddlmZddlmZddlmZddlmZddlmZdgZGd	d
�d
e�d
gd���ZGdd�de�ZGd
d�de�ZdS)z6Library for handling batch HTTP requests for apitools.�N)�http_client)�urllib_parse)�range)�
exceptions)�http_wrapper�BatchApiRequestc@seZdZdZdS)�RequestResponseAndHandleraOContainer for data related to completing an HTTP request.

    This contains an HTTP request, its response, and a callback for handling
    the response from the server.

    Attributes:
      request: An http_wrapper.Request object representing the HTTP request.
      response: The http_wrapper.Response object returned from the server.
      handler: A callback function accepting two arguments, response
        and exception. Response is an http_wrapper.Response object, and
        exception is an apiclient.errors.HttpError object if an error
        occurred, or otherwise None.
    N)�__name__�
__module__�__qualname__�__doc__�r
r
�:/opt/gsutil/third_party/apitools/apitools/base/py/batch.pyr)sr)�request�response�handlerc@s>eZdZdZGdd�de�Zddd�Zd
dd�Zdd
d�ZdS)rz4Batches multiple api requests into a single request.c@s\eZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	edd
��Z
dd�ZdS)zBatchApiRequest.ApiCalla/Holds request and response information for each request.

        ApiCalls are ultimately exposed to the client once the HTTP
        batch request has been completed.

        Attributes:
          http_request: A client-supplied http_wrapper.Request to be
              submitted to the server.
          response: A http_wrapper.Response object given by the server as a
              response to the user request, or None if an error occurred.
          exception: An apiclient.errors.HttpError object if an error
              occurred, or None.

        cCs>tt|tjg��|_d|_||_||_||_d|_	d|_
dS)arInitialize an individual API request.

            Args:
              request: An http_wrapper.Request object.
              retryable_codes: A list of integer HTTP codes that can
                  be retried.
              service: A service inheriting from base_api.BaseApiService.
              method_config: Method config for the desired API request.

            N)�list�setr�UNAUTHORIZED�_ApiCall__retryable_codes�_ApiCall__http_response�_ApiCall__service�_ApiCall__method_config�http_request�_ApiCall__response�_ApiCall__exception)�selfr�retryable_codes�service�
method_configr
r
r�__init__Os�z BatchApiRequest.ApiCall.__init__cCs
|jduS�N)�	exception�rr
r
r�is_erroresz BatchApiRequest.ApiCall.is_errorcCs|jSr!)rr#r
r
rrisz BatchApiRequest.ApiCall.responsecCs|jSr!)rr#r
r
rr"msz!BatchApiRequest.ApiCall.exceptioncCs|jo|jjtjkSr!)r�status_coderrr#r
r
r�authorization_failedqs�z,BatchApiRequest.ApiCall.authorization_failedcCs |jdurdS|jj}||jvS)NF)rr%r)rZ
response_coder
r
r�terminal_statevs
z&BatchApiRequest.ApiCall.terminal_statecCs0||_||_|jr,|js,|j�|j|j�|_dS)apHandles incoming http response to the request in http_request.

            This is intended to be used as a callback function for
            BatchHttpRequest.Add.

            Args:
              http_response: Deserialized http_wrapper.Response object.
              exception: apiclient.errors.HttpError object if an error
                  occurred.

            N)rrr'r�ProcessHttpResponserr)r�
http_responser"r
r
r�HandleResponse}s�z&BatchApiRequest.ApiCall.HandleResponseN)r	r
rrr �propertyr$rr"r&r'r*r
r
r
r�ApiCall>s




r,NcCs$g|_|pg|_|pd|_||_dS)aInitialize a batch API request object.

        Args:
          batch_url: Base URL for batch API calls.
          retryable_codes: A list of integer HTTP codes that can be retried.
          response_encoding: The encoding type of response content.
        z https://www.googleapis.com/batchN)�api_requestsr�	batch_url�response_encoding)rr.rr/r
r
rr �s	

zBatchApiRequest.__init__c	CsH|�|�}|�|�}|j||||d�}|�||j||�}|j�|�dS)a�Add a request to the batch.

        Args:
          service: A class inheriting base_api.BaseApiService.
          method: A string indicated desired method from the service. See
              the example in the class docstring.
          request: An input message appropriate for the specified
              service.method.
          global_params: Optional additional parameters to pass into
              method.PrepareHttpRequest.

        Returns:
          None

        )�
global_params�
upload_configN)�GetMethodConfig�GetUploadConfig�PrepareHttpRequestr,rr-�append)	rr�methodrr0rr1rZapi_requestr
r
r�Add�s

�
�zBatchApiRequest.Add�c
Cs�dd�|jD�}|pt|�}t|�D]�}|r6t�|�tdt|�|�D]�}	t|j||jd�}
t�	||	|	|�D]}|
�
|j|j�qn|
�
|�t|jd�rFtdd�t�	||	|	|�D��rF|jj�|�qFdd�|jD�}|s$q�q$|jS)	a�Execute all of the requests in the batch.

        Args:
          http: httplib2.Http object for use in the request.
          sleep_between_polls: Integer number of seconds to sleep between
              polls.
          max_retries: Max retries. Any requests that have not succeeded by
              this number of retries simply report the last response or
              exception, whatever it happened to be.
          max_batch_size: int, if specified requests will be split in batches
              of given size.
          batch_request_callback: function of (http_response, exception) passed
              to BatchHttpRequest which will be run on any given results.

        Returns:
          List of ApiCalls.
        cSsg|]}|js|�qSr
�r'��.0rr
r
r�
<listcomp>�s�z+BatchApiRequest.Execute.<locals>.<listcomp>r)r.�callbackr/�credentialscss|]}|jVqdSr!)r&r:r
r
r�	<genexpr>�s�z*BatchApiRequest.Execute.<locals>.<genexpr>cSsg|]}|js|�qSr
r9r:r
r
rr<�s�)r-�lenr�time�sleep�BatchHttpRequestr.r/�	itertools�islicer7rr*�Execute�hasattrr�anyr>�refresh)r�httpZsleep_between_pollsZmax_retriesZmax_batch_sizeZbatch_request_callback�requestsZ
batch_size�attempt�iZbatch_http_requestrr
r
rrF�s:
���
��zBatchApiRequest.Execute)NNN)N)r8r8NN)	r	r
rr�objectr,r r7rFr
r
r
rr;sQ�

�c@s`eZdZdZddd�Zdd�Zedd��Zd	d
�Zdd�Z	d
d�Z
ddd�Zdd�Zdd�Z
dS)rCzDBatches multiple http_wrapper.Request objects into a single request.NcCs0||_||_||_i|_t��|_t��|_	dS)a/Constructor for a BatchHttpRequest.

        Args:
          batch_url: URL to send batch requests to.
          callback: A callback to be called for each response, of the
              form callback(response, exception). The first parameter is
              the deserialized Response object. The second is an
              apiclient.errors.HttpError exception object if an HTTP error
              occurred while processing the request, or None if no error
              occurred.
          response_encoding: The encoding type of response content.
        N)
�_BatchHttpRequest__batch_url�_BatchHttpRequest__callback�$_BatchHttpRequest__response_encoding�,_BatchHttpRequest__request_response_handlersrD�count�_BatchHttpRequest__last_auto_id�uuid�uuid4�_BatchHttpRequest__base_id)rr.r=r/r
r
rr �s
zBatchHttpRequest.__init__cCsd|jt�|�fS)aKConvert an id to a Content-ID header value.

        Args:
          request_id: String identifier for a individual request.

        Returns:
          A Content-ID header with the id_ encoded into it. A UUID is
          prepended to the value because Content-ID headers are
          supposed to be universally unique.

        z<%s+%s>)rWr�quote)r�
request_idr
r
r�_ConvertIdToHeadersz#BatchHttpRequest._ConvertIdToHeadercCsZ|�d�s"|�d�s"t�d|��d|vr8t�d|��|dd��dd�\}}t�|�S)awConvert a Content-ID header value to an id.

        Presumes the Content-ID header conforms to the format that
        _ConvertIdToHeader() returns.

        Args:
          header: A string indicating the Content-ID header value.

        Returns:
          The extracted id value.

        Raises:
          BatchError if the header is not in the expected format.
        �<�>z Invalid value for Content-ID: %s�+����)�
startswith�endswithr�
BatchError�rsplitr�unquote)�header�_rYr
r
r�_ConvertHeaderToId%s��z#BatchHttpRequest._ConvertHeaderToIdc
Cs�t�|j�}t�dd|j|jdf�}t|tj�s:|�	d�}d�
|j|df�}|j�
dd��d�\}}t�||�}|j��D]\}}	|dkr�qz|	||<qz|j|d<|�d	�|jd	ur�|�|j�t��}
tj|
d
d�}|j|dd
�|
��}||S)z�Convert a http_wrapper.Request object into a string.

        Args:
          request: A http_wrapper.Request to serialize.

        Returns:
          The request as a string in application/http format.
        �zutf-8� z	HTTP/1.1
�content-typezapplication/json�/�HostNr)�maxheaderlenF)�unixfrom)r�urlsplit�url�
urlunsplit�path�query�
isinstance�six�	text_type�decode�join�http_method�headers�get�split�mime_nonmultipart�MIMENonMultipart�items�netloc�set_unixfrom�body�set_payload�StringIO�	generator�	Generator�flatten�getvalue)
rr�parsedZrequest_line�status_line�major�minor�msg�key�valueZstr_io�genr�r
r
r�_SerializeRequest?s<
�
���



z"BatchHttpRequest._SerializeRequestc	Cs\|�dd�\}}|�dd�\}}}t��}|�|�}t|�}||d<|��}t�|||j�S)z�Convert string into Response and content.

        Args:
          payload: Header and body string to be deserialized.

        Returns:
          A Response object
        �
r^ri��status)	r|�email_parser�Parser�parsestr�dict�get_payloadr�ResponserO)	r�payloadr�rfr��parserr��info�contentr
r
r�_DeserializeResponsems

z%BatchHttpRequest._DeserializeResponsecCstt|j��S)z�Create a new id.

        Auto incrementing number that avoids conflicts with ids already used.

        Returns:
           A new unique id string.
        )�str�nextrTr#r
r
r�_NewId�szBatchHttpRequest._NewIdcCst|d|�}||j|��<dS)aAdd a new request.

        Args:
          request: A http_wrapper.Request to add to the batch.
          callback: A callback to be called for this response, of the
              form callback(response, exception). The first parameter is the
              deserialized response object. The second is an
              apiclient.errors.HttpError exception object if an HTTP error
              occurred while processing the request, or None if no errors
              occurred.

        Returns:
          None
        N)rrRr�)rrr=rr
r
rr7�szBatchHttpRequest.AddcCs^t�d�}t|ddd��|jD]L}t�dd�}d|d<|�|�|d	<|�|j|j�}|�	|�|�
|�q t�|j
d
�}|��|_d|��|jd<t�||�}|jd
kr�tj�|��d|jd}|j}	t|	t�r�|jr�|j�|j�}	t��}
|
�||	�}|� ��st�!d��|�"�D]:}|�#|d	�}
|�$|�"��}|j|
j%|d�|j|
<�qdS)a=Serialize batch request, send to server, process response.

        Args:
          http: A httplib2.Http object to be used to make the request with.

        Raises:
          httplib2.HttpLib2Error if a transport error has occured.
          apiclient.errors.BatchError if the response is the wrong format.
        �mixed�_write_headerscSsdSr!r
r#r
r
r�<lambda>��z+BatchHttpRequest._Execute.<locals>.<lambda>ZapplicationrJ�binaryzContent-Transfer-Encodingz
Content-ID�POSTzmultipart/mixed; boundary="%s"rj�,zcontent-type: %s

z'Response not in multipart/mixed format.)rN)&�mime_multipart�
MIMEMultipart�setattrrRr}r~rZr�rr��attachr�RequestrO�	as_stringr��get_boundaryrz�MakeRequestr%r�	HttpError�FromResponser�r�rt�bytesrQrwr�r�r��is_multipartrbr�rgr��_replace)rrJ�messager�r�r�rrrer�r�Z
mime_response�partrYr
r
r�_Execute�sF



�

�


�
��zBatchHttpRequest._ExecutecCst|�|�|jD]^}|j|j}|j|j}d}|jdkrFtj�|�}|durX|||�|jdur|�||�qdS)aExecute all the requests as a single batched HTTP request.

        Args:
          http: A httplib2.Http object to be used with the request.

        Returns:
          None

        Raises:
          BatchError if the response is the wrong format.
        Nr�)	r�rRrrr%rr�r�rP)rrJr�rr=r"r
r
rrF�s




zBatchHttpRequest.Execute)NN)N)r	r
rrr rZ�staticmethodrgr�r�r�r7r�rFr
r
r
rrC�s
 
.

<rC)r�collections�email.generatorr��email.mime.multipart�mime�	multipartr��email.mime.nonmultipart�nonmultipartr}�email.parserr�r�rDrArUru�	six.movesrrr�apitools.base.pyrr�__all__�
namedtuplerrNrrCr
r
r
r�<module>s,��9