
    hF                     L   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$                  rd dlZddlmZ ddlmZ ddlmZ  G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d d e!      Z" G d! d"e!      Z# G d# d$e"e#      Z$ G d% d&e!      Z% G d' d(e"e%      Z& G d) d*e      Z' G d+ d,e      Z( G d- d.e      Z)d/ejT                  d0d1fd2Z+ G d3 d4e      Z, G d5 d6e      Z-d:d7ej\                  ejT                     d8ej\                  ejT                     d0efd9Z/ e       Z0 e       Z1 e#       Z2 e%       Z3 e'       Z4 e(       Z5y);    N)datetime)gettext)ngettext   )_get_argv_encoding)open_streamBadParameter)format_filename)LazyFile)safecall)Context)	ParameterCompletionItemc            	          e Zd ZU dZdZej                  e   ed<   dZ	ej                  e
   ed<   eed<   dZej                  ej                  e      ed<   d	ej                  eej                  f   fd
Z	 	 ddej                  dej                  d   dej                  d   d	ej                  fdZddd	ej                  e   fdZddd	ej                  e   fdZdej                  dej                  d   dej                  d   d	ej                  fdZded	ej*                  e   fdZ	 	 ddedej                  d   dej                  d   d	dfdZddddded	ej0                  d   fdZy)	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.
    Fis_compositer   aritynameNenvvar_list_splitterreturnc                     t        |       j                  j                  d      d   }|j                  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   ParameterTyper   )
param_typer   )type__name__	partitionhasattrr   )selfr   r   s      4D:\EasyAligner\venv\Lib\site-packages\click/types.pyto_info_dictzParamType.to_info_dict8   s]     $Z((22;?B
))/:1=
 4 99DD($77    valueparamr   ctxr   c                 .    || j                  |||      S y N)convertr    r$   r%   r&   s       r!   __call__zParamType.__call__M   s"     <<uc22 r#   c                      y)z>Returns the metavar default for this param if it provides one.N r    r%   s     r!   get_metavarzParamType.get_metavarV       r#   c                      y)ztOptionally might return extra information about a missing
        parameter.

        .. versionadded:: 2.0
        Nr-   r.   s     r!   get_missing_messagezParamType.get_missing_messageY   r0   r#   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*   s       r!   r)   zParamType.convert`   s	    , r#   rvc                 @    |xs dj                  | 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    r4   s     r!   split_envvar_valuezParamType.split_envvar_valuex   s     b 9 9::r#   messagez
t.NoReturnc                     t        |||      )z4Helper method to fail with an invalid value message.)r&   r%   r	   )r    r9   r%   r&   s       r!   failzParamType.fail   s     7599r#   
incompleter   c                     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<   s       r!   shell_completezParamType.shell_complete   s	     	r#   )NN)r   
__module____qualname____doc__r   tClassVarbool__annotations__r   intstrr   OptionalDictAnyr"   r+   r/   r2   r)   Sequencer8   r;   Listr>   r-   r#   r!   r   r      s   " &+L!**T"*E1::c? I 9=!**QZZ_5<8affS!%%Z0 80 *.%)	3uu3 zz+&3 ZZ	"	3
 
3M MC M C UU#$::k#:ABIAV	
0;S ;QZZ_ ; *.%)	:: zz+&: ZZ	"	:
 
:%0>A	
 	!r#   r   c                   &    e Zd ZdZedefd       Zy)CompositeParamTypeTr   c                     t               r(   NotImplementedErrorr    s    r!   r   zCompositeParamType.arity   s    !##r#   N)r   r?   r@   r   propertyrF   r   r-   r#   r!   rN   rN      s     L$s $ $r#   rN   c                   "    e Zd Zdej                  ej
                  gej
                  f   ddfdZdej                  eej
                  f   f fdZ	dej
                  dej                  d   d	ej                  d
   dej
                  fdZ xZS )FuncParamTypefuncr   Nc                 4    |j                   | _        || _        y r(   )r   r   rV   )r    rV   s     r!   __init__zFuncParamType.__init__   s    		r#   c                 B    t         |          }| j                  |d<   |S )NrV   )superr"   rV   r    	info_dict	__class__s     r!   r"   zFuncParamType.to_info_dict   s$    G(*	 II	&r#   r$   r%   r   r&   r   c                     	 | j                  |      S # t        $ rD 	 t        |      }n!# t        $ r |j	                  dd      }Y nw xY w| j                  |||       Y y w xY wNzutf-8replace)rV   
