
    
!iy                        S r SSKJr  SSKrSSKrSSKJr  SSKJr   " S S\	\R                  S9r " S	 S
\5      r " S S\5      r " S S\R                  5      rg)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                  r   ^  \ rS rSrSrS	U 4S jjrS
S jrS rSS jr\	R                  SS j5       rSrU =r$ )_ParserBaseException$   z7Base class for parser exceptions including normal exit.c                f   > [         TU ]  " SR                  U5      /UQ70 UD6  Xl        S U l        g )N )super__init__join_msgs_ipython_env)selfmsgsargskwargs	__class__s       f/home/james-whalen/.local/lib/python3.13/site-packages/google/generativeai/notebook/argument_parser.pyr   _ParserBaseException.__init__'   s/    888
;?    c                    Xl         g N)r   r   envs     r   set_ipython_env$_ParserBaseException.set_ipython_env,   s    r   c                :    U R                  U R                  5        g r   )displayr   r   s    r   _ipython_display_&_ParserBaseException._ipython_display_/   s    T&&'r   c                    U R                   $ r   )r   r    s    r   r   _ParserBaseException.msgs2   s    zzr   c                    g)z-Display this exception on an IPython console.N r   s     r   r   _ParserBaseException.display5   s    r   )r   r   )r   Sequence[str])r   zipython_env.IPythonEnvreturnNone)r)   r(   r   zipython_env.IPythonEnv | Noner)   r*   )__name__
__module____qualname____firstlineno____doc__r   r   r!   r   abcabstractmethodr   __static_attributes____classcell__r   s   @r   r   r   $   s5    A@
 ( 	< <r   r   )	metaclassc                  "    \ rS rSrSrSS jrSrg)ParserNormalExit>   zrException thrown when the parser exits normally.

This is usually thrown when the user requests the help message.
c                @    U R                    H  n[        U5        M     g r   )r   printr   r   msgs      r   r   ParserNormalExit.displayD   s    ::C#J r   r&   Nr+   r,   r-   r.   r/   r0   r   r3   r&   r   r   r8   r8   >   s    
r   r8   c                  "    \ rS rSrSrSS jrSrg)ParserErrorI   z(Exception thrown when there is an error.c                j    U R                    H  n[        U5        M     Ub  UR                  S5        g g )Nz,<b style='font-family:courier new'>ERROR</b>)r   r;   display_htmlr<   s      r   r   ParserError.displayL   s0    ::C#J ?KL r   r&   Nr+   r?   r&   r   r   rA   rA   I   s    2Mr   rA   c                  @   ^  \ rS rSrSrU 4S jrSS jrSS jrSrU =r	$ )	ArgumentParserT   a  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                4   > [         TU ]  " U0 UD6  / U l        g r   )r   r   	_messages)r   r   r   r   s      r   r   ArgumentParser.__init__]   s    $)&)$&r   c                <    AU R                   R                  U5        g)z2Override ArgumentParser's _print_message() method.N)rJ   append)r   messagefiles      r   _print_messageArgumentParser._print_messagea   s    g&r   c                    U(       a  U R                  U5        U R                  n/ U l        US:X  a	  [        US9e[        US9e)z(Override ArgumentParser's exit() method.r   )r   )rP   rJ   r8   rA   )r   statusrN   r   s       r   exitArgumentParser.exitf   s@    (~~Q;"--4((r   )rJ   r   )r   N)
r,   r-   r.   r/   r0   r   rP   rT   r3   r4   r5   s   @r   rG   rG   T   s    ''

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