Ë
    ümxiy  ã                  óÀ   — 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       €úc/home/htdocs/ttos/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   € Ø�z‰zÐ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   