ValueErrorrG   UnicodeErrordecoder;   r*   s       r!   r)   zFuncParamType.convert   sd    	)99U## 	)9E
 9Wi89 IIeUC(	)s/    	A )A AA AA A )r   r?   r@   rB   CallablerJ   rX   rI   rG   r"   rH   r)   __classcell__r]   s   @r!   rU   rU      s    QZZ7 D affS!%%Z0 
)UU)#$::k#:)ABIAV)	
)r#   rU   c                       e Zd ZdZdej
                  dej                  d   dej                  d   dej
                  fdZdefd	Z	y
)UnprocessedParamTypetextr$   r%   r   r&   r   r   c                     |S r(   r-   r*   s       r!   r)   zUnprocessedParamType.convert   s	     r#   c                      y)NUNPROCESSEDr-   rR   s    r!   __repr__zUnprocessedParamType.__repr__   s    r#   N
r   r?   r@   r   rB   rJ   rH   r)   rG   rm   r-   r#   r!   rh   rh      sR    DUU#$::k#:ABIAV	

# r#   rh   c                       e Zd ZdZdej
                  dej                  d   dej                  d   dej
                  fdZdefd	Z	y
)StringParamTyperi   r$   r%   r   r&   r   r   c                 Z   t        |t              rt               }	 |j                  |      }|S t        |      S # t        $ rg t        j                         }||k7  r8	 |j                  |      }Y |S # t        $ r |j                  dd      }Y Y |S w xY w|j                  dd      }Y |S w xY wr_   )
isinstancebytesr   rc   rb   sysgetfilesystemencodingrG   )r    r$   r%   r&   encfs_encs         r!   r)   zStringParamType.convert   s     eU#$&C
=S) L5z   =224S=A %V 4
 L	 ( A %Wi @ L	A "LL)<EL=s-   : "B*A11BB*BB*)B*c                      y)NSTRINGr-   rR   s    r!   rm   zStringParamType.__repr__   s    r#   Nrn   r-   r#   r!   rp   rp      sR    DUU#$::k#:ABIAV	
&# r#   rp   c            	       `    e Zd ZdZdZddej                  e   deddfdZ	dej                  eej                  f   f fdZd	d
defdZd	d
defdZdej                  d	ej                  d
   dej                  d   dej                  fdZdefdZddd	d
