File: //lib/python3/dist-packages/lazr/restfulclient/__pycache__/_browser.cpython-38.pyc
U
��[�J � @ s$ d Z eZdddgZddlZddlZddlmZ ddlZddl Z ddl
Z
ddlZddlZddl
mZ ddlmZmZ zdd lmZ W n& ek
r� dd
lmZ ejZY nX zddlmZ W n ek
r� ddlmZ Y nX zddlmZ W n" ek
�r dd
lmZ Y nX zddlmZ W n" ek
�rB ddlmZ Y nX ddl 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�dZ7nddlm8Z7 G dd� de�Z9G dd� de:�Z;G dd� de;�Z<G d 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 [?/:|]+c C s� zRt | t�r| �d�}n| }t�|�rPt | t�rF| �d�} | �d�} n
| �d�} W n tk
rf Y nX t | t�r|| �d�} t| �� � }t
�d| �} t�d| �} t
j}|d d }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_typer Z 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+ 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.
Z%LP_DISABLE_SSL_CERTIFICATE_VALIDATIONF)�bool�os�environ�getr) r) r) r* r � s �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 s@ t � }tt| �j||||td� || _| jd k r<| j�| � d S )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
sJ d|kr|d= | j dk r*| j �||||� tt| ��||||||||| � S )z4Use the authorizer to authorize an outgoing request.Z
authorizationN)r5 ZauthorizeRequestr2 r �_request)
r6 ZconnZhostZabsolute_uri�request_uri�method�body�headersZredirections�cachekeyr: r) r* r<