o
    1)h                     @  sf  d dl m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	Z
d dlmZ d dlmZ d dlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ e
jrod dlZddlmZ ddlmZ ddlmZ e
 dZ!G dd dZ"G dd de"Z#G dd de"Z$G dd de"Z%G dd de"Z&G dd de"e
j'e! Z(G dd de"Z)G dd  d e"Z*G d!d" d"e*Z+G d#d$ d$e*Z,G d%d& d&e+e,Z-G d'd( d(e*Z.G d)d* d*e+e.Z/G d+d, d,e"Z0G d-d. d.e"Z1G d/d0 d0e"Z2dDd5d6Z3G d7d8 d8e"Z4G d9d: d:e#Z5dEdFd>d?Z6e% Z7e& Z8e, Z9e. Z:e0 Z;e1 Z<G d@dA dAe
j=dBdCZ>dS )G    )annotationsN)datetime)gettext)ngettext   )_get_argv_encoding)open_streamBadParameter)format_filename)LazyFile)safecall)Context)	ParameterCompletionItemParamTypeValuec                   @  s   e Zd ZU dZdZded< dZded< ded	< d
Zded< d.ddZ	
	
d/d0ddZ	d1ddZ
d2ddZd0d d!Zd3d$d%Z	
	
d/d4d(d)Zd5d,d-Zd
S )6	ParamTypea  Represents the type of a parameter. Validates and converts values
    from the command line or Python into the correct type.

    To implement a custom type, subclass and implement at least the
    following:

    -   The :attr:`name` class attribute must be set.
    -   Calling an instance of the type with ``None`` must return
        ``None``. This is already implemented by default.
    -   :meth:`convert` must convert string values to the correct type.
    -   :meth:`convert` must accept values that are already the correct
        type.
    -   It must be able to convert a value if the ``ctx`` and ``param``
        arguments are ``None``. This can occur when converting prompt
        input.
    Fzt.ClassVar[bool]is_compositer   zt.ClassVar[int]aritystrnameNzt.ClassVar[str | None]envvar_list_splitterreturndict[str, t.Any]c                 C  sB   t | jdd }|dd }t| dr| j}n|}||dS )zGather information that could be useful for a tool generating
        user-facing documentation.

        Use :meth:`click.Context.to_info_dict` to traverse the entire
        CLI structure.

        .. versionadded:: 8.0
        r   r   ZParameterTyper   )
param_typer   )type__name__	partitionhasattrr   )selfr   r    r!   JC:\Users\User\Downloads\Proyecto_IoT\venv\Lib\site-packages\click/types.pyto_info_dict>   s   


zParamType.to_info_dictvaluet.AnyparamParameter | NonectxContext | Nonec                 C  s   |d ur|  |||S d S N)convertr    r$   r&   r(   r!   r!   r"   __call__S   s   zParamType.__call__r   r   
str | Nonec                 C     dS )z>Returns the metavar default for this param if it provides one.Nr!   r    r&   r(   r!   r!   r"   get_metavar\       zParamType.get_metavarc                 C  r/   )ztOptionally might return extra information about a missing
        parameter.

        .. versionadded:: 2.0
        Nr!   r0   r!   r!   r"   get_missing_message_   r2   zParamType.get_missing_messagec                 C     |S )a  Convert the value to the correct type. This is not called if
        the value is ``None`` (the missing value).

        This must accept string values from the command line, as well as
        values that are already the correct type. It may also convert
        other compatible types.

        The ``param`` and ``ctx`` arguments may be ``None`` in certain
        situations, such as when converting prompt input.

        If the value cannot be converted, call :meth:`fail` with a
        descriptive message.

        :param value: The value to convert.
        :param param: The parameter that is using this type to convert
            its value. May be ``None``.
        :param ctx: The current context that arrived at this value. May
            be ``None``.
        r!   r,   r!   r!   r"   r+   f   s   zParamType.convertrvcabc.Sequence[str]c                 C  s   |pd | jS )au  Given a value from an environment variable this splits it up
        into small chunks depending on the defined envvar list splitter.

        If the splitter is set to `None`, which means that whitespace splits,
        then leading and trailing whitespace is ignored.  Otherwise, leading
        and trailing splitters usually lead to empty items being included.
         )splitr   )r    r5   r!   r!   r"   split_envvar_value~   s   zParamType.split_envvar_valuemessage