dedej$                  d   fdZ xZS )Choicea>  The choice type allows a value to be checked against a fixed set
    of supported values. All of these values have to be strings.

    You should only pass a list or tuple of choices. Other iterables
    (like generators) may lead to surprising results.

    The resulting value will always be one of the originally passed choices
    regardless of ``case_sensitive`` or any ``ctx.token_normalize_func``
    being specified.

    See :ref:`choice-opts` for an example.

    :param case_sensitive: Set to false to make choices case
        insensitive. Defaults to true.
    choicechoicescase_sensitiver   Nc                      || _         || _        y r(   )r}   r~   )r    r}   r~   s      r!   rX   zChoice.__init__   s    ,r#   c                 `    t         |          }| j                  |d<   | j                  |d<   |S )Nr}   r~   )rZ   r"   r}   r~   r[   s     r!   r"   zChoice.to_info_dict   s5    G(*	#||	)&*&9&9	"#r#   r%   r   c                     dj                  | j                        }|j                  r|j                  dk(  rd| dS d| dS )N|argument{}[])joinr}   requiredparam_type_name)r    r%   choices_strs      r!   r/   zChoice.get_metavar   sJ    hht||, >>e33zA}B'' ;-q!!r#   c                 j    t        d      j                  dj                  | j                              S )NzChoose from:
	{choices}z,
	)r}   )_formatr   r}   r.   s     r!   r2   zChoice.get_missing_message
  s)    ,-44W\\$,,=W4XXr#   r$   r&   r   c           	         |}| j                   D ci c]  }|| }}|O|j                  C|j                  |      }|j                         D ci c]  \  }}|j                  |      | }}}| j                  sA|j	                         }|j                         D ci c]  \  }}|j	                         | }}}||v r||   S dj                  t        t        | j                               }	| j                  t        ddt        | j                               j                  ||	|	      ||       y c c}w c c}}w c c}}w )N, z{value!r} is not {choice}.z"{value!r} is not one of {choices}.)r$   r|   r}   )r}   token_normalize_funcitemsr~   casefoldr   mapreprr;   r   lenr   )
r    r$   r%   r&   normed_valuer|   normed_choicesnormed_choiceoriginalr   s
             r!   r)   zChoice.convert  sX    7;||D|V&&.|D?s77C33E:L 0>/C/C/E/E+M8 ((7A/E  
 ""'002L 0>/C/C/E/E+M8 &&((2/E  
 >)!,//iiD$,, 78		,4DLL! f5kfJ	
) Es   
D1D6D<c                 4    dt        | j                         dS )NzChoice())listr}   rR   s    r!   rm   zChoice.__repr__3  s    dll+,A..r#   r<   r   c                     ddl m} t        t        | j                        }| j
                  rfd|D        }nj                         fd|D        }|D cg c]
  } ||       c}S c c}w )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   F   K   | ]  }|j                        s|  y wr(   )
startswith.0cr<   s     r!   	<genexpr>z(Choice.shell_complete.<locals>.<genexpr>F  s     J+Qj1Iq+s   !!c              3   b   K   | ]&  }|j                         j                        s#| ( y wr(   )lowerr   r   s     r!   r   z(Choice.shell_complete.<locals>.<genexpr>I  s%     R+Q1E1Ej1Qq+s   $//)click.shell_completionr   r   rG   r}   r~   r   )r    r&   r%   r<   r   str_choicesmatchedr   s      `    r!   r>   zChoice.shell_complete6  s`     	:#t||,J+JG#))+JR+RG+237aq!7333s   A+)T)r   r?   r@   rA   r   rB   rK   rG   rD   rX   rI   rJ   r"   r/   r2   rH   r)   rm   rL   r>   re   rf   s   @r!   r{   r{      s      D-

3 - -QU -affS!%%Z0 " " "Y Y Y$
UU$
#$::k#:$
ABIAV$
	
$
L/# /44%04>A4	
 	!4r#   r{   c                   r    e Zd ZdZdZddej                  ej                  e      fdZ	dej                  eej                  f   f fdZdddefd	Zd
ej                  dedej                  e   fdZd
ej                  dej                  d   dej                  d   dej                  fdZdefdZ x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   formatsc                     |xs g d| _         y )N)z%Y-%m-%dz%Y-%m-%dT%H:%M:%Sz%Y-%m-%d %H:%M:%S)r   )r    r   s     r!   rX   zDateTime.__init__e  s    (/ )
 4
