a
    Sic;                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddlm
Z
 ddlmZ zddlZW n ey   dZY n0 e
jZe
ddd e
d	dd
 e
dd	 e
ddd e
ddd e
ddd e
jddddd g ZG dd deZG dd deZG dd de
jZG dd deZG dd de
jZG d d! d!e
jZd"d# Zdad$d% Zdefd&d'Zde_d(d) Z d*d+ Z!defd,d-Z"e# Z$d.d/ Z%d0d1 Z&de&_d8d2d3Z'G d4d5 d5e(Z)d6d7 Z*dS )9aP  Generic entry point for Abseil Python applications.

To use this module, define a ``main`` function with a single ``argv`` argument
and call ``app.run(main)``. For example::

    def main(argv):
      if len(argv) > 1:
        raise app.UsageError('Too many command-line arguments.')

    if __name__ == '__main__':
      app.run(main)
    N)command_name)flags)loggingrun_with_pdbFzSet to true for PDB debug modepdb_post_mortemz?Set to true to handle uncaught exceptions with PDB post mortem.pdb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.only_check_argsz&Set to true to validate args and exit.allow_hide_cppc                   @   s   e Zd ZdS )ErrorN)__name__
__module____qualname__ r   r   D/var/www/html/django/DPS/env/lib/python3.9/site-packages/absl/app.pyr   I   s   r   c                       s"   e Zd ZdZd fdd	Z  ZS )
UsageErrora  Exception 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.
     c                    s   t t| | || _d S )N)superr   __init__exitcode)selfmessager   	__class__r   r   r   W   s    zUsageError.__init__)r   )r   r   r   __doc__r   __classcell__r   r   r   r   r   M   s   	r   c                       s0   e Zd ZdZdZdZ fddZdd Z  ZS )HelpFlagz?Special boolean flag that displays usage and raises SystemExit.help?c                    s"   t t| j| jdd| jdd d S )NFzshow this helpT)
short_namer   )r   r   r   NAME
SHORT_NAMEr   r   r   r   r   a   s    
zHelpFlag.__init__c                 C   s2   |  |r.tddd t  td td d S )NT)	shorthelpwriteto_stdoutz*Try --helpfull to get a list of all flags.r   )_parseusageprintsysexitr   argr   r   r   parsef   s
    
zHelpFlag.parse)	r   r   r   r   r#   r$   r   r/   r   r   r   r   r   r   \   s
   r   c                   @   s   e Zd ZdZdZdZdS )HelpshortFlagz#--helpshort is an alias for --help.Z	helpshortN)r   r   r   r   r#   r$   r   r   r   r   r0   o   s   r0   c                       s(   e Zd ZdZ fddZdd Z  ZS )HelpfullFlagzDDisplay help for flags in the main module and all dependent modules.c                    s   t t| jddddd d S )NZhelpfullFzshow full helpTr   )r   r1   r   r%   r   r   r   r   x   s    
zHelpfullFlag.__init__c                 C   s"   |  |rtdd td d S )NT)r'   r   )r(   r)   r+   r,   r-   r   r   r   r/   |   s    

zHelpfullFlag.parser   r   r   r   r   r/   r   r   r   r   r   r1   u   s   r1   c                       s(   e Zd ZdZ fddZdd Z  ZS )HelpXMLFlagz<Similar to HelpfullFlag, but generates output in XML format.c                    s   t t| jddddd d S )NZhelpxmlFz)like --helpfull, but generates XML outputTr   )r   r3   r   r%   r   r   r   r      s    
zHelpXMLFlag.__init__c                 C   s&   |  |r"tjtj td d S )Nr   )r(   r   FLAGSwrite_help_in_xml_formatr+   stdoutr,   r-   r   r   r   r/      s    
zHelpXMLFlag.parser2   r   r   r   r   r3      s   r3   c              
   C   s   z
t | W S  tjy| } zXt|}d|v r>dt|d }nd| }tj| tjd t	d W Y d}~n
d}~0 0 dS )a'  Tries to parse the flags, print usage, and exit if unparsable.

  Args:
    args: [str], a non-empty list of the command line arguments including
        program name.

  Returns:
    [str], a non-empty list of remaining command line arguments after parsing
    flags, including program name.
  
