%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/lazr/restfulclient/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/lazr/restfulclient/__pycache__/_browser.cpython-312.pyc

�

}�;e$L��h�dZeZgd�ZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZddlmZmZ	dd	lmZ	ddlmZddlmZdd
lm Z ddl!m"Z"m#Z#ddl$m%Z%e&e'ure(Z)e*Z+ne'Z)e'Z+ejXd�Z-ejXd�Z.ejXd�Z/d�Z0d�Z1ejdjgd�rdZ4nddlm5Z4Gd�de�Z6Gd�de7�Z8Gd�de8�Z9Gd�d�Z:y#e$rdd
lmZej2ZY��wxYw#e$r	ddlmZY��wxYw)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)�BytesIO)�dumps)�sleep)�Http�urlnorm)�proxy_info_from_environment)�	ProxyInfo)�	urlencode)�Application)�DatetimeJSONEncoder)�	HTTPError�	error_for)�URIs^\w+://z^\w+://s[?/:|]+c��	t|t�r|jd�}n|}tj	|�rDt|t�r#|jd�}|jd�}n|jd�}t|t�r|jd�}t|�j�}tjd|�}tjd|�}tj}|dz
dz
}t|�|kDr|d|}dj!|jd�|f�S#t$rY��wxYw)	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-8�idna��,� �N�,)�
isinstance�bytes�decode�re_url_scheme_s�match�encode�UnicodeError�unicode_typer�	hexdigest�
re_url_scheme�sub�re_slashr�maximum_cache_filename_length�len�join)�filename�filename_match�filemd5�maximum_filename_length�maximum_length_before_md5_sums     �=/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py�safenamer1Ws��

��h��&�%�_�_�W�5�N�%�N�� � ��0��(�E�*�#�?�?�7�3��#�?�?�6�2��#�?�?�6�2���(�L�)��?�?�7�+���(�m�%�%�'�G�� � ��h�/�H��|�|�D�(�+�H� *�G�G��$;�b�$@�1�$D�!�
�8�}�4�4��:�:�;���8�8�X�_�_�W�-�w�7�8�8��5�
��
�s�A=D2�2	D>�=D>c�T�ttjjdd��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.
    �%LP_DISABLE_SSL_CERTIFICATE_VALIDATIONF)�bool�os�environ�get�rr0rr�s����
�
���F��N�O�Orz"/etc/ssl/certs/ca-certificates.crt)�CA_CERTSc�@��eZdZdZdZdddef�fd�	Z�fd�Zd�Z�xZ	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.
    �Nc���t�}tt|�||||t��||_|j
�|j
j
|�yy)N)�"disable_ssl_certificate_validation�ca_certs)r�superr�__init__�SYSTEM_CA_CERTS�
authorizer�authorizeSession)�selfrB�cache�timeout�
proxy_info�
cert_disabled�	__class__s      �r0r@zRestfulHttp.__init__�sZ���<�=�
�
�k�4�)����/<�$�	*�	
�%����?�?�&��O�O�,�,�T�2�'rc
���d|vr|d=|j�|jj||||�tt|�|||||||||	�	S)z4Use the authorizer to authorize an outgoing request.�
authorization)rB�authorizeRequestr?r�_request)rD�conn�host�absolute_uri�request_uri�method�body�headers�redirections�cachekeyrIs          �r0rMzRestfulHttp._request�sm����g�%���(��?�?�&��O�O�,�,��f�d�G�
��[�$�0����������

�
	
rc�p�t|jt�r|jj||�Sy)�+Retrieve a cached value for an HTTP header.N)rrE�MultipleRepresentationCache�_getCachedHeader)rD�uri�headers   r0rZzRestfulHttp._getCachedHeader�s+���d�j�j�"=�>��:�:�.�.�s�F�;�;�r)
�__name__�
__module__�__qualname__�__doc__r(rr@rMrZ�
__classcell__�rIs@r0rr�s.����%(�!����.�3�&#
�Jrrc�6�eZdZdZdZefd�Zd�Zd�Zd�Z	d�Z
y)	�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��tjj|�|_||_	tj
|j�y#t$r(}|jtjk7r�Yd}~yd}~wwxYw)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)	r5�path�normpath�
_cache_dir�_get_safe_name�makedirs�OSError�errno�EEXIST)rDrE�safe�es    r0r@zAtomicFileCache.__init__�s_���'�'�*�*�5�1���"���	��K�K����(���	��w�w�%�,�,�&��'��	�s�A
�
	A>�A9�9A>c���|j|�}|j|j�rtd|jz��tj