t.NoReturnc                 C  s   t |||d)z4Helper method to fail with an invalid value message.r(   r&   r	   )r    r:   r&   r(   r!   r!   r"   fail   s   zParamType.fail
incompletelist[CompletionItem]c                 C  s   g S )a  Return a list of
        :class:`~click.shell_completion.CompletionItem` objects for the
        incomplete value. Most types do not provide completions, but
        some do, and this allows custom types to provide custom
        completions as well.

        :param ctx: Invocation context for this command.
        :param param: The parameter that is requesting completion.
        :param incomplete: Value being completed. May be empty.

        .. versionadded:: 8.0
        r!   )r    r(   r&   r>   r!   r!   r"   shell_complete   s   zParamType.shell_completer   r   )NNr$   r%   r&   r'   r(   r)   r   r%   r&   r   r(   r   r   r.   )r&   r   r(   r)   r   r.   )r5   r   r   r6   )r:   r   r&   r'   r(   r)   r   r;   r(   r   r&   r   r>   r   r   r?   )r   
__module____qualname____doc__r   __annotations__r   r   r#   r-   r1   r3   r+   r9   r=   r@   r!   r!   r!   r"   r      s$   
 

	


	r   c                   @  s   e Zd ZdZedddZdS )CompositeParamTypeTr   intc                 C  s   t  r*   NotImplementedErrorr    r!   r!   r"   r      s   zCompositeParamType.arityNr   rJ   )r   rE   rF   r   propertyr   r!   r!   r!   r"   rI      s    rI   c                      s2   e Zd ZdddZd fdd	ZdddZ  ZS )FuncParamTypefunct.Callable[[t.Any], t.Any]r   Nonec                 C  s   |j | _|| _d S r*   )r   r   rQ   )r    rQ   r!   r!   r"   __init__   s   
zFuncParamType.__init__r   c                      t   }| j|d< |S )NrQ   )superr#   rQ   r    Z	info_dict	__class__r!   r"   r#         

zFuncParamType.to_info_dictr$   r%   r&   r'   r(   r)   c                 C  s\   z|  |W S  ty-   zt|}W n ty"   |dd}Y nw | ||| Y d S w Nzutf-8replace)rQ   
ValueErrorr   UnicodeErrordecoder=   r,   r!   r!   r"   r+      s   zFuncParamType.convert)rQ   rR   r   rS   rA   rB   )r   rE   rF   rT   r#   r+   __classcell__r!   r!   rX   r"   rP      s    
rP   c                   @  $   e Zd ZdZdd	d
ZdddZdS )UnprocessedParamTypetextr$   r%   r&   r'   r(   r)   r   c                 C  r4   r*   r!   r,   r!   r!   r"   r+      s   zUnprocessedParamType.convertr   c                 C  r/   )NUNPROCESSEDr!   rM   r!   r!   r"   __repr__      zUnprocessedParamType.__repr__NrB   r   r   r   rE   rF   r   r+   re   r!   r!   r!   r"   rb      s    
rb   c                   @  ra   )StringParamTyperc   r$   r%   r&   r'   r(   r)   r   c                 C  s   t |trDt }z||}W |S  tyC   t }||kr:z	||}W Y |S  ty9   |dd}Y Y |S w |dd}Y |S w t|S r[   )
isinstancebytesr   r_   r^   sysgetfilesystemencodingr   )r    r$   r&   r(   encZfs_encr!   r!   r"   r+      s&   


zStringParamType.convertr   c                 C  r/   )NSTRINGr!   rM   r!   r!   r"   re      rf   zStringParamType.__repr__NrB   rg   rh   r!   r!   r!   r"   ri      s    
ri   c                      s   e Zd ZdZdZ	d.d/d
dZd0 fddZ	d1d2ddZd3ddZd4ddZ	d5dd Z
d6d$d%Zd7d&d'Zd8d(d)Zd9d,d-Z  ZS ):Choicea9  The choice type allows a value to be checked against a fixed set
    of supported values.

    You may pass any iterable value which will be converted to a tuple
    and thus will only be iterated once.

    The resulting value will always be one of the originally passed choices.
    See :meth:`normalize_choice` for more info on the mapping of strings
    to choices. See :ref:`choice-opts` for an example.

    :param case_sensitive: Set to false to make choices case
        insensitive. Defaults to true.

    .. versionchanged:: 8.2.0
        Non-``str`` ``choices`` are now supported. It can additionally be any
        iterable. Before you were not recommended to pass anything but a list or
        tuple.

    .. versionadded:: 8.2.0
        Choice normalization can be overridden via :meth:`normalize_choice`.
    choiceTchoicescabc.Iterable[ParamTypeValue]case_sensitiveboolr   rS   c                 C  s   t || _|| _d S r*   )tuplerr   rt   )r    rr   rt   r!   r!   r"   rT     s   

