
    cjhV                       d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
mZmZmZmZmZmZ ddlmZmZmZmZ ej,                  dk\  reZneZdd	lmZ dd
lmZmZmZmZmZ ddl m!Z! dZ"e
rddl#m$Z$ e G d d             Z%eeeeed	 	 	 	 	 	 	 	 	 	 	 ddZ&ddZ'	 	 	 	 	 	 	 	 d dZ( G d de)      Z*	 	 	 	 	 	 	 	 	 	 d!dZ+	 	 	 	 	 	 	 	 	 	 d"dZ,d#d$dZ- edd      Z. G d de*      Z/y)%ae  
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotationsN)	dataclassfield)TYPE_CHECKINGAnyIteratorLiteralPatternTypeVarUnion)MISSINGMissingFieldmaybe_coroutineresolve_annotation)         )run_converters)BadFlagArgumentCommandErrorMissingFlagArgumentMissingRequiredFlagTooManyFlags)
StringView)FlagflagFlagConverter)Contextc                      e Zd ZU dZeZded<    ee      Z	ded<   eZ
ded<   eZded	<   eZded
<   eZded<   eZded<   dZded<   edd       Zy)r   aj  Represents a flag parameter for :class:`FlagConverter`.

    The :func:`~discord.ext.commands.flag` function helps
    create these flag objects, but it is not necessary to
    do so. These cannot be constructed manually.

    Attributes
    ----------
    name: :class:`str`
        The name of the flag.
    aliases: List[:class:`str`]
        The aliases of the flag name.
    attribute: :class:`str`
        The attribute in the class that corresponds to this flag.
    default: Any
        The default value of the flag, if available.
    annotation: Any
        The underlying evaluated annotation of the flag.
    max_args: :class:`int`
        The maximum number of arguments the flag can accept.
        A negative value indicates an unlimited amount of arguments.
    override: :class:`bool`
        Whether multiple given values overrides the previous value.
    strname)default_factory	list[str]aliases	attributer   
annotationdefaultintmax_argsbooloverrideFcast_to_dictc                &    | j                   t        u S )zUWhether the flag is required.

        A required flag has no default value.
        )r'   r   )selfs    M/var/www/html/venv/lib/python3.12/site-packages/discord/ext/commands/flags.pyrequiredzFlag.requiredb   s     ||w&&    Nreturnr*   )__name__
__module____qualname____doc___MISSINGr!   __annotations__r   listr$   r%   r&   r'   r)   r+   r,   propertyr0    r1   r/   r   r   >   sp    2 D#t4GY4IsJGSHcHdL$' 'r1   r   r!   r$   r'   r)   r+   c                "    t        | ||||      S )a  Override default functionality and parameters of the underlying :class:`FlagConverter`
    class attributes.

    Parameters
    ----------
    name: :class:`str`
        The flag name. If not given, defaults to the attribute name.
    aliases: List[:class:`str`]
        Aliases to the flag name. If not given, no aliases are set.
    default: Any
        The default parameter. This could be either a value or a callable that takes
        :class:`Context` as its sole parameter. If not given then it defaults to
        the default value given to the attribute.
    max_args: :class:`int`
        The maximum number of arguments the flag can accept.
        A negative value indicates an unlimited amount of arguments.
        The default value depends on the annotation given.
    override: :class:`bool`
        Whether multiple given values overrides the previous value. The default
        value depends on the annotation given.
    r=   )r   r=   s        r/   r   r   k   s     :  r1   c                    | st        d      | D ]K  }|j                         rt        d| d      |dk(  rt        d| d      ||v s;t        d| d|d       y )Nzflag names should not be emptyz
flag name z cannot have spaces\z cannot have backslashesz cannot have any of z within them)
ValueErrorisspace)r!   	forbiddenchs      r/   validate_flag_namerE      s    9:: ::<z$1DEFF:z$1IJKK?TH$8\R r1   c                l   | j                  di       }| d   }i }i }t               } |j                         D ]  \  }}	| j                  |t              }
t        |
t              r|	|
_        nt        ||	|
      }
