t_c@sdZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd l mZdd lmZd Zd Zd ZedZdefdYZdefdYZdefdYZdefdYZdefdYZdeefdYZdefdYZied6ed6ed6ed 6ed!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(tconditionally_calculate_md5(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((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pytcreate_serializer?s   t SerializercBsweZdZeZdZdZdZdZdZ dZ d dZ dZ d Zd 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((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRQs$cCs0idd6dd6|jd6id6dd6}|S(Nt/turl_pathtt query_stringtmethodtheaderstbody(tDEFAULT_METHOD(Rt serialized((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_create_default_requestws  cCs+|jdkrt}nt}|j|S(Ni(t microsecondt ISO8601_MICROtISO8601tstrftime(Rtvaluettimestamp_format((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_timestamp_iso8601s cCsttj|jS(N(tinttcalendarttimegmt timetuple(RR'((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_timestamp_unixtimestampscCs4t|tjr$|j|}nt|dtS(Ntusegmt(t isinstancetdatetimeR.RtTrue(RR'((s=/opt/awscli/lib/python2.7/site-packages/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((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_convert_timestamp_to_strs     cCs|jjd|S(Ntname(t serializationtget(Rtshapet default_name((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_get_serialized_namescCsFt|tjr'|j|j}ntj|jj|jS(N( R0Rt text_typetencodetDEFAULT_ENCODINGtbase64t b64encodetstriptdecode(RR'((s=/opt/awscli/lib/python2.7/site-packages/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(s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pys s( tendpointR4t input_shapetmemberstitemsR=R>tdicttformat( RRRtoperation_endpointthost_prefix_expressiont input_memberstmemberR?t host_labelst format_kwargs((Rs=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_expand_host_prefixs    cCs|jrt|n|S(s;Determine if additional traits are required for given model(thttp_checksum_requiredR(RtrequestR((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_prepare_additional_traitss  N(t__name__t __module__R RQtMAP_TYPERDRR"R)R.R3R4R;RARIRYR\(((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRHs &      tQuerySerializercBseZdZdZddZddZddZddZddZddZ dd Z dd Z d Z RS( R cCs|j}|j}|jjd|j|dR R_R<tmetadataR4t _serializeRYR\(RRRR?R!t body_paramsRd((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs$           RcCs6t|d|j|j}||||d|dS(Ns_serialize_type_%stprefix(R7t type_namet_default_serialize(RR!R'R?RiR((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRgs c Csu|j}xe|jD]W\}}||}|j||}|rWd||f}n|j||||qWdS(Ns%s.%s(RORPRARg( RR!R'R?RiROtkeyt member_shapet member_prefix((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_serialize_type_structures  c Cs|sd||RAtjointsplitt enumerateRg( RR!R'R?Rit list_prefixR<t list_nametitelementtelement_prefixt element_shape((s=/opt/awscli/lib/python2.7/site-packages/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@RlR'iRwtsuffix(RqRlR'RARtRRRg(RR!R'R?Rit full_prefixttemplatet key_shapet value_shapet key_suffixt value_suffixRwRlt key_prefixt value_prefix((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_serialize_type_maps     cCs|j|||(RR!R'R?Ri((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt_serialize_type_timestampscCs!|rd||(RR?((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRq)s( R]R^R5RRgRoR{RRRRRkRq(((s=/opt/awscli/lib/python2.7/site-packages/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<((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRA7s   Rc CsSxLt|dD];\}}d||f}|j}|j||||qWdS(Nis%s.%s(RtRVRg( RR!R'R?RiRwRxRyRz((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyR{Ds (R]R^t__doc__RAR{(((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyR-s tJSONSerializercBsYeZdZdZd dZdZdZdZdZ dZ dZ RS( t unixtimestampc Csd|jd|jf}|jd}|j}|jjd|j|dR R_RNR4RgRtdumpsRCRDRYR\( RRRttargett json_versionR!RRNRd((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRNs(            cCs3t|d|j|j}|||||dS(Ns_serialize_type_%s(R7RjRk(RR!R'R?RlR((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRggs c Cs|dk r+|j}|||<|}n|j}xY|jD]K\}}||} d| jkrv| jd}n|j||| |qAWdS(NR<(R4R_RORPR=Rg( RR!R'R?Rltnew_serializedROt member_keyt member_valueRm((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRols      cCsP|j}||||D]6}i}|j|||jd|j|dqWdS(Nt __current__(RgRVtappend(RR!R'R?Rltlist_objt list_itemtwrapper((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyR{s   cCs|||(RR!R'R?Rl((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRscCs|j|||R RNR4ROR_RPt_partition_parameterst_render_uri_templatet_serialize_payloadRYR\( RRRR!R?t shape_memberst partitionedt param_namet param_valueRd((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs@                  cCsti}x^tjd|D]J}|jdrOt||d dd||R4Rjt_encode_payloadt_serialize_body_params( RRRR!R?Rtpayload_membert body_payloadRh((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs     cCs&t|tjr"|j|jS|S(N(R0RRBRCRD(RR((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyR sc Cs{||}|jjd}|jjd|}|dkrN||d|R0RQtupdatetbooltstrR6RjtQUERY_STRING_TIMESTAMP_FORMATR;t_convert_header_valuet_do_serialize_header_map( RRRRRRVRtkey_nameR(R?R't header_prefix((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs4         cCs5x.|jD] \}}||}|||tHEADER_TIMESTAMP_FORMATR;RRIRR(RR?R'R8RR(((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRCs   (R]R^RRRtKNOWN_LOCATIONSRRRRRRRR(((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs  3    ,  tRestJSONSerializercBseZdZRS(cCs8|j}|j|||tj|j|jS(N(R_RgRRRCRD(RRR?tserialized_body((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRTs (R]R^R(((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRRstRestXMLSerializercBs_eZdZdZdZdZdZdZdZdZ dZ d Z RS( R cCsX|jd}tjd}|j||||t|d}tj|d|jS(NR<Ritencoding(R=RtElementRgtlistttostringRD(RRR?t root_namet pseudo_roott real_root((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyR]s  cCs3t|d|j|j}|||||dS(Ns_serialize_type_%s(R7RjRk(RR?RtxmlnodeR<R((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRgds c Cstj||}d|jkrl|jd}d}|jdrX|d|d7}n|d|j|tattribRPROR4Rg( RRRR?R<tstructure_nodetnamespace_metadatatattribute_nameRlR'Rmt member_nametxml_attribute_name((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRois"     c Cs||j}|jjdr*|}|}n'|jjdd}tj||}x$|D]}|j||||qXWdS(NRR<RV(RVR=R>RRRg( RRRR?R<Rmt element_namet list_nodetitem((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyR{s   c Cstj||}x|jD]\}}tj|d}|j|jdd} |j|jdd} |j|j||| |j|j||| qWdS(NtentryR@RlR'(RRRPRARlR'Rg( RRRR?R<tnodeRlR't entry_nodeRtval_name((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs  cCs4tj||}|r!d}nd}||_dS(NRR(RRttext(RRRR?R<Rt str_value((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRs  cCs(tj||}|j||_dS(N(RRRIR(RRRR?R<R((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRscCs7tj||}|j||jjd|_dS(NR(RRR;R=R>R(RRRR?R<R((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRscCs(tj||}tj||_dS(N(RRRRBR(RRRR?R<R((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRks( R]R^R5RRgRoR{RRRRRk(((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyRZs      tec2tqueryRs rest-jsonsrest-xml( RRRER+R1t xml.etreeRtbotocore.compatRRRtbotocore.utilsRRRRtbotocoreRtDEFAULT_TIMESTAMP_FORMATR%R$R2RtobjectRR`RRRRRR (((s=/opt/awscli/lib/python2.7/site-packages/botocore/serialize.pyt's:     {jO`