zChoice.__init__r   c                   s"   t   }| j|d< | j|d< |S )Nrr   rt   )rV   r#   rr   rt   rW   rX   r!   r"   r#     s   


zChoice.to_info_dictNr(   r)   !cabc.Mapping[ParamTypeValue, str]c                   s    fddj D S )a  
        Returns mapping where keys are the original choices and the values are
        the normalized values that are accepted via the command line.

        This is a simple wrapper around :meth:`normalize_choice`, use that
        instead which is supported.
        c                   s   i | ]
}|j | d qS )rq   r(   )normalize_choice.0rq   r(   r    r!   r"   
<dictcomp>  s    z.Choice._normalized_mapping.<locals>.<dictcomp>rr   )r    r(   r!   r|   r"   _normalized_mapping  s   
zChoice._normalized_mappingr   r   c                 C  sH   t |tjr	|jnt|}|dur|jdur||}| js"| }|S )a1  
        Normalize a choice value, used to map a passed string to a choice.
        Each choice must have a unique normalized value.

        By default uses :meth:`Context.token_normalize_func` and if not case
        sensitive, convert it to a casefolded value.

        .. versionadded:: 8.2.0
        N)rj   enumEnumr   r   Ztoken_normalize_funcrt   casefold)r    rq   r(   normed_valuer!   r!   r"   ry      s   

zChoice.normalize_choicer&   r   r   r.   c                 C  s~   |j dkr|jsdd | jD }dg t|}nddd | j|d D }|jr9|j dkr9d| d	S d
| dS )Noptionc                 S  s   g | ]}t t|j qS r!   )convert_typer   r   upperrz   r!   r!   r"   
<listcomp>6  s    z&Choice.get_metavar.<locals>.<listcomp>|c                 S     g | ]}t |qS r!   )r   )r{   ir!   r!   r"   r   <      r(   Zargument{}[])	Zparam_type_nameZshow_choicesrr   joindictfromkeysr   valuesrequired)r    r&   r(   Zchoice_metavarschoices_strr!   r!   r"   r1   4  s   zChoice.get_metavarc                 C  s"   t djd| j|d dS )zt
        Message shown when no choice is passed.

        .. versionchanged:: 8.2.0 Added ``ctx`` argument.
        zChoose from:
	{choices}z,
	r   r~   )_formatr   r   r   r0   r!   r!   r"   r3   F  s   zChoice.get_missing_messager$   r%   r'   c                   sf   | j ||d | j|d}zt fdd| D W S  ty2   | j| j||d||d Y dS w )z
        For a given value from the parser, normalize it and find its
        matching normalized value in the list of choices. Then return the
        matched "original" choice.
        rx   r   c                 3  s     | ]\}}| kr|V  qd S r*   r!   )r{   original
normalizedr   r!   r"   	<genexpr>\  s    z!Choice.convert.<locals>.<genexpr>)r$   r(   r&   r(   N)ry   r   nextitemsStopIterationr=   get_invalid_choice_message)r    r$   r&   r(   Znormalized_mappingr!   r   r"   r+   P  s   
zChoice.convertc                 C  s:   d tt| j|d }tddt| jj|||dS )zGet the error message when the given choice is invalid.

        :param value: The invalid value.

        .. versionadded:: 8.2
        , r   z{value!r} is not {choice}.z"{value!r} is not one of {choices}.)r$   rq   rr   )	r   mapreprr   r   r   lenrr   r   )r    r$   r(   r   r!   r!   r"   r   h  s   z!Choice.get_invalid_choice_messagec                 C  s   dt | j dS )NzChoice())listrr   rM   r!   r!   r"   re   v     zChoice.__repr__r>   r?   c                   s^   ddl m  tt| j}| jrfdd|D }n fdd|D } fdd|D S )a  Complete choices that start with the incomplete value.

        :param ctx: Invocation context for this command.
        :param param: The parameter that is requesting completion.
        :param incomplete: Value being completed. May be empty.

        .. versionadded:: 8.0
        r   r   c                 3  s    | ]
}|  r|V  qd S r*   )
startswithr{   cr>   r!   r"   r     s    z(Choice.shell_complete.<locals>.<genexpr>c                 3  s"    | ]}|   r|V  qd S r*   )lowerr   r   r   r!   r"   r     s     c                   s   g | ]} |qS r!   r!   r   r   r!   r"   r     r   z)Choice.shell_complete.<locals>.<listcomp>)click.shell_completionr   r   r   rr   rt   r   )r    r(   r&   r>   Zstr_choicesZmatchedr!   )r   r>   r"   r@   y  s   zChoice.shell_complete)T)rr   rs   rt   ru   r   rS   rA   r*   )r(   r)   r   rw   )rq   r   r(   r)   r   r   rC   )r&   r   r(   r)   r   r   )r$   r%   r&   r'   r(   r)   r   r   )r$   r%   r(   r)   r   r   rg   rD   )r   rE   rF   rG   r   rT   r#   r   ry   r1   r3   r+   r   re   r@   r`   r!   r!   rX   r"   rp      s    






