3 f÷ÔYÆdã@s´dZddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z m Z mZmZddlmZddlmZmZdd lmZdd lmZmZGd d „d eƒZdS) aƒ Copyright 2016 SmartBear Software Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ref: https://github.com/swagger-api/swagger-codegen é)Úabsolute_importN)ÚdateÚdatetime)ÚPY3Ú integer_typesÚ iteritemsÚ text_type)Úquoteé)ÚmodelsÚ ws_client)Ú configuration)Ú ApiExceptionÚRESTClientObjectc @sÖeZdZdZddddefdd„Zedd„ƒZejdd„ƒZdd „Z d-d d „Z d d„Z dd„Z dd„Z d.dd„Zd/dd„Zdd„Zd0dd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„ZdS)1Ú ApiClienta¦ Generic API client for Swagger client library builds. Swagger 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 Swagger templates. NOTE: This class is auto generated by the swagger code generator program. Ref: https://github.com/swagger-api/swagger-codegen Do not edit the class manually. :param host: The base path for the server to call. :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. NcCsV||_t|jd�|_i|_|dk r,||j|<|dkr@|jj|_n||_||_d|_dS)z+ Constructor of the class. )ÚconfigNz%Swagger-Codegen/1.0.0-snapshot/python)rrÚ rest_clientÚdefault_headersÚhostÚcookieÚ user_agent)ÚselfrÚ header_nameÚ header_valuerr©rúM/Users/olari/OneDrive/sandbox/awsBlog2/lambda/kubernetes/client/api_client.pyÚ__init__:s  zApiClient.__init__cCs |jdS)z" Gets user agent. z User-Agent)r)rrrrrLszApiClient.user_agentcCs||jd<dS)z" Sets user agent. z User-AgentN)r)rÚvaluerrrrSscCs||j|<dS)N)r)rrrrrrÚset_default_headerZszApiClient.set_default_headerTc Cs||pi}|j|jƒ|jr$|j|d<|rB|j|ƒ}t|j|| ƒƒ}|r†|j|ƒ}|j|| ƒ}x(|D] \}}|jd|tt|ƒƒƒ}qbW|r |j|ƒ}|j|| ƒ}|s¨|rÊ|j ||ƒ}|j|ƒ}|j|| ƒ}|j ||| ƒ|ræ|j|ƒ}|j |}|j ||||||||d�}||_ |}|�r2| �r.|j|| ƒ}nd}| �r^| �rH| |ƒn| ||j|jƒfƒn| �rh|S||j|jƒfSdS)NÚCookiez{%s})Ú query_paramsÚheadersÚ post_paramsÚbodyÚ_preload_contentÚ_request_timeout)ÚupdaterrÚsanitize_for_serializationÚdictÚparameters_to_tuplesÚreplacer ÚstrÚprepare_post_parametersÚupdate_params_for_authrÚrequestÚ last_responseÚ deserializeÚstatusÚ getheaders)rÚ resource_pathÚmethodÚ path_paramsr Ú header_paramsr#r"ÚfilesÚ response_typeÚ auth_settingsÚcallbackÚ_return_http_data_onlyÚcollection_formatsr$r%ÚkÚvÚurlZ response_dataZ return_datarrrZ __call_api]sb          zApiClient.__call_apicsÎttttfttƒtf}tˆtdƒƒr,dStˆ|ƒr:ˆStˆt ƒrV‡fdd„ˆDƒStˆtƒrvt‡fdd„ˆDƒƒStˆt t fƒrŒˆj ƒStˆt ƒrœˆ}n‡fdd„tˆjƒDƒ}‡fdd„t|ƒDƒSdS) 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 swagger model, return the properties dict. :param obj: The data to serialize. :return: The serialized form of data. Ncsg|]}ˆj|ƒ‘qSr)r')Ú.0Úsub_obj)rrrú Ász8ApiClient.sanitize_for_serialization..c3s|]}ˆj|ƒVqdS)N)r')r@rA)rrrú Äsz7ApiClient.sanitize_for_serialization..cs0i|](\}}tˆ|ƒdk rtˆ|ƒˆj|“qS)N)ÚgetattrÚ attribute_map)r@ÚattrÚ_)Úobjrrú Ñsz8ApiClient.sanitize_for_serialization..csi|]\}}ˆj|ƒ|“qSr)r')r@ÚkeyÚval)rrrrIÕs)r+ÚfloatÚboolÚbytesÚtuplerrÚ isinstanceÚtypeÚlistrrÚ isoformatr(rÚ swagger_types)rrHÚtypesZobj_dictr)rHrrr'¬s&         z$ApiClient.sanitize_for_serializationc CsJd|kr|j|ƒSytj|jƒ}Wntk r<|j}YnX|j||ƒ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ÚloadsÚdataÚ ValueErrorÚ_ApiClient__deserialize)rÚresponser8rZrrrr0Øs   zApiClient.deserializecs|dkr dSt|tƒr®|jdƒrFtjd|ƒjdƒ‰‡‡fdd„|DƒS|jdƒrztjd|ƒjd ƒ‰‡‡fd d „t|ƒDƒS|dkrŒt|ƒ}n"|dkr¢trœt nt }n td|ƒ}|t ksÄ|t tt fkrЈj||ƒS|tkrâˆj|ƒS|tk�röˆj|ƒS|tk�r ˆj|ƒSˆj||ƒSdS)z¿ Deserializes dict, list, str into an object. :param data: dict, list or str. :param klass: class literal, or string of class name. :return: object. Nzlist[z list\[(.*)\]r csg|]}ˆj|ˆƒ‘qSr)r\)r@Zsub_data)rÚsub_klsrrrBþsz+ApiClient.__deserialize..zdict(zdict\(([^,]*), (.*)\)écsi|]\}}ˆj|ˆƒ|“qSr)r\)r@r=r>)rr^rrrIsz+ApiClient.__deserialize..ÚintrLr+rMrrÚobjectÚlongzmodels.)r`rLr+rMrrra)rPr+Ú startswithÚreÚmatchÚgrouprÚevalrr`rbrrLrMÚ!_ApiClient__deserialize_primitiveraÚ_ApiClient__deserialize_objectrÚ_ApiClient__deserialize_daterÚ _ApiClient__deserialize_datatimeÚ_ApiClient__deserialize_model)rrZÚklassr)rr^rZ __deserializeïs4               zApiClient.__deserializecCsh| dkr.|j||||||||| | | | | ||ƒStj|j||||||||| | | | | ||fd�}|jƒ|S)a Makes the HTTP request (synchronous) and return the deserialized data. To make an async request, define a function for callback. :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 callback function: Callback function for asynchronous request. If provide this parameter, the request will be called asynchronously. :param _return_http_data_only: response data without head status code and headers :param collection_formats: dict of collection formats for path, query, header, and post parameters. :param _preload_content: if False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True. :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. :return: If provide parameter callback, the request will be called asynchronously. The method will return the request thread. If parameter callback is None, then the method will return the response directly. N)ÚtargetÚargs)Ú_ApiClient__call_apiÚ threadingÚThreadÚstart)rr3r4r5r r6r#r"r7r8r9r:r;r<r$r%ÚthreadrrrÚcall_apis&- zApiClient.call_apic Cs0|jdƒs|jdƒr<|dks$|dkr.Zssvú Ztsvú Zpipesú|ú,css|]}t|ƒVqdS)N)r+)r@rrrrrCÁs)rPr(rÚextendÚappendÚjoin)rÚparamsr<Ú new_paramsr>Zcollection_formatÚ delimiterr)r=rr)§s& zApiClient.parameters_to_tuplesc Cs¬g}|r |}|r¨x–t|ƒD]Š\}}|s(qt|tƒr6|n|g}xf|D]^}t|dƒ�J}tjj|jƒ} |jƒ} t j | ƒdpxd} |j t |t | | | gƒgƒƒWdQRXqBWqW|S)z² Builds form parameters. :param post_params: Normal form parameters. :param files: File parameters. :return: Form parameters with files. Úrbrzapplication/octet-streamN) rrPrRÚopenÚosÚpathÚbasenameÚnameÚreadÚ mimetypesÚ guess_typerƒrO) rr"r7r…r=r>Z file_namesÚnÚfÚfilenameZfiledataÚmimetyperrrr,Æs"   z!ApiClient.prepare_post_parameterscCs4|sdSttdd„|ƒƒ}d|kr&dSdj|ƒSdS)z¤ Returns `Accept` based on an array of accepts provided. :param accepts: List of headers. :return: Accept (e.g. application/json). NcSs|jƒS)N)Úlower)ÚxrrrÚísz0ApiClient.select_header_accept..zapplication/jsonz, )rRÚmapr„)rZacceptsrrrÚselect_header_acceptãs zApiClient.select_header_acceptcCs:|sdSttdd„|ƒƒ}d|ks*d|kr.dS|dSdS)z Returns `Content-Type` based on an array of content_types provided. :param content_types: List of content-types. :return: Content-Type (e.g. application/json). zapplication/jsoncSs|jƒS)N)r•)r–rrrr—þsz6ApiClient.select_header_content_type..z*/*rN)rRr˜)rZ content_typesrrrÚselect_header_content_typeôs z$ApiClient.select_header_content_typecCs„|sdSxv|D]n}|jjƒj|ƒ}|r|ds2qq|ddkrP|d||d<q|ddkrt|j|d|dfƒqtdƒ‚qWdS)a Updates header and query params based on authentication setting. :param headers: Header parameters dict to be updated. :param querys: Query parameters tuple list to be updated. :param auth_settings: Authentication setting identifiers list. NrÚinÚheaderrJÚqueryz3Authentication token must be in `query` or `header`)rr9Úgetrƒr[)rr!Zquerysr9ÚauthZ auth_settingrrrr-s    z ApiClient.update_params_for_authc Cs„tj|jjd�\}}tj|ƒtj|ƒ|jdƒ}|r^tj d|ƒj dƒ}tj j tj j |ƒ|ƒ}t|dƒ�}|j|jƒWdQRX|S)zÛ 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. )ÚdirzContent-Dispositionz filename=[\'"]?([^\'"\s]+)[\'"]?r ÚwN)ÚtempfileÚmkstemprÚtemp_folder_pathrŠÚcloseÚremoveÚ getheaderrdÚsearchrfr‹r„Údirnamer‰ÚwriterZ)rr]Úfdr‹Úcontent_dispositionr“r’rrrZ__deserialize_files     zApiClient.__deserialize_filec CsDy ||ƒ}Wn2tk r(t|ƒ}Yntk r>|}YnX|S)z§ Deserializes string to primitive type. :param data: str. :param klass: class literal. :return: int, long, float, str, bool. )ÚUnicodeEncodeErrorÚunicodeÚ TypeError)rrZrmrrrrZ__deserialize_primitive6s    z!ApiClient.__deserialize_primitivecCs|S)zD Return a original value. :return: object. r)rrrrrZ__deserialize_objectGszApiClient.__deserialize_objectc Cs^|sdSyddlm}||ƒjƒStk r4|Stk rXtddj|ƒd�‚YnXdS)zb Deserializes string to date. :param string: str. :return: date. Nr)Úparsez(Failed to parse `{0}` into a date object)r1Úreason)Údateutil.parserr°rÚ ImportErrorr[rÚformat)rÚstringr°rrrZ__deserialize_dateOs  zApiClient.__deserialize_datec CsZ|sdSyddlm}||ƒStk r0|Stk rTtddj|ƒd�‚YnXdS)z¤ Deserializes string to datetime. The string should be in iso8601 datetime format. :param string: str. :return: datetime. Nr)r°z,Failed to parse `{0}` into a datetime object)r1r±)r²r°r³r[rr´)rrµr°rrrZ__deserialize_datatimeds  z ApiClient.__deserialize_datatimecCsŒ|ƒ}|js|Sxvt|jƒD]h\}}|dk r|j||krt|ttfƒr||j|}|dkrpt|tƒrlgni}t|||j||ƒƒqW|S)z› Deserializes list or dict to model. :param data: dict, list. :param klass: class literal. :return: model object. N)rTrrErPrRr(Úsetattrr\)rrZrmÚinstancerFZ attr_typerrrrZ__deserialize_model{szApiClient.__deserialize_model) NNNNNNNNNNNTN) NNNNNNNNNNNTN)NNNNTN)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r rÚpropertyrÚsetterrrpr'r0r\rur.r)r,r™ršr-rWrhrirjrkrlrrrrr(sB  J,. = G r)r»Ú __future__rrXr�rŠrdr¢rqrrÚsixrrrrZsix.moves.urllib.parser Úr r r ÚrestrrrarrrrrÚs