o
    #`^hu                     @   s   d Z ddlZddlZddlmZ ddlZddlZddlm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ZddlmZ dd	lmZmZ dd
lmZ G dd deZdS )z
    LINE Messaging API

    This document describes LINE Messaging API.  # noqa: E501

    The version of the OpenAPI document: 0.0.1
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
    N)parse)
ThreadPool)quote)Configuration)ApiResponse)rest)ApiValueErrorApiException)__version__c                	   @   sn  e Zd ZdZeeeeefZ	eeeeee
je
j
edZdZ		d?ddZdd Zd	d
 Zdd Zedd Zedd Zejdd Zdd ZdZedd Zedd Z						d@ddZdd Zdd Zdd  Z						dAd!d"Z 			dBd#d$Z!d%d& Z"d'd( Z#dCd)d*Z$d+d, Z%d-d. Z&	dCd/d0Z'd1d2 Z(d3d4 Z)d5d6 Z*d7d8 Z+d9d: Z,d;d< Z-d=d> Z.dS )D	ApiClienta  Generic API client for OpenAPI client library builds.

    OpenAPI generic API client. This client handles the client-
    server communication, and is invariant across implementations. Specifics of
    the methods and models for each application are generated from the OpenAPI
    templates.

    :param configuration: .Configuration object for this client
    :param header_name: a header to pass when making calls to the API.
    :param header_value: a header value to pass when making calls to
        the API.
    :param cookie: a cookie to include in the header when making calls
        to the API
    :param pool_threads: The number of threads to use for async requests
        to the API. More threads means more concurrent API requests.
    )intlongfloatstrbooldatedatetimeobjectN   c                 C   sn   |d u rt  }|| _|| _t|| _i | _|d ur || j|< d|j | jd< || _	dt
 | _|j| _d S )NzBearer Authorizationzline-bot-sdk-python/)r   get_defaultconfigurationpool_threadsr   RESTClientObjectrest_clientdefault_headersaccess_tokencookier
   
user_agentclient_side_validation)selfr   header_nameheader_valuer   r    r#   ]/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/linebot/v3/messaging/api_client.py__init__A   s   
zApiClient.__init__c                 C   s   | S Nr#   r    r#   r#   r$   	__enter__S   s   zApiClient.__enter__c                 C   s   |    d S r&   )close)r    exc_type	exc_value	tracebackr#   r#   r$   __exit__V   s   zApiClient.__exit__c                 C   sB   | j r| j   | j   d | _ ttdrt| j d S d S d S )N
unregister)_poolr)   joinhasattratexitr.   r'   r#   r#   r$   r)   Y   s   


zApiClient.closec                 C   s(   | j du rt| j t| j| _ | j S )zrCreate thread pool on first request
         avoids instantiating unused threadpool for blocking clients.
        N)r/   r2   registerr)   r   r   r'   r#   r#   r$   poola   s   
zApiClient.poolc                 C   s
   | j d S )zUser agent for this API client
User-Agentr   r'   r#   r#   r$   r   k   s   
zApiClient.user_agentc                 C   s   || j d< d S )Nr5   r6   r    valuer#   r#   r$   r   p   s   c                 C   s   || j |< d S r&   r6   )r    r!   r"   r#   r#   r$   set_default_headert   s   zApiClient.set_default_headerc                 C   s   | j du r	t | _ | j S )zReturn new instance of ApiClient.

        This method returns newly created, based on default constructor,
        object of ApiClient class or returns a copy of default
        ApiClient.

        :return: The ApiClient object.
        N)_defaultr   )clsr#   r#   r$   r   z   s   

zApiClient.get_defaultc                 C   s
   || _ dS )zSet default instance of ApiClient.

        It stores default ApiClient.

        :param default: object of ApiClient.
        N)r:   )r;   defaultr#   r#   r$   set_default      
zApiClient.set_defaultTc              
   C   sL  | j }|pi }|| j | jr| j|d< |r$| |}t| ||}|rG| |}| ||}|D ]\}}|d| tt	||j
d}q3|sK|rd|rO|ng }| |}| ||}|| | | j|||
||||d |rw| |}| j jd ur| j j| }n|| }|r| |}| ||}|d| 7 }z| j||||||||d}W n ty } z|jr|jd|_|d }~ww || _d }|s|r|	t	|jd }|dkr|j|_n!d }|d	}|d urtd
|}|r|dnd}|j||_|dkr	|j}n|r| ||}nd }|r|S t|j|| |jdS )NCookiez{%s})safe)request_auth?)query_paramsheaderspost_paramsbody_preload_content_request_timeoutzutf-8	bytearrayzcontent-typezcharset=([a-zA-Z\-\d]+)[\s;]?r   )status_codedatarD   raw_data)r   updater   r   sanitize_for_serializationdictparameters_to_tuplesreplacer   r   safe_chars_for_path_paramextendfiles_parametersupdate_params_for_authhostparameters_to_url_queryrequestr	   rF   decodelast_responsegetstatusrK   	getheaderresearchgroupdeserializer   
getheaders)r    resource_pathmethodpath_paramsrC   header_paramsrF   rE   filesresponse_types_mapauth_settings_return_http_data_onlycollection_formatsrG   rH   _host_request_authconfigkvurl	url_queryresponse_dataereturn_dataresponse_typematchcontent_typeencodingr#   r#   r$   
__call_api   s   