rp   c                      sZ   e Zd ZdZdZd d!ddZd" fd
dZd#ddZd$ddZd%ddZ	d&ddZ
  ZS )'DateTimeaK  The DateTime type converts date strings into `datetime` objects.

    The format strings which are checked are configurable, but default to some
    common (non-timezone aware) ISO 8601 formats.

    When specifying *DateTime* formats, you should only pass a list or a tuple.
    Other iterables, like generators, may lead to surprising results.

    The format strings are processed using ``datetime.strptime``, and this
    consequently defines the format strings which are allowed.

    Parsing is tried using each format, in order, and the first format which
    parses successfully is used.

    :param formats: A list or tuple of date format strings, in the order in
                    which they should be tried. Defaults to
                    ``'%Y-%m-%d'``, ``'%Y-%m-%dT%H:%M:%S'``,
                    ``'%Y-%m-%d %H:%M:%S'``.
    r   Nformatscabc.Sequence[str] | Nonec                 C  s   |pg d| _ d S )N)z%Y-%m-%dz%Y-%m-%dT%H:%M:%Sz%Y-%m-%d %H:%M:%S)r   )r    r   r!   r!   r"   rT     r   zDateTime.__init__r   r   c                   rU   )Nr   )rV   r#   r   rW   rX   r!   r"   r#     rZ   zDateTime.to_info_dictr&   r   r(   r   r.   c                 C  s   dd | j dS )Nr   r   r   )r   r   r0   r!   r!   r"   r1        zDateTime.get_metavarr$   r%   r   r   datetime | Nonec                 C  s$   zt ||W S  ty   Y d S w r*   )r   strptimer]   )r    r$   r   r!   r!   r"   _try_to_convert_date  s
   zDateTime._try_to_convert_dater'   r)   c                 C  st   t |tr|S | jD ]}| ||}|d ur|  S q
dtt| j}| tddt	| jj
|||d|| d S )Nr   z-{value!r} does not match the format {format}.z/{value!r} does not match the formats {formats}.)r$   r   r   )rj   r   r   r   r   r   r   r=   r   r   r   )r    r$   r&   r(   r   Z	convertedZformats_strr!   r!   r"   r+     s&   

zDateTime.convertc                 C  r/   )Nr   r!   rM   r!   r!   r"   re     rf   zDateTime.__repr__r*   )r   r   rA   rC   )r$   r%   r   r   r   r   rB   rg   )r   rE   rF   rG   r   rT   r#   r1   r   r+   re   r`   r!   r!   rX   r"   r     s    


