File: //lib/python3/dist-packages/lazr/restfulclient/__pycache__/_browser.cpython-310.pyc
o
�`J � @ s� d Z eZg d�ZddlZddlZddlmZ ddlm Z ddl
mZ ddlZddl
Z
ddlZddlZddlZddlmZ ddlmZmZ zdd lmZ W n ey^ dd
lmZ ejZY nw zddlmZ W n eyv ddlmZ Y nw ddlmZ dd
lm Z ddl!m"Z"m#Z# ddl$m%Z% e&e'u r�e(Z)e*Z+ne'Z)e'Z+e
�,d�Z-e
�,d�Z.e
�,d�Z/dd� Z0dd� Z1ej2�3d�r�dZ4nddlm5Z4 G dd� de�Z6G dd� de7�Z8G dd� de8�Z9G dd � 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)�BytesIO)�dumps)�sleep)�Http�urlnorm)�proxy_info_from_environment)� ProxyInfo)� urlencode)�Application)�URI)� error_for� HTTPError)�DatetimeJSONEncoders ^\w+://z^\w+://s [?/:|]+c C s� z)t | t�r| �d�}n| }t�|�r(t | t�r#| �d�} | �d�} n| �d�} W n ty2 Y nw t | t�r=| �d�} t| �� � }t
�d| �} t�d| �} t
j}|d d }t| �|krd| 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-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_sum� r. �=/usr/lib/python3/dist-packages/lazr/restfulclient/_browser.py�safenameU s.
��
r0 c C s t tj�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.
�%LP_DISABLE_SSL_CERTIFICATE_VALIDATIONF)�bool�os�environ�getr. r. r. r/ r � s �r z"/etc/ssl/certs/ca-certificates.crt)�CA_CERTSc sB e Zd ZdZdZdddef� fdd� Z� fdd�Zdd � Z� Z S )
r z�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 sD t � }tt| �j||||td� || _| jd ur | j�| � d S d S )N)�"disable_ssl_certificate_validation�ca_certs)r �superr �__init__�SYSTEM_CA_CERTS�
authorizer�authorizeSession)�selfr= �cache�timeout�
proxy_info�
cert_disabled�� __class__r. r/ r; � s
�
�zRestfulHttp.__init__c
sJ d|v r|d= | j dur| j �||||� tt| ��||||||||| � S )z4Use the authorizer to authorize an outgoing request.�
authorizationN)r= �authorizeRequestr: r �_request)
r? �conn�host�absolute_uri�request_uri�method�body�headers�redirections�cachekeyrD r. r/ rH � s
�
�zRestfulHttp._requestc C s t | jt�r
| j�||�S dS )�+Retrieve a cached value for an HTTP header.N)r r@ �MultipleRepresentationCache�_getCachedHeader)r? �uri�headerr. r. r/ rT � s zRestfulHttp._getCachedHeader)
�__name__�
__module__�__qualname__�__doc__r&