j
|j|�S)z0Return the path on disk where ``key`` is stored.z Cache key cannot start with '%s')ri�
startswith�TEMPFILE_PREFIX�
ValueErrorr5rfr*rh)rD�key�safe_keys   r0�
_get_key_pathzAtomicFileCache._get_key_path�s^���&�&�s�+�����t�3�3�4��2�T�5I�5I�I��
��w�w�|�|�D�O�O�X�6�6rc��|j|�}	t|d�}	|j�|j�S#|j�wxYw#tt
f$r(}|jtjk7r�Yd}~yd}~wwxYw)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)rv�open�read�close�IOErrorrkrl�ENOENT)rDrt�cache_full_path�fros     r0r7zAtomicFileCache.getsr���,�,�S�1��	��_�d�+�A�
��v�v�x����	�����	����!�	��w�w�%�,�,�&��'��	�s-�A�A�A�A�A�B�$B�Bc��tj|j|j��\}}t	j
|d�}|j
|�|j�|j|�}tjdk(r4tjj|�rt	j|�t	j||�y)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�wb�win32N)�tempfile�mkstemprrrhr5�fdopen�writer{rv�sys�platformrf�exists�unlink�rename)rDrt�value�handle�	path_namerr~s       r0�setzAtomicFileCache.sets���%�,�,��'�'�T�_�_�
���	�
�I�I�f�d�#��	�����	���	��,�,�S�1���<�<�7�"�r�w�w�~�~�o�'F��I�I�o�&�
�	�	�)�_�-rc��|j|�}	tj|�y#t$r(}|jtj
k7r�Yd}~yd}~wwxYw)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)rvr5�removerkrlr})rDrtr~ros    r0�deletezAtomicFileCache.delete.sM���,�,�S�1��	��I�I�o�&���	��w�w�%�,�,�&��'��	�s�)�	A�A�AN)r]r^r_r`rrr1r@rvr7r�r�r8rr0rdrd�s*����O�#+��"
7��,.�&rrdc�.��eZdZdZ�fd�Zd�Zd�Z�xZS)rYa>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.
    c�P��tt|�||j�d|_y)z>Tell FileCache to call append_media_type when generating keys.N)r?rYr@�append_media_type�request_media_type)rDrErIs  �r0r@z$MultipleRepresentationCache.__init__Ms(���
�)�4�9��4�)�)�	
�#'��rc�T�|j�|dz|jz}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.
        �-)r�r1)rDrts  r0r�z-MultipleRepresentationCache.append_media_typeTs.���"�"�.���)�d�5�5�5�C���}�rc��t|�\}}}}|j|�}|dz}t|t�s|j	d�}|�?t|�D]1}	|	j
|�s�|	t|�dj�cSy)rX�:rN)	rr7rrr!rrqr)�strip)
rDr[r\�scheme�	authorityrQrV�cached_value�header_start�lines
          r0rZz,MultipleRepresentationCache._getCachedHeader_s���5<�S�\�2���K���x�x��)����|���,��.�'�.�.�w�7�L��#���-�
=���?�?�<�0���L� 1� 3�4�:�:�<�<�
=�r)r]r^r_r`r@r�rZrarbs@r0rYrY=s���
�'�	�rrYc�t�eZdZdZe�ZdZddddefd�Zd�Z				d
d�Z	dd�Z
d�Zd	�Zdd
�Z
d�Zdd�Zy)rz6A class for making calls to lazr.restful web services.�Nc��|�8tj�}tjtj
|�t
|t�rt|�}|j||||�|_
||_||_y)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)
r��mkdtemp�atexit�register�shutil�rmtreer�	str_typesrY�httpFactory�_connection�
user_agent�max_retries)rD�service_root�credentialsrErFrGr�r�s        r0r@zBrowser.__init__ssj�� �=��$�$�&�E��O�O�F�M�M�5�1��e�Y�'�/��6�E�'�3�3�����
���%���&��rc��td|jdz�D]b}|jj||||��\}}|jdvr,||jkrtd|dz
z�}t
|��_||fSfS)Nrr�rRrSrT)i�i��)�ranger�r��request�status�intr	)	rD�urlrRrSrT�retry_count�response�content�	sleep_fors	         r0�_request_and_retryzBrowser._request_and_retry�s��� ��D�$4�$4�q�$8�9�
	�K� $� 0� 0� 8� 8��F��w�!9�!��H�g����:�-��$�"2�"2�2� ��k�A�o� 6�7�	��i� ���� � �
	��� � rc���|dk(rtd��d|i}|j�|j|d<t|jjt
�r||jj_|�|j|�|jt|�|||��\}}|jdk(r2|dk(r"d|vsd	|vr||jfSt||��d
|_
||fSt||�}	|	�|	�||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.�Acceptz
User-Agentr�i0rz
If-None-MatchzIf-Modified-Since��)rsr�rr�rErYr��updater��strr��NOT_MODIFIEDrr)
rDr��datarR�
media_type�
extra_headersrTr�r��errors
          r0rMzBrowser._request�s%���3�3��@��
��Z�(���?�?�&�$(�O�O�G�L�!��d�&�&�,�,�.I�J�8B�D���"�"�5��$��N�N�=�)� �3�3���H�V�$��4�
���'��?�?�c�!��#�~�#�w�.�*�g�5�$�T�%6�%6�6�6�$�H�g�6�6�#&����W�$�$��(�G�,�����K��� � rc��t|ttf�r|}n!|jd�}|j	�}|j||��\}}|r||fS|S)z2GET a representation of the given resource or URI.r7�r�)rr�r�
get_method�build_request_urlrM)rD�resource_or_urirT�return_responser�rRr�r�s        r0r7zBrowser.get�s^���o�	�3�'7�8�!�C�$�/�/��6�F��*�*�,�C� �M�M�#�W�M�E���'���g�&�&��rc��d}|j||��\}}t|�}t|t�s|j	d�}t||�S)z?GET a WADL representation of the resource at the requested url.zapplication/vnd.sun.wadl+xml)r�r)rMr�rrr!r)rDr��	wadl_typer�r�s     r0�get_wadl_applicationzBrowser.get_wadl_application�sL��2�	� �M�M�#�)�M�D���'��#�h���'�5�)��n�n�W�-�G��3��(�(rc�H�||d<t|�}|j||d�S)z"POST a request to the web service.zws.op�POST)rrM)rDr��method_name�kwsr�s     r0�postzBrowser.post�s'��"��G����~���}�}�S�$��/�/rc�Z�d|i}|�|j|�|j||d|��S)z(PUT the given representation to the URL.�Content-Type�PUTr�)r�rM)rDr��representationr�rTr�s      r0�putzBrowser.puts?��'��4�
���� � ��)��}�}����m��
�	
rc�*�|j|d��y)z%DELETE the resource at the given URL.�DELETE)rRN)rM)rDr�s  r0r�zBrowser.deletes���
�
�c�(�
�+�rc��ddi}|�|j|�|jjt|�d�}|�|jjs||d<|j|t
|t��d|��S)z8PATCH the object at url with the updated representation.r��application/json�etagzIf-Match)�cls�PATCHr�)r�r�rZr��ignore_etagrMrr)rDr�r�rTr��cached_etags      r0�patchz
Browser.patchs���'�);�<�
���� � ��)��&�&�7�7��C��&�I���"�4�+;�+;�+G�+G�"-�G�J���}�}���.�&9�:��'�	�
�	
r)N�GETr�N)NF)N)r]r^r_r`�objectr��MAX_RETRIESr@r�rMr7r�r�r�r�r�r8rr0rrms_��@��8�L��K������'�6!�*��%��
E!�N
�)�0�
��

rr);r`�type�
__metaclass__�__all__r�rlr5�rer�r�r��hashlibr�ior�jsonr�timer	�httplib2r
rr�ImportErrorr
�from_environment�urllib.parser�urllib�wadllib.applicationr�lazr.restfulclient._jsonr�lazr.restfulclient.errorsrr�lazr.urirrr��unicoder#�
basestringr��compiler%rr'r1rrfr�rAr9rr�rdrYrr8rr0�<module>r�s=��&��
�����	�	�
�
������"�=�4�!�&�,�8�:���C�<��L��I��L��I���
�
�;�'�
��"�*�*�Z�(���2�:�:�k�"��,9�^P��7�7�>�>�6�7�:�O�4�F�$�F�R[�f�[�|-�/�-�`u
�u
��s	�=�"�"+�"<�"<��=���!� �!�s$�D�
D#�D �D �#D1�0D1

Zerion Mini Shell 1.0