o
    e[                     @   s,  d Z ddlZddlZddlZddlZddlZddlZddl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 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 ddlmZ ddlmZ ddlmZ ddlmZ ejrddlmZ nddlmZ e e!Z"G dd de	j#Z$dS )zh
This module provides a client class for CFC.
API Reference: https://cloud.baidu.com/doc/CFC/index.html
    N)bce_base_client)utils)bce_v1_signer)bce_http_client)handler)http_content_types)http_headers)http_methods)cfc_handler)models)BceClientError)BceServerError)required)compat)quotec                   @   sD  e Zd ZdZdZd=ddZ		d>dd	Z		d>d
dZ				d?ddZ		d@ddZ	dAddZ
dAddZ		dBddZdAddZ			d@ddZdCdd ZdAd!d"Z		dBd#d$Z		dBd%d&Zd=d'd(Z		dCd)d*Zd=d+d,Zd=d-d.ZdCd/d0ZdAd1d2Zd=d3d4Zed5d6 Zed7d8 Z			dDd9d:Z	dEd;d<ZdS )F	CfcClientz
    CdnClient
    z/v1Nc                 C   s   t j| | d S N)r   BceBaseClient__init__)selfconfig r   PD:\Projects\ConvertPro\env\Lib\site-packages\baidubce/services/cfc/cfc_client.pyr   8   s   zCfcClient.__init__RequestResponseNonec                 C   sV   i }||d< ||d< |dur||d< |du ri }| j tjd| d t|||ddS )	  
        invoking function

        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param invocation_type: (required)  Event/RequestResponse/DryRun
        :type invocation_type string

        :param  log_type: None / Tail You can set this optional parameter to Tail in the request only if you
                         specify the InvocationType parameter with value RequestResponse. In this case,CFC
                         returns the base64-encoded last 4 KB of log data produced by your cfc function in
                         the x-bce-log-result header.
        :type log_type string

        :param qualifier Minimum length of 1. Maximum length of 128. You can use function versions or function aliases.
                         If you don't, the default is $LATEST.
        :type qualifier string

        :param body: json

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: httplib.httpresponse
        ZinvocationTypeZlogTypeN	Qualifier/functions/z/invocationsT)bodyparamsr   special_send_requestr	   POSTjsondumps)r   function_nameinvocation_typelog_typer   	qualifierr   r   r   r   r   invocations;   s   !
zCfcClient.invocationsc                 C   s   |  ||||||S )r   )r*   )r   r&   r'   r(   r   r)   r   r   r   r   invokej   s   !zCfcClient.invoke   bjFpython2   c              
   C   s   |du ri }||d|||
|||	|d|id	}|r1t |d}| }t|d}||d d< n||d d< i }| jtjd	t	|||d
S )ai  
        Create cfc function

        :param function_name  (required)
        :type function_name string

        :param description - A short, user-defined function description. Minimum length of 0. Maximum length of 256.
        :type description string

        :param environment environment's configuration settings.
        :type environment String to string map, [a-zA-Z]([a-zA-Z0-9_])+

        :param handler  (required) Maximum length of 128. [^\s]+
        :type handler string

        :param memory_size  The amount of memory, in MB.The default value is 128 MB. The value must be a multiple of 64
                            MB. From 128M to 3008M. Now it only supports 128M.
        :type memory_size int

        :param region  bj or gz. Now it only supports bj.
        :type region string

        :param zip_file  (required)
        :type zip_file bytes The contents of your zip file containing your deployment package.
                        the contents of the zip file must be base64-encoded.

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :param publish  This boolean parameter can be used to request CFC to create the CFC function and publish
                        a version as an atomic operation.
        :type publish: boolean

        :param run_time: python2 | nodejs6.11
        :type run_time: string

        :param timeout: 1-300 The default is 3 seconds.
        :type timeout: int

        :param code_zip_file: the file path of the zipped code.
        :type code_zip_file: string

        :return:
        :rtype: baidubce.bce_response.BceResponse
        N)PublishDryRun	Variables)	CodeDescriptionRegionTimeoutZFunctionNameHandlerRuntimeZ
