Ë
    ümxi~C  ã                  ó¬  — d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZ eeeef   Zeeej(                  eee	eegef   f   e
e   ej*                  ej,                  f   Ze	egef   Zdd„Zdd„Z ej6                  d	¬
«       G d„ dej8                  «      «       Z	 	 d	 	 	 	 	 	 	 	 	 dd„Z G d„ dej>                  «      Z  G d„ dej>                  «      Z! G d„ dej>                  «      Z" ej6                  d	¬
«       G d„ de«      «       Z# G d„ de#«      Z$ G d„ de«      Z% ej6                  d	¬
«       G d„ de«      «       Z&y) aY  Classes that define arguments for populating ArgumentParser.

The argparse module's ArgumentParser.add_argument() takes several parameters and
is quite customizable. However this can lead to bugs where arguments do not
behave as expected.

For better ease-of-use and better testability, define a set of classes for the
types of flags used by LLM Magics.

Sample usage:

  str_flag = SingleValueFlagDef(name="title", required=True)
  enum_flag = EnumFlagDef(name="colors", required=True, enum_type=ColorsEnum)

  str_flag.add_argument_to_parser(my_parser)
  enum_flag.add_argument_to_parser(my_parser)
é    )ÚannotationsN)ÚAnyÚCallableÚSequenceÚTupleÚUnion)Úllmfn_inputs_source)Úllmfn_outputsc                óP   — 	 | j                   S # t        $ r t        | «      cY S w xY w©N)Ú__name__ÚAttributeErrorÚstr©Úxs    ú\/home/htdocs/ttos/venv/lib/python3.12/site-packages/google/generativeai/notebook/flag_def.pyÚ_get_type_namer   ?   s)   € ðØ�z‰zÐøÜò Ü�1‹vŠðús   ‚ Ž%¤%c                óF   — | st        d«      ‚| d   dk(  rt        d«      ‚| S )z.Validation for long and short names for flags.zCannot be emptyr   ú-zCannot start with dash)Ú
ValueError)Únames    r   Ú_validate_flag_namer   F   s-   € áÜÐ*Ó+Ð+ØˆA�w�#‚~ÜÐ1Ó2Ð2Ø€Kó    T)Úfrozenc                  óä   — e Zd ZU dZded<   dZded<   dZded	<   eZd
ed<   dZ	ded<   dZ
ded<   dZded<   dZded<   ej                  dd„«       Zej                  dd„«       Zdd„Z	 	 dd„Zd„ Zy)ÚFlagDefaã  Abstract base class for flag definitions.

    Attributes:
      name: Long name, e.g. "colors" will define the flag "--colors".
      required: Whether the flag must be provided on the command line.
      short_name: Optional short name.
      parse_type: The type that ArgumentParser should parse the command line
        argument to.
      dest_type: The type that the parsed value is converted to. This is used when
        we want ArgumentParser to parse as one type, then convert to a different
        type. E.g. for enums we parse as "str" then convert to the desired enum
        type in order to provide cleaner help messages.
      parse_to_dest_type_fn: If provided, this function will be used to convert
        the value from `parse_type` to `dest_type`. This can be used for
        validation as well.
      choices: If provided, limit the set of acceptable values to these choices.
      help_msg: If provided, adds help message when -h is used in the command
        line.
    r   r   FÚboolÚrequiredNú