||
_        |
j                  t        u r||
_	        t        |
j                  |||      x}	|
_        |
j                  t        u r-t        |	d      r!|	j                         r|	j                  |
_        |
j                  t        u rg |
_        	 |	j                   }|t"        u rM|
j$                  t        u rd|
_        |	j&                  d   t)        d       u r|
j                  t        u rd |
_        n|t*        u r|
j$                  t        u rd|
_        n|t,        u r|
j$                  t        u rd|
_        n|t.        u r:d|
_        |
j$                  t        u rd|
_        |
j2                  t        u rFd|
_        n>|t4        u r|
j$                  t        u r$d|
_        nt7        d|	d	|
j                  d
      |
j2                  t        u rd|
_        |r|
j                  j;                         n|
j                  }||v rt7        |
j                  d      |j=                  |       |
j                  D ]F  }|r|j;                         n|}||v rt7        |
j                  d|d      |j=                  |       H |
||
j                  <    |S # t8        $ r |
j$                  t        u rd|
_        Y w xY w)Nr9   "__commands_flag_case_insensitive__)r!   r&   r'   __commands_is_flag__r   TzUnsupported typing annotation z for z flagFz, flag conflicts with previous flag or alias.z flag alias z' conflicts with previous flag or alias.)getsetitemspopr   
isinstancer   r&   r%   r!   r   r'   hasattr_can_be_constructible_construct_defaultr$   
__origin__r   r)   __args__typetupler:   dictr,   r+   r	   	TypeErrorAttributeErrorcasefoldadd)	namespaceglobalslocalsr   case_insensitiveflagscachenamesr!   r&   r   originaliass                r/   	get_flagsrd      s    -- 126K !EFEEeE-K--/ b j}}T7+dD!(DOTj$GD99DI'9OOWfe(
 	

T_
 LLG#
$:;002%88DL<<7"DL(	**F ==G+$%DM&&r*d4j8T\\W=T#'DL5 ==G+$%DM4==G+$&DM4 %)!==G+$&DM==G+$(DM7"==G+$%DM4ZN C		}E+ 
 ==G#!DM (8tyy!!#TYY5=99-KL  IIdO\\ 		!E(8ENN$eE~yym<y 9! ! 
 		% 		!  diiEb H LC  	"}}' !	"s   L"L32L3c                      e Zd ZU er#ded<   ded<   ded<   ded<   ded	<   d
ed<   d
ed<   eeed	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)	FlagsMetar*   rH   dict[str, Flag]__commands_flags__zdict[str, str]__commands_flag_aliases__zPattern[str]__commands_flag_regex__rG   r    __commands_flag_delimiter____commands_flag_prefix__)r^   	delimiterprefixc          
     0   d|d<   	 t         j                  |d      j                  }t	        j
                         }	 |i }	n/|j                  |j                  }	n|j                  j                  }	~i }
i }t        |      D ]  }|j                  j                  dd      s |
j                  |j                  d          |j                  |j                  d          |t        u r|j                  d   |d<   |t        u r|j                  d   |d<   |t        u s|j                  d	   |d	<    |t        ur||d<   |t        ur||d<   |t        ur||d	<   |j                  dd      }|j                  dd
      }|j                  d	d      }t        |||	      j                         D ]4  \  }}||