MemorySizeEnvironmentrbutf-8r3   ZipFilez
/functionsr   r   r   )
openreadbase64	b64encodedecoder"   r	   r#   r$   r%   )r   r&   descriptionenvironmentr   Zmemory_sizeregionzip_filepublishrun_timetimeoutdry_runZcode_zip_filer   data	code_filecodeZcode_base64r   r   r   r   create_function   s:   1
zCfcClient.create_functionc                 C   sj   i }|dur
||d< |dur||d< |dur||d< |dur"||d< |dur*||d< | j tjdi ||dS )	a  
        List cfc function

        :param function_version
        :type function_version string

        :param page
        :type page int

        :param page_size
        :type page_size int

        :param marker
        :type marker int

        :param max_items
        :type max_items int

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        NFunctionVersionpageZpageSizeMarkerMaxItemsr   r=   r"   r	   GET)r   function_versionrP   Z	page_sizemarker	max_itemsr   r   r   r   r   list_functions   s$   zCfcClient.list_functionsc                 C   s.   i }|dur
||d< | j tjd| i ||dS )a  
        get function

        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param qualifier Minimum length of 1. Maximum length of 128. You can use function versions or function aliases.
                         If you don't, the default is $LATEST.
        :type qualifier string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr   r   r=   rS   r   r&   r)   r   r   r   r   r   get_function     zCfcClient.get_functionc                 C   s.   i }|dur
||d< | j tjd| i i |dS )a  
        delete_function

        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param qualifier Minimum length of 1. Maximum length of 128. You can use function versions or function aliases.
                         If you don't, the default is $LATEST.
        :type qualifier string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr   r   r=   r"   r	   DELETErY   r   r   r   delete_function*  r[   zCfcClient.delete_functionc                 C   sX   i }|dur
||d< |dur||d< |dur||d< | j tjd| d t|i |dS )a  
        update_function_code

        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param zip_file
        :type zip_file bytes The contents of your zip file containing your deployment package.
                        the contents of the zip file must be base64-encoded.
        :param publish  This boolean parameter can be used to request CFC to create the CFC function and publish
                        a version as an atomic operation.
        :type publish: boolean

        :param dry_run  This boolean parameter can be used to test your request to CFC to update the function and
                        publish a version as an atomic operation. It will do all necessary computation and validation
                        of your code but will not upload it or a publish a version. Each time this operation is invoked,
                        the CodeSha256 hash value of the provided code will also be computed and returned in the
                        response.
        :type dry_run: boolean

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr<   r0   r1   r   z/coder=   r"   r	   PUTr$   r%   )r   r&   rF   rG   rJ   r   r   r   r   r   update_function_codeI  s    
zCfcClient.update_function_codec                 C   s2   i }|dur
||d< | j tjd| d i i |dS )a  
        get_function_configuration
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param qualifier Minimum length of 1. Maximum length of 128. You can use function versions or function aliases.
                         If you don't, the default is $LATEST.
        :type qualifier string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr   r   /configurationr=   rS   rY   r   r   r   get_function_configurationx     
z$CfcClient.get_function_configurationc           	      C   s|   i }|dur
||d< |durd|i|d< |dur||d< |dur$||d< |dur,||d< | j tjd| d	 t|i |d
S )a4  
        update_function_configuration
        :param function_name  (required)
        :type function_name string

        :param description - A short, user-defined function description. Minimum length of 0. Maximum length of 256.
        :type description string

        :param environment environment's configuration settings.
        :type environment String to string map, [a-zA-Z]([a-zA-Z0-9_])+

        :param handler  (required) Maximum length of 128. [^\s]+
        :type handler string

        :param run_time: python2 | nodejs6.11
        :type run_time: string

        :param timeout: 1-300 The default is 3 seconds.
        :type timeout: int

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr4   r2   r9   r7   r8   r6   r   rb   r=   r_   )	r   r&   rC   rD   r   rH   rI   r   rK   r   r   r   update_function_configuration  s$   
z'CfcClient.update_function_configurationc                 C   sB   i }|dur
||d< |dur||d< | j tjd| d i ||dS )a  
        list_versions_by_function
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

                :param marker
        :type marker int

        :param max_items
        :type max_items int

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        NrQ   rR   r   	/versionsr=   rS   )r   r&   rV   rW   r   r   r   r   r   list_versions_by_function  s   
z#CfcClient.list_versions_by_functionc                 C   s2   i }|dur
||d< | j tjd| d i ||dS )a  
        publish_version
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param description  A short, user-defined function publish description. Minimum length of 0. Maximum length of
                            256.
        :type description string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr4   r   rf   r=   )r"   r	   r#   )r   r&   rC   r   r   r   r   r   publish_version  rd   zCfcClient.publish_versionc                 C   sR   i }|dur
