U B1_v@s$dZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd l mZdd lmZd Zd Zd Zd ddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeeZGdddeZeeeeedZdS)!aProtocol 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)validateiso8601z%Y-%m-%dT%H:%M:%SZz%Y-%m-%dT%H:%M:%S.%fZTcCs&t|}|r"t}t||}|SN) SERIALIZERSr ZParamValidatorZParamValidationDecorator)Z protocol_nameZinclude_validation serializerZ validatorrm/private/var/folders/2d/2jcwkxfx4hj39rq32sgz27wh9m_5lk/T/pip-target-h8a8k1vx/lib/python/botocore/serialize.pycreate_serializer?s   rc@sjeZdZdZeZdZddZddZddZ d d Z d d Z dddZ ddZ ddZddZddZd S) SerializerPOSTzutf-8cCs tddS)aSerialize 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_requestNNotImplementedError)self parametersoperation_modelrrrrQs$zSerializer.serialize_to_requestcCsdd|jidd}|S)N/)url_path query_stringmethodheadersbody)DEFAULT_METHOD)r serializedrrr_create_default_requestwsz"Serializer._create_default_requestcCs|jdkrt}nt}||S)Nr) microsecond ISO8601_MICROISO8601strftime)rvaluetimestamp_formatrrr_timestamp_iso8601s zSerializer._timestamp_iso8601cCstt|Sr )intcalendartimegm timetuplerr)rrr_timestamp_unixtimestampsz#Serializer._timestamp_unixtimestampcCs"t|tjr||}t|ddS)NT)usegmt) isinstancedatetimer1rr0rrr_timestamp_rfc822s  zSerializer._timestamp_rfc822NcCs8|dkr|j}|}t|}t|d|}||}|S)Nz _timestamp_%s)TIMESTAMP_FORMATlowerrgetattr)rr)r* datetime_obj converterZ final_valuerrr_convert_timestamp_to_strsz$Serializer._convert_timestamp_to_strcCs|jd|SNname serializationget)rshape default_namerrr_get_serialized_nameszSerializer._get_serialized_namecCs.t|tjr||j}t||jSr ) r3r text_typeencodeDEFAULT_ENCODINGbase64 b64encodestripdecoder0rrr _get_base64s   zSerializer._get_base64csV|j}|dkrdS|d}|jj}dd|D}tfdd|D}|jf|S)NZ hostPrefixcSs g|]\}}|jdr|qS)Z hostLabelr>).0memberrArrr s z2Serializer._expand_host_prefix..c3s|]}||fVqdSr r)rLr=rrr sz1Serializer._expand_host_prefix..)Zendpoint input_shapemembersitemsdictformat)rrrZoperation_endpointZhost_prefix_expressionZ input_membersZ host_labelsZ format_kwargsrrOr_expand_host_prefixszSerializer._expand_host_prefixcCs|jrt||S)z;Determine if additional traits are required for given model)Zhttp_checksum_requiredr )rrequestrrrr_prepare_additional_traitssz%Serializer._prepare_additional_traits)N)__name__ __module__ __qualname__r"rTMAP_TYPErFrr$r+r1r5r;rCrKrVrXrrrrrHs&  rc@speZdZdZddZdddZdddZdd d Zdd d Zdd dZ dddZ dddZ dddZ ddZ dS) QuerySerializerr cCs|j}|}|jd|j|d<ddi|d<|}|j|d<|jd|d<|dk rd||||||d<| ||}|dk r||d <| ||}|S) Nr Content-Typez0application/x-www-form-urlencoded; charset=utf-8r ZActionZ apiVersionVersionr! host_prefix) rQr$httpr@r"r\r=metadata _serializerVrX)rrrrAr# body_paramsr`rrrrs*  z$QuerySerializer.serialize_to_requestrcCs(t|d|j|j}|||||ddS)N_serialize_type_%s)prefixr8 type_name_default_serialize)rr#r)rArfrrrrrcs zQuerySerializer._serializec CsP|j}|D]<\}}||}|||}|r:d||f}|||||qdS)N%s.%s)rRrSrCrc) rr#r)rArfrRkey member_shapeZ member_prefixrrr_serialize_type_structures  z)QuerySerializer._serialize_type_structurec Cs|sd||<dS||r\|}|jjdrx|j|jdd}d|ddd|g}n|jjdd}d||f}t|dD]*\}} d||f} |j} ||| | | qdS) Nrr=rB.rMrj) _is_shape_flattenedrMr?r@rCjoinsplit enumeraterc) rr#r)rArfZ list_prefixr=Z list_nameielementelement_prefix element_shaperrr_serialize_type_lists    z$QuerySerializer._serialize_type_listcCs||r|}nd|}|d}|j}|j}|j|dd} ||d} t|dD]H\} } |j| | d} |j| | d}||| || |||| ||qPdS)Nz%s.entryz .{i}.{suffix}rkrnr)rq)rvsuffix)rrrkr)rCrurUrc)rr#r)rArfZ full_prefixtemplateZ key_shapeZ value_shapeZ key_suffixZ value_suffixrvrkZ key_prefixZ value_prefixrrr_serialize_type_maps  z#QuerySerializer._serialize_type_mapcCs||||<dSr rKrr#r)rArfrrr_serialize_type_blobsz$QuerySerializer._serialize_type_blobcCs|||jd||<dSNtimestampFormatr;r?r@rrrr_serialize_type_timestamps z)QuerySerializer._serialize_type_timestampcCs|rd||<nd||<dSNtruefalserrrrr_serialize_type_boolean s z'QuerySerializer._serialize_type_booleancCs |||<dSr rrrrrri&sz"QuerySerializer._default_serializecCs |jdS)N flattenedr>)rrArrrrr)sz#QuerySerializer._is_shape_flattenedN)r)r)r)r)r)r)r)r)rYrZr[r6rrcrmrzr}rrrrirrrrrrr]s      r]c@s"eZdZdZddZdddZdS) 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|ddS|SdS)NZ queryNamer=rrq)r?upper)rrArBr=rrrrC7s     z"EC2Serializer._get_serialized_namerc Cs:t|dD]*\}}d||f}|j}|||||q dS)Nrqrj)rurMrc) rr#r)rArfrvrwrxryrrrrzDs z"EC2Serializer._serialize_type_listN)r)rYrZr[__doc__rCrzrrrrr-s  rc@sReZdZdZddZdddZddZd d Zd d Zd dZ ddZ ddZ dS)JSONSerializerZ unixtimestampc Csd|jd|jf}|jd}|}|jd|j|d<|d|d|d<|}|j}|dk rp||||t | |j |d<| ||}|dk r||d <|||}|S) NrjZ targetPrefixZ jsonVersionrzapplication/x-amz-json-%s)z X-Amz-Targetr^r r!r`)rbr=r$rar@r"r\rQrcrdumpsrErFrVrX) rrrtargetZ json_versionr#r!rQr`rrrrNs.    z#JSONSerializer.serialize_to_requestNcCs&t|d|j|j}|||||dSNrerg)rr#r)rArkrrrrrcgs zJSONSerializer._serializec Csd|dk r|}|||<|}|j}|D]4\}}||} d| jkrN| jd}|||| |q*dSr<)r\rRrSr?rc) rr#r)rArkZnew_serializedrRZ member_key member_valuerlrrrrmls  z(JSONSerializer._serialize_type_structurecCs8|}|||<|D]\}}||||j|qdSr )r\rSrcr))rr#r)rArkZmap_objZsub_keyZ sub_valuerrrr}}sz"JSONSerializer._serialize_type_mapcCs>g}|||<|D](}i}||||jd||dqdS)NZ __current__)rcrMappend)rr#r)rArklist_objZ list_itemwrapperrrrrzs z#JSONSerializer._serialize_type_listcCs |||<dSr rrr#r)rArkrrrrisz!JSONSerializer._default_serializecCs|||jd||<dSrrrrrrrs z(JSONSerializer._serialize_type_timestampcCs||||<dSr r~rrrrrsz#JSONSerializer._serialize_type_blob)N) rYrZr[r6rrcrmr}rzrirrrrrrrKs  rc@sdeZdZdZdZdZddddgZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)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 Zrfc822uri querystringheaderr c Cs|}|jd|j|d<|j}|dkr<|jd|d<|S|j}||||d}|D]"\}}|dkrzqh|||||qh| |jd|d|d<|d|d<|dr|d|d<| |||||| ||} | dk r| |d <| ||}|S) NrZ requestUrir)uri_path_kwargsquery_string_kwargs body_kwargsr rrrr r`) r$rar@r"rQrRr\rS_partition_parameters_render_uri_template_serialize_payloadrVrX) rrrr#rA shape_members partitioned param_name param_valuer`rrrrsN     z'BaseRestSerializer.serialize_to_requestcCsZi}td|D]<}|dr|d|d7}|d|j|<|D]`\}} |j|} | jd|} | dkrdS| jdr| jd} | |j| <qT|| | || qTdS)NZ xmlNamespacexmlnsrfz:%srr=Z xmlAttribute)r SubElementr?r@attribrSrRrc) rrrrAr=Zstructure_nodeZnamespace_metadataZattribute_namerkr)rl member_nameZxml_attribute_namerrrrmis"        z+RestXMLSerializer._serialize_type_structurec CsT|j}|jdr|}|}n|jdd}t||}|D]}|||||q:dS)Nrr=rM)rMr?r@rrrc) rrrrAr=rlZ element_nameZ list_nodeitemrrrrzs  z&RestXMLSerializer._serialize_type_listc Csrt||}|D]X\}}t|d}|j|jdd} |j|jdd} ||j||| ||j||| qdS)Nentryrkrnr))rrrSrCrkr)rc) rrrrAr=noderkr)Z entry_noderZval_namerrrr}s  z%RestXMLSerializer._serialize_type_mapcCs$t||}|rd}nd}||_dSr)rrtext)rrrrAr=rZ str_valuerrrrs  z)RestXMLSerializer._serialize_type_booleancCst||}|||_dSr )rrrKrrrrrAr=rrrrrs z&RestXMLSerializer._serialize_type_blobcCs&t||}|||jd|_dSr)rrr;r?r@rrrrrrs   z+RestXMLSerializer._serialize_type_timestampcCst||}t||_dSr )rrrrDrrrrrris z$RestXMLSerializer._default_serializeN) rYrZr[r6rrcrmrzr}rrrrirrrrrZs  r)Zec2queryrz rest-jsonzrest-xml)T)rrrGr-r4Z xml.etreerZbotocore.compatrrrZbotocore.utilsrrrr Zbotocorer ZDEFAULT_TIMESTAMP_FORMATr'r&robjectrr]rrrrrr rrrr s<        {jO9a