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__/http_wrapper.cpython-39.pyc
a

�z�g]<�@shdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZzddlmZWney�ddlmZYn0gd	�Zd
ZdZe	je	je	je	jefZe�dgd
��Zejd)dd��ZGdd�de �Z!Gdd�de�dgd���Z"dd�Z#dd�Z$dd�Z%dd�Z&ddd e&e#fd!d"�Z'd e#fd#d$�Z(gZ)d%d&�Z*d'd(�Z+dS)*zpHTTP wrapper for apitools.

This library wraps the underlying http library we use, which is
currently httplib2.
�N)�http_client)�parse)�
exceptions)�util)�HttpAccessTokenRefreshError)�AccessTokenRefreshError)�
CheckResponse�GetHttp�)HandleExceptionsAndRebuildHttpConnections�MakeRequest�RebuildHttpConnections�Request�Response�RethrowExceptionHandler�4i��ExceptionRetryArgs)�http�http_request�exc�num_retries�max_retry_wait�total_wait_secccs�|jdurdVdStj}i}|t_|dur^|j��D]&\}}d|vrHq6|j||<|�|�q6dV|t_|dur�|��D]"\}}||jvrz|j|�|�qzdS)a�Temporarily change the value of httplib2.debuglevel, if necessary.

    If http_request has a `loggable_body` distinct from `body`, then we
    need to prevent httplib2 from logging the full body. This sets
    httplib2.debuglevel for the duration of the `with` block; however,
    that alone won't change the value of existing HTTP connections. If
    an httplib2.Http object is provided, we'll also change the level on
    any cached connections attached to it.

    Args:
      http_request: a Request we're logging.
      level: (int) the debuglevel for logging.
      http: (optional) an httplib2.Http whose connections we should
        set the debuglevel on.

    Yields:
      None.
    N�:)�
loggable_body�httplib2�
debuglevel�connections�items�set_debuglevel)r�levelrZ	old_levelZhttp_levelsZconnection_key�
connection�r!�A/opt/gsutil/third_party/apitools/apitools/base/py/http_wrapper.py�_Httplib2DebuglevelKs$


r#c@sNeZdZdZd
dd�Zedd��Zejd	d��Zed
d��Zejdd��ZdS)r
z1Class encapsulating the data for an HTTP request.��GETNcCs,||_||_|pi|_d|_d|_||_dS�N)�url�http_method�headers�_Request__body�_Request__loggable_body�body)�selfr'r(r)r,r!r!r"�__init__{s
zRequest.__init__cCs|jSr&)r+�r-r!r!r"r�szRequest.loggable_bodycCs|jdurt�d��||_dS)Nz0Cannot set loggable body on request with no body)r,r�RequestErrorr+)r-�valuer!r!r"r�s

�cCs|jSr&)r*r/r!r!r"r,�szRequest.bodycCsb||_|dur6t|jdd�p$t|j�}t|�|jd<n|j�dd�t|td�tj	f�s^d|_
dS)z>Sets the request body; handles logging and length measurement.N�length�content-lengthz<media body>)r*�getattr�len�strr)�pop�
isinstance�type�six�string_typesr)r-r1�body_lengthr!r!r"r,�s��)r$r%Nr$)	�__name__�
__module__�__qualname__�__doc__r.�propertyr�setterr,r!r!r!r"r
ws



r
c@sLeZdZdZdZdd�Zedd��Zedd��Zed	d
��Z	edd��Z
d
S)rz.Class encapsulating data for an HTTP response.r!cCs|jSr&)r2r/r!r!r"�__len__�szResponse.__len__cCsfdd�}d|jvr*d|jvr*||jd�Sd|jvrDt|j�d��Sd|jvr\||jd�St|j�S)z�Return the length of this response.

        We expose this as an attribute since using len() directly can fail
        for responses larger than sys.maxint.

        Returns:
          Response length (as int or long)
        cSsD|�d�\}}}|�d�\}}}|�d�\}}}t|�t|�dS)N� �/�-�)�	partition�int)Z
content_range�_Z
range_specZ
byte_range�start�endr!r!r"�ProcessContentRange�sz,Response.length.<locals>.ProcessContentRangez-content-encodingz
content-ranger3)�inforI�getr5�content)r-rMr!r!r"r2�s


zResponse.lengthcCst|jd�S)N�status)rIrNr/r!r!r"�status_code�szResponse.status_codecCsd|jvrt|jd�SdS)Nzretry-after)rNrIr/r!r!r"�retry_after�s
zResponse.retry_aftercCs|jtvod|jvS)N�location)rR�_REDIRECT_STATUS_CODESrNr/r!r!r"�is_redirect�s
�zResponse.is_redirectN)r=r>r?r@�	__slots__rCrAr2rRrSrVr!r!r!r"r�s


rZHttpResponse)rNrP�request_urlcCsR|durt�d|j��n4|jdks.|jtkr<tj�|��n|jrNtj�|��dS)Nz,Request to url %s did not return a response.��)	rr0rXrR�TOO_MANY_REQUESTS�BadStatusCodeError�FromResponserS�RetryAfterError)�responser!r!r"r�s��
�rcCs4t|dd�r0t|j���D]}d|vr|j|=qdS)a�Rebuilds all http connections in the httplib2.Http instance.

    httplib2 overloads the map in http.connections to contain two different
    types of values:
    { scheme string:  connection class } and
    { scheme + authority string : actual http connection }
    Here we remove all of the entries for actual connections so that on the
    next request httplib2 will rebuild them from the connection types.

    Args:
      http: An httplib2.Http instance.
    rNr)r4�listr�keys)r�conn_keyr!r!r"r�s
