Current File : //usr/lib/python2.7/site-packages/requestbuilder/command.pyc
�
n�3Xc@@stddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
yddlZWnek
r�ddlZnXddlZddlmZmZddlmZmZddlmZddlmZddlmZddlmZm Z d	e!fd
��YZ"d�Z#d�Z$d
d�Z%dS(i(tabsolute_importtprint_functionN(tArgtMutuallyExclusiveArgList(t
ConfigDatat
ConfigView(t
ArgumentError(tconfigure_root_logger(tRequestBuilder(tadd_default_routestaggregate_subclass_fieldstBaseCommandcB@s�eZdZdZdZgZdZeZ	e
Zdde
d�Ze
d��Zd�Zd�Zd�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Ze
d��Zed��Zd�Zd�Zed��Zd�Zd�Z RS(s3
    The basis for a command line tool.  To invoke this as a command line tool,
    call the run() method on the class.  Arguments will be parsed from the
    command line.  To invoke this in another context, such as from inside
    another command, pass keyword arguments to __init__() with names that match
    those stored by the argument parser and then call main() to retrieve a
    result.

    The general workflow of a command involves two methods:  main(), which
    inspects the arguments stored in self.args, does something, and returns a
    result; and print_result(), which takes the output of main() and prints it
    to stdout.  By default, both of these methods do nothing.  It is up to you
    to implement them to do what the tool is designed to do.

    Important members of this class include:
     - DESCRIPTION:  a string that describes the tool, which is re-wrapped and
                     used as part of the command line help string.  If it is
                     not supplied, the class's doc string, if any, will be
                     used instead.
     - USAGE:        a usage message for the command line help string.  If this
                     is None, one will be generated automatically.
     - ARGS:         a list of Arg and/or MutuallyExclusiveArgGroup objects
                     are used to generate command line arguments.  Inheriting
                     classes needing to add command line arguments should
                     contain their own ARGS lists, which are combined with
                     those of their parent classes.
    tcK@s||_||_d|_|j�|_i|_d|_t|_	||_
|j|�|j�|j
r�t
jr�|j�tt
_n|j�|j
r�|j�n|j�y|j�WnBtk
r
}|j
r|j	r|jjt|��q�nXdS(N(targstconfigtNonetlogtSUITEtsuitet_arg_routest_cli_parsertFalset_BaseCommand__debugt_BaseCommand__do_clit_configure_loggingt_process_configfilesRt%_BaseCommand__CONFIGURED_GLOBAL_STATEt_configure_global_loggingtTruet
_build_parsertprocess_cli_argstdistribute_argst	configureRterrortstr(tselfRtloglevelt_do_clitkwargsterr((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyt__init__Ns.							


	
	


cK@s/|jd|jj�|d|j|�}|S(NR$R(t
setdefaultRtlevelR(tclstotherR&tnew((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyt
from_other|scC@sWtj|j�|_|dk	r4|jj|�n|jrS|jjtj�ndS(N(tloggingt	getLoggertnameRRtsetLeveltdebugtDEBUG(R#R$((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�s
	cC@su|jdkr<|jj�}t|�}t|�|_n|jrq|jjt	j
�|jjjt	j
�ndS(N(RRRtlist_config_filesRRR3RR2R/R4(R#tconfig_filestconfig_data((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�s	cC@s3|jjd�dkr(tdt�nt�dS(NR3tcolortcolourt	use_color(R8R9(Rtget_global_optionRR(R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�scC@sIt|jp|jpd�}tjd|d|jdtdtj�}|j�}|j	||�|j
dddd	d
dtjdd
�|j
dddd	ddtjdd�|j
dddd|jj
�dd�td�|D��r|j
ddddtjdd�n%|j
dddddtjdd�||_dS(NRtdescriptiontusagetadd_helptformatter_classs--debugtactiont
store_truetdestt_debugtdefaultthelpsshow debugging outputs
--debuggert	_debuggers$launch interactive debugger on errors	--versiontversions#show the program's version and exitcs@s-|]#}t|t�rd|jkVqdS(s-hN(t
isinstanceRtpargs(t.0targ_obj((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pys	<genexpr>�ss--helpsshow this help message and exits-h(t_rewrap_descriptiontDESCRIPTIONt__doc__targparsetArgumentParsertUSAGERtRawDescriptionHelpFormattertcollect_arg_objst_populate_parsertadd_argumenttSUPPRESSRtformat_versiontanyR(R#R<tparsertarg_objs((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�s0			
	cC@s&t|jd�}t||j�|S(NtARGS(R
t	__class__R	tDEFAULT_ROUTES(R#RZ((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyRS�scC@s%x|D]}|j||�qWdS(N(t#_BaseCommand__add_arg_to_cli_parser(R#RYRZRK((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyRT�s
cC@sIt|t�r�|jjd�tjkr.gS|j|j|j�}|jdkrhd|j
|j<n|j|j
|j<|gSn�t|t�r�|j
d|j�}g}x'|D]}|j|j||��q�W|St|t�s�t|t�r/g}x'|D]}|j|j||��qW|Std|jj��dS(NRBtrequiredsUnknown argument type (N(RHRR&tgetRORVRURItroutesRRRBRtadd_mutually_exclusive_grouptis_requiredtextendR^tlistttuplet	TypeErrorR\t__name__(R#targlike_objRYtargtexgroupR
t	group_arg((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyt__add_arg_to_cli_parser�s.
	

cC@st|jj��}|jdt�r3t|_n|jdt�rmt|_tt_	t
j
t
jt�n|j
j|�tdd	id�d6��}x[t|j��D]G}d|j�ks�d|j�kr�||dk	r�|||<q�q�W|jjdt|��dS(
NRCRFtREDACTEDcS@sdS(Ns
<redacted>((R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyt<lambda>�st__repr__tpasswordtsecretsparsed arguments from CLI: %s((tvarsRt
parse_argstpopRRRt_debugger_except_hooktsyst
excepthooktsignaltSIGUSR1t_debugger_usr1_handlerR
tupdatettypeRetkeystlowerRRR3R"(R#tcli_argstredactedtkey((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�s			$cC@s�x�tj|j�D]�\}}||jkrFtdj|���n|j|}xB|D]:}|dk	rZt|�r�||�}n|||<qZqZWqWdS(Nsgot unrecognized arg: "{0}"(tsixt	iteritemsR
RRgtformatRtcallable(R#R�tvalRatroute((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�s

cC@sdS(N((R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR scC@s�y|dt�}WnMtk
rb}djtjjtjd��}t|t	�r�|g}t
|dd�r�|j|j
�nt
|dd�r�|dcd7<|j|j�ntdj|�d	tj�n^t|j�dkr|jdrt||jdd	tj�nt|t|�d	tj�td
�dD��rR�ntjd
�nXy|j�}|j|�Wn tk
r�}|j|�nXdS(NR%s{0}: error:itstrerrortfilenamei����t:t tfilecs@s|]}|tjkVqdS(N(Rwtargv(RJRj((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pys	<genexpr>"ss--debugs
--debuggeri(s--debugs
--debugger(Rt	ExceptionR�tostpathtbasenameRwR�RHtEnvironmentErrortgetattrRtappendR�R�tprinttjointstderrtlenR
R"RXtexittmaintprint_resultthandle_cli_exception(R+tcmdR't
msg_prefixterr_bitstresult((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pytrun
s."	" cC@s
|jjS(N(R\Rh(R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR1+scC@sdS(s}
        The main processing method.  main() is expected to do something with
        self.args and return a result.
        N((R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�/scC@sdS(sJ
        Take a result produced by main() and print it to stdout.
        N((R#tdata((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�6scC@s;|j�rtS|jrtStd�dD��r7tStS(Ncs@s|]}|tjkVqdS(N(RwR�(RJRj((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pys	<genexpr>Bss--debugs
--debugger(s--debugs
--debugger(t&_BaseCommand__config_enables_debuggingRRRXR(R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR3<s	cC@sldjtjjtjd��}t|t�r]|jr]|j	r]|j
jt|��nt|t
�r�|g}t|dd�r�|j|j�nt|dd�r�|dcd7<|j|j�ntdj|�dtj�n^t|j�dkr0|jdr0t||jddtj�nt|t|�dtj�|j	r[�ntjd	�dS(
Ns{0}: error:iR�R�i����R�R�R�i(R�R�R�R�RwR�RHRRR3RR!R"R�R�RR�R�R�R�R�R�R�R
R�(R#R'R�R�((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR�Gs"""	" 	cC@sU|jdkrtS|jjd�dkr/tS|jj|jjd��rQtStS(NR3R8R9(scolorscolour(RRRR;Rtconvert_to_bool(R#((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyt__config_enables_debugging`sN((!Rht
__module__RNRMRRQR[R]RRRRR(tclassmethodR.RRRRRSRTR^RRR R�tpropertyR1R�R�R3R�R�(((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR*s4.										!			cC@s�|tjkrtjd�ntjt_tjj�r~tjj�r~dtj	krnt
j|||�q�tj|�nt
j|�tjd�dS(s\
    Launch epdb (or pdb if epdb is unavailable) when an uncaught exception
    occurs.
    itepdbN(tbdbtBdbQuitRwR�t__excepthook__RxtstdouttisattytstdintmodulesR�tpost_mortemtpdbt	tracebacktprint_tb(ttype_tvaluettracebk((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyRvjs
cC@sVi|d6}|j|j�|j|j�tdjtj|��dtj�dS(s�
    Show a traceback and local variables when sent SIGUSR1.  Note that
    this could cause exceptions due to interrupted system calls.
    t_frameRR�N(	R|t	f_globalstf_localsR�R�R�tformat_stackRwR�(t_tframet
frame_dict((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyR{}s
iFc@sidd6dd6dd6dd6dd6��fd���fd��d	���fd
�}|tdtjjtjd��;}tj|j�j	d
��j
�}g}g}d}x�|D]�}|j�s|j||d|��|2|jd�d}q��|�}�|�}	|rE|j||d|��|2n,|	|krq|j||d|��|2n|	}|j|�q�W|r�|j||d|��nxVt
t|�ddd�D]8}
||
||
dko�dknr�||
=q�q�Wd
j|�S(s�
    Split lines into paragraphs based on blank lines and changes in
    indentation level, rewrap the text in each of those paragraphs, and
    yield each of those paragraphs.  In paragraphs that start with
    common shell prompt characters (#, $, and %) or bullets (* and -)
    followed by whitespace, those characters do not count against the
    paragraph's indentation level.
    s\1 \2s
^(\s*)\#(\s+)s
^(\s*)\$(\s+)s
^(\s*)\%(\s+)s
^(\s*)\*(\s+)s
^(\s*)\-(\s+)c@s\|j�sdSx/�j�D]!\}}tj|||�}qWt|�t|j��S(Ni����(tstripR�tretsubR�tlstrip(tlinetpatternR�(tbullets(s:/usr/lib/python2.7/site-packages/requestbuilder/command.pytmeasure_margin�s
c@s1x*�D]"}|rtj||�r|SqWdS(N(R�tmatch(R�R�(R�(s:/usr/lib/python2.7/site-packages/requestbuilder/command.pytfind_bullet_pattern�s
iFc@s`|s
dS�|d���|d�}|r�t|d�t|dj��}|d|�!}tj|�||dd�|d<ntjdjd�|D��d|��}|r�d|||dgg|dD]}d�|^q�}n!g|D]}d�|^q}dj�fd�|D��}|r\d|||�}n|S(	NRiis
cs@s|]}|j�VqdS(N(R�(RJR�((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pys	<genexpr>�stwidthR�c3@s|]}d�|VqdS(R�N((RJR�(tmargin(s:/usr/lib/python2.7/site-packages/requestbuilder/command.pys	<genexpr>�s(R�R�R�R�ttextwraptwrapR�(tlinesR�R�tfirstline_margintbullet_textt	rewrappedR�tcombined(R�R�R�(R�s:/usr/lib/python2.7/site-packages/requestbuilder/command.pytreformat_paragraph�s$$'
)!tprogis
R�Ri����i(tdictR�R�R�RwR�R�tdedenttrstripR�t
splitlinesR�R�txrangeR�R�(ttextR�R�tin_linest
paragraphst
current_linestcurrent_marginR�R�R�ti((R�R�R�s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyRL�sL


&$


	

#((&t
__future__RRROR�R/tos.pathR�R�RyRwR�R�twarningsR�tImportErrorR�R�trequestbuilderRRtrequestbuilder.configRRtrequestbuilder.exceptionsRtrequestbuilder.loggingRtrequestbuilder.suiteRtrequestbuilder.utilR	R
tobjectRRvR{RL(((s:/usr/lib/python2.7/site-packages/requestbuilder/command.pyt<module>s4
�A