zFATAL Flags parsing error:
%s
z  zFATAL Flags parsing error: %s
z5Pass --helpshort or --helpfull to see help on flags.
r   N)
r4   r   r   strtextwrapindentr+   stderrwriter,   )argserrorr   Zfinal_messager   r   r   parse_flags_with_usage   s    
r?   c                   C   s<   t s8tt  tt  tt  tt  da dS )z!Registers help flags. Idempotent.TN)_define_help_flags_calledr   DEFINE_flagr   r0   r1   r3   r   r   r   r   define_help_flags   s    rB   c                 C   sh   t jrtdt  | du r"tjn| }||}t s>tdtj	rNt
d td jr^dt_dt _|S )ag  Registers 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_usagedoneSystemErrorrB   r+   argvr4   	is_parsedr   r   r,   using_default_valuerC   )rG   flags_parserZoriginal_argvZargs_to_mainr   r   r   rD      s    

rD   c                 C   s   t jrtt| | n~t js&t jrddl}t j	r>ddl
}nddl}| }t jrf||jt j n||j || |}t| nt| | dS )z,Calls main, optionally with pdb or profiler.r   N)r4   r   r+   r,   r   Zruncallr   r	   atexitr
   cProfileprofileZProfileregisterZ
dump_statsZprint_stats)mainrG   rK   rM   profilerretvalr   r   r   	_run_main   s    
rR   c              
   C   sT   t D ]J}z|| r||  W q   ztt  W n   Y n0 Y q0 qdS )z'Calls any installed exception handlers.N)EXCEPTION_HANDLERSwantshandler   r>   	traceback
format_exc)	exceptionhandlerr   r   r   _call_exception_handlers  s    
rZ   c              
   C   s  zt |du rtjn||}tr.t }|  qzt| | W n typ } ztd||jd W Y d}~nhd}~0    t	 d }t
|tr|js tjrtj rt  t  td t  t   Y n0 W n0 ty } zt|  W Y d}~n
d}~0 0 dS )aw  Begins 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.
        Should be passed as a keyword-only arg which will become mandatory in a
        future release.
  - 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_errorr   r   z' *** Entering post-mortem debugging ***)	_run_initr+   rG   _init_callbackspopleftrR   r   r)   r   exc_info
isinstance
SystemExitcoder4   r   r6   isattyrV   	print_excr*   r   Zpost_mortem	ExceptionrZ   )rO   rG   rJ   r=   callbackr>   excer   r   r   run  s4    $ri   c                 C   s   t jr|   n
t|  dS )a  Calls 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)r\   rE   r]   append)rf   r   r   r   call_after_initP  s    rk   c                 C   sX   t jr|| S t  t  t| |d}trNzt  W n t	yL   Y n0 dt _|S )z:Does one-time initialization and re-parses flags on rerun.)rG   rJ   T)
r\   rE   r   Zmake_process_name_usefulr   use_absl_handlerrD   faulthandlerenablere   )rG   rJ   r=   r   r   r   r\   g  s    r\   c           	   
   C   s8  |rt j}nt j}t jd j}|sBdt jd  }tj|ddd}nJ|dd|d	  }z|t jd f| ; }W n t	t
tfy   Y n0 | rt }nt }zF|| |r|d
 || |d |dur|d|  W n6 ty } z|jtjkr
 W Y d}~n
d}~0 0 |dur4t | dS )a  Writes __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]
r   z        )r:   firstline_indent%   z%%z
flags:
r7   Nz
%s
)r+   r6   r;   modulesr   rG   r   	text_wrapcountOverflowError	TypeError
ValueErrorr4   main_module_helpget_helpr<   IOErrorerrnoEPIPEr,   )	r&   r'   r[   r   ZstdfiledocZnum_specifiersZflag_strrh   r   r   r   r)     s8    





r)   c                   @   s    e Zd ZdZdd Zdd ZdS )ExceptionHandlerz4Base exception handler from which other may inherit.c                 C   s   ~dS )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   r   rg   r   r   r   rT     s    	zExceptionHandler.wantsc                 C   s
   t  dS )zDo something with the current exception.

    Args:
      exc: Exception, the current exception

    This method must be overridden.
    N)NotImplementedErrorr   r   r   r   rU     s    zExceptionHandler.handleN)r   r   r   r   rT   rU   r   r   r   r   r     s   r   c                 C   s(   t | tstdt|  t|  dS )ae  Installs 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)r`   r   rx   typerS   rj   )rY   r   r   r   install_exception_handler  s
    
r   )FFNN)+r   collectionsr}   osr   r+   r9   rV   abslr   r   r   rm   ImportErrorr4   DEFINE_booleanDEFINE_aliasDEFINE_stringrS   re   r   r   BooleanFlagr   r0   r1   r3   r?   r@   rB   rD   rE   rR   rZ   ri   dequer]   rk   r\   r)   objectr   r   r   r   r   r   <module>   sz   

.
<  
3