r#   r   c                 B    t         |          }| j                  |d<   |S )Nr   )rZ   r"   r   r[   s     r!   r"   zDateTime.to_info_dictl  s$    G(*	#||	)r#   r%   r   c                 @    ddj                  | j                         dS )Nr   r   r   )r   r   r.   s     r!   r/   zDateTime.get_metavarq  s    388DLL)*!,,r#   r$   r   c                 N    	 t        j                  ||      S # t        $ r Y y w xY wr(   )r   strptimera   )r    r$   r   s      r!   _try_to_convert_datezDateTime._try_to_convert_datet  s,    	$$UF33 		s    	$$r&   r   c           	      R   t        |t              r|S | j                  D ]  }| j                  ||      }||c S  dj	                  t        t        | j                              }| j                  t        ddt        | j                              j                  |||      ||       y )Nr   z-{value!r} does not match the format {format}.z/{value!r} does not match the formats {formats}.)r$   r   r   )rr   r   r   r   r   r   r   r;   r   r   r   )r    r$   r%   r&   r   	convertedformats_strs          r!   r)   zDateTime.convertz  s     eX&LllF11%@I$  	 # iiD$,, 78		?ADLL! f5kfJ	
r#   c                      y)Nr   r-   rR   s    r!   rm   zDateTime.__repr__  s    r#   r(   )r   r?   r@   rA   r   rB   rH   rK   rG   rX   rI   rJ   r"   r/   r   r   r)   rm   re   rf   s   @r!   r   r   N  s    ( D


1::c? ; 
affS!%%Z0 
- - -!%%  HAU 
UU
#$::k#:
ABIAV
	

.# r#   r   c                       e Zd ZU ej                  ej
                  ej                        ed<   dej                  dej                  d   dej                  d   dej                  fdZ	y	)
_NumberParamTypeBase_number_classr$   r%   r   r&   r   r   c                     	 | j                  |      S # t        $ r: | j                  t        d      j	                  || j
                        ||       Y y w xY w)Nz'{value!r} is not a valid {number_type}.)r$   number_type)r   ra   r;   r   r   r   r*   s       r!   r)   z_NumberParamTypeBase.convert  s^    		%%e,, 	II;<CCTYY D  	s    A AAN)
r   r?   r@   rB   rC   TyperJ   rE   rH   r)   r-   r#   r!   r   r     s\    ::affQUUm,,UU#$::k#:ABIAV	
r#   r   c                   ^    e Zd Z	 	 	 	 	 ddej                  e   dej                  e   dedededdfdZdej                  e	ej                  f   f fd	Zd
ej                  dej                  d   dej                  d   dej                  f fdZdedddedefdZde	fdZde	fdZ xZS )_NumberRangeBaseNminmaxmin_openmax_openclampr   c                 J    || _         || _        || _        || _        || _        y r(   r   r   r   r   r   )r    r   r   r   r   r   s         r!   rX   z_NumberRangeBase.__init__  s'       
r#   c                     t         |          }|j                  | j                  | j                  | j
                  | j                  | j                         |S )Nr   )rZ   r"   updater   r   r   r   r   r[   s     r!   r"   z_NumberRangeBase.to_info_dict  sN    G(*	]]]]** 	 	
 r#   r$   r%   r   r&   r   c                    dd l }t        | 	  |||      }| j                  d uxr5  | j                  r|j
                  n|j                  || j                        }| j                  d uxr5  | j                  r|j                  n|j                  || j                        }| j                  rR|r'| j                  | j                  d| j                        S |r'| j                  | j                  d| j                        S |s|r;| j                  t        d      j                  || j!                               ||       |S )Nr   r   z${value} is not in the range {range}.)r$   range)operatorrZ   r)   r   r   leltr   r   gegtr   _clampr;   r   r   _describe_range)	r    r$   r%   r&   r   r4   lt_mingt_maxr]   s	           r!   r)   z_NumberRangeBase.convert  s    	W_UE3/xxt+ 94==HKKhkk
