B =@Saowã@s$dZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd l mZdd lmZd Zd Zd Zd dd„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)Úconditionally_calculate_md5)Ú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új/private/var/folders/fg/1jzmct0d7d72tjkvm_1nhqc5sw67yj/T/pip-unpacked-wheel-ef76ia09/botocore/serialize.pyÚcreate_serializer?s   rc@sjeZdZdZeZdZdd„Zdd„Zdd„Z d d „Z d d „Z ddd„Z dd„Z dd„Zdd„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_modelrrrrQs$zSerializer.serialize_to_requestcCsdd|jiddœ}|S)Nú/Úó)Úurl_pathÚ query_stringÚmethodÚheadersÚbody)ÚDEFAULT_METHOD)rÚ serializedrrrÚ_create_default_requestws z"Serializer._create_default_requestcCs|jdkrt}nt}| |¡S)Nr)Ú microsecondÚ ISO8601_MICROÚISO8601Ústrftime)rÚvalueÚtimestamp_formatrrrÚ_timestamp_iso8601†s zSerializer._timestamp_iso8601cCstt | ¡¡ƒS)N)ÚintÚcalendarÚtimegmÚ timetuple)rr'rrrÚ_timestamp_unixtimestampsz#Serializer._timestamp_unixtimestampcCs"t|tjƒr| |¡}t|ddS)NT)Úusegmt)Ú isinstanceÚdatetimer.r)rr'rrrÚ_timestamp_rfc822s  zSerializer._timestamp_rfc822NcCs8|dkr|j}| ¡}t|ƒ}t|d|ƒ}||ƒ}|S)Nz _timestamp_%s)ÚTIMESTAMP_FORMATÚlowerrÚgetattr)rr'r(Ú datetime_objÚ converterZ final_valuerrrÚ_convert_timestamp_to_str•s z$Serializer._convert_timestamp_to_strcCs|j d|¡S)NÚname)Ú serializationÚget)rÚshapeÚ default_namerrrÚ_get_serialized_nameŸszSerializer._get_serialized_namecCs.t|tjƒr| |j¡}t |¡ ¡ |j¡S)N) r0rÚ text_typeÚencodeÚDEFAULT_ENCODINGÚbase64Ú b64encodeÚstripÚdecode)rr'rrrÚ _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)r:r;)Ú.0Úmemberr<rrrú µsz2Serializer._expand_host_prefix..c3s|]}|ˆ|fVqdS)Nr)rGr9)rrrú ¸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_prefixcCs|jrt|ƒ|S)z;Determine if additional traits are required for given model)Zhttp_checksum_requiredr )rÚrequestrrrrÚ_prepare_additional_traits¼sz%Serializer._prepare_additional_traits)N)Ú__name__Ú __module__Ú __qualname__r rNÚMAP_TYPErArr"r)r.r2r8r>rFrPrRrrrrrHs&  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) rKr"Úhttpr;r rVr9ÚmetadataÚ _serializerPrR)rrrr<r!Ú body_paramsrYrrrrÇs"    z$QuerySerializer.serialize_to_requestrcCs(t|d|j|jƒ}|||||ddS)Nz_serialize_type_%s)Úprefix)r5Ú type_nameÚ_default_serialize)rr!r'r<r^rrrrr\às zQuerySerializer._serializec CsT|j}xH| ¡D]<\}}||}| ||¡}|rr\) rr!r'r<r^rLÚkeyÚ member_shapeZ member_prefixrrrÚ_serialize_type_structureìs  z)QuerySerializer._serialize_type_structurec Cs¶|sd||<dS| |¡r\|}|jj d¡rx|j|jdd}d | d¡dd…|g¡}n|jj dd¡}d||f}x8t|dƒD]*\}} d||f} |j} | || | | ¡q„WdS) Nrr9)r=Ú.éÿÿÿÿrHz%s.%sé) Ú_is_shape_flattenedrHr:r;r>ÚjoinÚsplitÚ enumerater\) rr!r'r<r^Z list_prefixr9Z list_nameÚiÚelementÚelement_prefixÚ element_shaperrrÚ_serialize_type_listõs    z$QuerySerializer._serialize_type_listcCs¢| |¡r|}nd|}|d}|j}|j}|j|dd} | |d¡} xVt|dƒD]H\} } |j| | d} |j| | d}| || || ¡| ||| ||¡qRWdS)Nz%s.entryz .{i}.{suffix}ra)r=r'rf)rkÚsuffix)rgrar'r>rjrOr\)rr!r'r<r^Z full_prefixÚtemplateZ key_shapeZ value_shapeZ key_suffixZ value_suffixrkraZ key_prefixZ value_prefixrrrÚ_serialize_type_maps  z#QuerySerializer._serialize_type_mapcCs| |¡||<dS)N)rF)rr!r'r<r^rrrÚ_serialize_type_blobsz$QuerySerializer._serialize_type_blobcCs| ||j d¡¡||<dS)NÚtimestampFormat)r8r:r;)rr!r'r<r^rrrÚ_serialize_type_timestampsz)QuerySerializer._serialize_type_timestampcCs|rd||<nd||<dS)NÚtrueÚfalser)rr!r'r<r^rrrÚ_serialize_type_boolean s z'QuerySerializer._serialize_type_booleancCs |||<dS)Nr)rr!r'r<r^rrrr`&sz"QuerySerializer._default_serializecCs |j d¡S)NÚ flattened)r:r;)rr<rrrrg)sz#QuerySerializer._is_shape_flattenedN)r)r)r)r)r)r)r)r)rSrTrUr3rr\rcrorrrsrurxr`rgrrrrrWÃs      rWc@s"eZdZdZdd„Zddd„ZdS) Ú EC2SerializeraUEC2 specific customizations to the query protocol serializers. The EC2 model is almost, but not exactly, similar to the query protocol serializer. This class encapsulates those differences. The model will have be marked with a ``protocol`` of ``ec2``, so you don't need to worry about wiring this class up correctly. cCsHd|jkr|jdSd|jkr@|jd}|d ¡|dd…S|SdS)NZ queryNamer9rrf)r:Úupper)rr<r=r9rrrr>7s     z"EC2Serializer._get_serialized_namerc Cs>x8t|dƒD]*\}}d||f}|j}| ||||¡q WdS)Nrfz%s.%s)rjrHr\) rr!r'r<r^rkrlrmrnrrrroDs z"EC2Serializer._serialize_type_listN)r)rSrTrUÚ__doc__r>rorrrrrz-s rzc@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-TyperrrY)r[r9r"rZr;r rVrKr\rÚdumpsr@rArPrR) rrrÚtargetZ json_versionr!rrKrYrrrrNs&     z#JSONSerializer.serialize_to_requestNcCs&t|d|j|jƒ}|||||ƒdS)Nz_serialize_type_%s)r5r_r`)rr!r'r<rarrrrr\gs zJSONSerializer._serializec Csx|jr|||<nd|dk r,| ¡}|||<|}|j}x@| ¡D]4\}}||} d| jkr`| jd}| ||| |¡q         z'BaseRestSerializer.serialize_to_requestcCs^i}xLt d|¡D]<}| d¡r>t||dd…dd||<qt||ƒ||<qW|jf|ŽS)Nz{(.*?)}ú+rez/~)Úsafe)ÚreÚfindallÚendswithrrO)rZ uri_templateÚparamsZencoded_paramsZtemplate_paramrrrrŒá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Š)r:r;r_Ú_encode_payloadÚ_serialize_body_params) rrrr!r<rŽZpayload_memberZ body_payloadr]rrrròs     z%BaseRestSerializer._serialize_payloadcCst|tjƒr| |j¡S|S)N)r0rr?r@rA)rrrrrrš 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Úlocationr9r…rˆr†r‰Ú timestamprtr‡rrŠ) r:r;r0rNÚupdateÚboolÚstrr4r_ÚQUERY_STRING_TIMESTAMP_FORMATr8Ú_convert_header_valueÚ_do_serialize_header_map) rrrr‘rŽrHrœÚkey_namer(r<r'Ú header_prefixrrrr‹s4       z(BaseRestSerializer._partition_parameterscCs*x$| ¡D]\}}||}|||<q WdS)N)rM)rr¥rZ user_inputraÚvalZfull_keyrrrr£>sz+BaseRestSerializer._do_serialize_header_mapcCs tdƒ‚dS)Nr›)r)rr—r<rrrr›Csz)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…r9Z xmlAttribute)rÚ SubElementr:r;ÚattribrMrLr\) rr³r—r<r9Zstructure_nodeZnamespace_metadataZattribute_namerar'rbÚ member_nameZxml_attribute_namerrrrcls"        z+RestXMLSerializer._serialize_type_structurec CsX|j}|j d¡r|}|}n|j dd¡}t ||¡}x|D]}| ||||¡qrar'r\) rr³r—r<r9Únoderar'Z entry_noder¤Zval_namerrrrr‘s  z%RestXMLSerializer._serialize_type_mapcCs$t ||¡}|rd}nd}||_dS)Nrvrw)rrµÚtext)rr³r—r<r9rºZ str_valuerrrrx¤s  z)RestXMLSerializer._serialize_type_booleancCst ||¡}| |¡|_dS)N)rrµrFr»)rr³r—r<r9rºrrrrs¯s z&RestXMLSerializer._serialize_type_blobcCs&t ||¡}| ||j d¡¡|_dS)Nrt)rrµr8r:r;r»)rr³r—r<r9rºrrrru³s z+RestXMLSerializer._serialize_type_timestampcCst ||¡}t |¡|_dS)N)rrµrr?r»)rr³r—r<r9rºrrrr`¸s z$RestXMLSerializer._default_serializeN) rSrTrUr3r›r\rcrorrrxrsrur`rrrrr­]s  r­)Zec2Úqueryrz rest-jsonzrest-xml)T)r|r”rBr+r1Z xml.etreerZbotocore.compatrrrZbotocore.utilsrrrr Zbotocorer ZDEFAULT_TIMESTAMP_FORMATr%r$rÚobjectrrWrzr}r„r¬r­r rrrrÚ's:        {jR9a