str | NoneÚ
short_nameztype[_PARSETYPES]Ú
parse_typeztype[_DESTTYPES] | NoneÚ	dest_typez_PARSEFN | NoneÚparse_to_dest_type_fnzlist[_PARSETYPES] | NoneÚchoicesÚhelp_msgc                 ó   — y)zþAdds this flag as an argument to `parser`.

        Child classes should implement this as a call to parser.add_argument()
        with the appropriate parameters.

        Args:
          parser: The parser to which this argument will be added.
        N© )ÚselfÚparsers     r   Úadd_argument_to_parserzFlagDef.add_argument_to_parserq   ó   � r   c                 ó   — y)z.For child classes to do additional validation.Nr'   ©r(   s    r   Ú_do_additional_validationz!FlagDef._do_additional_validation|   r+   r   c                óJ   — | j                   €| j                  S | j                   S )z!Returns the final converted type.)r"   r!   r-   s    r   Ú_get_dest_typezFlagDef._get_dest_type€   s   € à"&§.¡.Ð"8ˆt�‰ÐL¸d¿n¹nÐLr   c                óz   — | j                   �| j                   S | j                  «       }|| j                  k(  rd„ S |S )z;Returns a function to convert from parse_type to dest_type.c                ó   — | S r   r'   r   s    r   ú<lambda>z4FlagDef._get_parse_to_dest_type_fn.<locals>.<lambda>�   s   € ˜Q€ r   )r#   r0   r!   )r(   r"   s     r   Ú_get_parse_to_dest_type_fnz"FlagDef._get_parse_to_dest_type_fn„   sB   € ð ×%Ñ%Ð1Ø×-Ñ-Ð-à×'Ñ'Ó)ˆ	Ø˜Ÿ™Ò'ÙÐàÐr   c                ó�   — t        | j                  «       | j                  �t        | j                  «       | j                  «        y r   )r   r   r    r.   r-   s    r   Ú__post_init__zFlagDef.__post_init__‘   s0   € Ü˜DŸI™IÔ&Ø�?‰?Ð&Ü §¡Ô0à×&Ñ&Õ(r   ©r)   úargparse.ArgumentParserÚreturnÚNone©r9   r:   )r9   ztype[_DESTTYPES])r9   Ú_PARSEFN)r   Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r    r   r!   r"   r#   r$   r%   ÚabcÚabstractmethodr*   r.   r0   r4   r6   r'   r   r   r   r   O   s¢   … ñð( ƒIØ€HˆdÓà!€J�
Ó!à$'€JÐ!Ó'Ø)-€IÐ&Ó-Ø-1Ð˜?Ó1à(,€GÐ%Ó,Ø€HˆjÓà×Ñòó ðð 	×Ñò=ó ð=óMðà	óó)r   r   c                ó@   — t        | |«      sy|syt        | |«      |k7  S )a  Returns true if `namespace.dest` is set to a non-default value.

    Args:
      namespace: The Namespace that is populated by ArgumentParser.
      dest: The attribute in the Namespace to be populated.
      has_default: "None" is a valid default value so we use an additional
        `has_default` boolean to indicate that `default_value` is present.
      default_value: The default value to use when `has_default` is True.

    Returns:
      Whether namespace.dest is set to something other than the default value.
    FT)ÚhasattrÚgetattr)Ú	namespaceÚdestÚhas_defaultÚdefault_values       r   Ú_has_non_default_valuerJ   ™   s+   € ô$ �9˜dÔ#Øáð ä�9˜dÓ# }Ñ4Ð4r   c                  óF   ‡ — e Zd ZdZ	 	 	 	 dˆ fd„Z	 d	 	 	 	 	 	 	 dd„Zˆ xZS )Ú_SingleValueStoreActionz�Custom Action for storing a value in an argparse.Namespace.

    This action checks that the flag is specified at-most once.
    c                óD   •— t        ‰| �  ||fi |¤Ž || _        || _        y r   ©ÚsuperÚ__init__Ú
