HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/lazr/restfulclient/__pycache__/_browser.cpython-38.pyc
U

��[�J�@s$dZeZdddgZddlZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZzdd	lmZWn&ek
r�dd
lmZejZYnXzddlmZWn ek
r�ddlmZYnXzddlmZWn"ek
�rdd
lmZYnXzddlmZWn"ek
�rBddlmZYnXddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ddl'm(Z(e)e*k�r�e+Z,e-Z.ne*Z,e*Z.e	�/d�Z0e	�/d�Z1e	�/d�Z2dd�Z3dd�Z4ej5�6d��r�dZ7nddlm8Z7Gdd�de�Z9Gdd�de:�Z;Gdd�de;�Z<Gd d�d�Z=dS)!z�Browser object to make requests of lazr.restful web services.

The `Browser` class does some massage of HTTP requests and responses,
and handles custom caches. It is not part of the public
lazr.restfulclient API. (But maybe it should be?)
�Browser�RestfulHttp�#ssl_certificate_validation_disabled�N)�md5)�sleep)�Http�urlnorm)�proxy_info_from_environment)�	ProxyInfo)�dumps)�BytesIO)�StringIO)�	urlencode)�Application)�URI)�	error_for�	HTTPError)�DatetimeJSONEncoders^\w+://z^\w+://s[?/:|]+cCs�zRt|t�r|�d�}n|}t�|�rPt|t�rF|�d�}|�d�}n
|�d�}Wntk
rfYnXt|t�r||�d�}t|��	�}t
�d|�}t�d|�}t
j}|dd}t|�|kr�|d|�}d�|�d�|f�S)	z�Return a filename suitable for the cache.

    Strips dangerous and common characters to create a filename we
    can use to store the cache in.
    �utf-8Zidna��,� �N�,)�
isinstance�bytes�decode�re_url_scheme_s�match�encode�UnicodeError�unicode_typerZ	hexdigest�
re_url_scheme�sub�re_slashr�maximum_cache_filename_length�len�join)�filenameZfilename_matchZfilemd5Zmaximum_filename_lengthZmaximum_length_before_md5_sum�r)�=/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py�safename^s*





r+cCsttj�dd��S)z�Whether the user has disabled SSL certificate connection.

    Some testing servers have broken certificates.  Rather than raising an
    error, we allow an environment variable,
    ``LP_DISABLE_SSL_CERTIFICATE_VALIDATION`` to disable the check.
    Z%LP_DISABLE_SSL_CERTIFICATE_VALIDATIONF)�bool�os�environ�getr)r)r)r*r�s�z"/etc/ssl/certs/ca-certificates.crt)�CA_CERTScsBeZdZdZdZdddef�fdd�	Z�fdd�Zdd	�Z�Z	S)
rz�An Http subclass with some custom behavior.

    This Http client uses the TE header instead of the Accept-Encoding
    header to ask for compressed representations. It also knows how to
    react when its cache is a MultipleRepresentationCache.
    �Ncs@t�}tt|�j||||td�||_|jdk	r<|j�|�dS)N)Z"disable_ssl_certificate_validationZca_certs)r�superr�__init__�SYSTEM_CA_CERTS�
authorizerZauthorizeSession)�selfr5�cache�timeout�
proxy_infoZ
cert_disabled��	__class__r)r*r3�s
�
zRestfulHttp.__init__c

sJd|kr|d=|jdk	r*|j�||||�tt|��|||||||||	�	S)z4Use the authorizer to authorize an outgoing request.Z
authorizationN)r5ZauthorizeRequestr2r�_request)
r6ZconnZhostZabsolute_uri�request_uri�method�body�headersZredirections�cachekeyr:r)r*r<�s(
�
�zRestfulHttp._requestcCst|jt�r|j�||�SdS)�+Retrieve a cached value for an HTTP header.N)rr7�MultipleRepresentationCache�_getCachedHeader)r6�uri�headerr)r)r*rD�szRestfulHttp._getCachedHeader)
�__name__�
__module__�__qualname__�__doc__r%r	r3r<rD�
__classcell__r)r)r:r*r�s�c@s@eZdZdZdZefdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
S)�AtomicFileCachez�A FileCache that can be shared by multiple processes.

    Based on a patch found at
    <http://code.google.com/p/httplib2/issues/detail?id=125>.
    z.tempc
