B “äî\wtã@sdZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd lmZd Zd Zd Zddd„ZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deeƒZGdd„deƒZeeeeedœZdS) aîProtocol input serializes. This module contains classes that implement input serialization for the various AWS protocol types. These classes essentially take user input, a model object that represents what the expected input should look like, and it returns a dictionary that contains the various parts of a request. A few high level design decisions: * Each protocol type maps to a separate class, all inherit from ``Serializer``. * The return value for ``serialize_to_request`` (the main entry point) returns a dictionary that represents a request. This will have keys like ``url_path``, ``query_string``, etc. This is done so that it's a) easy to test and b) not tied to a particular HTTP library. See the ``serialize_to_request`` docstring for more details. Unicode ------- The input to the serializers should be text (str/unicode), not bytes, with the exception of blob types. Those are assumed to be binary, and if a str/unicode type is passed in, it will be encoded as utf-8. éN)Ú ElementTree)Úsix)ÚjsonÚ formatdate)Úparse_to_aware_datetime)Úpercent_encode)Úis_json_value_header)ÚvalidateÚiso8601z%Y-%m-%dT%H:%M:%SZz%Y-%m-%dT%H:%M:%S.%fZTcCs&t|ƒ}|r"t ¡}t ||¡}|S)N)Ú SERIALIZERSr ZParamValidatorZParamValidationDecorator)Z protocol_nameZinclude_validationÚ serializerZ validator©r ú6/tmp/pip-build-uw_ogi45/botocore/botocore/serialize.pyÚcreate_serializer>s   rc@sbeZdZdZeZdZdd„Zdd„Zdd„Z d d „Z d d „Z ddd„Z dd„Z dd„Zdd„Zd S)Ú SerializerÚPOSTzutf-8cCs tdƒ‚dS)aöSerialize parameters into an HTTP request. This method takes user provided parameters and a shape model and serializes the parameters to an HTTP request. More specifically, this method returns information about parts of the HTTP request, it does not enforce a particular interface or standard for an HTTP request. It instead returns a dictionary of: * 'url_path' * 'host_prefix' * 'query_string' * 'headers' * 'body' * 'method' It is then up to consumers to decide how to map this to a Request object of their HTTP library of choice. Below is an example return value:: {'body': {'Action': 'OperationName', 'Bar': 'val2', 'Foo': 'val1', 'Version': '2014-01-01'}, 'headers': {}, 'method': 'POST', 'query_string': '', 'host_prefix': 'value.', 'url_path': '/'} :param parameters: The dictionary input parameters for the operation (i.e the user input). :param operation_model: The OperationModel object that describes the operation. Úserialize_to_requestN)ÚNotImplementedError)ÚselfÚ parametersÚoperation_modelr r rrPs$zSerializer.serialize_to_requestcCsdd|jiddœ}|S)Nú/Úó)Úurl_pathÚ query_stringÚmethodÚheadersÚbody)ÚDEFAULT_METHOD)rÚ serializedr r rÚ_create_default_requestvs z"Serializer._create_default_requestcCs|jdkrt}nt}| |¡S)Nr)Ú microsecondÚ ISO8601_MICROÚISO8601Ústrftime)rÚvalueÚtimestamp_formatr r rÚ_timestamp_iso8601…s zSerializer._timestamp_iso8601cCstt | ¡¡ƒS)N)ÚintÚcalendarÚtimegmÚ timetuple)rr&r r rÚ_timestamp_unixtimestampŒsz#Serializer._timestamp_unixtimestampcCs"t|tjƒr| |¡}t|ddS)NT)Úusegmt)Ú isinstanceÚdatetimer-r)rr&r r rÚ_timestamp_rfc822s  zSerializer._timestamp_rfc822NcCs8|dkr|j}| ¡}t|ƒ}t|d|ƒ}||ƒ}|S)Nz _timestamp_%s)ÚTIMESTAMP_FORMATÚlowerrÚgetattr)rr&r'Ú datetime_objÚ converterZ final_valuer r rÚ_convert_timestamp_to_str”s z$Serializer._convert_timestamp_to_strcCs|j d|¡S)NÚname)Ú serializationÚget)rÚshapeÚ default_namer r rÚ_get_serialized_namežszSerializer._get_serialized_namecCs.t|tjƒr| |j¡}t |¡ ¡ |j¡S)N) r/rÚ text_typeÚencodeÚDEFAULT_ENCODINGÚbase64Ú b64encodeÚstripÚdecode)rr&r r rÚ _get_base64£s  zSerializer._get_base64csV|j}|dkrdS|d}|jj}dd„| ¡Dƒ}t‡fdd„|Dƒƒ}|jf|ŽS)NZ hostPrefixcSs g|]\}}|j d¡r|‘qS)Z hostLabel)r9r:)Ú.0Úmemberr;r r rú ´sz2Serializer._expand_host_prefix..c3s|]}|ˆ|fVqdS)Nr )rFr8)rr rú ·sz1Serializer._expand_host_prefix..)ZendpointÚ input_shapeÚmembersÚitemsÚdictÚformat)rrrZoperation_endpointZhost_prefix_expressionZ input_membersZ host_labelsZ format_kwargsr )rrÚ_expand_host_prefix¬szSerializer._expand_host_prefix)N)Ú__name__Ú __module__Ú __qualname__rrMÚMAP_TYPEr@rr!r(r-r1r7r=rErOr r r rrGs&  rc@speZdZdZdd„Zddd„Zddd„Zdd d „Zdd d „Zdd d„Z ddd„Z ddd„Z ddd„Z dd„Z dS) ÚQuerySerializerr cCsŒ|j}| ¡}|j d|j¡|d<ddi|d<| ¡}|j|d<|jd|d<|dk rd| |||¡||d<|  ||¡}|dk rˆ||d <|S) Nrz Content-Typez0application/x-www-form-urlencoded; charset=utf-8rZActionZ apiVersionÚVersionrÚ host_prefix) rJr!Úhttpr:rrSr8ÚmetadataÚ _serializerO)rrrr;r Ú body_paramsrVr r rrÀs    z$QuerySerializer.serialize_to_requestrcCs(t|d|j|jƒ}|||||ddS)Nz_serialize_type_%s)Úprefix)r4Ú type_nameÚ_default_serialize)rr r&r;r[rr r rrY×s zQuerySerializer._serializec CsT|j}xH| ¡D]<\}}||}| ||¡}|rx8t|dƒD]*\}}d||f}|j}| ||||¡q WdS)Nrcz%s.%s)rgrGrY) rr r&r;r[rhrirjrkr r rrl;s z"EC2Serializer._serialize_type_listN)r)rPrQrRÚ__doc__r=rlr r r rrw$s rwc@sReZdZdZdd„Zddd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dS)ÚJSONSerializerZ unixtimestampc Cs¦d|jd|jf}|jd}| ¡}|j d|j¡|d<|d|dœ|d<| ¡}|j}|dk rp| |||¡t   |¡  |j ¡|d<|  ||¡}|dk r¢||d <|S) Nz%s.%sZ targetPrefixZ jsonVersionrzapplication/x-amz-json-%s)z X-Amz-Targetz Content-TyperrrV)rXr8r!rWr:rrSrJrYrÚdumpsr?r@rO) rrrÚtargetZ json_versionr rrJrVr r rrEs"     z#JSONSerializer.serialize_to_requestNcCs&t|d|j|jƒ}|||||ƒdS)Nz_serialize_type_%s)r4r\r])rr r&r;r^rr r rrY\s zJSONSerializer._serializec Csh|dk r| ¡}|||<|}|j}x@| ¡D]4\}}||} d| jkrP| jd}| ||| |¡q,WdS)Nr8)rSrKrLr9rY) rr r&r;r^Znew_serializedrKZ member_keyÚ member_valuer_r r rr`as  z(JSONSerializer._serialize_type_structurecCs<| ¡}|||<x&| ¡D]\}}| |||j|¡qWdS)N)rSrLrYr&)rr r&r;r^Zmap_objZsub_keyZ sub_valuer r rrorsz"JSONSerializer._serialize_type_mapcCsBg}|||<x0|D](}i}| |||jd¡| |d¡qWdS)NZ __current__)rYrGÚappend)rr r&r;r^Úlist_objZ list_itemÚwrapperr r rrlxs  z#JSONSerializer._serialize_type_listcCs |||<dS)Nr )rr r&r;r^r r rr]„sz!JSONSerializer._default_serializecCs| ||j d¡¡||<dS)Nrq)r7r9r:)rr r&r;r^r r rrr‡sz(JSONSerializer._serialize_type_timestampcCs| |¡||<dS)N)rE)rr r&r;r^r r rrp‹sz#JSONSerializer._serialize_type_blob)N) rPrQrRr2rrYr`rorlr]rrrpr r r rrzBs  rzc@sdeZdZdZdZdZddddgZdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„ZdS)ÚBaseRestSerializera=Base class for rest protocols. The only variance between the various rest protocols is the way that the body is serialized. All other aspects (headers, uri, etc.) are the same and logic for serializing those aspects lives here. Subclasses must implement the ``_serialize_body_params`` method. r Zrfc822ÚuriÚ querystringÚheaderrc Csü| ¡}|j d|j¡|d<|j}|dkr<|jd|d<|S|j}| ¡| ¡| ¡| ¡dœ}x.| ¡D]"\}}|dkr|qj| ||||¡qjW|  |jd|d¡|d<|d|d<|drÊ|d|d<|  |||||¡|  ||¡} | dk rø| |d <|S) NrZ requestUrir)Úuri_path_kwargsÚquery_string_kwargsÚ body_kwargsrr…r†rrrV) r!rWr:rrJrKrSrLÚ_partition_parametersÚ_render_uri_templateÚ_serialize_payloadrO) rrrr r;Ú shape_membersÚ partitionedÚ param_nameÚ param_valuerVr r rr s:         z'BaseRestSerializer.serialize_to_requestcCs^i}xLt d|¡D]<}| d¡r>t||dd…dd||<qt||ƒ||<qW|jf|ŽS)Nz{(.*?)}ú+rbz/~)Úsafe)ÚreÚfindallÚendswithrrN)rZ uri_templateÚparamsZencoded_paramsZtemplate_paramr r rr‰Ñs z'BaseRestSerializer._render_uri_templatec Cs’|j d¡}|dk rB||jdkrB| |d¡}| |¡}||d<nL|dk rr| |¡}|dk rŽ| |||¡|d<n|drŽ| |d|¡|d<dS)NÚpayload)ZblobÚstringrrr‡)r9r:r\Ú_encode_payloadÚ_serialize_body_params) rrŒrr r;r‹Zpayload_memberZ body_payloadrZr r rrŠâs     z%BaseRestSerializer._serialize_payloadcCst|tjƒr| |j¡S|S)N)r/rr>r?r@)rrr r rr—ýs  z"BaseRestSerializer._encode_payloadc Cs||}|j d¡}|j d|¡}|dkr8||d|<nÜ|dkr¸t|tƒrZ|d |¡n\t|tƒrzt|ƒ ¡|d|<n<|jdkrª|j d|j ¡}|  ||¡|d|<n ||d|<n\|d kræ||} |  | |¡} t| ƒ|d |<n.|d kr|} |  | |d |¡n ||d |<dS) NÚlocationr8r‚r…rƒr†Ú timestamprqr„rr‡) r9r:r/rMÚupdateÚboolÚstrr3r\ÚQUERY_STRING_TIMESTAMP_FORMATr7Ú_convert_header_valueÚ_do_serialize_header_map) rrŒrrŽr‹rGr™Úkey_namer'r;r&Ú header_prefixr r rrˆs4       z(BaseRestSerializer._partition_parameterscCs*x$| ¡D]\}}||}|||<q WdS)N)rL)rr¢rZ user_inputr^ÚvalZfull_keyr r rr .sz+BaseRestSerializer._do_serialize_header_mapcCs tdƒ‚dS)Nr˜)r)rr”r;r r rr˜3sz)BaseRestSerializer._serialize_body_paramscCs`|jdkr|d|d7}|d|j|<xj| ¡D]^\}} |j|} | j d|¡} | dkr‚dS| j d¡r¤| jd} | |j| <qV| | | || ¡qVWdS)NZ xmlNamespaceÚxmlnsr[z:%sr‚r8Z xmlAttribute)rÚ SubElementr9r:ÚattribrLrKrY) rr¯r”r;r8Zstructure_nodeZnamespace_metadataZattribute_namer^r&r_Ú member_nameZxml_attribute_namer r rr`\s"        z+RestXMLSerializer._serialize_type_structurec CsX|j}|j d¡r|}|}n|j dd¡}t ||¡}x|D]}| ||||¡qr·)rr¯r”r;r8r¶r r rr]¨s z$RestXMLSerializer._default_serializeN) rPrQrRr2r˜rYr`rlrorurprrr]r r r rrªMs  rª)Zec2Úqueryrz rest-jsonzrest-xml)T)ryr‘rAr*r0Z xml.etreerZbotocore.compatrrrZbotocore.utilsrrrZbotocorer ZDEFAULT_TIMESTAMP_FORMATr$r#rÚobjectrrTrwrzrr©rªr r r r rÚ's8       uhM7a