dhh1 xxt+ 94==HKKhkk
dhh1 ::{{488Q>>{{488R??VII89@@D$8$8$: A   	r#   bounddirte.Literal[1, -1]openc                     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.
        rP   r    r   r   r   s       r!   r   z_NumberRangeBase._clamp  s
     "!r#   c                 4   | j                   !| j                  rdnd}d| | j                   S | j                  !| j                  rdnd}d| | j                    S | j                  rdnd}| j                  rdnd}| j                    | d| | j                   S )z(Describe the range for use in help text.<z<=x>z>=)r   r   r   r   )r    oploprops       r!   r   z _NumberRangeBase._describe_range  s    884Brd488*%%884Brd488*%%]]c]]c((C5#txxj11r#   c                 z    | j                   rdnd}dt        |       j                   d| j                          | dS )Nz clampedr6   r    r   )r   r   r   r   )r    r   s     r!   rm   z_NumberRangeBase.__repr__  s=    "jj
b4:&&'q)=)=)?(@qIIr#   NNFFF)r   r?   r@   rB   rH   floatrD   rX   rI   rG   rJ   r"   r)   r   r   rm   re   rf   s   @r!   r   r     s     "&!%ZZ ZZ 	
   
	affS!%%Z0 	UU#$::k#:ABIAV	
>"E "(; "4 "E "2 2J# Jr#   r   c                        e Zd ZdZeZdefdZy)IntParamTypeintegerr   c                      y)NINTr-   rR   s    r!   rm   zIntParamType.__repr__  s    r#   N)r   r?   r@   r   rF   r   rG   rm   r-   r#   r!   r   r     s    DM# r#   r   c                   ,    e Zd ZdZdZdedddedefdZy	)
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   r   r   r   r   c                     |s|S ||z   S r(   r-   r   s       r!   r   zIntRange._clamp  s     Ls{r#   N)r   r?   r@   rA   r   rF   rD   r   r-   r#   r!   r   r     s3     D2:>	r#   r   c                        e Zd ZdZeZdefdZy)FloatParamTyper   r   c                      y)NFLOATr-   rR   s    r!   rm   zFloatParamType.__repr__#  s    r#   N)r   r?   r@   r   r   r   rG   rm   r-   r#   r!   r   r     s    DM# r#   r   c                        e Zd ZdZdZ	 	 	 	 	 ddej                  e   dej                  e   dededed	df fd
Z	deddded	efdZ
 x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 rangeNr   r   r   r   r   r   c                 R    t         |   |||||       |s|r|rt        d      y y )Nr   *Clamping is not supported for open bounds.)rZ   rX   	TypeError)r    r   r   r   r   r   r]   s         r!   rX   zFloatRange.__init__9  s>     	x(% 	 	
 eHII ',r#   r   r   r   r   c                      |s|S t        d      )Nr   )RuntimeErrorr   s       r!   r   zFloatRange._clampH  s    L
 GHHr#   r   )r   r?   r@   rA   r   rB   rH   r   rD   rX   r   re   rf   s   @r!   r   r   '  s     D "&!%JZZJ ZZJ 	J
 J J 
JIE I(; I4 IE Ir#   r   c                       e Zd ZdZdej
                  dej                  d   dej                  d   dej
                  fdZdefd	Z	y
)BoolParamTypebooleanr$   r%   r   r&   r   r   c                     |dv rt        |      S |j                         j                         }|dv ry|dv ry| j                  t	        d      j                  |      ||       y )N>   FT>   1rB   yonyestrueT>   0fnnoofffalseFz!{value!r} is not a valid boolean.r$   )rD   stripr   r;   r   r   )r    r$   r%   r&   norms        r!   r)   zBoolParamType.convertU  si     M!;{{}""$7788		12999Fs	
r#   c                      y)NBOOLr-   rR   s    r!   rm   zBoolParamType.__repr__g      r#   Nrn   r-   r#   r!   r   r   R  sR    D
UU
#$::k#:
ABIAV
	

$# r#   r   c                       e Zd ZdZdej
                  dej                  d   dej                  d   dej
                  fdZdefd	Z	y
)UUIDParameterTypeuuidr$   r%   r   r&   r   r   c                     dd l }t        ||j                        r|S |j                         }	 |j                  |      S # t        $ r/ | j                  t        d      j                  |      ||       Y y w xY w)Nr   z{value!r} is not a valid UUID.r  )r  rr   UUIDr  ra   r;   r   r   )r    r$   r%   r&   r  s        r!   r)   zUUIDParameterType.convertn  sp     	eTYY'L	99U## 	II23:::GPS	s   ? 5A76A7c                      y)Nr  r-   rR   s    r!   rm   zUUIDParameterType.__repr__  r  r#   Nrn   r-   r#   r!   r  r  k  sR    DUU#$::k#:ABIAV	
"# r#   r  c                   4    e Zd ZU dZdZej                  j                  Ze	j                  e   ed<   	 	 	 	 	 ddede	j                  e   de	j                  e   de	j                  e   d	ed
dfdZd
e	j                   ee	j"                  f   f fdZddd
efdZde	j(                  ede	j*                  e	j"                     f   de	j                  d   de	j                  d   d
e	j*                  e	j"                     fdZddddded
e	j.                  d   fdZ xZS )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.
    filenamer   Nmodeencodingerrorslazyatomicr   c                 J    || _         || _        || _        || _        || _        y r(   )r  r  r  r  r  )r    r  r  r  r  r  s         r!   rX   zFile.__init__  s'     	 	r#   c                 r    t         |          }|j                  | j                  | j                         |S )N)r  r  )rZ   r"   r   r  r  r[   s     r!   r"   zFile.to_info_dict  s1    G(*	dii$--@r#   r$   t.Union[str, os.PathLike[str]]c                     | j                   | j                   S t        j                  |      dk(  ryd| j                  v ryy)N-FwT)r  osfspathr  r    r$   s     r!   resolve_lazy_flagzFile.resolve_lazy_flag  s<    99 9999Us"DIIr#   os.PathLike[str]r%   r   r&   r   c                    t        |      r|S t        j                  d|      }	 | j                  |      }|rt	        || j
                  | j                  | j                  | j                        }||j                  |j                         t        j                  t        j                  t        j                     |      S t        || j
                  | j                  | j                  | j                        \  }}|L|r&|j                  t        |j                               |S |j                  t        |j                                |S # t"        $ r6}| j%                  dt'        |       d|j(                   ||       Y d }~y d }~ww xY w)Nr  )r  'z': )_is_file_likerB   castr$  r   r  r  r  r  call_on_closeclose_intelligentlyIOrJ   r   r   closeflushOSErrorr;   r   strerror)	r    r$   r%   r&   r  lfr  should_closees	            r!   r)   zFile.convert  sC    L7?	O))%0D499dmmT[[ ?%%b&<&<=vvadd155k2..)tyy$--T[[OA| %%hqww&78 H %%hqww&78H 	OII/%01QZZLA5#NN	Os%   BE A$E '%E 	F,FFr<   r   c                 $    ddl m}  ||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   s        r!   r>   zFile.shell_complete  s     	:z788r#   )rNstrictNF)r   r?   r@   rA   r   r!  pathpathsepr   rB   rC   rG   rE   rH   rD   rX   rI   rJ   r"   r$  Unionr,  r)   rL   r>   re   rf   s   @r!   r  r    s_   : D,.GGOO!**S/; $("*!% **S/ 

