&>ac@sdZddlZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl m Z ddl mZdd l mZdd l mZdd lmZd Zd ZdZedZdefdYZdefdYZdefdYZdefdYZdefdYZdeefdYZdefdYZied6ed6ed 6ed!6ed"6Z dS(#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(t has_header(tvalidatetiso8601s%Y-%m-%dT%H:%M:%SZs%Y-%m-%dT%H:%M:%S.%fZcCs8t|}|r4tj}tj||}n|S(N(t SERIALIZERSR tParamValidatortParamValidationDecorator(t protocol_nametinclude_validationt serializert validator((s3/usr/lib/fence-agents/bundled/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((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRRs$cCs0idd6dd6|jd6id6dd6}|S(Nt/turl_pathtt query_stringtmethodtheaderstbody(tDEFAULT_METHOD(Rt serialized((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_create_default_requestxs  cCs+|jdkrt}nt}|j|S(Ni(t microsecondt ISO8601_MICROtISO8601tstrftime(Rtvaluettimestamp_format((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_timestamp_iso8601s cCsttj|jS(N(tinttcalendarttimegmt timetuple(RR(((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_timestamp_unixtimestampscCs4t|tjr$|j|}nt|dtS(Ntusegmt(t isinstancetdatetimeR/RtTrue(RR(((s3/usr/lib/fence-agents/bundled/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((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_convert_timestamp_to_strs     cCs|jjd|S(Ntname(t serializationtget(Rtshapet default_name((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_get_serialized_namescCsFt|tjr'|j|j}ntj|jj|jS(N( R1Rt text_typetencodetDEFAULT_ENCODINGtbase64t b64encodetstriptdecode(RR(((s3/usr/lib/fence-agents/bundled/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(s3/usr/lib/fence-agents/bundled/botocore/serialize.pys s( tendpointR5t input_shapetmemberstitemsR>R?tdicttformat( RRRtoperation_endpointthost_prefix_expressiont input_memberstmemberR@t host_labelst format_kwargs((Rs3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_expand_host_prefixs    cCs|jrt|n|S(s;Determine if additional traits are required for given model(thttp_checksum_requiredR(RtrequestR((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_prepare_additional_traitss  N(t__name__t __module__R!RRtMAP_TYPERERR#R*R/R4R5R<RBRJRZR](((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRIs &      tQuerySerializercBseZdZdZddZddZddZddZddZddZ dd Z dd Z d Z RS( R cCs|j}|j}|jjd|j|dR?RBtjointsplitt enumerateRh( RR"R(R@Rjt list_prefixR=t list_nametitelementtelement_prefixt element_shape((s3/usr/lib/fence-agents/bundled/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}RARmR(iRxtsuffix(RrRmR(RBRuRSRh(RR"R(R@Rjt full_prefixttemplatet key_shapet value_shapet key_suffixt value_suffixRxRmt key_prefixt value_prefix((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_serialize_type_map s     cCs|j|||R?(RR"R(R@Rj((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt_serialize_type_timestampscCs!|rd||R?(RR@((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRr+s( R^R_R6RRhRpR|RRRRRlRr(((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRas       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@RAR=((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRB9s   Rc CsSxLt|dD];\}}d||f}|j}|j||||qWdS(Nis%s.%s(RuRWRh( RR"R(R@RjRxRyRzR{((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR|Fs (R^R_t__doc__RBR|(((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR/s tJSONSerializercBsYeZdZdZd dZdZdZdZdZ dZ dZ RS( t unixtimestampc Csd|jd|jf}|jd}|j}|jjd|j|dRh( RR"R(R@Rmtnew_serializedRPt member_keyt member_valueRn((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRpos        cCsP|j}||||D]6}i}|j|||jd|j|dqWdS(Nt __current__(RhRWtappend(RR"R(R@Rmtlist_objt list_itemtwrapper((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR|s   cCs|||R?(RR"R(R@Rm((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCs|j|||R?t_has_streaming_payloadt_encode_payloadR5t_serialize_body_paramst_serialize_empty_bodyt_requires_empty_body( RRRR"R@Rtpayload_membert body_payloadRi((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs"    cCsdS(NR((R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCsdS(s Some protocols require varied Content-Type headers depending on user input. This allows subclasses to apply this conditionally. N((RR"R@R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCstS(s Some protocols require a specific body to represent an empty payload. This allows subclasses to apply this conditionally. (tFalse(RR@((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR scCs|dk o||jdkS(s5Determine if payload is streaming (a blob or string).tblobtstringN(Rsstring(R5Rk(RRR((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR's cCs&t|tjr"|j|jS|S(N(R1RRCRDRE(RR ((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR.scCs||}|jjd}|jjd|}|dkrN||d|R?R1RRtupdatetbooltstrR7RktQUERY_STRING_TIMESTAMP_FORMATR<t_convert_header_valuet_do_serialize_header_map(RRRRRRWRtkey_nametbool_strR)RR@R(t header_prefix((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR3s<          cCs5x.|jD] \}}||}|||R?tHEADER_TIMESTAMP_FORMATR<R5RRWRsRRJRR(RR@R(R9RR)tvtconverted_value((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRjs  1  (R^R_RRRtKNOWN_LOCATIONSRRRRRRRRRRRR(((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs   5        /  tRestJSONSerializercBs,eZdZdZdZdZRS(cCsdS(Ns{}((R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCs7x0|jjD]\}}d|jkrtSqWtS(sq Serialize an empty JSON object whenever the shape has members not targeting a location. R(RPRQR>R3R(RR@RWR((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCsm|jjd}|j||r(dS|ddk}td|d}|ri| rid|ddR?RR(RR"R@RRthas_bodythas_content_type((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs cCs8|j}|j|||tj|j|jS(N(R`RhRRRDRE(RRR@tserialized_body((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs (R^R_RRRR(((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs  tRestXMLSerializercBs_eZdZdZdZdZdZdZdZdZ dZ d Z RS( R cCsX|jd}tjd}|j||||t|d}tj|d|jS(NR=Ritencoding(R>RtElementRhRttostringRE(RRR@t root_namet pseudo_roott real_root((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs  cCs3t|d|j|j}|||||dS(Ns_serialize_type_%s(R8RkRl(RR@RtxmlnodeR=R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRhs c Cstj||}d|jkrl|jd}d}|jdrX|d|d7}n|d|j|R?tattribRQRPR5Rh( RRRR@R=tstructure_nodetnamespace_metadatatattribute_nameRmR(Rnt member_nametxml_attribute_name((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRps"     c Cs||j}|jjdr*|}|}n'|jjdd}tj||}x$|D]}|j||||qXWdS(NRR=RW(RWR>R?RRRh( RRRR@R=Rnt element_namet list_nodetitem((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyR|s   c Cstj||}x|jD]\}}tj|d}|j|jdd} |j|jdd} |j|j||| |j|j||| qWdS(NtentryRARmR((RRRQRBRmR(Rh( RRRR@R=tnodeRmR(t entry_nodeRtval_name((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs  cCs4tj||}|r!d}nd}||_dS(NRR(RRttext(RRRR@R=Rt str_value((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs  cCs(tj||}|j||_dS(N(RRRJR(RRRR@R=R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCs7tj||}|j||jjd|_dS(NR(RRR<R>R?R(RRRR@R=R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRscCs(tj||}tj||_dS(N(RRRRCR(RRRR@R=R((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRls( R^R_R6RRhRpR|RRRRRl(((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyRs      tec2tqueryRs rest-jsonsrest-xml(!RRRFR,R2t xml.etreeRtbotocore.compatRRRtbotocore.utilsRRRRRtbotocoreR tDEFAULT_TIMESTAMP_FORMATR&R%R3RtobjectRRaRRRRRR (((s3/usr/lib/fence-agents/bundled/botocore/serialize.pyt's<     {kS!`