
    ; iy                        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dS )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.msgsSequence[str]c                     t                      j        d                    |          g|R i | || _        d | _        d S )N )super__init__join_msgs_ipython_env)selfr   argskwargs	__class__s       /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/notebook/argument_parser.pyr   z_ParserBaseException.__init__'   sI    8888888
;?    envipython_env.IPythonEnvreturnNonec                    || _         d S N)r   r   r   s     r   set_ipython_envz$_ParserBaseException.set_ipython_env,   s    r   c                :    |                      | j                   d S 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
    zr   ipython_env.IPythonEnv | Nonec                    dS )z-Display this exception on an IPython console.N r   s     r   r    z_ParserBaseException.display5   s      r   )r   r	   )r   r   r   r   )r   r	   r   r$   r   r   )__name__
__module____qualname____doc__r   r   r"   r   abcabstractmethodr    __classcell__r   s   @r   r   r   $   s        AA@ @ @ @ @ @
       ( ( (    	< < < < < < < <r   r   )	metaclassc                      e Zd ZdZddZdS )	ParserNormalExitzzException thrown when the parser exits normally.

    This is usually thrown when the user requests the help message.
    r   r$   r   r   c                8    | j         D ]}t          |           d S r   )r   printr   r   msgs      r   r    zParserNormalExit.displayD   s*    : 	 	C#JJJJ	 	r   Nr'   r(   r)   r*   r+   r    r&   r   r   r2   r2   >   s2         
     r   r2   c                      e Zd ZdZddZdS )	ParserErrorz(Exception thrown when there is an error.r   r$   r   r   c                j    | j         D ]}t          |           ||                    d           d S d S )Nz,<b style='font-family:courier new'>ERROR</b>)r   r4   display_htmlr5   s      r   r    zParserError.displayL   sG    : 	 	C#JJJJ?KLLLLL ?r   Nr'   r7   r&   r   r   r9   r9   I   s4        22M M M M M Mr   r9   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                H     t                      j        |i | g | _        d S r   )r   r   	_messages)r   r   r   r   s      r   r   zArgumentParser.__init__]   s*    $)&)))$&r   Nc                <    ~| j                             |           dS )z2Override ArgumentParser's _print_message() method.N)r?   append)r   messagefiles      r   _print_messagezArgumentParser._print_messagea   s!    g&&&&&r   r   c                    |r|                      |           | j        }g | _        |dk    rt          |          t          |          )z(Override ArgumentParser's exit() method.r   )r   )rD   r?   r2   r9   )r   statusrB   r   s       r   exitzArgumentParser.exitf   sW     	)(((~Q;;"----4((((r   r   )r   N)r(   r)   r*   r+   r   rD   rG   r.   r/   s   @r   r=   r=   T   sj         ' ' ' ' '' ' ' '

) 
) 
) 
) 
) 
) 
) 
)r   r=   )r+   
__future__r   r,   argparsetypingr   google.generativeai.notebookr   RuntimeErrorABCMetar   r2   r9   r=   r&   r   r   <module>rN      s!    # " " " " " 



        4 4 4 4 4 4< < < < <<3; < < < <4    +   M M M M M& M M M) ) ) ) )X, ) ) ) ) )r   