o
    ýed  ã                   @   s€   d Z ddlmZ ddlZddlmZmZ ddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ G d
d„ deƒZdS )z9
This module provide base class for BCE service clients.
é    )Úabsolute_importN)ÚstrÚbytes)Úbce_client_configuration)ÚBceClientError)Úbce_v1_signer)Úhandler)Úbce_http_clientc                   @   s^   e Zd ZdZddd„Zdd„ Zdd„ Zdd
d„Zdd„ Zdd„ Z	dd„ Z
dd„ Zddd„Zd	S )ÚBceBaseClientz
    TODO: add docstring
    Tc                 C   sR   |   ¡ | _|| _t tj¡| _|dur| j |¡ | jj	du r'|  
¡ | j_	dS dS )aU  
        :param config: the client configuration. The constructor makes a copy of this parameter so
                        that it is safe to change the configuration after then.
        :type config: BceClientConfiguration

        :param region_supported: true if this client supports region.
        :type region_supported: bool
        N)Ú_compute_service_idÚ
service_idÚregion_supportedÚcopyÚdeepcopyr   ZDEFAULT_CONFIGÚconfigZmerge_non_none_valuesÚendpointÚ_compute_endpoint)Úselfr   r   © r   úHD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/bce_base_client.pyÚ__init__   s   
	ÿzBceBaseClient.__init__c                 C   s   | j  d¡d S )NÚ.é   )Ú
__module__Úsplit©r   r   r   r   r   2   s   z!BceBaseClient._compute_service_idc                 C   sH   | j jr| j jS | jrd| j j| j| j jtjf S d| j j| jtjf S )Ns   %s://%s.%s.%ss
   %s://%s.%s)r   r   r   Úprotocolr   ÚregionÚbaidubceZDEFAULT_SERVICE_DOMAINr   r   r   r   r   5   s   üýzBceBaseClient._compute_endpointNc              
   C   s$   t  | jtjtjtjg|||||¡S ©N)r	   Úsend_requestr   r   Úsignr   Zparse_errorZ
parse_json)r   Zhttp_methodÚpathÚheadersÚparamsÚbodyr   r   r   Ú_send_requestD   s   
þzBceBaseClient._send_requestc                 C   s   t  || ¡S r   )r   r   )r   ZapiDictZapiNamer   r   r   Ú_get_configI   s   zBceBaseClient._get_configc                 C   ó   |   |d ||¡ d S )Nr#   ©Ú_set_if_nonnull©r   Z	apiConfigÚkeyÚvaluer   r   r   Ú_add_headerL   s   zBceBaseClient._add_headerc                 C   r(   )NZqueriesr)   r+   r   r   r   Ú
_add_queryO   s   zBceBaseClient._add_queryc                 C   s0   |d u rt dƒ‚|d  d| d |¡|d< d S )Ns   Path param can't be none.r"   ú[ú])r   Úreplacer+   r   r   r   Ú_add_path_paramS   s    zBceBaseClient._add_path_paramc                 C   s   |d ur
|||< d S d S r   r   )r   r$   Ú
param_namer-   r   r   r   r*   X   s   ÿzBceBaseClient._set_if_nonnull)T)NNN)NN)Ú__name__r   Ú__qualname__Ú__doc__r   r   r   r&   r'   r.   r/   r3   r*   r   r   r   r   r
      s    

r
   )r7   Ú
__future__r   r   Úbuiltinsr   r   r   r   Zbaidubce.exceptionr   Zbaidubce.authr   Zbaidubce.httpr   r	   Úobjectr
   r   r   r   r   Ú<module>   s   