
    rhy                        d Z ddlmZ ddlZddlZddlmZ ddlmZ  G d de	ej                        Z G d	 d
e      Z G d de      Z G d dej                        Zy)a  Customized ArgumentParser.

The default behvaior of argparse.ArgumentParser's parse_args() method  is to
exit with a SystemExit exception in the following cases:
1. When the user requests a help message (with the --help or -h flags), or
2. When there's a parsing error (e.g. missing required flags or mistyped flags)

To make the errors more user-friendly, this class customizes
argparse.ArgumentParser and raises either ParserNormalExit for (1) or
ParserError for (2); this way the caller has control over how to display them
to the user.
    )annotationsN)Sequence)ipython_envc                  `     e Zd ZdZd fdZddZd Zd	dZej                  d
d       Z
 xZS )_ParserBaseExceptionz7Base class for parser exceptions including normal exit.c                f    t        |   dj                  |      g|i | || _        d | _        y )N )super__init__join_msgs_ipython_env)selfmsgsargskwargs	__class__s       /var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/google/generativeai/notebook/argument_parser.pyr   z_ParserBaseException.__init__'   s1    888
;?    c                    || _         y N)r   r   envs     r   set_ipython_envz$_ParserBaseException.set_ipython_env,   s
    r   c                :    | j                  | j                         y r   )displayr   r   s    r   _ipython_display_z&_ParserBaseException._ipython_display_/   s    T&&'r   c                    | j                   S r   )r   r   s    r   r   z_ParserBaseException.msgs2   s    zzr   c                     y)z-Display this exception on an IPython console.N r   s     r   r   z_ParserBaseException.display5   s    r   )r   Sequence[str])r   zipython_env.IPythonEnvreturnNone)r#   r"   r   zipython_env.IPythonEnv | Noner#   r$   )__name__
__module____qualname____doc__r   r   r   r   abcabstractmethodr   __classcell__r   s   @r   r   r   $   s5    A@
 ( 	< <r   r   )	metaclassc                      e Zd ZdZddZy)ParserNormalExitzzException thrown when the parser exits normally.

    This is usually thrown when the user requests the help message.
    c                <    | j                   D ]  }t        |        y r   )r   printr   r   msgs      r   r   zParserNormalExit.displayD   s    :: 	C#J	r   Nr%   r&   r'   r(   r)   r   r!   r   r   r0   r0   >   s    
r   r0   c                      e Zd ZdZddZy)ParserErrorz(Exception thrown when there is an error.c                d    | j                   D ]  }t        |        ||j                  d       y y )Nz,<b style='font-family:courier new'>ERROR</b>)r   r2   display_htmlr3   s      r   r   zParserError.displayL   s5    :: 	C#J	?KL r   Nr%   r5   r!   r   r   r7   r7   I   s    2Mr   r7   c                  2     e Zd ZdZ fdZddZddZ xZS )ArgumentParsera!  Customized ArgumentParser for LLM Magics.

    This class overrides the parent argparse.ArgumentParser's error-handling
    methods to avoid side-effects like printing to stderr. The messages are
    accumulated and passed into the raised exceptions for the caller to
    handle them.
    c                2    t        |   |i | g | _        y r   )r
   r   	_messages)r   r   r   r   s      r   r   zArgumentParser.__init__]   s    $)&)$&r   c                <    ~| j                   j                  |       y)z2Override ArgumentParser's _print_message() method.N)r=   append)r   messagefiles      r   _print_messagezArgumentParser._print_messagea   s    g&r   c                    |r| j                  |       | j                  }g | _        |dk(  rt        |      t        |      )z(Override ArgumentParser's exit() method.r   )r   )rB   r=   r0   r7   )r   statusr@   r   s       r   exitzArgumentParser.exitf   s@    (~~Q;"--4((r   r   )r   N)r&   r'   r(   r)   r   rB   rE   r,   r-   s   @r   r;   r;   T   s    ''

)r   r;   )r)   
__future__r   r*   argparsetypingr   google.generativeai.notebookr   RuntimeErrorABCMetar   r0   r7   r;   r!   r   r   <module>rL      s[    # 
   4<<3;; <4+ M& M)X,, )r   