o <&as@s0dZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd l mZdd l mZdd lmZd Zd ZdZd!ddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeeZGdddeZeeeeed ZdS)"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) has_header)validateiso8601z%Y-%m-%dT%H:%M:%SZz%Y-%m-%dT%H:%M:%S.%fZTcCs&t|}|rt}t||}|SN) SERIALIZERSr ParamValidatorParamValidationDecorator) protocol_nameinclude_validation serializer validatorr4/usr/lib/python3/dist-packages/botocore/serialize.pycreate_serializer@s  rc@sjeZdZdZeZdZddZddZddZ d d Z d d Z dddZ ddZ ddZddZddZd 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_modelrrrrRs$zSerializer.serialize_to_requestcCsdd|jidd}|S)N/)url_path query_stringmethodheadersbody)DEFAULT_METHOD)r serializedrrr_create_default_requestxsz"Serializer._create_default_requestcCs|jdkrt}nt}||S)Nr) microsecond ISO8601_MICROISO8601strftime)rvaluetimestamp_formatrrr_timestamp_iso8601s  zSerializer._timestamp_iso8601cCstt|Sr )intcalendartimegm timetuplerr0rrr_timestamp_unixtimestampz#Serializer._timestamp_unixtimestampcCs"t|tjr ||}t|ddS)NT)usegmt) isinstancedatetimer8rr7rrr_timestamp_rfc822s   zSerializer._timestamp_rfc822NcCs8|dur|j}|}t|}t|d|}||}|S)Nz _timestamp_%s)TIMESTAMP_FORMATlowerrgetattr)rr0r1 datetime_obj converter 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 ) r;r text_typeencodeDEFAULT_ENCODINGbase64 b64encodestripdecoder7rrr _get_base64s  zSerializer._get_base64csZ|j}|dur dS|d}|jj}dd|D}tfdd|D}|jdi|S)N hostPrefixcSs g|] \}}|jdr|qS) hostLabelrG).0memberrJrrr s  z2Serializer._expand_host_prefix..c3s|] }||fVqdSr r)rWrFrrr sz1Serializer._expand_host_prefix..r)endpoint input_shapemembersitemsdictformat)rrr operation_endpointhost_prefix_expression input_members host_labels format_kwargsrrZr_expand_host_prefixszSerializer._expand_host_prefixcCs|jrt||S)z;Determine if additional traits are required for given model)http_checksum_requiredr )rrequestr rrr_prepare_additional_traitssz%Serializer._prepare_additional_traitsr )__name__ __module__ __qualname__r)r`MAP_TYPErOrr+r2r8r=rDrLrTrgrjrrrrrIs&   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'Action apiVersionVersionr( host_prefix) r]r+httprIr)rnrFmetadata _serializergrj)rrr rJr* body_paramsrtrrrrs(  z$QuerySerializer.serialize_to_requestr"cCs(t|d|j|j}|||||ddS)N_serialize_type_%s)prefixr@ type_name_default_serialize)rr*r0rJrzr&rrrrws zQuerySerializer._serializec CsP|j}|D]\}}||}|||}|rd||f}|||||qdS)N%s.%s)r^r_rLrw) rr*r0rJrzr^key member_shape member_prefixrrr_serialize_type_structures  z)QuerySerializer._serialize_type_structurec Cs|sd||<dS||r.|}|jjdr-|j|jdd}d|ddd|g}n|jjdd}d||f}t|dD]\}} d||f} |j} ||| | | qAdS) Nr"rFrK.rXr~) _is_shape_flattenedrXrHrIrLjoinsplit enumeraterw) rr*r0rJrz list_prefixrF 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}rrr0r)rsuffix)rrr0rLrrarw)rr*r0rJrz full_prefixtemplate key_shape value_shape key_suffix value_suffixrr key_prefix value_prefixrrr_serialize_type_map s  z#QuerySerializer._serialize_type_mapcC||||<dSr rTrr*r0rJrzrrr_serialize_type_blobsz$QuerySerializer._serialize_type_blobcC|||jd||<dSNtimestampFormatrDrHrIrrrr_serialize_type_timestamp  z)QuerySerializer._serialize_type_timestampcCs|rd||<dSd||<dSNtruefalserrrrr_serialize_type_boolean"s  z'QuerySerializer._serialize_type_booleancC |||<dSr rrrrrr}( z"QuerySerializer._default_serializecCs |jdS)N flattenedrGrrJrrrr+rz#QuerySerializer._is_shape_flattenedNr")rkrlrmr>rrwrrrrrrr}rrrrrros       roc@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)N queryNamerFrr)rHupper)rrJrKrFrrrrL9s    z"EC2Serializer._get_serialized_namer"c Cs:t|dD]\}}d||f}|j}|||||qdS)Nrr~)rrXrw) rr*r0rJrzrrrrrrrrFs  z"EC2Serializer._serialize_type_listNr)rkrlrm__doc__rLrrrrrr/s  rc@sReZdZdZddZdddZddZd d Zd d Zd dZ ddZ ddZ dS)JSONSerializer unixtimestampc Csd|jd|jf}|jd}|}|jd|j|d<|d|d|d<|}|j}|dur8||||t | |j |d<| ||}|durQ||d <|||}|S) Nr~ targetPrefix jsonVersionr&zapplication/x-amz-json-%s)z X-Amz-Targetrpr'r(rt)rvrFr+rurIr)rnr]rwrdumpsrNrOrgrj) rrr target json_versionr*r(r]rtrrrrPs.    z#JSONSerializer.serialize_to_requestNcCs&t|d|j|j}|||||dSNryr{)rr*r0rJrr&rrrrwj zJSONSerializer._serializec Csv|jr |||<dS|dur|}|||<|}|j}|D]\}}||} d| jvr0| jd}|||| |qdSrE)is_document_typernr^r_rHrw) rr*r0rJrnew_serializedr^ member_key member_valuerrrrros   z(JSONSerializer._serialize_type_structurecCs8|}|||<|D] \}}||||j|q dSr )rnr_rwr0)rr*r0rJrmap_objsub_key sub_valuerrrrs z"JSONSerializer._serialize_type_mapcCs>g}|||<|D]}i}||||jd||dqdS)N __current__)rwrXappend)rr*r0rJrlist_obj list_itemwrapperrrrrsz#JSONSerializer._serialize_type_listcCrr rrr*r0rJrrrrr}rz!JSONSerializer._default_serializecCrrrrrrrrrz(JSONSerializer._serialize_type_timestampcCrr rrrrrrr9z#JSONSerializer._serialize_type_blobr ) rkrlrmr>rrwrrrr}rrrrrrrMs   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 rfc822)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) Nr& requestUrir$)uri_path_kwargsquery_string_kwargs body_kwargsr'rrr%r'rt)r+rurIr)r]r^rnr__partition_parameters_render_uri_template_serialize_payload_serialize_content_typergrj) rrr r*rJ shape_members partitioned param_name param_valuertrrrrsL     z'BaseRestSerializer.serialize_to_requestcCs^i}td|D]}|drt||dddd||<qt||||<q|jdi|S)Nz{(.*?)}+rz/~)safer)refindallendswithrra)r uri_templateparamsencoded_paramstemplate_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)Npayloadr#r(r)rHrI_has_streaming_payload_encode_payload_serialize_body_params_serialize_empty_body_requires_empty_body) rrrr*rJrpayload_member body_payloadrxrrrrs(        z%BaseRestSerializer._serialize_payloadcCdS)Nr#rrrrrrz(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*rJrrrrrsz*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)blobstring)r|)rrrrrrr's z)BaseRestSerializer._has_streaming_payloadcCst|tjr ||jS|Sr )r;rrMrNrO)rr(rrrr.s  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}||} | | |} t| |d |<dS|d kr|} | | |d |dS||d |<dS) NlocationrFrrrr timestamprrr'r) rHrIr;r`updateboolstrr?r|QUERY_STRING_TIMESTAMP_FORMATrD_convert_header_value_do_serialize_header_map)rrrrrrXrkey_namebool_strr1rrJr0 header_prefixrrrr3s>      z(BaseRestSerializer._partition_parameterscCs&|D] \}}||}|||<qdSr )r_)rrr' user_inputrvalfull_keyrrrr_s z+BaseRestSerializer._do_serialize_header_mapcCr)Nrr)rrrJrrrrdsz)BaseRestSerializer._serialize_body_paramscsjdkrt|}t|}jdj}||Sjdkr2fdd|D}d |St r@ t j |ddS|S) Nrrlistcs"g|] }|durj|qSr )rrX)rWvrrrrYos  z.,)r:) separators)r|rr4r5 utctimetuplerHrIHEADER_TIMESTAMP_FORMATrDrrrTrr)rrJr0rArr1converted_valuerrrrgs     z(BaseRestSerializer._convert_header_valueN)rkrlrmrrrKNOWN_LOCATIONSrrrrrrrrrrrrrrrrrs" 5, rc@s,eZdZddZddZddZddZd S) RestJSONSerializercCr)Ns{}rrrrrr~rz(RestJSONSerializer._serialize_empty_bodycCs(|jD] \}}d|jvrdSqdS)zq Serialize an empty JSON object whenever the shape has members not targeting a location. rTF)r^r_rH)rrJrXrrrrrs  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(r#rpr'zapplication/json)rHrIrr )rr*rJrrhas_bodyhas_content_typerrrrs   z*RestJSONSerializer._serialize_content_typecCs(|}||||t||jSr )rnrwrrrNrO)rrrJserialized_bodyrrrrsz)RestJSONSerializer._serialize_body_paramsN)rkrlrmrrrrrrrrr|s  rc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS)RestXMLSerializerr cCs@|jd}td}|||||t|d}tj||jdS)NrFr"r)encoding)rHrElementrwrtostringrO)rrrJ root_name pseudo_root real_rootrrrrs   z(RestXMLSerializer._serialize_body_paramscCs&t|d|j|j}|||||dSrr{)rrJrxmlnoderFr&rrrrwrzRestXMLSerializer._serializec Cst||}d|jvr&|jd}d}|dr|d|d7}|d|j|<|D]0\}} |j|} | jd|} | durAdS| jdrR| jd} | |j| <q*|| | || q*dS)N xmlNamespacexmlnsrzz:%srrF xmlAttribute)r SubElementrHrIattribr_r^rw) rrrrJrFstructure_nodenamespace_metadataattribute_namerr0r member_namexml_attribute_namerrrrs$        z+RestXMLSerializer._serialize_type_structurec CsT|j}|jdr|}|}n |jdd}t||}|D] }|||||qdS)NrrFrX)rXrHrIrrrw) rrrrJrFr element_name list_nodeitemrrrrs  z&RestXMLSerializer._serialize_type_listc Csrt||}|D],\}}t|d}|j|jdd} |j|jdd} ||j||| ||j||| q dS)Nentryrrr0)rrr_rLrr0rw) rrrrJrFnoderr0 entry_noderval_namerrrrs  z%RestXMLSerializer._serialize_type_mapcCs$t||}|r d}nd}||_dSr)rrtext)rrrrJrFr! str_valuerrrrs  z)RestXMLSerializer._serialize_type_booleancCst||}|||_dSr )rrrTr$rrrrJrFr!rrrr z&RestXMLSerializer._serialize_type_blobcCs&t||}|||jd|_dSr)rrrDrHrIr$r&rrrrs   z+RestXMLSerializer._serialize_type_timestampcCst||}t||_dSr )rrrrMr$r&rrrr}r'z$RestXMLSerializer._default_serializeN) rkrlrmr>rrwrrrrrrr}rrrrr s   r )ec2queryrz rest-jsonzrest-xml)T) rrrPr4r< xml.etreerbotocore.compatrrrbotocore.utilsrrrr r botocorer DEFAULT_TIMESTAMP_FORMATr.r-robjectrrorrrrr rrrrrs@           {kS]!a