zApiClient.__call_apic                    s   |du rdS t | jr|S t |tr fdd|D S t |tr,t fdd|D S t |tjtjfr9| S t |trA|}n| } fdd|	 D S )a  Builds a JSON POST object.

        If obj is None, return None.
        If obj is str, int, long, float, bool, return directly.
        If obj is datetime.datetime, datetime.date
            convert to string in iso8601 format.
        If obj is list, sanitize each element in the list.
        If obj is dict, return the dict.
        If obj is OpenAPI model, return the properties dict.

        :param obj: The data to serialize.
        :return: The serialized form of data.
        Nc                    s   g | ]}  |qS r#   rN   .0sub_objr'   r#   r$   
<listcomp>  s    z8ApiClient.sanitize_for_serialization.<locals>.<listcomp>c                 3   s    | ]}  |V  qd S r&   r{   r|   r'   r#   r$   	<genexpr>  s    z7ApiClient.sanitize_for_serialization.<locals>.<genexpr>c                    s   i | ]
\}}|  |qS r#   r{   )r}   keyvalr'   r#   r$   
<dictcomp>&  s    z8ApiClient.sanitize_for_serialization.<locals>.<dictcomp>)

isinstancePRIMITIVE_TYPESlisttupler   r   	isoformatrO   to_dictitems)r    objobj_dictr#   r'   r$   rN     s(   




z$ApiClient.sanitize_for_serializationc                 C   sH   |dkr	|  |S zt|j}W n ty   |j}Y nw | ||S )a  Deserializes response into an object.

        :param response: RESTResponse object to be deserialized.
        :param response_type: class literal for
            deserialized object, or string of class name.

        :return: deserialized object.
        file)_ApiClient__deserialize_filejsonloadsrK   
ValueError_ApiClient__deserialize)r    responserv   rK   r#   r#   r$   ra   )  s   

zApiClient.deserializec                    s   |du rdS t |tkrQ|dr$td|d fdd|D S |dr>td|d	 fd
d| D S | jv rI j| }ntt	j
jj|}| jv r\ ||S |tkre |S |tjkro |S |tjkry |S  ||S )zDeserializes dict, list, str into an object.

        :param data: dict, list or str.
        :param klass: class literal, or string of class name.

        :return: object.
        NzList[zList\[(.*)]r   c                    s   g | ]}  |qS r#   r   )r}   sub_datar    sub_klsr#   r$   r   M  s    z+ApiClient.__deserialize.<locals>.<listcomp>zDict[zDict\[([^,]*), (.*)]   c                    s   i | ]\}}|  |qS r#   r   )r}   ro   rp   r   r#   r$   r   R  s    z+ApiClient.__deserialize.<locals>.<dictcomp>)typer   
startswithr^   rw   r`   r   NATIVE_TYPES_MAPPINGgetattrlinebotv3	messagingmodelsr   !_ApiClient__deserialize_primitiver   _ApiClient__deserialize_objectr   r   _ApiClient__deserialize_date _ApiClient__deserialize_datetime_ApiClient__deserialize_modelr    rK   klassr#   r   r$   __deserialize?  s2   








zApiClient.__deserializec                 C   s\   |s|  |||||||||	|
||||||S | j| j |||||||||	|
||||||fS )a  Makes the HTTP request (synchronous) and returns deserialized data.

        To make an async_req request, set the async_req parameter.

        :param resource_path: Path to method endpoint.
        :param method: Method to call.
        :param path_params: Path parameters in the url.
        :param query_params: Query parameters in the url.
        :param header_params: Header parameters to be
            placed in the request header.
        :param body: Request body.
        :param post_params dict: Request post form parameters,
            for `application/x-www-form-urlencoded`, `multipart/form-data`.
        :param auth_settings list: Auth Settings names for the request.
        :param response: Response data type.
        :param files dict: key -> filename, value -> filepath,
            for `multipart/form-data`.
        :param async_req bool: execute request asynchronously
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :param collection_formats: dict of collection formats for path, query,
            header, and post parameters.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_token: dict, optional
        :return:
            If async_req parameter is True,
            the request will be called asynchronously.
            The method will return the request thread.
            If parameter async_req is False or missing,
            then the method will return the response directly.
        )_ApiClient__call_apir4   apply_async)r    rc   rd   re   rC   rf   rF   rE   rg   rh   ri   	async_reqrj   rk   rG   rH   rl   rm   r#   r#   r$   call_apif  s,   0zApiClient.call_apic	           	   	   C   s   |dkr| j j|||||dS |dkr| j j|||||dS |dkr-| j j|||||dS |dkr>| j j|||||||dS |dkrO| j j|||||||dS |d	kr`| j j|||||||dS |d