3	
 jj  
affS!%%Z0 
'G D )Owws.QUU;<)O zz+&)O ZZ	"	)O
 
aee)OV99%09>A9	
 	!9r#   r  r$   r   zte.TypeGuard[t.IO[t.Any]]c                 6    t        | d      xs t        | d      S )Nreadwrite)r   r  s    r!   r(  r(    s    5&!<WUG%<<r#   c                       e Zd ZU dZej
                  j                  Zej                  e
   ed<   	 	 	 	 	 	 	 	 	 ddedededededed	ed
ej                  ej                  ej                        defdZdej"                  e
ej                  f   f fdZ	 	 	 	 ddZdddej                  d   dej                  d   ddfdZddddde
dej*                  d   fdZ xZS )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   exists	file_okaydir_okaywritablereadableresolve_path
allow_dash	path_type
executablec
                 F   || _         || _        || _        || _        || _        |	| _        || _        || _        || _        | j                  r| j                  st        d      | _
        y | j                  r| j                  st        d      | _
        y t        d      | _
        y )Nr5  	directoryr9  )rA  rB  rC  rE  rD  rI  rF  rG  r   r   r   )
r    rA  rB  rC  rD  rE  rF  rG  rH  rI  s
             r!   rX   zPath.__init__#  s     "   $($	>>$--vYDI]]4>>+DI&	DIr#   r   c                     t         |          }|j                  | j                  | j                  | j
                  | j                  | j                  | j                         |S )N)rA  rB  rC  rD  rE  rG  )	rZ   r"   r   rA  rB  rC  rD  rE  rG  r[   s     r!   r"   zPath.to_info_dict@  sU    G(*	;;nn]]]]]] 	 	
 r#   r$   r  %t.Union[str, bytes, os.PathLike[str]]c                 0   | j                   t        || j                         ss| j                   t        u rt        j                  |      S | j                   t
        u rt        j                  |      S t        j                  d| j                  |            S |S )Nr%  )	r   rr   rG   r!  fsdecoders   fsencoderB   r)  r#  s     r!   coerce_path_resultzPath.coerce_path_resultL  sq     99 E499)EyyC{{5))e#{{5))vv0$))E2BCCr#   r%   r   r&   r   c           	         |}| j                   xr | j                  xr |dv }|s| j                  r6dd l}t	        j
                  |j                  |      j                               }	 t	        j                  |      }| j                   smt        j$                  j&                        rN| j                  t        d      j                  | j                  j!                         t#        |            ||       | j(                  smt        j*                  j&                        rN| j                  t        d      j                  | j                  j!                         t#        |            ||       | j,                  rrt	        j.                  |t        j0                        sN| j                  t        d      j                  | j                  j!                         t#        |            ||       | j2                  rrt	        j.                  |t        j4                        sN| j                  t        d      j                  | j                  j!                         t#        |            ||       | j6                  rrt	        j.                  |t        j8                        sN| j                  t        d	      j                  | j                  j!                         t#        |            ||       | j                  |      S # t        $ rq | j                  s| j                  |      cY S | j                  t        d      j                  | j                  j!                         t#        |            ||       Y w xY w)