|<   |j                  |j                  D ci c]  }|| c}       6 t!        |      j#                  |      }|
D ]  }t%        ||        |D ]  }t%        ||        d}|r|
j                         D ci c]  \  }}|j'                         | }
}}|j                         D ci c]$  \  }}|j'                         |j'                         & }}}t(        j*                  }|
D cg c]  }t)        j,                  |       }}|j/                  d |D               t1        |t2        d      }dj5                  |      }t)        j6                  dt)        j,                  |       d| dt)        j,                  |       d|      }||d<   |
|d<   ||d<   t8        j;                  | |||      S # t        $ r i }Y Qw xY w# ~w xY wc c}w c c}}w c c}}w c c}w )NTrH   r5   Frh   ri   rG   rk   rl   : r   c              3  F   K   | ]  }t        j                  |        y wN)reescape).0as     r/   	<genexpr>z$FlagsMeta.__new__.<locals>.<genexpr>g  s     2QBIIaL2s   !)keyreverse|z((z
)(?P<flag>)rj   )sysmodules__dict__KeyErrorinspectcurrentframef_backf_localsreversedrJ   updater   
setdefaultrd   rL   r$   rK   unionrE   rY   rt   
IGNORECASEru   extendsortedlenjoincompilerT   __new__)clsr!   basesattrsr^   rm   rn   	global_nsframelocal_nsr_   r$   base	flag_namer   
alias_namerC   regex_flagsry   valuekkeysjoinedpatterns                           r/   r   zFlagsMeta.__new__  s    )-$%	E,$78AAI $$&		}<<'$~~H$||44H!#"$UO 	D}}  !7?T]]+?@At}}-HIJ#w.BF--<CE>? ';?==5<E78 W$8<29E45	" 7*:JE67G#3<E/0 06E,- ++,PRWX$$%BCH	!!"<bA(	8DJJL 	SOIt#E)NNDLLQjJ	1QR	S 	N((0	 	5Iy)4	5! 	6Jz95	6 =B[[]KzsES\\^U*KEKCJ==?5?S% 00G  --K&+,		!,,2'22dT2$**6"#:fXQryy7K6LAN
 ,3'(&+"#-4)*||Cue44Y  	I	 D R L
 -s4    M* 4M< 	
N
3N$)N$N*M98M9<M?N)r   z
type[type]r!   r    r   ztuple[type, ...]r   dict[str, Any]r^   r*   rm   r    rn   r    )r4   r5   r6   r   r9   r   r   r<   r1   r/   rf   rf     s    ""++#11!--,00%(("%% ") Z5Z5Z5  Z5 	Z5 Z5 Z5 Z5r1   rf   c                  K   t        |      }g }| j                  }|j                  s{|j                          |j                  r	 t        |      S |j	                         }|	 t        |      S 	 t        | |||       d {   }|j                  |       |j                  s{t        |      S 7 -# t        $ r  t        $ r}	t        |      |	d }	~	ww xY wwrs   )r   current_parametereofskip_wsget_quoted_wordr   appendr   	Exceptionr   rU   )
ctxargumentr   	converterviewresultsparamword	convertedes
             r/   tuple_convert_allr   v  s      hDG"44Ehh88 > ##%< >	&,S)T5III NN9%! hh$ > J 	 	/!$'Q.	/sB   A,C/B0  B.B0 C#C.B0 0CCCCc                  K   t        |      }g }| j                  }|D ]\  }|j                          |j                  r n>|j	                         }| n*	 t        | |||       d {   }	|j                  |	       ^ t        |      t        |      k7  rt        |      t        |      S 7 D# t        $ r  t        $ r}
t        |      |
d }
~
ww xY wwrs   )r   r   r   r   r   r   r   r   r   r   r   rU   )r   r   r   
convertersr   r   r   r   r   r   r   s              r/   tuple_convert_flagr     s      hDG"44E &	88##%<	&,S)T5III NN9%!&$ 7|s:&d##> J 	 	/!$'Q.	/s=   ACB,%B*&B,*A C*B,,C>C

