Viewing File: /usr/lib/python2.7/site-packages/requestbuilder/request.pyc

ó
²GXc@@s]ddlmZmZddlZddlZddlmZddlZddlZ	ddl
Z
ddlZddlZddl
Z
ddlmZmZddlmZddlmZddlmZddlmZdd	lmZd
efd„ƒYZdefd
„ƒYZdd„Zd„Zde fd„ƒYZ!de fd„ƒYZ"dS(i(tabsolute_importtprint_functionN(tpartial(tEMPTYtPARAMS(tBaseCommand(tServerError(tBaseService(taggregate_subclass_fields(tparse_listdelimited_aws_xmltBaseRequestcB@sïeZdZeZdZdZdZe	fZ
ddd„Ze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|jd|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
preprocessRCtpostprocess(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
ƒ|jr\‚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_ROUTESRtpropertyRtsetterRtclassmethodR*R,R0R3R7RCRAR>RRRURSRTRa(((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR
$s."			
										tAWSQueryRequestcB@seeZdZgZgZd„Zd„Zed„ƒZ	d„Z
d„Zdd„Ze
d„ZRS(cC@sytj|||ƒ|jru|jddddddddd	d
ttd|jƒƒ|jƒ|_d|j	d<ndS(
Ns--filtertmetavars
NAME=VALUEtactionREtdesttfiltersthelps,restrict results to those that meet criteriattypetfilter_objs(N(
R
t_populate_parsertFILTERStadd_argumentRt
_parse_filtert#_AWSQueryRequest__build_filter_helptepilogRt_arg_routes(RtparserR/((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRqîs	cC@sUtj|ƒd|jkrQt|jjdƒƒ|jd<|jf|jd<ndS(NRmtFilter(R
tprocess_cli_argsR1t_process_filterstpopRRw(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRzùs
cC@s|jS(N(R7(R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyRkÿscC@s3|j}tj|jƒ}|j|jƒ}|j|d<|jpL|jj|d<t|ƒ}xI|D]A}|jƒj	dƒrft
ddid„d6ƒƒ||<qfqfW|jjd|ƒ|j
jƒdkrø|jjd	ƒ||_i|_n|jjd
ƒ||_ztj|ƒSWd||_XdS(NtActiontVersiontpasswordtREDACTEDcS@sdS(Ns
<redacted>((R((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyt<lambda>st__repr__sparameters: %stPOSTs)sending flattened parameters as form datas,sending flattened parameters as query string((Rtcopytdeepcopytflatten_paramsRktAPI_VERSIONRR:tlowertendswithRoR"RHRtupperRFRR
RC(Rtorig_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ƒ||<q4t|tƒrë|j
ƒ||<q4t|tƒr
t|ƒ||<q4|s|dkr2t|ƒ||<q4|tkr4d||<q4q4Wn1t|tƒrmxt|dƒD]õ\}}|r˜dj||ƒ}nt|ƒ}t|tƒsÂt|tƒrÞ|j|j	||ƒƒqqt|t
ƒrt|ƒjƒ||<qqt|tƒr(|j
ƒ||<qq|s:|dkrMt|ƒ||<qq|tkrqd||<qqqqWntd|jjƒ‚|S(s
        Given a possibly-nested dict of args and an arg routing
        destination, transform each element in the dict that matches the
        corresponding arg routing table into a simple dict containing
        key-value pairs suitable for use as query parameters.  This
        implementation flattens dicts and lists into the format given
        by AWS query APIs, which use dotted lists of dict keys and list
        indices to indicate nested structures.

        Keys with non-boolean, non-zero values that evaluate as false
        are ignored.  To include an empty string as a parameter, pass
        EMPTY (the object, not the string) as its value.

        Examples:
          in:  {'InstanceId': 'i-12345678', 'PublicIp': '1.2.3.4'}
          out: {'InstanceId': 'i-12345678', 'PublicIp': '1.2.3.4'}

          in:  {'RegionName': ['us-east-1', 'us-west-1']}
          out: {'RegionName.1': 'us-east-1',
                'RegionName.2': 'us-west-1'}

          in:  {'Filter': [{'Name':  'image-id',
                            'Value': ['ami-12345678']},
                           {'Name':  'instance-type',
                            'Value': ['m1.small', 't1.micro']}],
                'InstanceId': ['i-24680135']}
          out: {'Filter.1.Name':    'image-id',
                'Filter.1.Value.1': 'ami-12345678',
                'Filter.2.Name':    'instance-type',
                'Filter.2.Value.1': 'm1.small',
                'Filter.2.Value.2': 't1.micro',
                'InstanceId.1':     'i-24680135'}
        s{0}.{1}iRisnon-flattenable type: N(RRWR:tsixt	iteritemsRXtstrR’R2R†tboolRˆRVtreadtfloatRt	enumeratet	TypeErrorR.R6(	RR1tprefixt	flattenedRtvaltprefixed_keyti_itemtitem((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyR†&sJ"c
C@s„dtjkr)dtjkr)|r)dSdg}xB|jD]7}|jtjkrZq<q<|jr_|jjdƒ\}}}|jdƒr·|jdƒr·|dtj	|ƒ}n	|j}t
|jƒdkrdj|jƒ}tj
d	td
|dddƒ}	n:|jd
|jƒtj
d	td
dddddƒ}	|j|	j|ƒƒq<|jd
|jƒq<Wdj|ƒS(s±
        Return a pre-formatted help string for all of the filters defined in
        self.FILTERS.  The result is meant to be used as command line help
        output.
        s-hs--helpRsallowed filter names:s
t is  {0:<20}  tfix_sentence_endingstinitial_indenttsubsequent_indentis  (R[R\RrRntargparsetSUPPRESSt	partitiont
startswithttextwraptdedentRR7RXtTextWrapperR4RER-twraptjoin(
Rtforcet	helplinest
filter_objtfirstt_trestR?t	firstlinetwrapper((s:/usr/lib/python2.7/site-packages/requestbuilder/request.pyt__build_filter_helpus.%					
N(R6RcRR‡RrRRqRzRfRkRCR>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–(tcli_filterstfilter_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.pyt<module>s*ŵ	0
Back to Directory File Manager