U m‰^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úl/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/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_modelrrrrPs$zSerializer.serialize_to_requestcCsdd|jiddœ}|S)Nú/Úó)Úurl_pathÚ query_stringÚmethodÚheadersÚbody)ÚDEFAULT_METHOD)rÚ serializedrrrÚ_create_default_requestvsúz"Serializer._create_default_requestcCs|jdkrt}nt}| |¡S)Nr)Ú microsecondÚ ISO8601_MICROÚISO8601Ústrftime)rÚvalueÚtimestamp_formatrrrÚ_timestamp_iso8601…s zSerializer._timestamp_iso8601cCstt | ¡¡ƒSr )ÚintÚcalendarÚtimegmÚ timetuple©rr(rrrÚ_timestamp_unixtimestampŒsz#Serializer._timestamp_unixtimestampcCs"t|tjƒr| |¡}t|ddS)NT)Úusegmt)Ú isinstanceÚdatetimer0rr/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¡Sr ) r2rÚ text_typeÚencodeÚDEFAULT_ENCODINGÚbase64Ú b64encodeÚstripÚdecoder/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 hostLabelr=)Ú.0Úmemberr@rrrÚ ³s ÿz2Serializer._expand_host_prefix..c3s|]}|ˆ|fVqdSr r)rKr<©rrrÚ ·sz1Serializer._expand_host_prefix..)ZendpointÚ input_shapeÚmembersÚitemsÚdictÚformat)rrrZoperation_endpointZhost_prefix_expressionZ input_membersZ host_labelsZ format_kwargsrrNrÚ_expand_host_prefix¬sÿzSerializer._expand_host_prefix)N)Ú__name__Ú __module__Ú __qualname__r!rSÚMAP_TYPErErr#r*r0r4r:rBrJrUrrrrrGs&  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) Nrú Content-Typez0application/x-www-form-urlencoded; charset=utf-8rZActionZ apiVersionÚVersionr Ú host_prefix) rPr#Úhttpr?r!rYr<ÚmetadataÚ _serializerU)rrrr@r"Ú body_paramsr]rrrrÀs$ÿÿ  z$QuerySerializer.serialize_to_requestrcCs(t|d|j|jƒ}|||||ddS)Nú_serialize_type_%s)Úprefix©r7Ú type_nameÚ_default_serialize)rr"r(r@rcrrrrr`×s ÿzQuerySerializer._serializec CsP|j}| ¡D]<\}}||}| ||¡}|r:d||f}| ||||¡qdS)Nú%s.%s)rQrRrBr`) rr"r(r@rcrQÚ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}t|dƒD]*\}} d||f} |j} | || | | ¡q‚dS) Nrr<©rAÚ.éÿÿÿÿrLrgé) Ú_is_shape_flattenedrLr>r?rBÚjoinÚsplitÚ enumerater`) rr"r(r@rcZ list_prefixr<Z 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¡} t|dƒD]H\} } |j| | d} |j| | d}| || || ¡| ||| ||¡qPdS)Nz%s.entryz .{i}.{suffix}rhrkr(rn)rsÚsuffix)rorhr(rBrrrTr`)rr"r(r@rcZ full_prefixÚtemplateZ key_shapeZ value_shapeZ key_suffixZ value_suffixrsrhZ key_prefixZ value_prefixrrrÚ_serialize_type_mapÿs  z#QuerySerializer._serialize_type_mapcCs| |¡||<dSr ©rJ©rr"r(r@rcrrrÚ_serialize_type_blobsz$QuerySerializer._serialize_type_blobcCs| ||j d¡¡||<dS©NÚtimestampFormat©r:r>r?r|rrrÚ_serialize_type_timestamps ÿz)QuerySerializer._serialize_type_timestampcCs|rd||<nd||<dS©NÚtrueÚfalserr|rrrÚ_serialize_type_booleans z'QuerySerializer._serialize_type_booleancCs |||<dSr rr|rrrrfsz"QuerySerializer._default_serializecCs |j d¡S)NÚ flattenedr=)rr@rrrro sz#QuerySerializer._is_shape_flattenedN)r)r)r)r)r)r)r)r)rVrWrXr5rr`rjrwrzr}rr…rfrorrrrrZ¼s      rZc@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 queryNamer<rrn)r>Úupper)rr@rAr<rrrrB.s     z"EC2Serializer._get_serialized_namerc Cs:t|dƒD]*\}}d||f}|j}| ||||¡q dS)Nrnrg)rrrLr`) rr"r(r@rcrsrtrurvrrrrw;s z"EC2Serializer._serialize_type_listN)r)rVrWrXÚ__doc__rBrwrrrrr‡$s  r‡c@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) NrgZ targetPrefixZ jsonVersionrzapplication/x-amz-json-%s)z X-Amz-Targetr[rr r])r_r<r#r^r?r!rYrPr`rÚdumpsrDrErU) rrrÚtargetZ json_versionr"r rPr]rrrrEs( ÿ ÿþ  z#JSONSerializer.serialize_to_requestNcCs&t|d|j|jƒ}|||||ƒdS©Nrbrd)rr"r(r@rhrrrrr`\s ÿzJSONSerializer._serializec Csd|dk r| ¡}|||<|}|j}| ¡D]4\}}||} d| jkrN| jd}| ||| |¡q*dSr;)rYrQrRr>r`) rr"r(r@rhZnew_serializedrQZ member_keyÚ member_valuerirrrrjas  z(JSONSerializer._serialize_type_structurecCs8| ¡}|||<| ¡D]\}}| |||j|¡qdSr )rYrRr`r()rr"r(r@rhZmap_objZsub_keyZ sub_valuerrrrzrsz"JSONSerializer._serialize_type_mapcCs>g}|||<|D](}i}| |||jd¡| |d¡qdS)NZ __current__)r`rLÚappend)rr"r(r@rhÚlist_objZ list_itemÚwrapperrrrrwxs z#JSONSerializer._serialize_type_listcCs |||<dSr r©rr"r(r@rhrrrrf„sz!JSONSerializer._default_serializecCs| ||j d¡¡||<dSr~r€r’rrrr‡s ÿz(JSONSerializer._serialize_type_timestampcCs| |¡||<dSr r{r’rrrr}‹sz#JSONSerializer._serialize_type_blob)N) rVrWrXr5rr`rjrzrwrfrr}rrrrrŠBs  rŠc@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œ}| ¡D]"\}}|dkrzqh| ||||¡qh|  |jd|d¡|d<|d|d<|drÆ|d|d<|  |||||¡|  ||¡} | dk rô| |d <|S) NrZ requestUrir)Úuri_path_kwargsÚquery_string_kwargsÚ body_kwargsrr—r˜rrr]) r#r^r?r!rPrQrYrRÚ_partition_parametersÚ_render_uri_templateÚ_serialize_payloadrU) rrrr"r@Ú shape_membersÚ partitionedÚ param_nameÚ param_valuer]rrrr sHÿ ü ÿþ  ÿ z'BaseRestSerializer.serialize_to_requestcCsZi}t d|¡D]<}| d¡rr?reÚ_encode_payloadÚ_serialize_body_params) rržrr"r@rZpayload_memberZ body_payloadrarrrrœâs&  ÿ    þ ÿz%BaseRestSerializer._serialize_payloadcCst|tjƒr| |j¡S|Sr )r2rrCrDrE)rr rrrr©ý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Úlocationr<r”r—r•r˜Ú timestamprr–rr™) r>r?r2rSÚupdateÚboolÚstrr6reÚQUERY_STRING_TIMESTAMP_FORMATr:Ú_convert_header_valueÚ_do_serialize_header_map) rržrŸr rrLr«Úkey_namer)r@r(Ú header_prefixrrrršsJ    ÿÿ ÿÿÿÿ  þz(BaseRestSerializer._partition_parameterscCs&| ¡D]\}}||}|||<qdSr )rR)rr´rZ user_inputrhÚvalZfull_keyrrrr².sz+BaseRestSerializer._do_serialize_header_mapcCs tdƒ‚dS)Nrªr)rr¦r@rrrrª3sz)BaseRestSerializer._serialize_body_paramscCs`|jdkrr?ÚHEADER_TIMESTAMP_FORMATr:rrJrr‹)rr@r(r8r¬r)rrrr±6s ÿ z(BaseRestSerializer._convert_header_valueN)rVrWrXr‰r°rºZKNOWN_LOCATIONSrr›rœr©ršr²rªr±rrrrr“s  1,r“c@seZdZdd„ZdS)ÚRestJSONSerializercCs(| ¡}| |||¡t |¡ |j¡Sr )rYr`rr‹rDrE)rr¦r@Zserialized_bodyrrrrªGsz)RestJSONSerializer._serialize_body_paramsN)rVrWrXrªrrrrr»Esr»c@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)ÚRestXMLSerializerr cCs@|jd}t d¡}| ||||¡t|ƒd}tj||jdS)Nr<rr)Úencoding)r>rÚElementr`ÚlistÚtostringrE)rr¦r@Z root_nameZ pseudo_rootZ real_rootrrrrªPs    z(RestXMLSerializer._serialize_body_paramscCs&t|d|j|jƒ}|||||ƒdSrrd)rr@r¦Úxmlnoder<rrrrr`Ws ÿzRestXMLSerializer._serializec Csºt ||¡}d|jkrL|jd}d}| d¡r>|d|d7}|d|j|<| ¡D]`\}} |j|} | j d|¡} | dkr‚dS| j d¡r¤| jd} | |j| <qT| | | || ¡qTdS)NZ xmlNamespaceÚxmlnsrcz:%sr”r<Z xmlAttribute)rÚ SubElementr>r?ÚattribrRrQr`) rrÁr¦r@r<Zstructure_nodeZnamespace_metadataZattribute_namerhr(riÚ member_nameZxml_attribute_namerrrrj\s"        z+RestXMLSerializer._serialize_type_structurec CsT|j}|j d¡r|}|}n|j dd¡}t ||¡}|D]}| ||||¡q:dS)Nr†r<rL)rLr>r?rrÃr`) rrÁr¦r@r<riZ element_nameZ list_nodeÚitemrrrrwvs  z&RestXMLSerializer._serialize_type_listc Csrt ||¡}| ¡D]X\}}t |d¡}|j|jdd} |j|jdd} | |j||| ¡| |j||| ¡qdS)NÚentryrhrkr()rrÃrRrBrhr(r`) rrÁr¦r@r<Únoderhr(Z entry_noder³Zval_namerrrrzs  ÿz%RestXMLSerializer._serialize_type_mapcCs$t ||¡}|rd}nd}||_dSr‚)rrÃÚtext)rrÁr¦r@r<rÈZ str_valuerrrr…”s  z)RestXMLSerializer._serialize_type_booleancCst ||¡}| |¡|_dSr )rrÃrJrÉ©rrÁr¦r@r<rÈrrrr}Ÿs z&RestXMLSerializer._serialize_type_blobcCs&t ||¡}| ||j d¡¡|_dSr~)rrÃr:r>r?rÉrÊrrrr£s   ÿz+RestXMLSerializer._serialize_type_timestampcCst ||¡}t |¡|_dSr )rrÃrrCrÉrÊrrrrf¨s z$RestXMLSerializer._default_serializeN) rVrWrXr5rªr`rjrwrzr…r}rrfrrrrr¼Ms  r¼)Zec2Úqueryrz rest-jsonzrest-xml)T)r‰r£rFr,r3Z xml.etreerZbotocore.compatrrrZbotocore.utilsrrrZbotocorer ZDEFAULT_TIMESTAMP_FORMATr&r%rÚobjectrrZr‡rŠr“r»r¼r rrrrÚ s:       uhM7aû