r   c                   @  s    e Zd ZU ded< dd
dZdS )_NumberParamTypeBasezt.ClassVar[type[t.Any]]_number_classr$   r%   r&   r'   r(   r)   r   c              	   C  s@   z|  |W S  ty   | tdj|| jd|| Y d S w )Nz'{value!r} is not a valid {number_type}.)r$   number_type)r   r]   r=   r   r   r   r,   r!   r!   r"   r+     s   
z_NumberParamTypeBase.convertNrB   )r   rE   rF   rH   r+   r!   r!   r!   r"   r     s   
 r   c                      s`   e Zd Z					d%d&ddZd' fddZd( fddZd)ddZd*d!d"Zd*d#d$Z  Z	S )+_NumberRangeBaseNFminfloat | Nonemaxmin_openru   max_openclampr   rS   c                 C  "   || _ || _|| _|| _|| _d S r*   r   r   r   r   r   r    r   r   r   r   r   r!   r!   r"   rT     
   
z_NumberRangeBase.__init__r   c                   s,   t   }|j| j| j| j| j| jd |S )Nr   )rV   r#   updater   r   r   r   r   rW   rX   r!   r"   r#     s   
z_NumberRangeBase.to_info_dictr$   r%   r&   r'   r(   r)   c                   s   dd l }t |||}| jd uo| jr|jn|j|| j}| jd uo/| jr)|j	n|j
|| j}| jrI|r>| | jd| jS |rI| | jd| jS |sM|r]| tdj||  d|| |S )Nr   r   z${value} is not in the range {range}.)r$   range)operatorrV   r+   r   r   leltr   r   gegtr   _clampr=   r   r   _describe_range)r    r$   r&   r(   r   r5   Zlt_minZgt_maxrX   r!   r"   r+     s0   

z_NumberRangeBase.convertboundfloatdirt.Literal[1, -1]openc                 C  s   t )zFind the valid value to clamp to bound in the given
        direction.

        :param bound: The boundary value.
        :param dir: 1 or -1 indicating the direction to move.
        :param open: If true, the range does not include the bound.
        rK   r    r   r   r   r!   r!   r"   r   #  s   z_NumberRangeBase._clampr   c                 C  s   | j du r| jr
dnd}d| | j S | jdu r(| jrdnd}d| | j  S | jr-dnd}| jr4dnd}| j  | d| | j S )z(Describe the range for use in help text.N<z<=x>z>=)r   r   r   r   )r    opZlopZropr!   r!   r"   r   -  s   

z _NumberRangeBase._describe_rangec                 C  s.   | j rdnd}dt| j d|   | dS )Nz clampedr7   r    r   )r   r   r   r   )r    r   r!   r!   r"   re   ;  s    z_NumberRangeBase.__repr__NNFFFr   r   r   r   r   ru   r   ru   r   ru   r   rS   rA   rB   r   r   r   r   r   ru   r   r   rg   )
r   rE   rF   rT   r#   r+   r   r   re   r`   r!   r!   rX   r"   r     s    


r   c                   @     e Zd ZdZeZdddZdS )IntParamTypeintegerr   r   c                 C  r/   )NINTr!   rM   r!   r!   r"   re   D  rf   zIntParamType.__repr__Nrg   )r   rE   rF   r   rJ   r   re   r!   r!   r!   r"   r   @      r   c                   @  s   e Zd ZdZdZdd
dZdS )IntRangea  Restrict an :data:`click.INT` value to a range of accepted
    values. See :ref:`ranges`.

    If ``min`` or ``max`` are not passed, any value is accepted in that
    direction. If ``min_open`` or ``max_open`` are enabled, the
    corresponding boundary is not included in the range.

    If ``clamp`` is enabled, a value outside the range is clamped to the
    boundary instead of failing.

    .. versionchanged:: 8.0
        Added the ``min_open`` and ``max_open`` parameters.
    zinteger ranger   rJ   r   r   r   ru   r   c                 C  s   |s|S || S r*   r!   r   r!   r!   r"   r   Y  s   zIntRange._clampN)r   rJ   r   r   r   ru   r   rJ   )r   rE   rF   rG   r   r   r!   r!   r!   r"   r   H  s    r   c                   @  r   )FloatParamTyper   r   r   c                 C  r/   )NFLOATr!   rM   r!   r!   r"   re   f  rf   zFloatParamType.__repr__Nrg   )r   rE   rF   r   r   r   re   r!   r!   r!   r"   r   b  r   r   c                      s<   e Zd ZdZdZ					dd fddZdddZ  ZS )
FloatRangea&  Restrict a :data:`click.FLOAT` value to a range of accepted
    values. See :ref:`ranges`.

    If ``min`` or ``max`` are not passed, any value is accepted in that
    direction. If ``min_open`` or ``max_open`` are enabled, the
    corresponding boundary is not included in the range.

    If ``clamp`` is enabled, a value outside the range is clamped to the
    boundary instead of failing. This is not supported if either
    boundary is marked ``open``.

    .. versionchanged:: 8.0
        Added the ``min_open`` and ``max_open`` parameters.
    zfloat rangeNFr   r   r   r   ru   r   r   r   rS   c                   s2   t  j|||||d |s|r|rtdd S d S )Nr   *Clamping is not supported for open bounds.)rV   rT   	TypeErrorr   rX   r!   r"   rT   |  s   