CCc                  K   | j                   }|xs |j                  }	 |j                  }|t        u rX|j                  d   t
        u r#t        | |||j                  d          d {   S t        | |||j                         d {   S |t        u r%|j                  d   }t        | |||       d {   S |t        u rF|j                  d   t        d       u r,t        |j                  d d    }t        | |||       d {   S |t        u r t        | |||j                         d {   S 	 t        | |||       d {   S 7 7 7 7 I7 ## t        $ r Y ,w xY w7 # t        $ r  t         $ r}t#        |      |d }~ww xY ww)NrI   r   )r   r&   rR   rU   rS   Ellipsisr   r   r:   convert_flagr   rT   r   rV   rX   r   r   r   )r   r   r   r&   r   rb   r   s          r/   r   r     s    "44E.tJV&& U?""2&(2.4)<)<Q)?   04)<)<   t^#,,Q/J%c8T:FFFu_!4!4R!8DJ!Fz223B78J'Z5IIIt^+C4ATATUUU+#CXuEEE) G J V-  2 F  +d#*+s   FE ;F'E(FE,F4E
5AFE'F*E+F0E! EE! FF
FFF	EFEFE! !F3E??FFFr   )boundc                  z    e Zd ZdZed
d       Zedd       ZddZedd       ZddZ	edd       Z
edd       Zy	)r   aU  A converter that allows for a user-friendly flag syntax.

    The flags are defined using :pep:`526` type annotations similar
    to the :mod:`dataclasses` Python module. For more information on
    how this converter works, check the appropriate
    :ref:`documentation <ext_commands_flag_converter>`.

    .. container:: operations

        .. describe:: iter(x)

            Returns an iterator of ``(flag_name, flag_value)`` pairs. This allows it
            to be, for example, constructed as a dict or a list of pairs.
            Note that aliases are not shown.

    .. versionadded:: 2.0

    Parameters
    ----------
    case_insensitive: :class:`bool`
        A class parameter to toggle case insensitivity of the flag parsing.
        If ``True`` then flags are parsed in a case-insensitive manner.
        Defaults to ``False``.
    prefix: :class:`str`
        The prefix that all flags must be prefixed with. By default,
        there is no prefix.
    delimiter: :class:`str`
        The delimiter that separates a flag's argument from the flag's name.
        By default, this is ``:``.
    c                6    | j                   j                         S )z9A mapping of flag name to flag object this converter has.)rh   copyr   s    r/   rd   zFlagConverter.get_flags  s     %%**,,r1   c                V    t        d | j                  j                         D              S )Nc              3  6   K   | ]  }|j                      y wrs   )r0   )rv   r   s     r/   rx   z6FlagConverter._can_be_constructible.<locals>.<genexpr>  s     Qt}}$Qs   )allrh   valuesr   s    r/   rP   z#FlagConverter._can_be_constructible  s"    Q1G1G1N1N1PQQQr1   c              #     K   | j                   j                  j                         D ]&  }|j                  t	        | |j
                        f ( y wrs   )	__class__rh   r   r!   getattrr%   )r.   r   s     r/   __iter__zFlagConverter.__iter__   sB     NN55<<> 	;D))WT4>>:::	;s   AAc                N  K   | j                  |       }| j                  }|j                         D ]n  }t        |j                        r6t        |j                  |       d {   }t        ||j                  |       Nt        ||j                  |j                         p |S 7 Awrs   )r   rh   r   callabler'   r   setattrr%   )r   r   r.   r_   r   r'   s         r/   rQ   z FlagConverter._construct_default  s     ++c"&&LLN 	<D% /c BBdnng6dnndll;	< 	 Cs   AB%!B#"AB%c                   dj                  | j                         j                         D cg c]'  }|j                   dt	        | |j                        ) c}      }d| j
                  j                   d| dS c c}w )N =<>)r   rd   r   r%   r   r   r4   )r.   r   pairss      r/   __repr__zFlagConverter.__repr__  s{     !NN,335 >>"!GD$..$A#DE
 4>>**+1UG155s   ,A<c                   i }| j                   }| j                  }d}d }| j                  }| j                  j	                  |      D ]  }|j                  d      \  }	}