rcGs�dSr&r!)Zunused_argsr!r!r"r�srcCs�d}t|jtjtjtjf�r8t�dt|j�j	|j��nHt|jt
j�rXt�d|j��n(t|jt
j�rxt�d|j��nt|jt
j
�r�t�d|j�n�t|jtj�r�t�d|j�n�t|jt�r�t�d|j�n�t|jt��rt|jd��r|jjtk�s|jjd	k�rt�d
|j�nht|jtj��r4t�d�nLt|jtj��rVt�d|jj�n*t|jtj��rzt�d
�|jj}n|j�t|j�t�d|jj|j�t� |�p�t!j"|j#|j$d��dS)z�Exception handler for http failures.

    This catches known failures and rebuilds the underlying HTTP connections.

    Args:
      retry_args: An ExceptionRetryArgs tuple.
    Nz"Caught HTTP error %s, retrying: %sz!Caught socket error, retrying: %sz)Caught socket address error, retrying: %sz)Caught socket timeout error, retrying: %sz+Caught server not found error, retrying: %sz+Response content was invalid (%s), retryingrQrYz8Caught transient credential refresh error (%s), retryingz&Request returned no response, retryingz%Response returned status %s, retryingz0Response returned a retry-after header, retryingz-Retrying request to url %s after exception %s)�max_wait)%r8rr�
BadStatusLine�IncompleteRead�ResponseNotReady�logging�debugr9r=�socket�error�gaierror�timeoutr�ServerNotFoundError�
ValueError�TokenRefreshError�hasattrrQrZrr0r[rRr]rSrrrr'�time�sleepr�CalculateWaitForRetryrr)Z
retry_argsrSr!r!r"r
�sp

������
�
�
���



�
��r
��<�cCs�d}t��}t|d�r(t|j�dh|_zt||||d�WSty�}	zB|d7}||kr^�n"t��|}
|t|||	|||
��WYd}	~	q(d}	~	00q(dS)a�Send http_request via the given http, performing error/retry handling.

    Args:
      http: An httplib2.Http instance, or a http multiplexer that delegates to
          an underlying http, for example, HTTPMultiplexer.
      http_request: A Request to send.
      retries: (int, default 7) Number of retries to attempt on retryable
          replies (such as 429 or 5XX).
      max_retry_wait: (int, default 60) Maximum number of seconds to wait
          when retrying.
      redirections: (int, default 5) Number of redirects to follow.
      retry_func: Function to handle retries on exceptions. Argument is an
          ExceptionRetryArgs tuple.
      check_response_func: Function to validate the HTTP response.
          Arguments are (Response, response content, url).

    Raises:
      InvalidDataFromServerError: if there is no response after retries.

    Returns:
      A Response object.

    r�redirect_codesr)�redirections�check_response_funcrGN)rpro�setrv�_MakeRequestNoRetry�	Exceptionr)rr�retriesrrw�
retry_funcrx�retryZfirst_req_time�err!r!r"r9s"
��rc
	Cs�d}t|dd�r6t�|j�j}|r6||jvr6|j|}tjdkrDdnd}t|||d��:|j	t
|j�t
|j�|j|j
||d�\}}Wd�n1s�0Y|dur�t���t|||j�}	||	�|	S)a�Send http_request via the given http.

    This wrapper exists to handle translation between the plain httplib2
    request/response types and the Request and Response types above.

    Args:
      http: An httplib2.Http instance, or a http multiplexer that delegates to
          an underlying http, for example, HTTPMultiplexer.
      http_request: A Request to send.
      redirections: (int, default 5) Number of redirects to follow.
      check_response_func: Function to validate the HTTP response.
          Arguments are (Response, response content, url).

    Returns:
      A Response object.

    Raises:
      RequestError if no response could be parsed.

    Nr�r)r)�methodr,r)rw�connection_type)r4r�urlsplitr'�schemerrrr#�requestr6r(r,r)rr0r)
rrrwrxr�Z
url_schemeZnew_debuglevelrNrPr^r!r!r"rzks"
�(rzcCst�|�dSr&)�_HTTP_FACTORIES�append)�factoryr!r!r"�_RegisterHttpFactory�sr�cKs8tD]"}|fi|��}|dur|Sqtjfi|��Sr&)r�r�Http)�kwdsr�rr!r!r"r	�s

r	)N),r@�collections�
contextlibrfrhrprr:�	six.movesrZsix.moves.urllibr�apitools.base.pyrr�oauth2client.clientrrn�ImportErrorr�__all__ZRESUME_INCOMPLETErZ�MOVED_PERMANENTLY�FOUND�	SEE_OTHER�TEMPORARY_REDIRECTrU�
namedtupler�contextmanagerr#�objectr
rrrrr
rrzr�r�r	r!r!r!r"�<module>s`
��+-�3
=�
2�
/