o ?c}@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZdZdZd Zdd d ZGd ddZGdddeZGdddeZGdddeZGdddeZGdddeeZGdddeZeeeeedZdS)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)validate) formatdate) has_headeris_json_value_headerparse_to_aware_datetimepercent_encodeiso8601z%Y-%m-%dT%H:%M:%SZz%Y-%m-%dT%H:%M:%S.%fZTcCs&t|}|rt}t||}|SN) SERIALIZERSrZParamValidatorZParamValidationDecorator)Z protocol_nameZinclude_validation serializer validatorrm/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/serialize.pycreate_serializer?s  rc@sbeZdZdZeZdZddZddZddZ d d Z d d Z dddZ ddZ ddZddZd S) SerializerPOSTzutf-8cCtd)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_requestNotImplementedError)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_unixtimestampz#Serializer._timestamp_unixtimestampcCs"t|tjr ||}t|ddS)NT)usegmt) isinstancedatetimer1rr0rrr_timestamp_rfc822s   zSerializer._timestamp_rfc822NcCs:|dur|j}|}t|}t|d|}||}|S)NZ _timestamp_)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|tr ||j}t||jSr )r4strencodeDEFAULT_ENCODINGbase64 b64encodestripdecoder0rrr _get_base64s  zSerializer._get_base64csV|j}|dur dS|d}|jj}dd|D}fdd|D}|jdi|S)NZ hostPrefixcSs g|] \}}|jdr|qS)Z hostLabelr?).0memberrBrrr s  z2Serializer._expand_host_prefix..csi|]}||qSrr)rMr>rrr sz2Serializer._expand_host_prefix..r)Zendpoint input_shapemembersitemsformat)rrrZoperation_endpointZhost_prefix_expressionZ input_membersZ host_labelsZ format_kwargsrrPr_expand_host_prefixszSerializer._expand_host_prefixr )__name__ __module__ __qualname__r"dictMAP_TYPErGrr$r+r1r6r<rDrLrVrrrrrHs&   rc@speZdZdZddZdddZdddZdd d Zdd d Zdd dZ dddZ dddZ dddZ ddZ dS)QuerySerializerr cCs|j}|}|jd|j|d<ddi|d<|}|j|d<|jd|d<|dur2||||||d<| ||}|durD||d <|S) Nr Content-Typez0application/x-www-form-urlencoded; charset=utf-8r ZActionZ apiVersionVersionr! host_prefix) rRr$httprAr"r[r>metadata _serializerV)rrrrBr# body_paramsr_rrrrs"  z$QuerySerializer.serialize_to_requestrcCs*t|d|j|j}|||||ddS)NZ_serialize_type_)prefixr9 type_name_default_serialize)rr#r)rBrdrrrrrbs  zQuerySerializer._serializec CsR|j}|D]\}}||}|||}|r|d|}|||||qdS)N.)rSrTrDrb) rr#r)rBrdrSkey member_shapeZ member_prefixrrr_serialize_type_structures z)QuerySerializer._serialize_type_structurec Cs|sd||<dS||r.|}|jjdr-|j|jdd}d|ddd|g}n|jjdd}|d|}t|dD]\}} |d|} |j} ||| | | qBdS)Nrr>rCrhrN) _is_shape_flattenedrNr@rArDjoinsplit enumeraterb) rr#r)rBrdZ 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]$\} } |j| | d} |j| | d}||| || |||| ||q(dS)Nz%s.entryz .{i}.{suffix}rirlr)rn)rssuffix)rorir)rDrrrUrb)rr#r)rBrdZ full_prefixtemplateZ key_shapeZ value_shapeZ key_suffixZ value_suffixrsriZ key_prefixZ value_prefixrrr_serialize_type_maps  z#QuerySerializer._serialize_type_mapcC||||<dSr rLrr#r)rBrdrrr_serialize_type_blobsz$QuerySerializer._serialize_type_blobcC|||jd||<dSNtimestampFormatr<r@rAr}rrr_serialize_type_timestamp  z)QuerySerializer._serialize_type_timestampcCs|rd||<dSd||<dSNtruefalserr}rrr_serialize_type_booleans  z'QuerySerializer._serialize_type_booleancC |||<dSr rr}rrrrg" z"QuerySerializer._default_serializecCs |jdS)N flattenedr?rrBrrrro%rz#QuerySerializer._is_shape_flattenedNr)rWrXrYr7rrbrkrwrzr~rrrgrorrrrr\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. cCsDd|jvr |jdSd|jvr |jd}|d|ddS|S)NZ queryNamer>rrn)r@upper)rrBrCr>rrrrD3s    z"EC2Serializer._get_serialized_namerc Cs<t|dD]\}}|d|}|j}|||||qdS)Nrnrh)rrrNrb) rr#r)rBrdrsrtrurvrrrrw@s z"EC2Serializer._serialize_type_listNr)rWrXrY__doc__rDrwrrrrr)s  rc@sReZdZdZddZdddZddZd d Zd d Zd dZ ddZ ddZ dS)JSONSerializerZ unixtimestampc Csd|jd|j}|jd}|}|jd|j|d<|d|d|d<|}|j}|dur8| |||t | |j |d<|||}|durQ||d <|S) Nz{}.{}Z targetPrefixZ jsonVersionrzapplication/x-amz-json-%s)z X-Amz-Targetr]r r!r_)rUrar>r$r`rAr"r[rRrbjsondumpsrFrGrV) rrrtargetZ json_versionr#r!rRr_rrrrJs*   z#JSONSerializer.serialize_to_requestNcCs&t|d|j|j}|||||dSNz_serialize_type_%sre)rr#r)rBrirrrrrbd zJSONSerializer._serializec Csv|jr |||<dS|dur|}|||<|}|j}|D]\}}||} d| jvr0| jd}|||| |qdSr=)Zis_document_typer[rSrTr@rb) rr#r)rBriZnew_serializedrSZ member_key member_valuerjrrrrkls   z(JSONSerializer._serialize_type_structurecCs8|}|||<|D] \}}||||j|q dSr )r[rTrbr))rr#r)rBriZmap_objZsub_keyZ sub_valuerrrrzs z"JSONSerializer._serialize_type_mapcCs>g}|||<|D]}i}||||jd||dqdS)NZ __current__)rbrNappend)rr#r)rBrilist_objZ list_itemwrapperrrrrwsz#JSONSerializer._serialize_type_listcCrr rrr#r)rBrirrrrgrz!JSONSerializer._default_serializecCrrrrrrrrrz(JSONSerializer._serialize_type_timestampcCr{r r|rrrrr~r2z#JSONSerializer._serialize_type_blobr ) rWrXrYr7rrbrkrzrwrgrr~rrrrrGs   rc@seZdZdZdZdZgdZddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZdS)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 querystringheaderr c Cs|}|jd|j|d<|j}|dur|jd|d<|S|j}||||d}|D]\}}|dur=q4|||||q4| |jd|d|d<|d|d<|drc|d|d<| |||||| |||| ||} | dur| |d <|S) NrZ requestUrir)uri_path_kwargsquery_string_kwargs body_kwargsr rrrr r_) r$r`rAr"rRrSr[rT_partition_parameters_render_uri_template_serialize_payload_serialize_content_typerV) rrrr#rB shape_members partitioned param_name param_valuer_rrrrsD     z'BaseRestSerializer.serialize_to_requestcCs^i}td|D]}|drt||dddd||<qt||||<q|jdi|S)Nz{(.*?)}+rmz/~)safer)refindallendswithrrU)rZ uri_templateparamsZencoded_paramsZtemplate_paramrrrrs   z'BaseRestSerializer._render_uri_templatec Cs|jd}|||r||d}||}||d<dS|dur>||}|dur6|||||d<dS||d<dS|drN||d||d<dS||r[||d<dSdS)Npayloadrr!r)r@rA_has_streaming_payload_encode_payload_serialize_body_params_serialize_empty_body_requires_empty_body) rrrr#rBrZpayload_memberZ body_payloadrcrrrrs&        z%BaseRestSerializer._serialize_payloadcCdS)Nrrrrrrrz(BaseRestSerializer._serialize_empty_bodycCr)z Some protocols require varied Content-Type headers depending on user input. This allows subclasses to apply this conditionally. Nr)rr#rBrrrrrsz*BaseRestSerializer._serialize_content_typecCr)z Some protocols require a specific body to represent an empty payload. This allows subclasses to apply this conditionally. Frrrrrr%sz'BaseRestSerializer._requires_empty_bodycCs|duo ||jdvS)z5Determine if payload is streaming (a blob or string).N)Zblobstring)rf)rrrrrrr,sz)BaseRestSerializer._has_streaming_payloadcCst|tr ||jS|Sr )r4rErFrG)rr!rrrr3s  z"BaseRestSerializer._encode_payloadcCs>||}|jd}|jd|}|dkr||d|<dS|dkret|tr/|d|dSt|trBt|}||d|<dS|jdkr]|jd|j } | || } | |d|<dS||d|<dS|d kr||} |sv| jd krvdS| | |} t| |d |<dS|d kr|} | | |d |dS||d |<dS) Nlocationr>rrrr timestamprrlistr r) r@rAr4rZupdateboolrEr8rfQUERY_STRING_TIMESTAMP_FORMATr<_convert_header_value_do_serialize_header_map)rrrrrrNrkey_nameZbool_strr*rrBr) header_prefixrrrr8s@       z(BaseRestSerializer._partition_parameterscCs&|D] \}}||}|||<qdSr )rT)rrr Z user_inputrivalZfull_keyrrrris z+BaseRestSerializer._do_serialize_header_mapcCr)Nrr)rrrBrrrrnsz)BaseRestSerializer._serialize_body_paramscsjdkrt|}t|}jdj}||Sjdkr2fdd|D}d |St r@ t j |ddS|S) Nrrrcs"g|] }|durj|qSr )rrN)rMvrrrrOzs  z.,)r:) separators)rfrr-r. utctimetupler@rAHEADER_TIMESTAMP_FORMATr<rprrLrr)rrBr)r:rr*Zconverted_valuerrrrqs     z(BaseRestSerializer._convert_header_valueN)rWrXrYrrrZKNOWN_LOCATIONSrrrrrrrrrrrrrrrrrs" 5 1 rc@s,eZdZddZddZddZddZd S) RestJSONSerializercCr)Ns{}rrrrrrrz(RestJSONSerializer._serialize_empty_bodycCs(|jD] \}}d|jvrdSqdS)zq Serialize an empty JSON object whenever the shape has members not targeting a location. rTF)rSrTr@)rrBrNrrrrrs  z'RestJSONSerializer._requires_empty_bodycCsV|jd}|||rdS|ddk}td|d}|r'|s)d|dd<dSdSdS)z?Set Content-Type to application/json for all structured bodies.rNr!rr]r zapplication/json)r@rArr)rr#rBrrZhas_bodyZhas_content_typerrrrs   z*RestJSONSerializer._serialize_content_typecCs(|}||||t||jSr )r[rbrrrFrG)rrrBZserialized_bodyrrrrsz)RestJSONSerializer._serialize_body_paramsN)rWrXrYrrrrrrrrrs  rc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)RestXMLSerializerr cCs@|jd}td}|||||t|d}tj||jdS)Nr>rr)encoding)r@rElementrbrtostringrG)rrrBZ root_nameZ pseudo_rootZ real_rootrrrrs   z(RestXMLSerializer._serialize_body_paramscCs&t|d|j|j}|||||dSrre)rrBrxmlnoder>rrrrrbrzRestXMLSerializer._serializec Cst||}d|jvr&|jd}d}|dr|d|d7}|d|j|<|D]0\}} |j|} | jd|} | durAdS| jdrR| jd} | |j| <q*|| | || q*dS)NZ xmlNamespacexmlnsrdz:%srr>Z xmlAttribute)r SubElementr@rAattribrTrSrb) rrrrBr>Zstructure_nodeZnamespace_metadataZattribute_namerir)rj member_nameZxml_attribute_namerrrrks$        z+RestXMLSerializer._serialize_type_structurec CsT|j}|jdr|}|}n |jdd}t||}|D] }|||||qdS)Nrr>rN)rNr@rArrrb) rrrrBr>rjZ element_nameZ list_nodeitemrrrrws  z&RestXMLSerializer._serialize_type_listc Csrt||}|D],\}}t|d}|j|jdd} |j|jdd} ||j||| ||j||| q dS)Nentryrirlr))rrrTrDrir)rb) rrrrBr>noderir)Z entry_noderZval_namerrrrzs  z%RestXMLSerializer._serialize_type_mapcCs$t||}|r d}nd}||_dSr)rrtext)rrrrBr>rZ str_valuerrrrs  z)RestXMLSerializer._serialize_type_booleancCst||}|||_dSr )rrrLrrrrrBr>rrrrr~s z&RestXMLSerializer._serialize_type_blobcCs&t||}|||jd|_dSr)rrr<r@rArrrrrrs   z+RestXMLSerializer._serialize_type_timestampcCst||}t||_dSr )rrrErrrrrrgs z$RestXMLSerializer._default_serializeN) rWrXrYr7rrbrkrwrzrr~rrgrrrrrs   r)Zec2queryrz rest-jsonzrest-xml)T)rrHr-r5rrZ xml.etreerZbotocorerZbotocore.compatrZbotocore.utilsrrrrZDEFAULT_TIMESTAMP_FORMATr'r&rrr\rrrrrr rrrrs8      tmYi f