U!\c@sdZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd lmZd Zd Zd Zed ZdefdYZdefdYZdefdYZdefdYZdefdYZdeefdYZdefdYZied6ed6ed6ed6ed 6ZdS(!sProtocol 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. iN(t ElementTree(tsix(tjsont formatdate(tparse_to_aware_datetime(tpercent_encode(tis_json_value_header(tvalidatetiso8601s%Y-%m-%dT%H:%M:%SZs%Y-%m-%dT%H:%M:%S.%fZcCs8t|}|r4tj}tj||}n|S(N(t SERIALIZERSRtParamValidatortParamValidationDecorator(t protocol_nametinclude_validationt serializert validator((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pytcreate_serializer>s   t SerializercBsneZdZeZdZdZdZdZdZ dZ d dZ dZ d Zd ZRS( tPOSTsutf-8cCstddS(sSerialize 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. tserialize_to_requestN(tNotImplementedError(tselft parameterstoperation_model((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRPs$cCs0idd6dd6|jd6id6dd6}|S(Nt/turl_pathtt query_stringtmethodtheaderstbody(tDEFAULT_METHOD(Rt serialized((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_create_default_requestvs  cCs+|jdkrt}nt}|j|S(Ni(t microsecondt ISO8601_MICROtISO8601tstrftime(Rtvaluettimestamp_format((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_timestamp_iso8601s cCsttj|jS(N(tinttcalendarttimegmt timetuple(RR&((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_timestamp_unixtimestampscCs4t|tjr$|j|}nt|dtS(Ntusegmt(t isinstancetdatetimeR-RtTrue(RR&((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_timestamp_rfc822scCsS|dkr|j}n|j}t|}t|d|}||}|S(Ns _timestamp_%s(tNonetTIMESTAMP_FORMATtlowerRtgetattr(RR&R't datetime_objt convertert final_value((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_convert_timestamp_to_strs     cCs|jjd|S(Ntname(t serializationtget(Rtshapet default_name((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_get_serialized_namescCsFt|tjr'|j|j}ntj|jj|jS(N( R/Rt text_typetencodetDEFAULT_ENCODINGtbase64t b64encodetstriptdecode(RR&((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt _get_base64sc s|j}|dkrdS|d}|jj}g|jD]$\}}|jjdr<|^q<}tfd|D} |j| S(Nt hostPrefixt hostLabelc3s|]}||fVqdS(N((t.0R;(R(s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pys s( tendpointR3t input_shapetmemberstitemsR<R=tdicttformat( RRRtoperation_endpointthost_prefix_expressiont input_memberstmemberR>t host_labelst format_kwargs((Rs6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_expand_host_prefixs    N(t__name__t __module__RRPtMAP_TYPERCRR!R(R-R2R3R:R@RHRX(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRGs &      tQuerySerializercBseZdZdZddZddZddZddZddZddZ dd Z dd Z d Z RS( RcCs|j}|j}|jjd|j|dR t body_paramsR`((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs          RcCs6t|d|j|j}||||d|dS(Ns_serialize_type_%stprefix(R6t type_namet_default_serialize(RR R&R>ReR((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRcs c Csu|j}xe|jD]W\}}||}|j||}|rWd||f}n|j||||qWdS(Ns%s.%s(RNROR@Rc( RR R&R>ReRNtkeyt member_shapet member_prefix((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_serialize_type_structures  c Cs|sd||Ret list_prefixR;t list_nametitelementtelement_prefixt element_shape((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_serialize_type_lists ) cCs|j|r|}n d|}|d}|j}|j}|j|dd} |j|d} x}t|dD]l\} } |jd| d| } |jd| d| }|j|| || |j||| ||quWdS( Ns%s.entrys .{i}.{suffix}R?RhR&iRstsuffix(RmRhR&R@RpRQRc(RR R&R>Ret full_prefixttemplatet key_shapet value_shapet key_suffixt value_suffixRsRht key_prefixt value_prefix((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_serialize_type_maps     cCs|j|||Re((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_serialize_type_blobscCs&|j||jjd||Re((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_serialize_type_timestampscCs!|rd||Re((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt_serialize_type_booleans cCs|||Re((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRgscCs|jjdS(Nt flattened(R<R=(RR>((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRm s( RYRZR4RRcRkRwRRRRRgRm(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyR\s       t EC2SerializercBs#eZdZdZddZRS(sUEC2 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. cCsTd|jkr|jdSd|jkrL|jd}|dj|dS|SdS(Nt queryNameR;ii(R<tupper(RR>R?R;((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyR@.s   Rc CsSxLt|dD];\}}d||f}|j}|j||||qWdS(Nis%s.%s(RpRURc( RR R&R>ReRsRtRuRv((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRw;s (RYRZt__doc__R@Rw(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyR$s tJSONSerializercBsYeZdZdZd dZdZdZdZdZ dZ dZ RS( t unixtimestampc Csd|jd|jf}|jd}|j}|jjd|j|dRhR((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRc\s c Cs|dk r+|j}|||<|}n|j}xY|jD]K\}}||} d| jkrv| jd}n|j||| |qAWdS(NR;(R3R[RNROR<Rc( RR R&R>Rhtnew_serializedRNt member_keyt member_valueRi((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRkas      cCsP|j}|||Rhtmap_objtsub_keyt sub_value((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRrs  cCsUg}||||D]6}i}|j|||jd|j|dqWdS(Nt __current__(RcRUtappend(RR R&R>Rhtlist_objt list_itemtwrapper((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRwxs   cCs|||Rh((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRgscCs&|j||jjd||Rh((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRscCs|j|||Rh((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRsN( RYRZR4RR3RcRkRRwRgRR(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRBs      tBaseRestSerializercBsteZdZdZdZddddgZdZdZd Zd Z d Z d Z d Z dZ RS(s=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. Rtrfc822turit querystringtheaderRc Csl|j}|jjd|j|d<|j}|dkrR|jd|d<|S|j}i|jd6|jd6|jd6|jd6}xB|jD]4\}}|dkrqn|j ||||qW|j |jd|d|d<|d|d<|dr$|d|dt shape_memberst partitionedt param_namet param_valueR`((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs<                cCsti}x^tjd|D]J}|jdrOt||d dd||Rtpayload_membert body_payloadRd((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs     cCs&t|tjr"|j|jS|S(N(R/RRARBRC(RR((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRsc Cs{||}|jjd}|jjd|}|dkrN||d|R&t header_prefix((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs4         cCs5x.|jD] \}}||}|||((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyR3scCs|jdkrXt|}tj|j}|jjd|j}|j||St |r|j t j |ddS|SdS(NRRt separatorst,t:(RR( RfRR*R+t utctimetupleR<R=tHEADER_TIMESTAMP_FORMATR:RRHRR(RR>R&R7RR'((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyR6s   (RYRZRRRtKNOWN_LOCATIONSRRRRRRRR(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs  1    ,  tRestJSONSerializercBseZdZRS(cCs8|j}|j|||tj|j|jS(N(R[RcRRRBRC(RRR>tserialized_body((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRGs (RYRZR(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyREstRestXMLSerializercBs_eZdZdZdZdZdZdZdZdZ dZ d Z RS( RcCsX|jd}tjd}|j||||t|d}tj|d|jS(NR;Ritencoding(R<RtElementRctlistttostringRC(RRR>t root_namet pseudo_roott real_root((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRPs  cCs3t|d|j|j}|||||dS(Ns_serialize_type_%s(R6RfRg(RR>RtxmlnodeR;R((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRcWs c Cstj||}d|jkrl|jd}d}|jdrX|d|d7}n|d|j|R;tstructure_nodetnamespace_metadatatattribute_nameRhR&Rit member_nametxml_attribute_name((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRk\s"     c Cs||j}|jjdr*|}|}n'|jjdd}tj||}x$|D]}|j||||qXWdS(NRR;RU(RUR<R=RRRc( RRRR>R;Rit element_namet list_nodetitem((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRwvs   c Cstj||}x|jD]\}}tj|d}|j|jdd} |j|jdd} |j|j||| |j|j||| qWdS(NtentryR?RhR&(RRROR@RhR&Rc( RRRR>R;tnodeRhR&t entry_nodeRtval_name((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs  cCs4tj||}|r!d}nd}||_dS(NRR(RRttext(RRRR>R;Rt str_value((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRs  cCs(tj||}|j||_dS(N(RRRHR(RRRR>R;R((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRscCs7tj||}|j||jjd|_dS(NR(RRR:R<R=R(RRRR>R;R((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRscCs(tj||}tj||_dS(N(RRRRAR(RRRR>R;R((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRgs( RYRZR4RRcRkRwRRRRRg(((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyRMs      tec2tqueryRs rest-jsonsrest-xml(RRRDR*R0t xml.etreeRtbotocore.compatRRRtbotocore.utilsRRRtbotocoreRtDEFAULT_TIMESTAMP_FORMATR$R#R1RtobjectRR\RRRRRR (((s6/tmp/pip-install-usGedi/botocore/botocore/serialize.pyt's8     uhM`