||d< |dur||d< |dur||d< | j tjd| d i ||dS )a  
        list_aliases
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param function_version
        :type function_version string

        :param marker
        :type marker int

        :param max_items
        :type max_items int

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        NrO   rQ   rR   r   /aliasesr=   rS   )r   r&   rU   rV   rW   r   r   r   r   r   list_aliases  s   
zCfcClient.list_aliasesc                 C   sX   i }|dur
||d< |dur||d< |dur||d< | j tjd| d t|i |dS )a,  
        create_alias
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param name alias name
        :type name string

        :param function_version function version for which you are creating the alias. (\$LATEST|[0-9]+)
        :type function_version string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :param description   Description of the alias.
        :type description string

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr4   rO   Namer   ri   r=   r!   )r   r&   rU   namerC   r   rK   r   r   r   create_alias0  s   
zCfcClient.create_aliasc                 C   "   | j tjd| d | i i |dS )aL  
        get_alias
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param alias_name alias name
        :type alias_name string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        r   	/aliases/r=   rS   r   r&   
alias_namer   r   r   r   	get_aliasY     zCfcClient.get_aliasc                 C   sL   i }|dur
||d< |dur||d< | j tjd| d | t|i |dS )a6  
        update_alias
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param alias_name alias name
        :type alias_name string

        :param function_version function version for which you are update the alias. (\$LATEST|[0-9]+)
        :type function_version string

        :param description   Description of the alias.
        :type description string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nr4   rO   r   ro   r=   r_   )r   r&   rq   rU   rC   r   rK   r   r   r   update_aliass  s   zCfcClient.update_aliasc                 C   rn   )aO  
        delete_alias
        :param function_name  (required) The cfc function name. You can specify a function name (function_name)
                                or you can specify Baidu Resource Name (BRN) of the function (for example,
                                brn:bce:cfc:bj:account-id:function:function_name). Cfc also allows you
                                to specify a simple BRN (for example, account_id:function_name). The length of BRN is
                                limited to 1 to 140 characters. The function name is limited to 64 characters in length.
        :type function_name string

        :param alias_name alias name
        :type alias_name string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        r   ro   r=   r\   rp   r   r   r   delete_alias  rs   zCfcClient.delete_aliasc                 C   s*   i }|dur
||d< | j tjdi ||dS )a  
        list_triggers
        :param function_brn  (required) The cfc function brn.
        :type function_brn string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return: message result as following format
            {
              "Relation": [
                {
                  "RelationId": "brn:bce:cfc-http-trigger:bj:cd64f99c69d7c404b61de0a4f1865834:b8542048977633ad0a867aefc33fd32a/cfc/GET/cfc/docs",
                  "Sid": "cfc-dfbd5359-1afb-49e7-81d7-16554056c79d",
                  "Source": "cfc-http-trigger/v1/CFCAPI",
                  "Target": "brn:bce:cfc:bj:cd64f99c69d7c404b61de0a4f1865834:function:helloCFCDocs:$LATEST",
                  "Data": {
                    "AuthType": "anonymous",
                    "Brn": "brn:bce:cfc-http-trigger:bj:cd64f99c69d7c404b61de0a4f1865834:b8542048977633ad0a867aefc33fd32a/cfc/GET/cfc/docs",
                    "EndpointPrefix": "https://6ewfn1337kndc.cfc-execute.bj.baidubce.com",
                    "Method": "GET",
                    "ResourcePath": "/cfc/docs"
                  }
                },
                {
                  "RelationId": "brn:bce:cfc-http-trigger:bj:cd64f99c69d7c404b61de0a4f1865834:b8542048977633ad0a867aefc33fd32a/cfc/POST,PUT/cfc/docs/edit",
                  "Sid": "cfc-dfbd5359-1afb-49e7-81d7-16554056c79d",
                  "Source": "cfc-http-trigger/v1/CFCAPI",
                  "Target": "brn:bce:cfc:bj:cd64f99c69d7c404b61de0a4f1865834:function:helloCFCDocs:$LATEST",
                  "Data": {
                    "AuthType": "anonymous",
                    "Brn": "brn:bce:cfc-http-trigger:bj:cd64f99c69d7c404b61de0a4f1865834:b8542048977633ad0a867aefc33fd32a/cfc/POST,PUT/cfc/docs/edit",
                    "EndpointPrefix": "https://6ewfn1337kndc.cfc-execute.bj.baidubce.com",
                    "Method": "POST,PUT",
                    "ResourcePath": "/cfc/docs/edit"
                  }
                }
              ]
            }
        :rtype: baidubce.bce_response.BceResponse
        NZFunctionBrn	/relationr=   rS   )r   function_brnr   r   r   r   r   list_triggers  s   *zCfcClient.list_triggersc                 C   sv   i }|dur