_dest_typeÚ_parse_to_dest_type_fn©r(   Úoption_stringsrG   r"   r#   ÚkwargsÚ	__class__s         €r   rP   z _SingleValueStoreAction.__init__¼   ó(   ø€ ô 	‰Ñ˜¨Ñ8°Ò8Ø#ˆŒØ&;ˆÕ#r   c                óŠ  — t        |t        «      st        |t        «      rJ ‚t        || j                  t        | d«      t        | d«      ¬«      r%t        j                  | dj                  |«      «      ‚	 | j                  |d   «      }t        || j                  «      s@t        dj                  t        | j                  «      t        t        |«      «      «      «      ‚t!        || j                  |«       y # t        $ rA}t        j                  | dj                  |d   t        t        |«      «      |«      «      ‚d }~ww xY w)NÚdefault©rH   rI   úCannot set {} more than oncer   ú!Error with value "{}", got {}: {}ú+Converted to wrong type, expected {} got {})Ú
isinstancer   ÚbytesrJ   rG   rD   rE   ÚargparseÚArgumentErrorÚformatrR   Ú	Exceptionr   ÚtyperQ   ÚRuntimeErrorÚsetattr)r(   r)   rF   ÚvaluesÚoption_stringÚconverted_valueÚes          r   Ú__call__z _SingleValueStoreAction.__call__È   s  € ô ˜f¤cÔ*´:¸fÄeÔ3LÐLÐLä!ØØ�I‰IÜ  iÓ0Ü! $¨	Ó2õ	
ô ×(Ñ(¨Ð/M×/TÑ/TÐUbÓ/cÓdÐdð	Ø"×9Ñ9¸&À¹)ÓDˆOô ˜/¨4¯?©?Ô;ÜØ=×DÑDÜ" 4§?¡?Ó3Ü"¤4¨Ó#8Ó9óóð ô 	�	˜4Ÿ9™9 oÕ6øô ò 	Ü×(Ñ(ØØ3×:Ñ:¸6À!¹9ÄnÔUYÐZ[ÓU\ÓF]Ð_`Óaóð ûð	ús   Á6C8 Ã8	EÄ<D=Ä=E©r"   ú	type[Any]r#   r<   r   ©r)   r8   rF   úargparse.Namespacerg   zstr | Sequence[Any] | Nonerh   r   ©r   r=   r>   r?   rP   rk   Ú__classcell__©rV   s   @r   rL   rL   ¶   sQ   ø„ ñð

<ð ð	
<ð
  (õ
<ð" %)ð"7à'ð"7ð &ð"7ð +ð	"7ð
 "÷"7r   rL   c                  óF   ‡ — e Zd ZdZ	 	 	 	 dˆ fd„Z	 d	 	 	 	 	 	 	 dd„Zˆ xZS )Ú_MultiValuesAppendActionz‚Custom Action for appending values in an argparse.Namespace.

    This action checks that the flag is specified at-most once.
    c                óD   •— t        ‰| �  ||fi |¤Ž || _        || _        y r   rN   rS   s         €r   rP   z!_MultiValuesAppendAction.__init__ó   rW   r   c                óŠ  — t        |t        «      st        |t        «      rJ ‚t        || j                  «      }|r%t        j                  | dj                  |«      «      ‚|D ]’  }	 | j                  |«      }t        || j                  «      s.t        dj                  | j                  t        |«      «      «      ‚||v r%t        j                  | dj                  |«      «      ‚|j                  |«       Œ” y # t        $ rA}t        j                  | dj                  |d   t        t        |«      «      |«      «      ‚d }~ww xY w)Nr[   r\   r   r]   zDuplicate values "{}")r^   r   r_   rE   rG   r`   ra   rb   rR   rc   r   rd   rQ   re   Úappend)	r(   r)   rF   rg   rh   Ú
