Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/google/apputils/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/google/apputils/__pycache__/app.cpython-35.opt-1.pyc



B��]�,�@s'dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
ZejZej
ddd�ej
ddd�ej
ddd�ejd	dd
�ej
ddd
�gZdZGdd�de�ZGdd�de�ZGdd�dej�ZGdd�de�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zdd�Zdadd �Zd!d"�Zdd#d$�Zd%d&�Zd'd(�Z ddddd)d*�Z!Gd+d,�d,e"�Z#d-d.�Z$dS)/a�Generic entry point for Google applications.

To use this module, simply define a 'main' function with a single
'argv' argument and add the following to the end of your source file:

if __name__ == '__main__':
  app.run()

TODO(user): Remove silly main-detection logic, and force all clients
of this module to check __name__ explicitly.  Fix all current clients
that don't check __name__.
�N�run_with_pdbzSet to true for PDB debug mode�pdb_post_mortemz?Set to true to handle uncaught exceptions with PDB post mortem.�run_with_profilingzmSet to true for profiling the script. Execution will be slower, and the output format might change over time.�profile_filezXDump profile information to a file (for python -m pstats). Implies --run_with_profiling.�use_cprofile_for_profilingTzpUse cProfile instead of the profile module for profiling. This has no effect unless --run_with_profiling is set.Fc@seZdZdS)�ErrorN)�__name__�
__module__�__qualname__�rr�D/opt/alt/python35/lib/python3.5/site-packages/google/apputils/app.pyr>src@s%eZdZdZddd�ZdS)�
UsageErrora{The arguments supplied by the user are invalid.

  Raise this when the arguments supplied are invalid from the point of
  view of the application. For example when two mutually exclusive
  flags have been supplied or when there are not enough non-flag
  arguments. It is distinct from flags.FlagsError which covers the lower
  level of parsing and validating individual flags.
  �cCstj||�||_dS)N)r�__init__�exitcode)�self�messagerrrrrLszUsageError.__init__N)rr	r
�__doc__rrrrrr
Bsr
c@s4eZdZdZdZdd�Zdd�ZdS)�HelpFlagz?Special boolean flag that displays usage and raises SystemExit.�helpc	Cs,tjj||jdddddd�dS)Nrzshow this helpZ
short_name�?�allow_overrider)�flags�BooleanFlagr�NAME)rrrrrUszHelpFlag.__init__cCs;|r7tdddd�t�td�tjd�dS)N�	shorthelpr�writeto_stdoutz*Try --helpfull to get a list of all flags.)�usage�print�sys�exit)r�argrrr�ParseYs