CsZtj�|�|_||_zt�|j�Wn0tk
rT}z|jtjkrD�W5d}~XYnXdS)aUConstruct an ``AtomicFileCache``.

        :param cache: The directory to use as a cache.
        :param safe: A function that takes a key and returns a name that's
            safe to use as a filename.  The key must never return a string
            that begins with ``TEMPFILE_PREFIX``.  By default uses
            ``safename``.
        N)	r-�path�normpath�
_cache_dir�_get_safe_name�makedirs�OSError�errnoZEEXIST)r6r7Zsafe�er)r)r*r3�s	zAtomicFileCache.__init__cCs4|�|�}|�|j�r$td|j��tj�|j|�S)z0Return the path on disk where ``key`` is stored.z Cache key cannot start with '%s')rP�
startswith�TEMPFILE_PREFIX�
ValueErrorr-rMr'rO)r6�keyZsafe_keyr)r)r*�
_get_key_path�s
�zAtomicFileCache._get_key_pathc
Csl|�|�}z(t|d�}z|��W�WS|��XWn4ttfk
rf}z|jtjkrV�W5d}~XYnXdS)a�Get the value of ``key`` if set.

        This behaves slightly differently to ``FileCache`` in that if
        ``set()`` fails to store a key, this ``get()`` will behave as if that
        key were never set whereas ``FileCache`` returns the empty string.

        :param key: The key to retrieve.  Must be either bytes or unicode
            text.
        :return: The value of ``key`` if set, None otherwise.
        �rbN)rY�open�close�read�IOErrorrRrS�ENOENT)r6rX�cache_full_path�frTr)r)r*r/�s

zAtomicFileCache.getcCsntj|j|jd�\}}t�|d�}|�|�|��|�|�}t	j
dkr^tj�|�r^t�
|�t�||�dS)z�Set ``key`` to ``value``.

        :param key: The key to set.  Must be either bytes or unicode text.
        :param value: The value to set ``key`` to.  Must be bytes.
        )�prefix�dir�wbZwin32N)�tempfileZmkstemprVrOr-�fdopen�writer\rY�sys�platformrM�exists�unlink�rename)r6rX�valueZhandle�	path_namerar`r)r)r*�sets�



zAtomicFileCache.setc
CsN|�|�}zt�|�Wn0tk
rH}z|jtjkr8�W5d}~XYnXdS)z�Delete ``key`` from the cache.

        If ``key`` has not already been set then has no effect.

        :param key: The key to delete.  Must be either bytes or unicode text.
        N)rYr-�removerRrSr_)r6rXr`rTr)r)r*�deletes
zAtomicFileCache.deleteN)rGrHrIrJrVr+r3rYr/rorqr)r)r)r*rL�srLcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)rCa>A cache that can hold different representations of the same resource.

    If a resource has two representations with two media types,
    FileCache will only store the most recently fetched
    representation. This cache can keep track of multiple
    representations of the same resource.

    This class works on the assumption that outside calling code sets
    an instance's request_media_type attribute to the value of the
    'Accept' header before initiating the request.

    This class is very much not thread-safe, but FileCache isn't
    thread-safe anyway.
    cstt|��||j�d|_dS)z>Tell FileCache to call append_media_type when generating keys.N)r2rCr3�append_media_type�request_media_type)r6r7r:r)r*r37s

�z$MultipleRepresentationCache.__init__cCs |jdk	r|d|j}t|�S)z�Append the request media type to the cache key.

        This ensures that representations of the same resource will be
        cached separately, so long as they're served as different
        media types.
        N�-)rsr+)r6rXr)r)r*rr=s
z-MultipleRepresentationCache.append_media_typec
Csrt|�\}}}}|�|�}|d}t|t�s6|�d�}|dk	rnt|�D]&}	|	�|�rF|	t|�d���SqFdS)rB�:rN)	rr/rrrrrUr&�strip)
r6rErFZschemeZ	authorityr=rAZcached_valueZheader_start�liner)r)r*rDHs