N)   -r  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.)rB  rG  rF  pathlibr!  rO  r@  resolvestatr/  rA  rQ  r;   r   r   r   titler   S_ISREGst_moderC  S_ISDIRrE  accessR_OKrD  W_OKrI  X_OK)r    r$   r%   r&   r4   is_dashrT  sts           r!   r)   zPath.convertY  s    ..JT__J{9J   [[b!1!9!9!;<WWR[ >>dll2::&>		67>>!YY__.9O ?   ==T\\"**%=		;<CC!YY__.9O D   }}RYYr277%;		<=DD!YY__.9O E   }}RYYr277%;		<=DD!YY__.9O E   ryy'@		>?FF!YY__.9O G   &&r**o  	{{22266		;<CC!YY__.9O D  	s   )K; ;&M5#AM54M5r<   r   c                 \    ddl m} | j                  r| j                  sdn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   r5  r6  )r   r   rC  rB  )r    r&   r%   r<   r   r   s         r!   r>   zPath.shell_complete  s*     	:dnnu&z566r#   )	FTTFTFFNF)r$   r  r   rM  )r   r?   r@   rA   r!  r9  r:  r   rB   rC   rG   rE   rD   rH   r   rJ   rX   rI   r"   rQ  r)   rL   r>   re   rf   s   @r!   r@  r@     sY   @ -/GGOO!**S/; " /3 "" " 	"
 " " " " ::affQUUm," ":
affS!%%Z0 
5	0K+/K+ zz+&K+ ZZ	"	K+
 
1K+Z77%07>A7	
 	!7r#   r@  c                   p    e Zd ZdZdej
                  ej                  ej                  ej                     e	f      ddfdZ
dej                  eej                  f   f fdZedefd       Zedefd       Zd	ej                  d
ej$                  d   dej$                  d   dej                  fdZ x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.
    typesr   Nc                 J    |D cg c]  }t        |       c}| _        y c c}w r(   )convert_typerd  )r    rd  tys      r!   rX   zTuple.__init__  s     HM,N"\"-=,N
