ó ² GXc@@s]ddlmZmZddlZddlZddlmZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlmZmZddlmZddlmZddlmZddlmZdd lmZd efd „ƒYZd efd „ƒYZdd„Zd„Zde fd„ƒYZ!de fd„ƒYZ"dS(i(tabsolute_importtprint_functionN(tpartial(tEMPTYtPARAMS(t BaseCommand(t ServerError(t BaseService(taggregate_subclass_fields(tparse_listdelimited_aws_xmlt BaseRequestcB@sïeZdZeZdZdZdZe fZ ddd„Z e d„ƒZ e jd„ƒZ e d„ƒZed„ƒZd„Zd„Zd „Ze d „ƒZd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„ZRS(s The basis for a command line tool that represents a request. The data for this request are stored in a few instance members: - method: the HTTP method to use (e.g. 'GET'). Defaults to self.METHOD. - path: the path to append to the service's path (e.g. 'sub/dir') - headers: a dict of HTTP headers - params: a dict of query parameters - body: a string or file object containing a request body, or a dict to pass to the server as form data This specialization of BaseCommand that implements main() as a three-step process: - preprocess(): do any processing needed before sending the request, such as parsing complex command line arguments and storing them in self.params, self.headers, and so forth. - send(): send this request to the server using the data stored in its attributes, parse it using self.parse_result(), and return it - postprocess(): given a parsed response, do any processing needed before main() returns the response. Most requests need only implement preprocess(). Requests whose workflows involve sending other requests often do so in postprocess(), where the result of the request is known. Important members of this class, in addition to those inherited from BaseCommand, include: - SERVICE_CLASS: a class corresponding to the web service in use - AUTH_CLASS: a class corresponding to the authentication method to use, if any - NAME: a string representing the name of this request. This defaults to the class's name. - METHOD: the HTTP method to use by default tGETcK@sq|j|_d|_i|_i|_d|_i|_d|_t |_ ||_ ||_ t j||dS(Nt(tMETHODtmethodtNonetpaththeaderstparamstbodytfilestresponsetFalset_BaseRequest__configuredt_BaseRequest__autht_BaseRequest__serviceRt__init__(tselftservicetauthtkwargs((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyROs          cC@sD|j r=|jdk r=|j|jd|jjƒ|_n|jS(Ntloglevel(Rt AUTH_CLASSRtconfigtlogtlevel(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRas$cC@s ||_dS(N(R(Rtnewval((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRiscC@sD|j r=|jdk r=|j|jd|jjƒ|_n|jS(NR(Rt SERVICE_CLASSRR!R"R#(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRmscK@sU|jd|jƒ|jd|jƒ|jd|jjƒ|d|j|}|S(NRRRR!(t setdefaultRRR"R#R!(tclstotherRtnew((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyt from_otherts cC@sotj|ƒ}|jdk r=|jt|jjdƒƒn|jdk rk|jt|jjdƒƒn|S(NtARGS(Rtcollect_arg_objsRRtextendRt __class__R(Rtarg_objs((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR,}scC@satj|ƒ|jdk r5|jjj|jƒn|jdk r]|jjj|jƒndS(N(Rtdistribute_argsRRtargstupdateR(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR0‡s  cC@sXtj|ƒ|jdk r,|jjƒn|jdk rK|jjƒnt|_dS(N(Rt configureRRRtTrueR(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR3Žs  cC@s|jp|jjS(N(tNAMER.t__name__(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pytname—scC@s|js|jjdƒnt|jp+iƒ}|jd|jjƒƒyb|jj d|j d|j d|d|j d|j d|jd |jƒ|_|j|jƒSWn]tk r }|j|_y |jdk ré|jjnWntk rýnX|j|ƒSXdS( Ns1send() called before configure(); bugs may results User-AgentRRRRtdataRR(RR"twarntdictRR&tsuitetget_user_agentRt send_requestRRRRRRRtparse_responseRRtcontentt RuntimeErrorthandle_server_error(RRterr((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pytsend›s$    cC@sg|jjdditd6ƒ|jj|jjditd6ƒ|jjdƒ|jjdƒ‚dS(Ns-- response content -- textratappends-- end of response content --sresult: failure(R"tdebugR4Rttexttinfo(RRB((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRA³s #cC@s|S(N((RR((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR>ºscK@sy|jjdditd6ƒt|jjdƒƒ.}t||jtjƒ}|||}WdQX|jjdƒ|S(Ns-- response content -- RDREi@s-- end of response content --( R"RFR4t_IteratorFileObjAdapterRt iter_contentt_ReadLoggingFileWrappertloggingtDEBUG(RRt parse_funcRtcontent_fileobjtlogged_fileobjtparsed_response((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pytlog_and_parse_response½s  cC@s'|jƒ|jƒ}|j|ƒ|S(s The main processing method for this type of request. In this method, inheriting classes generally populate self.headers, self.params, and self.body with information gathered from self.args or elsewhere, call self.send, and return the response. (t preprocessRCt postprocess(RR((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pytmainËs   cC@sdS(N((R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRS×scC@sdS(N((RR((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRTÚscC@s€t|tƒrldjtjjtjdƒ|jƒƒ}t |dtj ƒ|j r\‚ntj dƒnt j||ƒdS(Ns{0}: {1}itfilei(t isinstanceRtformattosRtbasenametsystargvtformat_for_clitprinttstderrRFtexitRthandle_cli_exception(RRBtmsg((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRaÝs N(R6t __module__t__doc__RR%RR R5R RtDEFAULT_ROUTESRtpropertyRtsetterRt classmethodR*R,R0R3R7RCRAR>RRRURSRTRa(((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR $s."         tAWSQueryRequestcB@seeZdZgZgZd„Zd„Zed„ƒZ d„Z d„Z dd„Z e d„ZRS(cC@sytj|||ƒ|jru|jddddddddd d ttd |jƒƒ|jƒ|_d |j d((R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pytst__repr__sparameters: %stPOSTs)sending flattened parameters as form datas,sending flattened parameters as query string((Rtcopytdeepcopytflatten_paramsRkt API_VERSIONRR:tlowertendswithRoR"RHRtupperRFRR RC(Rt orig_paramsRtredacted_paramstkey((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRCs(    '   cC@sK|j|td|jƒ}t|ƒdks3t‚|t|jƒƒdS(Nt list_tagsii(RRR t LIST_TAGStlentAssertionErrortlisttkeys(RRt response_dict((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR>sc C@s‡i}|dkrnnt|tƒrRx\tj|ƒD]\}}|r[dj||ƒ}n t|ƒ}t|tƒs…t|tƒr¡|j|j ||ƒƒq4t|t ƒrÉt|ƒj ƒ||R†RRu(((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRiés    OcC@sfg|p gD]}|j|ƒr |^q }|sUdj|ƒ}tj|ƒ‚n|dj|ƒS(s Given a "key=value" string given as a command line parameter, return a pair with the matching filter's dest member and the given value after converting it to the type expected by the filter. If this is impossible, an ArgumentTypeError will result instead. s""{0}" matches no available filtersi(tmatches_argvalRXR§tArgumentTypeErrortconvert(t filter_strRptobjRb((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRtžs cC@s~i}x;|piD]-\}}|j|gƒ||j|ƒqWgtj|ƒD] \}}i|d6|d6^qT}|S(sÄ Change filters from the [(key, value), ...] format given at the command line to [{'Name': key, 'Value': [value, ...]}, ...] format, which flattens to the form the server expects. tNametValue(R&RER•R–(t cli_filterst filter_argsRRŸR7tvaluesRm((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR{®s3RIcB@sGeZd„Zd„Zd„Zed„ƒZd„Zdd„ZRS(cC@s(||_g|_t|_d|_dS(Ni(t_sourcet_buflistRt_closedt_len(Rtsource((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRÀs   cC@s|S(N((R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyt __enter__ÆscG@s|jƒdS(N(tclose(RR1((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyt__exit__ÉscC@s|jS(N(RÅ(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pytclosedÌscC@s"|jsd|_t|_ndS(N(RÅRRÄR4(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRÉÐs  iÿÿÿÿcC@s2|dks|dkrcx!|jD]}|jj|ƒq"Wdj|jƒ}g|_d|_nËx`|j|krÅy8t|jƒ}|jj|ƒ|jt|ƒ7_Wqftk rÁPqfXqfWdj|jƒ}t|ƒ|}g|_d|_|dkr.|| g|_||_|| }n|S(NiR ( RRÃRÄRER¯RÆtnextRt StopIteration(Rtsizetchunktresultt extra_len((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR™Õs,        ( R6RcRRÈRÊRfRËRÉR™(((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRI¿s     RKcB@seZd„Zdd„ZRS(cC@s||_||_||_dS(N(tfileobjtloggerR#(RRÒRÓR#((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRðs  iÿÿÿÿcC@s9|jj|ƒ}|jj|j|ditd6ƒ|S(NRDRE(RÒR™RÓR"R#R4(RRÎRÏ((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR™õs#(R6RcRR™(((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRKïs (#t __future__RRR§R„t functoolsRRLtos.pathRYR[R«twarningsR•trequestbuilderRRtrequestbuilder.commandRtrequestbuilder.exceptionsRtrequestbuilder.serviceRtrequestbuilder.utilRtrequestbuilder.xmlparseR R RiRRtR{tobjectRIRK(((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyts*        ŵ  0