curr_valueÚvalueri   rj   s	            r   rk   z!_MultiValuesAppendAction.__call__ÿ   s/  € ô ˜f¤cÔ*´:¸fÄeÔ3LÐLÐLä˜Y¨¯	©	Ó2ˆ
ÙÜ×(Ñ(¨Ð/M×/TÑ/TÐUbÓ/cÓdÐdàò 	/ˆEðØ"&×"=Ñ"=¸eÓ"D�ô ˜o¨t¯©Ô?Ü"ØA×HÑHØŸ™¬¨oÓ)>óóð ð
  *Ñ,Ü×,Ñ,¨TÐ3J×3QÑ3QÐRWÓ3XÓYÐYà×Ñ˜oÕ.ñ)	/øô ò Ü×,Ñ,ØØ7×>Ñ>Ø˜q™	¤>´$°q³'Ó#:¸Aóóð ûðús   Á&C8Ã8	EÄ<D=Ä=Erl   r   rn   rp   rr   s   @r   rt   rt   í   sQ   ø„ ñð

<ð ð	
<ð
  (õ
<ð" %)ð#/à'ð#/ð &ð#/ð +ð	#/ð
 "÷#/r   rt   c                  ó<   ‡ — e Zd ZdZˆ fd„Z	 d	 	 	 	 	 	 	 dd„Zˆ xZS )Ú_BooleanValueStoreActionzßCustom Action for setting a boolean value in argparse.Namespace.

    The boolean flag expects the default to be False and will set the value to
    True.
    This action checks that the flag is specified at-most once.
    c                ó(   •— t        ‰| �  ||fi |¤Ž y r   )rO   rP   )r(   rT   rG   rU   rV   s       €r   rP   z!_BooleanValueStoreAction.__init__-  s   ø€ ô 	‰Ñ˜¨Ñ8°Ó8r   c                ó®   — t        || j                  dd¬«      r%t        j                  | dj	                  |«      «      ‚t        || j                  d«       y )NTFrZ   r[   )rJ   rG   r`   ra   rb   rf   )r(   r)   rF   rg   rh   s        r   rk   z!_BooleanValueStoreAction.__call__5  sN   € ô "ØØ�I‰IØØõ	
ô ×(Ñ(¨Ð/M×/TÑ/TÐUbÓ/cÓdÐdä�	˜4Ÿ9™9 dÕ+r   r   rn   rp   rr   s   @r   r{   r{   %  s=   ø„ ñô9ð %)ð,à'ð,ð &ð,ð +ð	,ð
 "÷,r   r{   c                  óv   — e Zd ZU dZ G d„ dej
                  «      Zej                  Zde	d<   d
d„Z
dd„Zdd„Zy	)ÚSingleValueFlagDefao  Definition for a flag that takes a single value.

    Sample usage:
      # This defines a flag that can be specified on the command line as:
      #   --count=10
      flag = SingleValueFlagDef(name="count", parse_type=int, required=True)
      flag.add_argument_to_parser(argument_parser)

    Attributes:
      default_value: Default value for optional flags.
    c                  ó   — e Zd ZdZdZy)ú SingleValueFlagDef._DefaultValuezíSpecial value to represent "no value provided".

        "None" can be used as a default value, so in order to differentiate between
        "None" and "no value provided", create a special value for "no value
        provided".
        N)r   r=   r>   r?   ÚNOT_SETr'   r   r   Ú_DefaultValuer�   U  s   „ ñ	ð ‰r   rƒ   z!_DESTTYPES | _DefaultValue | NonerI   c                óP   — | j                   t        j                  j                  k7  S )z2Returns whether `default_value` has been provided.)rI   r   rƒ   r‚   r-   s    r   Ú_has_default_valuez%SingleValueFlagDef._has_default_valuea  s    € à×!Ñ!Ô%7×%EÑ%E×%MÑ%MÑMÐMr   c           
     óª  — d| j                   z   g}| j                  �|d| j                  z   gz  }i }| j                  «       r| j                  |d<   | j                  �| j                  |d<   | j
                  �| j
                  |d<    |j                  |t        | j                  | j                  «       | j                  «       | j                  ddœ|¤Ž y )Nú--r   rY   r$   Úhelpé   )Úactionrd   r"   r#   r   Únargs)r   r    r…   rI   r$   r%   Úadd_argumentrL   r!   r0   r4   r   ©r(   r)   ÚargsrU   s       r   r*   z)SingleValueFlagDef.add_argument_to_parsere  sÌ   € Ø�t—y‘yÑ Ð!ˆØ�?‰?Ð&Ø�S˜4Ÿ?™?Ñ*Ð+Ñ+ˆDàˆØ×"Ñ"Ô$Ø $× 2Ñ 2ˆF�9ÑØ�<‰<Ð#Ø $§¡ˆF�9ÑØ�=‰=Ð$Ø!Ÿ]™]ˆF�6‰Nàˆ×ÑØÜ*Ø—‘Ø×)Ñ)Ó+Ø"&×"AÑ"AÓ"CØ—]‘]Øñ		
ð ó		
r   c                ó"  — | j                   r| j                  «       r&t        d«      ‚| j                  «       st        d«      ‚| j                  «       r=| j                  �0t	        | j                  | j                  «       «      st        d«      ‚y y y )Nz(Required flags cannot have default valuez(Optional flags must have a default valuez>Default value must be of the same type as the destination type)r   r…   r   rI   r^   r0   r-   s    r   r.   z,SingleValueFlagDef._do_additional_validation}  s„   € Ø�=Š=Ø×&Ñ&Ô(Ü Ð!KÓLÐLà×*Ñ*Ô,Ü Ð!KÓLÐLà×"Ñ"Ô$¨×);Ñ);Ð)GÜ˜d×0Ñ0°$×2EÑ2EÓ2GÔHÜ Ð!aÓbÐbð Ið *HÐ$r   N)r9   r   r7   r;   )r   r=   r>   r?   ÚenumÚEnumrƒ   r‚   rI   r@   r…   r*   r.   r'   r   r   r   r   G  s<   … ñ
ô˜Ÿ	™	ô ð 8E×7LÑ7L€MÐ4ÓLóNó
ô0
cr   r   c                  ó$   ‡ — e Zd ZdZdˆ fd„Zˆ xZS )ÚEnumFlagDefaT  Definition for a flag that takes a value from an Enum.

    Sample usage:
      # This defines a flag that can be specified on the command line as:
      #   --color=red
      flag = SingleValueFlagDef(name="color", enum_type=ColorsEnum,
                                required=True)
      flag.add_argument_to_parser(argument_parser)
    c               óŠ  •— t        |t        j                  «      st        d«      ‚d|v rt	        d«      ‚t
        |d<   d|v rt	        d«      ‚||d<   d|v r|d   D ]  }	  ||«       Œ n|D �cg c]  }|j                  ‘Œ c}|d<   t        ‰| �$  |i |¤Ž y # t        $ r t	        dj                  |«      «      d ‚w xY wc c}w )Nz "enum_type" must be of type Enumr!   z@Cannot set "parse_type" for EnumFlagDef; set "enum_type" insteadr"   z?Cannot set "dest_type" for EnumFlagDef; set "enum_type" insteadr$   z Invalid value in "choices": "{}")
Ú
issubclassr�   r‘   Ú	TypeErrorr   r   rb   ry   rO   rP   )r(   Ú	enum_typerŽ   rU   r   rV   s        €r   rP   zEnumFlagDef.__init__•  sä   ø€ Ü˜)¤T§Y¡YÔ/ÜÐ>Ó?Ð?ð ˜6Ñ!ÜÐ_Ó`Ð`Ü"ˆˆ|Ñà˜&Ñ ÜÐ^Ó_Ð_Ø'ˆˆ{Ñà˜Ñà˜IÑ&ò ]�ð]Ù˜a•Lñ]ð 3<Ö <¨Q §£Ò <ˆF�9Ñä‰Ñ˜$Ð) &Ó)øô "ò ]Ü$Ð%G×%NÑ%NÈqÓ%QÓRÐX\Ð\ð]üò !=s   Á BÁ/C Â%B=)r—   ztype[enum.Enum])r   r=   r>   r?   rP   rq   rr   s   @r   r“   r“   Š  s   ø„ ñ÷*ñ *r   r“   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚMultiValuesFlagDefa6  Definition for a flag that takes multiple values.

    Sample usage:
      # This defines a flag that can be specified on the command line as:
      #   --colors=red green blue
      flag = MultiValuesFlagDef(name="colors", parse_type=str, required=True)
      flag.add_argument_to_parser(argument_parser)
    c                ón  — d| j                   z   g}| j                  �|d| j                  z   gz  }i }| j                  �| j                  |d<   | j                  �| j                  |d<    |j                  |t
        | j                  | j                  «       | j                  «       | j                  g ddœ|¤Ž y )Nr‡   r   r$   rˆ   ú+)rŠ   rd   r"   r#   r   rY   r‹   )
r   r    r$   r%   rŒ   rt   r!   r0   r4   r   r�   s       r   r*   z)MultiValuesFlagDef.add_argument_to_parser¹  s³   € Ø�t—y‘yÑ Ð!ˆØ�?‰?Ð&Ø�S˜4Ÿ?™?Ñ*Ð+Ñ+ˆDàˆØ�<‰<Ð#Ø $§¡ˆF�9ÑØ�=‰=Ð$Ø!Ÿ]™]ˆF�6‰Nàˆ×ÑØÜ+Ø—‘Ø×)Ñ)Ó+Ø"&×"AÑ"AÓ"CØ—]‘]ØØñ
	
ð ó
	
r   c                 ó   — y r   r'   r-   s    r   r.   z,MultiValuesFlagDef._do_additional_validationÐ  s   € àr   Nr7   r;   )r   r=   r>   r?   r*   r.   r'   r   r   r™   r™   ¯  s   „ ñó
ô.r   r™   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚBooleanFlagDefzÐDefinition for a Boolean flag.

    A boolean flag is always optional with a default value of False. The flag does
    not take any values. Specifying the flag on the commandline will set it to
    True.
    c                óŽ   — | j                   �t        d«      ‚| j                  �t        d«      ‚| j                  �t        d«      ‚y )Nz*dest_type cannot be set for BooleanFlagDefz6parse_to_dest_type_fn cannot be set for BooleanFlagDefz(choices cannot be set for BooleanFlagDef)r"   r   r#   r$   r-   s    r   r.   z(BooleanFlagDef._do_additional_validationÞ  sK   € Ø�>‰>Ð%ÜÐIÓJÐJØ×%Ñ%Ð1ÜÐUÓVÐVØ�<‰<Ð#ÜÐGÓHÐHð $r   c           	     óÜ   — d| j                   z   g}| j                  �|d| j                  z   gz  }i }| j                  �| j                  |d<    |j                  |t        t
        ddddœ|¤Ž y )Nr‡   r   rˆ   Fr   )rŠ   rd   r   rY   r‹   )r   r    r%   rŒ   r{   r   r�   s       r   r*   z%BooleanFlagDef.add_argument_to_parseræ  s{   € Ø�t—y‘yÑ Ð!ˆØ�?‰?Ð&Ø�S˜4Ÿ?™?Ñ*Ð+Ñ+ˆDàˆØ�=‰=Ð$Ø!Ÿ]™]ˆF�6‰Nàˆ×ÑØÜ+ÜØØØñ	
ð ó	
r   Nr;   r7   )r   r=   r>   r?   r.   r*   r'   r   r   rž   rž   Õ  s   „ ñóIô
r   rž   )r   rm   r9   r   )r   r   r9   r   )FN)
rF   ro   rG   r   rH   r   rI   r   r9   r   )'r?   Ú
__future__r   rA   r`   Údataclassesr�   Útypingr   r   r   r   r   Ú google.generativeai.notebook.libr	   r
   r   ÚintÚfloatÚ_PARSETYPESr‘   ÚLLMFnInputsSourceÚLLMFnOutputsSinkÚ
_DESTTYPESr<   r   r   Ú	dataclassÚABCr   rJ   ÚActionrL   rt   r{   r   r“   r™   rž   r'   r   r   ú<module>r®      s±  ðñõ" #ã 
Û Û Û ß 8Õ 8å @Ý :ð �C˜˜e�OÑ$€ð ØØ‡I�IØ	ˆ#ˆx˜˜c˜
 C˜Ñ(Ð
(Ñ)ØˆS�MØ×)Ñ)Ø×"Ñ"ð$ñ€
ð �[�M :Ð-Ñ.€óóð €×Ñ˜dÔ#ôF)ˆc�g‰gó F)ó $ðF)ðX Øð	5Ø!ð5à
ð5ð ð5ð ð	5ð
 
ó5ô:47˜hŸo™oô 47ôn5/˜xŸ™ô 5/ôp,˜xŸ™ô ,ðD €×Ñ˜dÔ#ô?c˜ó ?có $ð?côD"*Ð$ô "*ôJ#˜ô #ðL €×Ñ˜dÔ#ô!
�Wó !
ó $ñ!
r   