krp| j j||||||dS td)z(Makes the HTTP request using RESTClient.GET)rC   rG   rH   rD   HEADOPTIONS)rC   rD   rG   rH   POST)rC   rD   rE   rG   rH   rF   PUTPATCHDELETE)rC   rD   rG   rH   rF   zQhttp method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`.)	r   get_requesthead_requestoptions_requestpost_requestput_requestpatch_requestdelete_requestr   )	r    rd   rq   rC   rD   rE   rF   rG   rH   r#   r#   r$   rX     sv   zApiClient.requestc                    s   g }|du ri }t |tr| n|D ]K\ } |v rW|  }|dkr0| fdd|D  q|dkr7d}n|dkr>d}n	|d	krEd
}nd}| |dd |D f q| |f q|S )a  Get parameters as list of tuples, formatting collections.

        :param params: Parameters as dict or list of two-tuples
        :param dict collection_formats: Parameter collection formats
        :return: Parameters as list of tuples, collections formatted
        Nmultic                 3       | ]} |fV  qd S r&   r#   r}   r8   ro   r#   r$   r         z1ApiClient.parameters_to_tuples.<locals>.<genexpr>ssv tsv	pipes|,c                 s   s    | ]}t |V  qd S r&   )r   r   r#   r#   r$   r      r   )r   rO   r   rS   appendr0   r    paramsrk   
new_paramsrp   collection_format	delimiterr#   r   r$   rP     s(   zApiClient.parameters_to_tuplesc                    s  g }|du ri }t |tr| n|D ]o\ }t |ttfr"t|}t |tr-t| }t |tr7t	|} |v rw|  }|dkrP|
 fdd|D  q|dkrWd}n|dkr^d}n	|d	kred
}nd}| |dd |D f q| tt|f qddd |D S )a  Get parameters as list of tuples, formatting collections.

        :param params: Parameters as dict or list of two-tuples
        :param dict collection_formats: Parameter collection formats
        :return: URL query string (e.g. a=Hello%20World&b=123)
        Nr   c                 3   r   r&   r#   r   r   r#   r$   r     r   z4ApiClient.parameters_to_url_query.<locals>.<genexpr>r   r   r   r   r   r   r   c                 s   s    | ]	}t t|V  qd S r&   )r   r   r   r#   r#   r$   r   %  s    &c                 S   s   g | ]}d  |qS )=)r0   )r}   itemr#   r#   r$   r   )  s    z5ApiClient.parameters_to_url_query.<locals>.<listcomp>)r   rO   r   r   r   r   r   lowerr   dumpsrS   r   r0   r   r   r#   r   r$   rW     s4   


z!ApiClient.parameters_to_url_queryc                 C   s   g }|rW|  D ]N\}}|sqt|tu r|n|g}|D ]9}t|d*}tj|j}| }	t	
|d p7d}
|t|t||	|
gg W d   n1 sPw   Y  qq|S )zuBuilds form parameters.

        :param files: File parameters.
        :return: Form parameters with files.
        rbr   zapplication/octet-streamN)r   r   r   openospathbasenamenameread	mimetypes
guess_typer   r   )r    rg   r   ro   rp   
file_namesnffilenamefiledatamimetyper#   r#   r$   rT   +  s(   	zApiClient.files_parametersc                 C   2   |sdS |D ]}t d|t jr|  S q|d S )zReturns `Accept` based on an array of accepts provided.

        :param accepts: List of headers.
        :return: Accept (e.g. application/json).
        Nr   r   r^   r_   
IGNORECASE)r    acceptsacceptr#   r#   r$   select_header_acceptC     zApiClient.select_header_acceptc                 C   r   )zReturns `Content-Type` based on an array of content_types provided.

        :param content_types: List of content-types.
        :return: Content-Type (e.g. application/json).
        Nr   r   r   )r    content_typesrx   r#   r#   r$   select_header_content_typeR  r   z$ApiClient.select_header_content_typec           
   	   C   sZ   |sdS |r|  |||||| dS |D ]}| j |}	|	r*|  ||||||	 qdS )a  Updates header and query params based on authentication setting.

        :param headers: Header parameters dict to be updated.
        :param queries: Query parameters tuple list to be updated.
        :param auth_settings: Authentication setting identifiers list.
        :resource_path: A string representation of the HTTP request resource path.
        :method: A string representation of the HTTP request method.
        :body: A object representing the body of the HTTP request.
        The object type is the return value of sanitize_for_serialization().
        :param request_auth: if set, the provided settings will
                             override the token in the configuration.
        N)_apply_auth_paramsr   ri   r[   )
r    rD   queriesri   rc   rd   rF   rA   authauth_settingr#   r#   r$   rU   a  s"   z ApiClient.update_params_for_authc                 C   sz   |d dkr|d |d< dS |d dkr&|d dkr$|d ||d < dS dS |d d	kr9| |d |d f dS td
)a,  Updates the request parameters based on a single auth_setting

        :param headers: Header parameters dict to be updated.
        :param queries: Query parameters tuple list to be updated.
        :resource_path: A string representation of the HTTP request resource path.
        :method: A string representation of the HTTP request method.
        :body: A object representing the body of the HTTP request.
        The object type is the return value of sanitize_for_serialization().
        :param auth_setting: auth settings for the endpoint
        inr   r8   r?   headerr   zhttp-signaturer   queryz3Authentication token must be in `query` or `header`N)r   r   )r    rD   r   rc   rd   rF   r   r#   r#   r$   r     s   zApiClient._apply_auth_paramsc                 C   s   t j| jjd\}}t| t| |d}|r/t	d|
d}tjtj||}t|d}||j W d   |S 1 sFw   Y  |S )zDeserializes body to file

        Saves response body into a file in a temporary folder,
        using the filename from the `Content-Disposition` header if provided.

        :param response:  RESTResponse.
        :return: file path.
        )dirzContent-Dispositionz filename=[\'"]?([^\'"\s]+)[\'"]?r   wbN)tempfilemkstempr   temp_folder_pathr   r)   remover]   r^   r_   r`   r   r0   dirnamer   writerK   )r    r   fdr   content_dispositionr   r   r#   r#   r$   __deserialize_file  s"   	



