B s `;@sdZddlmZddlmZddlmZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl m Z ddl mZy ddlZWnek rdZYnXe jZe d d d e d d d e dd e dd de ddde ddde jdd dddgZGdddeZGdddeZGddde jZGdd d eZGd!d"d"e jZGd#d$d$e jZd%d&Zd ad'd(Z defd)d*Z!d e!_"d+d,Z#d-d.Z$defd/d0Z%e&Z'd1d2Z(d3d4Z)d e)_"d;d5d6Z*Gd7d8d8e+Z,d9d:Z-dS) 1: raise app.UsageError('Too many command-line arguments.') if __name__ == '__main__': app.run(main) )absolute_import)division)print_functionN) command_name)flags)logging run_with_pdbFzSet to true for PDB debug modepdb_post_mortemz?Set to true to handle uncaught exceptions with PDB post mortem.pdbrun_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.only_check_argsz&Set to true to validate args and exit.)allow_hide_cppc@s eZdZdS)ErrorN)__name__ __module__ __qualname__rr,/tmp/pip-unpacked-wheel-00lyeop_/absl/app.pyrLsrcs"eZdZdZdfdd ZZS) UsageErroraException raised when 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.Error which covers the lower level of parsing and validating individual flags. cstt||||_dS)N)superr__init__exitcode)selfmessager) __class__rrrZszUsageError.__init__)r)rrr__doc__r __classcell__rr)rrrPsrcs0eZdZdZdZdZfddZddZZS)HelpFlagz?Special boolean flag that displays usage and raises SystemExit.help?cs"tt|j|jdd|jdddS)NFzshow this helpT)Z short_namer)rr rNAME SHORT_NAME)r)rrrrds zHelpFlag.__init__cCs2||r.tdddttdtddS)NT) shorthelpwriteto_stdoutz*Try --helpfull to get a list of all flags.r)_parseusageprintsysexit)rargrrrparseis   zHelpFlag.parse) rrrrr#r$rr-rrr)rrr _s  r c@seZdZdZdZdZdS) HelpshortFlagz#--helpshort is an alias for --help.Z helpshortN)rrrrr#r$rrrrr.rsr.cs(eZdZdZfddZddZZS) HelpfullFlagzDDisplay help for flags in the main module and all dependent modules.cstt|jddddddS)NZhelpfullFzshow full helpT)r)rr/r)r)rrrr{s zHelpfullFlag.__init__cCs"||rtddtddS)NT)r&r)r'r(r*r+)rr,rrrr-s  zHelpfullFlag.parse)rrrrrr-rrr)rrr/xs r/cs(eZdZdZfddZddZZS) HelpXMLFlagztdtj rNt dtdj r^dt_ dt_|S)agRegisters help flags, parses arguments and shows usage if appropriate. This also calls sys.exit(0) if flag --only_check_args is True. Args: argv: [str], a non-empty list of the command line arguments including program name, sys.argv is used if None. flags_parser: Callable[[List[Text]], Any], the function used to parse flags. The return value of this function is passed to `main` untouched. It must guarantee FLAGS is parsed after this function is called. Returns: The return value of `flags_parser`. When using the default `flags_parser`, it returns the following: [str], a non-empty list of remaining command line arguments after parsing flags, including program name. Raises: Error: Raised when flags_parser is called, but FLAGS is not parsed. SystemError: Raised when it's called more than once. z(Flag registration can be done only once.Nz2FLAGS must be parsed after flags_parser is called.r verbosityT) $_register_and_parse_flags_with_usagedone SystemErrorr9r*argvr1Z is_parsedrrr+Zusing_default_valuer:)r> flags_parserZ original_argvZ args_to_mainrrrr;s  r;cCstjrtt||n~tjs&tjrddl}tj r>ddl }nddl }| }tjrf| |jtjn | |j|||}t|nt||dS)z,Calls main, optionally with pdb or profiler.rN)r1rr*r+r Zruncallr r atexitr ZcProfileprofileZProfileregisterZ dump_statsZ print_stats)mainr>r@rAZprofilerretvalrrr _run_mains     rEc CsXxRtD]J}y||r ||WqyttWn YnXYqXqWdS)z'Calls any installed exception handlers.N)EXCEPTION_HANDLERSwantshandlerr6 traceback format_exc) exceptionhandlerrrr_call_exception_handlerss  rMc Csyt|dkrtjn||}xtr0t}|qWyt||Wntk rr}ztd||jdWdd}~XYn`t d}t |t r|j st jrtjrtttdttYnXWn.tk r}zt|Wdd}~XYnXdS)aBegins executing the program. Args: main: The main function to execute. It takes an single argument "argv", which is a list of command line arguments with parsed flags removed. The return value is passed to `sys.exit`, and so for example a return value of 0 or None results in a successful termination, whereas a return value of 1 results in abnormal termination. For more details, see https://docs.python.org/3/library/sys#sys.exit argv: A non-empty list of the command line arguments including program name, sys.argv is used if None. flags_parser: Callable[[List[Text]], Any], the function used to parse flags. The return value of this function is passed to `main` untouched. It must guarantee FLAGS is parsed after this function is called. - Parses command line flags with the flag module. - If there are any errors, prints usage(). - Calls main() with the remaining arguments. - If main() raises a UsageError, prints usage and the error message. NT)r%detailed_errorrrz' *** Entering post-mortem debugging ***) _run_initr*r>_init_callbackspopleftrErr(rexc_info isinstance SystemExitcoder1r r2isattyrI print_excr)r Z post_mortem ExceptionrM)rCr>r?r5callbackr6excerrrruns2    r\cCstjr|n t|dS)aCalls the given callback only once ABSL has finished initialization. If ABSL has already finished initialization when `call_after_init` is called then the callback is executed immediately, otherwise `callback` is stored to be executed after `app.run` has finished initializing (aka. just before the main function is called). If called after `app.run`, this is equivalent to calling `callback()` in the caller thread. If called before `app.run`, callbacks are run sequentially (in an undefined order) in the same thread as `app.run`. Args: callback: a callable to be called once ABSL has finished initialization. This may be immediate if initialization has already finished. It takes no arguments and returns nothing. N)rOr<rPappend)rYrrrcall_after_initKsr^cCsZtjr||Sttt||d}trPy tWnt k rNYnXdt_|S)z:Does one-time initialization and re-parses flags on rerun.)r>r?T) rOr<rZmake_process_name_usefulrZuse_absl_handlerr; faulthandlerenablerX)r>r?r5rrrrObs rOc Cs8|r tj}ntj}tjdj}|sBdtjd}tj|ddd}nL|dd|d }y|tjdf|;}Wnt t t fk rYnX|rt }nt }yF|||r|d |||d |d k r|d |Wn4tk r}z|jtjkrWd d }~XYnX|d k r4t|d S)aWrites __main__'s docstring to stderr with some help text. Args: shorthelp: bool, if True, prints only flags from the main module, rather than all flags. writeto_stdout: bool, if True, writes help message to stdout, rather than to stderr. detailed_error: str, additional detail about why usage info was presented. exitcode: optional integer, if set, exits with this status code after writing help. __main__z USAGE: %s [flags] rz )indentZfirstline_indent%z%%z flags:  Nz %s )r*r2r3modulesrr>rZ text_wrapcount OverflowError TypeError ValueErrorr1Zmain_module_helpZget_helpr4IOErrorerrnoEPIPEr+) r%r&rNrZstdfiledocZnum_specifiersZflag_strr[rrrr(~s8        r(c@s eZdZdZddZddZdS)ExceptionHandlerz4Base exception handler from which other may inherit.cCs~dS)zReturns whether this handler wants to handle the exception or not. This base class returns True for all exceptions by default. Override in subclass if it wants to be more selective. Args: exc: Exception, the current exception. Tr)rrZrrrrGs zExceptionHandler.wantscCs tdS)zDo something with the current exception. Args: exc: Exception, the current exception This method must be overridden. N)NotImplementedError)rrZrrrrHszExceptionHandler.handleN)rrrrrGrHrrrrrps rpcCs(t|tstdt|t|dS)aeInstalls an exception handler. Args: handler: ExceptionHandler, the exception handler to install. Raises: TypeError: Raised when the 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)rSrprjtyperFr])rLrrrinstall_exception_handlers  rs)FFNN).r __future__rrr collectionsrmosr r*rIZabslrrrr_ ImportErrorr1ZDEFINE_booleanZ DEFINE_aliasZ DEFINE_stringrFrXrrZ BooleanFlagr r.r/r0r7r8r9r;r<rErMr\dequerPr^rOr(objectrprsrrrrsn           , 7 2