||d< |dur||d< |dur-t |tjr)| |d< | |d< n||d< | jtjdt	|i |dS )a  
        create_trigger
        :param function_brn  (required) The cfc function brn.
        :type function_brn string

        :param source. The trigger source type. For example, models.CRONTAB_TRIGGER
        :type source string

        :param trigger_data The trigger data. You can get details from
            https://cloud.baidu.com/doc/CFC/s/Kjwvz47o9/#relationconfiguration
        :type trigger_data models.AbstractTriggerDateModel

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:  message result as following format
            {
                "Relation": {
                    "Sid": "cfc-c53bef4e-2cac-4bc6-84c1-2d5ec2f8bec2",
                    "RelationId" : "00457f0b-20d8-4f3d-8555-c2u121f38313",
                    "Source": "string",
                    "Target": "brn:bce:cfc:bj:640c8817bd1de2928d47256dd0620ce5:function:test:$LATEST",
                    "Data": {
                        "EventType":["PutObject", "PostObject"],
                        "Prefix":"images/",
                        "Suffix":".jpg",
                        "Status":"enabled"
                    }
                }
            }
        :rtype: baidubce.bce_response.BceResponse
        NTargetSourceDatarv   r=   )

isinstancer   AbstractTriggerDataModelget_trigger_source	serializer"   r	   r#   r$   r%   )r   rw   sourcetrigger_datar   rK   r   r   r   create_trigger  s"   !zCfcClient.create_triggerc                 C   s   i }|dur
||d< |dur||d< |dur-t |tjr)| |d< | |d< n||d< |dur5||d< | jtjdt	|i |dS )aD  
        create_trigger
        :param function_brn  (required) The cfc function brn.
        :type function_brn string

        :param source  (required) The trigger source type. For example, models.CRONTAB_TRIGGER
        :type source string

        :param relation_id  (required) The relation_id.
        :type relation_id string

        :param trigger_data The trigger data. You can get details from
            https://cloud.baidu.com/doc/CFC/s/Kjwvz47o9/#relationconfiguration
        :type trigger_data models.AbstractTriggerDateModel

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return: message result as following format
            {
                "Relation": {
                    "Sid": "cfc-c53bef4e-2cac-4bc6-84c1-2d5ec2f8bec2",
                    "RelationId" : "00457f0b-20d8-4f3d-8555-c2u121f38313",
                    "Source": "string",
                    "Target": "brn:bce:cfc:bj:640c8817bd1de2928d47256dd0620ce5:function:test:$LATEST",
                    "Data": {
                        "EventType":["PutObject", "PostObject"],
                        "Prefix":"images/",
                        "Suffix":".jpg",
                        "Status":"enabled"
                    }
                }
            }
        :rtype: baidubce.bce_response.BceResponse
        Nry   rz   r{   
RelationIdrv   r=   )
r|   r   r}   r~   r   r"   r	   r`   r$   r%   )r   rw   relation_idr   r   r   rK   r   r   r   update_trigger  s&   $zCfcClient.update_triggerc                 C   sJ   i }|dur
||d< |dur||d< |dur||d< | j tjdi ||dS )a  
        delete_trigger
        :param function_brn  (required) The cfc function brn.
        :type function_brn string

        :param source  (required) The trigger source type.
        :type source string

        :param relation_id  (required) The relation_id.
        :type relation_id string

        :param config: None
        :type config: baidubce.BceClientConfiguration

        :return:
        :rtype: baidubce.bce_response.BceResponse
        Nry   rz   r   rv   r=   r\   )r   rw   r   r   r   r   r   r   r   delete_triggerT  s   zCfcClient.delete_triggerc                 C   s   dS )N r   )r   r&   r   r   r   _encode_function_namet  s   zCfcClient._encode_function_namec                 C   s(   |d u r| j S t| j }|| |S r   )r   copyZmerge_non_none_values)r   r   Z
new_configr   r   r   _merge_configx  s
   
zCfcClient._merge_configc	           	      C   st   |  | |}|d u rtj}|pi }tj|tj< |jd ur&|pi }|j|tj< | 	|t
jtj|g|tj| ||||	S r   )r   r
   Z