zApiClient.__deserialize_filec                 C   s:   z||W S  t y   t| Y S  ty   | Y S w )zDeserializes string to primitive type.

        :param data: str.
        :param klass: class literal.

        :return: int, long, float, str, bool.
        )UnicodeEncodeErrorr   	TypeErrorr   r#   r#   r$   __deserialize_primitive  s   
z!ApiClient.__deserialize_primitivec                 C   s   |S )z<Return an original value.

        :return: object.
        r#   r7   r#   r#   r$   __deserialize_object  s   zApiClient.__deserialize_objectc                 C   sF   zt | W S  ty   | Y S  ty"   tjdd|dw )zYDeserializes string to date.

        :param string: str.
        :return: date.
        r   z$Failed to parse `{0}` as date objectr\   reason)r   r   ImportErrorr   r   r	   formatr    stringr#   r#   r$   __deserialize_date  s   zApiClient.__deserialize_datec                 C   sB   zt |W S  ty   | Y S  ty    tjdd|dw )zDeserializes string to datetime.

        The string should be in iso8601 datetime format.

        :param string: str.
        :return: datetime.
        r   z(Failed to parse `{0}` as datetime objectr   )r   r  r   r   r	   r  r  r#   r#   r$   __deserialize_datetime  s   
z ApiClient.__deserialize_datetimec                 C   s
   | |S )zDeserializes list or dict to model.

        :param data: dict, list.
        :param klass: class literal.
        :return: model object.
        )	from_dictr   r#   r#   r$   __deserialize_model  r>   zApiClient.__deserialize_model)NNNNr   )NNNNNNNNNNTNNN)NNNNNNNNNNNTNNN)NNNNTNr&   )/__name__
__module____qualname____doc__r   r   bytesr   r   r   r   r   r   r   r/   r%   r(   r-   r)   propertyr4   r   setterr9   r:   classmethodr   r=   r   rN   ra   r   r   rX   rP   rW   rT   r   r   rU   r   r   r   r   r   r   r   r#   r#   r#   r$   r   "   s    


	





o((
F
;
&
r   )r  r2   r   dateutil.parserr   r   r   multiprocessing.poolr   r   r^   r   urllib.parser   "linebot.v3.messaging.configurationr   !linebot.v3.messaging.api_responser   linebot.v3.messaging.modelsr   linebot.v3.messagingr   linebot.v3.messaging.exceptionsr   r	   linebot.__about__r
   r   r   r#   r#   r#   r$   <module>   s$   