zFloatRange.__init__r   r   r   r   r   c                 C  s   |s|S t d)Nr   )RuntimeErrorr   r!   r!   r"   r     s   zFloatRange._clampr   r   r   )r   rE   rF   rG   r   rT   r   r`   r!   r!   rX   r"   r   j  s    r   c                   @  ra   )BoolParamTypebooleanr$   r%   r&   r'   r(   r)   r   c                 C  sR   |dv rt |S |  }|dv rdS |dv rdS | tdj|d|| d S )N>   FT>   trueonyes1ytT>   falsenfnooff0Fz!{value!r} is not a valid boolean.r$   )ru   stripr   r=   r   r   )r    r$   r&   r(   Znormr!   r!   r"   r+     s   zBoolParamType.convertr   c                 C  r/   )NBOOLr!   rM   r!   r!   r"   re     rf   zBoolParamType.__repr__NrB   rg   rh   r!   r!   r!   r"   r     s    
r   c                   @  ra   )UUIDParameterTypeuuidr$   r%   r&   r'   r(   r)   r   c                 C  s\   dd l }t||jr|S | }z||W S  ty-   | tdj|d|| Y d S w )Nr   z{value!r} is not a valid UUID.r   )r   rj   UUIDr   r]   r=   r   r   )r    r$   r&   r(   r   r!   r!   r"   r+     s   
zUUIDParameterType.convertr   c                 C  r/   )Nr   r!   rM   r!   r!   r"   re     rf   zUUIDParameterType.__repr__NrB   rg   rh   r!   r!   r!   r"   r     s    
r   c                      sl   e Zd ZU dZdZejjZde	d< 					d+d,ddZ
d- fddZd.ddZd/d#d$Zd0d)d*Z  ZS )1Filea+  Declares a parameter to be a file for reading or writing.  The file
    is automatically closed once the context tears down (after the command
    finished working).

    Files can be opened for reading or writing.  The special value ``-``
    indicates stdin or stdout depending on the mode.

    By default, the file is opened for reading text data, but it can also be
    opened in binary mode or for writing.  The encoding parameter can be used
    to force a specific encoding.

    The `lazy` flag controls if the file should be opened immediately or upon
    first IO. The default is to be non-lazy for standard input and output
    streams as well as files opened for reading, `lazy` otherwise. When opening a
    file lazily for reading, it is still opened temporarily for validation, but
    will not be held open until first IO. lazy is mainly useful when opening
    for writing to avoid creating the file until it is needed.

    Files can also be opened atomically in which case all writes go into a
    separate file in the same folder and upon completion the file will
    be moved over to the original location.  This is useful if a file
    regularly read by other users is modified.

    See :ref:`file-args` for more information.

    .. versionchanged:: 2.0
        Added the ``atomic`` parameter.
    filenamet.ClassVar[str]r   rNstrictFmoder   encodingr.   errorslazybool | Noneatomicru   r   rS   c                 C  r   r*   )r  r  r  r  r  )r    r  r  r  r  r  r!   r!   r"   rT     r   zFile.__init__r   c                   s    t   }|j| j| jd |S )N)r  r  )rV   r#   r   r  r  rW   rX   r!   r"   r#     s   
zFile.to_info_dictr$   str | os.PathLike[str]c                 C  s4   | j d ur| j S t|dkrdS d| jv rdS dS )N-FwT)r  osfspathr  r    r$   r!   r!   r"   resolve_lazy_flag  s   

zFile.resolve_lazy_flag$str | os.PathLike[str] | t.IO[t.Any]r&   r'   r(   r)   t.IO[t.Any]c           	   
   C  s   t |r|S td|}zP| |}|r2t|| j| j| j| jd}|d ur+|	|j
 td|W S t|| j| j| j| jd\}}|d urZ|rR|	t|j |W S |	t|j |W S  ty } z| dt| d|j || W Y d }~d S d }~ww )Nr  )r  r  'z': )_is_file_liker   castr  r   r  r  r  r  Zcall_on_closeZclose_intelligentlyr   r   closeflushOSErrorr=   r   strerror)	r    r$   r&   r(   r  lfr   Zshould_closeer!   r!   r"   r+     s2   

	.zFile.convertr   r   r>   r?   c                 C  s   ddl m} ||ddgS )ac  Return a special completion marker that tells the completion
        system to use the shell to provide file path completions.

        :param ctx: Invocation context for this command.
        :param param: The parameter that is requesting completion.
        :param incomplete: Value being completed. May be empty.

        .. versionadded:: 8.0
        r   r   filer   )r   r   )r    r(   r&   r>   r   r!   r!   r"   r@   .  s   zFile.shell_complete)r   Nr   NF)r  r   r  r.   r  r.   r  r  r  ru   r   rS   rA   )r$   r  r   ru   )r$   r  r&   r'   r(   r)   r   r  rD   )r   rE   rF   rG   r   r
  pathpathsepr   rH   rT   r#   r  r+   r@   r`   r!   r!   rX   r"   r     s   
 

	+r   r$   r%   r   te.TypeGuard[t.IO[t.Any]]c                 C  s   t | dp	t | dS )Nreadwrite)r   r   r!   r!   r"   r  ?  r   r  c                      sp   e Zd ZU dZejjZded< 									d*d+ddZ	d, fddZ