zHelpFlag.ParseN)rr	r
rrrr"rrrrrQsrc@seZdZdZdZdS)�
HelpshortFlagz#--helpshort is an alias for --help.Z	helpshortN)rr	r
rrrrrrr#bsr#c@s.eZdZdZdd�Zdd�ZdS)�HelpfullFlagz@Display help for flags in this module and all dependent modules.cCs#tjj|ddddd�dS)NZhelpfullrzshow full helprr)rrr)rrrrrjszHelpfullFlag.__init__cCs$|r tdd�tjd�dS)Nrr)rrr )rr!rrrr"ns
zHelpfullFlag.ParseN)rr	r
rrr"rrrrr$gsr$c@s.eZdZdZdd�Zdd�ZdS)�HelpXMLFlagz<Similar to HelpfullFlag, but generates output in XML format.cCs#tjj|ddddd�dS)NZhelpxmlFz)like --helpfull, but generates XML outputrr)rrr)rrrrrwszHelpXMLFlag.__init__cCs*|r&tjjtj�tjd�dS)Nr)r�FLAGSZWriteHelpInXMLFormatr�stdoutr )rr!rrrr"|szHelpXMLFlag.ParseN)rr	r
rrr"rrrrr%tsr%c@s.eZdZdZdd�Zdd�ZdS)�
BuildDataFlagz8Boolean flag that writes build data to stdout and exits.cCstjj|ddd�dS)NZshow_build_datarzshow build data and exit)rrr)rrrrr�szBuildDataFlag.__init__cCs-|r)tjjtj��tjd�dS)Nr)rr'�writeZ
build_dataZ	BuildDatar )rr!rrrr"�szBuildDataFlag.ParseN)rr	r
rrr"rrrrr(�sr(cCstyt|�}|SWnYtjk
ro}z6tjjd|�tjjd�tjd�WYdd}~XnXdS)zATry parsing the flags, printing usage and exiting if unparseable.zFATAL Flags parsing error: %s
z5Pass --helpshort or --helpfull to see help on flags.
rN)r&rZ
FlagsErrorr�stderrr)r )�args�argv�errorrrr�parse_flags_with_usage�sr.cCs`ts\tjt��tjt��tjt��tjt��tjt��dadS)z Register help flags. Idempotent.TN)�_define_help_flags_calledrZDEFINE_flagrr#r$r%r(rrrr�DefineHelpFlags�sr0cCst�ttj�}|S)z~Register help flags, parse arguments and show usage if appropriate.

  Returns:
    remaining arguments after flags parsing
  )r0r.rr,)r,rrr�RegisterAndParseFlagsWithUsage�sr1cCsrt�}|dkr%tjdj}y�tjrMtjtj||��n�tj	s_tj
r�ddl}tjr�ddl
}nddl}|j�}tj
r�|j|jtj
�n|j|j�|j||�}tj|�ntj||��Wnhtk
rF}z!tddd|d|j�WYdd}~Xn(tjrftj�tj��YnXdS)a=Initializes flag values, and calls main with non-flag arguments.

  Only non-flag arguments are passed to main().  The return value of main() is
  used as the exit status.

  Args:
    main: Main function to run with the list of non-flag arguments, or None
      so that sys.modules['__main__'].main is to be used.
  N�__main__rrr�detailed_errorr)r1r�modules�mainr&rr �pdbZruncallrr�atexitrZcProfile�profileZProfile�registerZ
dump_statsZprint_statsr
rrr�	traceback�	print_excZpost_mortem)r5r,r7r8ZprofilerZretvalr-rrr�really_start�s2
				.	

r<cCst�S)z�Begin executing the program.

  - Parses command line flags with the flag module.
  - If there are any errors, print usage().
  - Calls main() with the remaining arguments.
  - If main() raises a UsageError, print usage and the error message.
  )�
_actual_startrrrr�run�sr>cCs[d}ytd��Wn"tk
r:tj�d}YnX|jjj}|sTdS|jjdd�}|dkr�|jd�r�dS~ttd�r�tj	�yt
�Wn�tk
r�}z�WYdd}~Xn}tk
rV}z]xRt
D]J}y |j|�r|j|�Wq�tjjtj���Yq�Xq�W�WYdd}~XnXdS)z$Another layer in the starting stack.N��rr2z.appcommands�	exc_clear)�ZeroDivisionErrorr�exc_info�tb_frame�f_back�	f_globals�get�endswith�hasattrrAr<�
SystemExit�	Exception�EXCEPTION_HANDLERS�Wants�Handler*r)r:�
format_exc)�tbZprev_prev_frameZprev_prev_name�e�handlerrrrr=�s8


r=c	Cs�|rtj}n	tj}tjdj}|s`dtjd}tj|dddd�}nx|jd�d	|jd
�}y|tjdf|;}Wnt	t
tfk
r�YnXtr�tjtj
|��}|r�tj�}ntt�}y[|j|�|r)|jd�|j|�|jd�|d
k	rS|jd|�Wn:tk
r�}z|jtjkr~�WYd
d
}~XnX|d
k	r�tj|�d
S)afWrite __main__'s docstring to stderr with some help text.

  Args:
    shorthelp: print only flags from this module, rather than all flags.
    writeto_stdout: write help message to stdout, rather than to stderr.
    detailed_error: additional detail about why usage info was presented.
    exitcode: if set, exit with this status code after writing help.
  r2z
USAGE: %s [flags]
r�indentz       Zfirstline_indentr?�%r@z%%z
flags:
�
Nz
%s
)rr'r*r4rr,rZTextWrap�count�
OverflowError�	TypeError�
ValueError�help_text_wrapZ	DocToHelpr&ZMainModuleHelp�strr)�IOError�errnoZEPIPEr )	rrr3rZstdfile�docZnum_specifiersZflag_strrQrrrrs<		 



rc@s.eZdZdZdd�Zdd�ZdS)�ExceptionHandlerz4Base exception handler from which other may inherit.cCsdS)aCheck if this exception handler want to handle this exception.

    Args:
      unused_exc: Exception, the current exception

    Returns:
      boolean

    This base handler wants to handle all exceptions, override this
    method if you want to be more selective.
    Tr)rZ
unused_excrrrrMQszExceptionHandler.WantscCs
t��dS)z�Do something with the current exception.

    Args:
      exc: Exception, the current exception

    This method must be overridden.
    N)�NotImplementedError)r�excrrrrN_szExceptionHandler.HandleN)rr	r
rrMrNrrrrr_Nsr_cCs6t|t�s%tdt|���tj|�dS)aaInstall an exception handler.

  Args:
    handler: an object conforming to the interface defined in ExceptionHandler

  Raises:
    TypeError: handler was not of the correct type

  All installed exception handlers will be called if main() exits via
  an abnormal exception, i.e. not one of SystemExit, KeyboardInterrupt,
  FlagsError or UsageError.
  z9handler of type %s does not inherit from ExceptionHandlerN)�
isinstancer_rX�typerL�append)rRrrr�InstallExceptionHandlerjs
re)%rr]�osr6Zsocket�statZstructrZtimer:Zgflagsrr&ZDEFINE_booleanZ
DEFINE_stringrLrZrKrr
rrr#r$r%r(r.r/r0r1r<r>r=r�objectr_rerrrr�<module>sN	

--1