|j                  d      }|r|j                         }||v r||   }|j                  |      }|rF|D|||	dz
   j                         }|st        |      	 ||j                     }|j                  |       |
}|} |rE|C||d  j                         }|st        |      	 ||j                     }|j                  |       |S |S # t        $ r |g||j                  <   Y jw xY w# t        $ r |g||j                  <   Y |S w xY w)Nr   r   r   )rh   ri   rG   rj   finditerspangrouprY   rJ   lstripr   r!   r   r   strip)r   r   resultr_   r$   last_position	last_flagr^   matchbeginendry   r   r   r   s                  r/   parse_flagszFlagConverter.parse_flags  s   ')&&//!%	AA0099(C 	EAJE3++f%Cllng~cl99S>D!6 ;BBD-i88)#INN3F MM%(MI/	4 Y2]^,224E))44%	/ e$ v-   5.3WF9>>*5   1*/y~~&
 1s$   D1E 1EEE-,E-c           	       K   | j                  |      }| j                  }| j                  |       }|j                         D ]  \  }}	 ||   }d|j                  cxk  rt        |      k  r,n n)|j                  r||j                   d }nt        ||      |j                  dk(  r0t!        ||d   |       d{   }
t        ||j                  |
       |D 
cg c]  }
t!        ||
|       d{    }}
|j"                  rt%        |      }t        ||j                  |        |S # t        $ r |j
                  rt        |      t        |j                        r7t        |j                  |       d{  7  }	t        ||j                  |	       n!t        ||j                  |j                         Y yw xY w7 7 c c}
w w)as  |coro|

        The method that actually converters an argument to the flag mapping.

        Parameters
        ----------
        cls: Type[:class:`FlagConverter`]
            The flag converter class.
        ctx: :class:`Context`
            The invocation context.
        argument: :class:`str`
            The argument to convert from.

        Returns
        -------
        :class:`FlagConverter`
            The flag converter instance with all flags parsed.

        Raises
        ------
        FlagError
            A flag related parsing error.
        CommandError
            A command related error.
        Nr   r   )r   rh   r   rL   r   r0   r   r   r'   r   r   r%   r)   r   r+   r   r   r,   rV   )r   r   r   	argumentsr_   r.   r!   r   r   r'   r   s              r/   convertzFlagConverter.convertK  s    6 OOH-	&&++c"++- $	2JD$"4 4==.3v;.==#T]]N$45F&tV44 }}!*3q	4@@dnne4 IOOuLeT:::OFO  fD$..&1I$	2L G  	==-d33-(7c(J"J"Jdnng>dnndllC	& A ;Osh   AGD*A,G9F>: GG/G0G64G*AF;8E;9>F;7G:F;;GGGN)r3   rg   r2   )r3   zIterator[tuple[str, Any]])r   type[F]r   r   r3   r   )r3   r    )r   r    r3   zdict[str, list[str]])r   r   r   r   r   r    r3   r   )r4   r5   r6   r7   classmethodrd   rP   r   rQ   r   r   r   r<   r1   r/   r   r     sz    > - - R R; 	 	6 / /b D Dr1   )	metaclass)r!   r    r$   r#   r'   r   r)   r(   r+   r*   r3   r   )r!   r    rC   zset[str])r[   r   r\   r   r]   r   r3   rg   )
r   r   r   r    r   r   r   r   r3   tuple[Any, ...])
r   r   r   r    r   r   r   r   r3   r   rs   )r   r    r   r   r&   r   r3   r   )0r7   
__future__r   r   rt   r}   dataclassesr   r   typingr   r   r   r	   r
   r   r   discord.utilsr   r   r   r   version_infor8   r   r   errorsr   r   r   r   r   r   r   __all__contextr   r   r   rE   rd   rT   rf   r   r   r   r   r   r<   r1   r/   <module>r      s  2 #  	 
 ( Q Q Q T TwHH %     )' )' )'\  #
# # 	#
 # # 	#Lll(6l@Nll^d5 d5N	'+8;6	'+9<<"+J C'yi yr1   