d-ddZd.d!d"Zd/d(d)Z  ZS )0Patha  The ``Path`` type is similar to the :class:`File` type, but
    returns the filename instead of an open file. Various checks can be
    enabled to validate the type of file and permissions.

    :param exists: The file or directory needs to exist for the value to
        be valid. If this is not set to ``True``, and the file does not
        exist, then all further checks are silently skipped.
    :param file_okay: Allow a file as a value.
    :param dir_okay: Allow a directory as a value.
    :param readable: if true, a readable check is performed.
    :param writable: if true, a writable check is performed.
    :param executable: if true, an executable check is performed.
    :param resolve_path: Make the value absolute and resolve any
        symlinks. A ``~`` is not expanded, as this is supposed to be
        done by the shell only.
    :param allow_dash: Allow a single dash as a value, which indicates
        a standard stream (but does not open it). Use
        :func:`~click.open_file` to handle opening this value.
    :param path_type: Convert the incoming path value to this type. If
        ``None``, keep Python's default, which is ``str``. Useful to
        convert to :class:`pathlib.Path`.

    .. versionchanged:: 8.1
        Added the ``executable`` parameter.

    .. versionchanged:: 8.0
        Allow passing ``path_type=pathlib.Path``.

    .. versionchanged:: 6.0
        Added the ``allow_dash`` parameter.
    r   r   FTNexistsru   	file_okaydir_okaywritablereadableresolve_path
allow_dash	path_typetype[t.Any] | None
executablec
           
      C  sx   || _ || _|| _|| _|| _|	| _|| _|| _|| _| jr(| js(t	d| _
d S | jr5| js5t	d| _
d S t	d| _
d S )Nr  	directoryr  )r!  r"  r#  r%  r$  r*  r&  r'  r   r   r   )
r    r!  r"  r#  r$  r%  r&  r'  r(  r*  r!   r!   r"   rT   f  s   zPath.__init__r   r   c                   s0   t   }|j| j| j| j| j| j| jd |S )N)r!  r"  r#  r$  r%  r'  )	rV   r#   r   r!  r"  r#  r$  r%  r'  rW   rX   r!   r"   r#     s   
zPath.to_info_dictr$   r  str | bytes | os.PathLike[str]c                 C  sT   | j d ur(t|| j s(| j tu rt|S | j tu rt|S td|  |S |S )Nzos.PathLike[str])	r   rj   r   r
  fsdecoderk   fsencoder   r  r  r!   r!   r"   coerce_path_result  s   



zPath.coerce_path_resultr&   r'   r(   r)   c              	   C  s  |}| j o| jo|dv }|s| jrtj|}zt|}W n& tyD   | js/| 	| Y S | 
tdj| j t|d|| Y nw | j sat|jra| 
tdj| j t|d|| | js}t|jr}| 
tdj| j t|d|| | jrt|tjs| 
tdj| j t|d|| | jrt|tjs| 
tdj| j t|d|| | jrt|tjs| 
tdj| j t|d|| | 	|S )	N)   -r  z#{name} {filename!r} does not exist.)r   r   z{name} {filename!r} is a file.z#{name} {filename!r} is a directory.z${name} {filename!r} is not readable.z${name} {filename!r} is not writable.z&{name} {filename!r} is not executable.)r"  r'  r&  r
  r  realpathstatr  r!  r/  r=   r   r   r   titler   S_ISREGst_moder#  S_ISDIRr%  accessR_OKr$  W_OKr*  X_OK)r    r$   r&   r(   r5   Zis_dashstr!   r!   r"   r+     sv   
zPath.convertr   r   r>   r   r?   c                 C  s.   ddl m} | jr| jsdnd}|||dgS )a  Return a special completion marker that tells the completion
        system to use the shell to provide path completions for only
        directories or any paths.

        :param ctx: Invocation context for this command.
        :param param: The parameter that is requesting completion.
        :param incomplete: Value being completed. May be empty.

        .. versionadded:: 8.0
        r   r   r   r  r  )r   r   r#  r"  )r    r(   r&   r>   r   r   r!   r!   r"   r@     s   zPath.shell_complete)	FTTFTFFNF)r!  ru   r"  ru   r#  ru   r$  ru   r%  ru   r&  ru   r'  ru   r(  r)  r*  ru   rA   )r$   r  r   r,  )r$   r  r&   r'   r(   r)   r   r,  rD   )r   rE   rF   rG   r
  r  r  r   rH   rT   r#   r/  r+   r@   r`   r!   r!   rX   r"   r   C  s"   
  

