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/uaclient/http/__pycache__/serviceclient.cpython-38.pyc
U

��Jh��@stddlZddlZddlZddlZddlmZmZmZddlm	Z	ddl
mZmZm
Z
mZmZGdd�dejd�ZdS)�N)�Any�Dict�Optional)�	urlencode)�config�http�system�util�versionc@s�eZdZdZdZeejed�dd���Z	de
ejdd�dd�Z
d	d
�Zdee
eejd�d
d�Zed�dd�Zee
ejd�dd�ZdS)�UAServiceClient�N)�returncCsdS)z@String in subclasses, the UAConfig attribute containing base urlN���selfrr�=/usr/lib/python3/dist-packages/uaclient/http/serviceclient.py�cfg_url_base_attrsz!UAServiceClient.cfg_url_base_attr)�cfgr
cCs|st��|_n||_dS�N)r�UAConfigr)rrrrr�__init__szUAServiceClient.__init__cCsd�t���ddd�S)NzUA-Client/{}�application/json)z
user-agentZaccept�content-type)�formatr
Zget_versionrrrr�headerss�zUAServiceClient.headersT)�log_response_body�timeoutr
cCs�|�d�}|s|��}|�d�dkr>|r>tj|tjd��d�}t�	t
|j|j�|�}|�
|�}	|	rf|	S|r�dd�t|���D�}
|dt|
�7}|dk	r�|n|j}tj||||||d	�S)
N�/rr)�clszutf-8cSsi|]\}}|dk	r||�qSrr)�.0�k�vrrr�
<dictcomp>>sz/UAServiceClient.request_url.<locals>.<dictcomp>�?)�url�datar�methodrr)�lstripr�get�json�dumpsr	ZDatetimeAwareJSONEncoder�encode�	posixpath�join�getattrrr�_get_fake_responses�sorted�itemsr�url_timeoutrZreadurl)r�pathr%rr&Zquery_paramsrrr$Z
fake_responseZfiltered_paramsZtimeout_to_userrr�request_url%s2

�

��zUAServiceClient.request_url)r$cCsf|jdk	r|j�|g�S|jj�d�}|s2i|_n&tj�|�sFi|_nt�t	�
|��|_|j�|g�S)a.Return a list of fake response dicts for a given URL.

        serviceclient_url_responses in uaclient.conf should be a path
        to a json file which contains a dictionary keyed by full URL path.
        Each value will be a list of dicts representing each faked response
        for the given URL.

            The response dict item will have a code: <HTTP_STATUS_CODE> and
               response: "some string of content".
            The JSON string below fakes the available_resources URL on the
            contract server:
            '{"https://contracts.canonical.com/v1/resources":                [{"code": 200, "response": {"key": "val1", "key2": "val2"}}]}'

        :return: List of dicts for each faked response matching the url, or
           and empty list when no matching url found.
        NZserviceclient_url_responses)�_response_overlayr(rZfeatures�osr3�existsr)�loadsrZ	load_file)rr$Zresponse_overlay_pathrrr�_get_response_overlayMs
��z%UAServiceClient._get_response_overlay)r$r
cCs�|�|�}|sdSt|�dkr(|d}n
|�d�}i}g}|d}t|t�rR|}nt|t�r`|}tj|d|�di�t	j
|ddd�||d	�S)
z7Return response if faked for this URL in uaclient.conf.N�r�response�coderT)Z	sort_keys)r<rZbody�	json_dict�	json_list)r9�len�pop�
isinstance�dict�listr�HTTPResponser(r)r*)rr$Z	responsesr;r=r>Zresprrrr/os(





�z#UAServiceClient._get_fake_responses)N)NNNNTN)�__name__�
__module__�__qualname__r2r5�property�abc�abstractmethod�strrrrrrr�bool�intrrDr4r9r/rrrrrs(
��("r)�	metaclass)rIr)r6r,�typingrrrZurllib.parserZuaclientrrrr	r
�ABCMetarrrrr�<module>s