parse_jsonr   JSONr   ZCONTENT_TYPEsecurity_tokenSTS_SECURITY_TOKENsend_requestr   signZparse_errorr   prefix)	r   http_methodpathr   headersr   r   Zbody_parserr    r   r   r   r"     s   


zCfcClient._send_requestc
           !   
   C   s  t t }
td||||||
 |pi }|jdur |j|tj< g d}d}tj|vr-d}|j|tj	< |D ]}|
  }|tjrH|| q5dttjtjtjf }|dd}t|}||tj< t|}|ssd	|tj< nt|trt||tj< ntj|vrtd
tj d}t|drt|dr| }t !|j|j"\}}}t#|}||tj	< ||j"j$kr|tj	  dt| 7  < t|}||j%|||||d|tj&< t '|d}t|d	kr|d | }n|}t()| d	}g }	 d}z|du rt * |tj< |tj ||j%|||||d|tj&< |d	kr(|dur(|+| t(,||||j-}td||||| t(.||||||j/}|0 }tj1r{t|t2r{g }|D ] \}}|3d4d}|3d4d}| }|||f qX|}td|j5|f  |	r|W S t(6 }|7t8| |D ]}|||r |W S q|W S  t9y } zD|dur|:  |d;dd t<= > D  |j?@||r|j?A||} tB| d  nt(Cd|d;|f |W Y d}~nd}~ww q)az  
        Send request to BCE services.
        :param config
        :type config: baidubce.BceClientConfiguration
        :param sign_function:
        :param response_handler_functions:
        :type response_handler_functions: list
        :param request:
        :type request: baidubce.internal.InternalRequest
        :return:
        :rtype: baidubce.BceResponse
        s#   %s request start: %s %s, %s, %s, %dN)s   hosts   content-lengths   content-typeFTzbce-sdk-python/%s/%s/%s
r   r   s   No %s is specified.tellseek   :)headers_to_sign   ?z=request args:method=%s, uri=%s, headers=%s,patams=%s, body=%szlatin-1r;   z%request return: status=%d, headers=%sc                 s   s    | ]}d | V  qdS )z>>>>Nr   ).0liner   r   r   	<genexpr>  s    z)CfcClient.send_request.<locals>.<genexpr>g     @@zEUnable to execute HTTP request. Retried %d times. All trace backs:
%s)Dinttime_loggerdebugr   r   r   ZBCE_DATEZendpointZHOSTstriplower
startswithZ
BCE_PREFIXappendr   Zconvert_to_stringbaidubceZSDK_VERSIONsysversionplatformreplaceZconvert_to_bytesZ
USER_AGENTZCONTENT_LENGTHr|   byteslen
ValueErrorhasattrr   r   Zparse_host_portprotocolr   default_portcredentialsZAUTHORIZATIONZget_canonical_querystringr   Zcheck_headersZget_canonical_timer   Z_get_connectionZconnection_timeout_in_millsZ_send_http_requestZsend_buf_size
getheadersPY3listencoderB   statusZBceResponseZset_metadata_from_headersdict	Exceptionclosejoin	traceback
format_exc
splitlinesZretry_policyZshould_retryZ%get_delay_before_next_retry_in_millissleepZBceHttpClientError)!r   r   Zsign_functionZresponse_handler_functionsr   r   r   r   r   r    tr   Zshould_get_new_datekZk_lower
user_agentoffsetr   hostportZencoded_paramsuriZretries_attemptederrorsconnhttp_responseZheaders_listZ
temp_headsvresponseZhandler_functioneZdelay_in_millisr   r   r   r     s   














"zCfcClient.send_requestr   )r   r   NNN)NNNr,   r-   NFr.   r/   FNN)NNNNNN)NN)NNNN)NNN)NNNNNF)F)__name__
__module____qualname____doc__r   r   r*   r+   rN   rX   rZ   r^   ra   rc   re   rg   rh   rj   rm   rr   rt   ru   rx   r   r   r   staticmethodr   r   r"   r   r   r   r   r   r   2   sn    

/
#
R

,


/

/
"
)

)

'

4
3
9 



r   )%r   r   r$   loggingr   r   r   r   r@   r   r   Zbaidubce.authr   Zbaidubce.httpr   r   r   r   r	   Zbaidubce.services.cfcr
   r   Zbaidubce.exceptionr   r   Zbaidubce.utilsr   r   r   urllib.parser   urllib	getLoggerr   r   r   r   r   r   r   r   <module>   s8   