,Ns    c                     t         |          }| j                  D cg c]  } |j                          c}|d<   |S c c}w )Nrd  )rZ   r"   rd  )r    r\   rB   r]   s      r!   r"   zTuple.to_info_dict  sB    G(*	8<

C
1nann.
C	' Ds   >c                 N    ddj                  d | j                  D               dS )Nr   r   c              3   4   K   | ]  }|j                     y wr(   )r   )r   rg  s     r!   r   zTuple.name.<locals>.<genexpr>  s     9jBGGjs   r   )r   rd  rR   s    r!   r   z
Tuple.name  s%    3889djj99:!<<r#   c                 ,    t        | j                        S r(   )r   rd  rR   s    r!   r   zTuple.arity  s    4::r#   r$   r%   r   r&   r   c                    t        | j                        }t        |      }||k7  r0| j                  t        dd|      j	                  ||             t        fdt        | j                  |      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_value)r%   r&   c              3   8   K   | ]  \  }} ||        y wr(   r-   )r   rg  r   r&   r%   s      r!   r   z Tuple.convert.<locals>.<genexpr>  s!     K4J52qR5#&4Js   )r   rd  r;   r   r   tuplezip)r    r$   r%   r&   rm  rn  s     ``  r!   r)   zTuple.convert  sy     tzz?J	 IIPQ &(i&@   KC

E4JKKKr#   )r   r?   r@   rA   rB   rK   r;  r   rJ   r   rX   rI   rG   r"   rS   r   rF   r   rH   r)   re   rf   s   @r!   rc  rc    s    Oajj	1I)JK OPT OaffS!%%Z0 
 =c = = s  LUUL#$::k#:LABIAVL	
Lr#   rc  rg  defaultc                 D   d}| h|ft        |t        t        f      rC|rL|d   }t        |t        t        f      rt        t        t        |            } nt	        |      } nt	        |      } d}t        | t              rt        |       S t        | t              r| S | t        u s| t        S | t        u rt        S | t        u rt        S | t        u rt        S |rt        S 	 	 t        | t              rt!        d|  d      	 t%        |       S # t"        $ r Y t%        |       S w xY 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.
    Fr   Tz3Attempted to use an uninstantiated parameter type (z).)rr   rp  r   r   r   rc  r   rG   ry   rF   r   r   r   rD   r  
issubclassAssertionErrorr   rU   )rg  rr  guessed_typeitems       r!   rf  rf    s!   
 L	zg)gt}- qz
 dUDM2s4/BdBgB"eRy"i 		SyBJ	Sy
	U{	Tz	"i($I"RP  ) 	  			s   D	 		DDr(   )6r!  rV  rt   typingrB   r   r   r   r   _compatr   r   
exceptionsr
   utilsr   r   r   TYPE_CHECKINGtyping_extensionstecorer   r   shell_completionr   r   rN   rU   rh   rp   r{   r   r   r   r   r   r   r   r   r  r  rJ   r(  r@  rc  rH   rf  rl   ry   r   r   r  r  r-   r#   r!   <module>r     s   	  
      '   $ "  ??"0B BJ$ $)I )0	9 	i 4h4Y h4VDy DN9 $SJ+ SJl'  4) (I!> (IVI 2	 0v99 v9r= =#> =v79 v7r/L /Ld9QZZ& 9AEE1B 9i 9N #$ 
	 n 	  r#   