Ir   c                      sR   e Zd ZdZdddZd fd	d
ZedddZedddZdddZ	  Z
S )Tuplea  The default behavior of Click is to apply a type on a value directly.
    This works well in most cases, except for when `nargs` is set to a fixed
    count and different types should be used for different items.  In this
    case the :class:`Tuple` type can be used.  This type can only be used
    if `nargs` is set to a fixed number.

    For more information see :ref:`tuple-type`.

    This can be selected by using a Python tuple literal as a type.

    :param types: a list of types that should be used for the tuple items.
    types&cabc.Sequence[type[t.Any] | ParamType]r   rS   c                 C  s   dd |D | _ d S )Nc                 S  r   r!   )r   r{   tyr!   r!   r"   r     r   z"Tuple.__init__.<locals>.<listcomp>)r=  )r    r=  r!   r!   r"   rT     r   zTuple.__init__r   c                   s"   t   }dd | jD |d< |S )Nc                 S  s   g | ]}|  qS r!   )r#   )r{   r   r!   r!   r"   r     r   z&Tuple.to_info_dict.<locals>.<listcomp>r=  )rV   r#   r=  rW   rX   r!   r"   r#   	  s   
zTuple.to_info_dictr   c                 C  s   dd dd | jD  dS )Nr   r   c                 s  s    | ]}|j V  qd S r*   )r   r?  r!   r!   r"   r     s    zTuple.name.<locals>.<genexpr>r   )r   r=  rM   r!   r!   r"   r     s   z
Tuple.namerJ   c                 C  s
   t | jS r*   )r   r=  rM   r!   r!   r"   r     s   
zTuple.arityr$   r%   r&   r'   r(   r)   c                   s`   t | j}t |}||kr| jtdd|j||d d t fddt| j|ddD S )	Nz:{len_type} values are required, but {len_value} was given.z;{len_type} values are required, but {len_value} were given.)len_type	len_valuer   c                 3  s     | ]\}}|| V  qd S r*   r!   )r{   r@  r   r<   r!   r"   r   '  s    
z Tuple.convert.<locals>.<genexpr>F)r   )r   r=  r=   r   r   rv   zip)r    r$   r&   r(   rA  rB  r!   r<   r"   r+     s"   

zTuple.convert)r=  r>  r   rS   rA   rg   rN   rB   )r   rE   rF   rG   rT   r#   rO   r   r   r+   r`   r!   r!   rX   r"   r<    s    
r<  r@  t.Any | Nonedefaultc                 C  s  d}| du r1|dur1t |ttfr+|r*|d }t |ttfr&ttt|} n	t|} nt|} d}t | tr:t| S t | trA| S | tu sI| du rKtS | t	u rQt
S | tu rWtS | tu r]tS |ratS 	 zt| trptd|  dW t| S  ty   Y t| S w )zFind the most appropriate :class:`ParamType` for the given Python
    type. If the type isn't provided, it can be inferred from a default
    value.
    FNr   Tz3Attempted to use an uninstantiated parameter type (z).)rj   rv   r   r   r   r<  r   r   ro   rJ   r   r   r   ru   r   
issubclassAssertionErrorr   rP   )r@  rE  Zguessed_typeitemr!   r!   r"   r   ,  sJ   



r   c                   @  s.   e Zd ZU ded< ded< ded< ded< dS )OptionHelpExtraztuple[str, ...]envvarsr   rE  r   r   N)r   rE   rF   rH   r!   r!   r!   r"   rI    s
   
 rI  F)total)r$   r%   r   r  r*   )r@  rD  rE  rD  r   r   )?
__future__r   collections.abcabcZcabcr   r
  r2  rl   typingr   r   r   r   r   Z_compatr   r   
exceptionsr
   utilsr   r   r   TYPE_CHECKINGZtyping_extensionstecorer   r   Zshell_completionr   TypeVarr   r   rI   rP   rb   ri   Genericrp   r   r   r   r   r   r   r   r   r   r   r  r   r<  r   rd   ro   r   r   r   r   	TypedDictrI  r!   r!   r!   r"   <module>   sh    
  )GV+
y 64G