z,MultipleRepresentationCache._getCachedHeader)rGrHrIrJr3rrrDrKr)r)r:r*rC(srCc@sveZdZdZe�ZdZddddefdd�Zdd�Zdd
d�Z	dd
d�Z
dd�Zdd�Zddd�Z
dd�Zddd�ZdS)rz6A class for making calls to lazr.restful web services.�NcCsR|dkrt��}t�tj|�t|t�r0t|�}|�	||||�|_
||_||_dS)z�Initialize, possibly creating a cache.

        If no cache is provided, a temporary directory will be used as
        a cache. The temporary directory will be automatically removed
        when the Python process exits.
        N)
reZmkdtemp�atexit�register�shutilZrmtreer�	str_typesrCZhttpFactory�_connection�
user_agent�max_retries)r6Zservice_rootZcredentialsr7r8r9r~rr)r)r*r3\s
�zBrowser.__init__c	Cshtd|jd�D]N}|jj||||d�\}}|jdkrZ||jkrZtd|d�}t|�qq`q||fS)Nrr�r>r?r@)i�i��)�rangerr}Zrequest�status�intr)	r6�urlr>r?r@Zretry_count�response�contentZ	sleep_forr)r)r*�_request_and_retryns�

�
zBrowser._request_and_retry�GET�application/jsonc
Cs�|dkrtd��d|i}|jdk	r,|j|d<t|jjt�rD||jj_|dk	rV|�|�|jt	|�|||d�\}}|j
dkr�|dkr�d	|ks�d
|kr�||jfSt||��nd|_
||fSt
||�}	|	dk	r�|	�||fS)z'Create an authenticated request object.ztag:launchpad.net:2008:redactedzUYou tried to access a resource that you don't have the server-side permission to see.ZAcceptNz
User-Agentr�i0rz
If-None-MatchzIf-Modified-Since��)rWr~rr}r7rCrs�updater��strr��NOT_MODIFIEDrr)
r6r��datar>�
media_type�
extra_headersr@r�r��errorr)r)r*r<}s8



�

�
	
zBrowser._requestFcCsHt|ttf�r|}n|�d�}|��}|j||d�\}}|rD||fS|S)z2GET a representation of the given resource or URI.r/�r�)rr|rZ
get_methodZbuild_request_urlr<)r6Zresource_or_urir@Zreturn_responser�r>r�r�r)r)r*r/�s
zBrowser.getcCs<d}|j||d�\}}t|�}t|t�s2|�d�}t||�S)z?GET a WADL representation of the resource at the requested url.zapplication/vnd.sun.wadl+xml)r�r)r<r�rrrr)r6r�Z	wadl_typer�r�r)r)r*�get_wadl_application�s

zBrowser.get_wadl_applicationcKs||d<t|�}|�||d�S)z"POST a request to the web service.zws.opZPOST)rr<)r6r�Zmethod_nameZkwsr�r)r)r*�post�szBrowser.postcCs,d|i}|dk	r|�|�|j||d|d�S)z(PUT the given representation to the URL.�Content-TypeNZPUTr�)r�r<)r6r��representationr�r@r�r)r)r*�put�s
�zBrowser.putcCs|j|dd�dS)z%DELETE the resource at the given URL.ZDELETE)r>N)r<)r6r�r)r)r*rq�szBrowser.deletecCs^ddi}|dk	r|�|�|j�t|�d�}|dk	rD|jjsD||d<|j|t|td�d|d�S)	z8PATCH the object at url with the updated representation.r�r�NZetagzIf-Match)�clsZPATCHr�)r�r}rDr�Zignore_etagr<rr)r6r�r�r@r�Zcached_etagr)r)r*�patch�s

�z
Browser.patch)Nr�r�N)NF)N)N)rGrHrIrJ�objectr�ZMAX_RETRIESr3r�r<r/r�r�r�rqr�r)r)r)r*rVs&�
�
<
	
)>rJ�typeZ
__metaclass__�__all__ryrSZhashlibrr-�rer{rhre�timerZhttplib2rrr	�ImportErrorr
Zfrom_environmentZjsonrZ
simplejson�ior�	cStringIOr
Zurllib.parserZurllibZwadllib.applicationrZlazr.urirZlazr.restfulclient.errorsrrZlazr.restfulclient._jsonrrr�Zunicoder!Z
basestringr|�compiler"rr$r+rrMrjr4r0rr�rLrCrr)r)r)r*�<module>sj�



/.\.