a =jgjO @szddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddlmZejrddlZedZedZeedddZdddddZ ej!edddZ"dGee#edd d!Z$Gd"d#d#Z%Gd$d%d%Z&dHej'ej!ej'ej(ej!e)e)ej'e)dd(d)d*Z*d+ej+dd,d-Z,dId+ej'eej'eej-d/d0d1Z.dJej/ed3feej'eej'ee)e)ej(ej!d4d5d6Z0dKd7e)ed8d9d:Z1dLee)e)ed;dd?d?Z3dMej'eej'eed@dAdBZ4d&d&d&dCej5ee)e)e)ej6edDdEdFZ7dS)NN)update_wrapper) ModuleType) TracebackType)_default_text_stderr)_default_text_stdout)_find_binary_writer)auto_wrap_for_ansi)binary_streams) open_stream)should_strip_ansi) strip_ansi) text_streams)WIN)resolve_color_defaultPRnamereturncCsd|S)N-)joinsplitlower)rr5/usr/local/lib/python3.9/site-packages/click/utils.py _posixifysrzt.Callable[P, R]zt.Callable[P, t.Optional[R]])funcrcs&ddtjtdfdd }t|S)z0Wraps a function so that it swallows exceptions.zP.argszP.kwargs)argskwargsrcs(z|i|WSty"Yn0dSN) Exception)rrrrrwrapper$s  zsafecall..wrapper)tOptionalrr)rr#rr"rsafecall!sr&)valuercCsBt|tr:z|tWSty8|ddYS0t|S)z%Converts a value into a valid string.utf-8replace) isinstancebytesdecodesysgetfilesystemencoding UnicodeErrorstr)r'rrrmake_str.s   r1-)help max_lengthrcCs(|d}|dkr|d|}|}|s.dS|ddkrF|dd}d}t|d}t|D]b\}}|t||dk7}||krq|ddkrd |d|dS||kr^||kr^qq^d |S|td 7}|dkr|t|||dk8}||krq|d8}qd |d|d S) z+Returns a condensed version of help string.z Nrr. z...)findrlen enumerater)r3r4Z paragraph_endwords total_lengthZ last_indexiwordrrrmake_default_short_help8s4           rAc@seZdZdZdejedfeejeejeeddd Z eej d d d Z ed ddZ ej ej d ddZdd ddZdd ddZdd ddZejejeejeejeddddZejejd ddZdS)LazyFilezA lazy file works like a regular file but it does not fully open the file but it does perform some basic checks early to see if the filename parameter does make sense. This is useful for safely opening files for writing. rNstrictFos.PathLike[str])filenamemodeencodingerrorsatomiccCstt||_||_||_||_||_|||jdkrNt||||\|_|_ n"d|vrdt || d|_d|_ dS)NrrCT) osfspathrrGrHrIrJr _f should_closeopenclose)selfrFrGrHrIrJrrr__init__qs  zLazyFile.__init__rcCst||Sr )getattrrOrQrrrr __getattr__szLazyFile.__getattr__rcCs.|jdurt|jSdt|jd|jdS)Nz)rMreprformat_filenamerrGrQrrr__repr__s  zLazyFile.__repr__c Cs|jdur|jSz&t|j|j|j|j|jd\}|_WnBtyx}z*ddl m }||j|j d|WYd}~n d}~00||_|S)zOpens the file if it's not yet open. This call might fail with a :exc:`FileError`. Not handling this error will produce an error that Click shows. NrJr) FileError)hint) rMr rrGrHrIrJrNOSError exceptionsr]strerror)rQrver]rrrrOs  (z LazyFile.opencCs|jdur|jdS)z+Closes the underlying file, no matter what.N)rMrPrZrrrrPs zLazyFile.closecCs|jr|dS)zThis function only closes the file if it was opened by the lazy file wrapper. For instance this will never close stdin. N)rNrPrZrrrclose_intelligentlyszLazyFile.close_intelligentlycCs|Sr rrZrrr __enter__szLazyFile.__enter__exc_type exc_valuetbrcCs |dSr )rdrQrgrhrirrr__exit__szLazyFile.__exit__cCs|t|jSr )rOiterrMrZrrr__iter__szLazyFile.__iter__)rCNrDF)__name__ __module__ __qualname____doc__r$Unionr0r%boolrRAnyrUr[IOrOrPrdreType BaseExceptionrrkIteratorAnyStrrmrrrrrBjs0    rBc@seZdZejejddddZeejdddZddd d Z ej ej e ej e ej e dd d d ZedddZejejdddZdS) KeepOpenFileN)filercCs ||_dSr )_file)rQr{rrrrRszKeepOpenFile.__init__rcCs t|j|Sr )rSr|rTrrrrUszKeepOpenFile.__getattr__rVcCs|Sr rrZrrrreszKeepOpenFile.__enter__rfcCsdSr rrjrrrrkszKeepOpenFile.__exit__cCs t|jSr )rXr|rZrrrr[szKeepOpenFile.__repr__cCs t|jSr )rlr|rZrrrrmszKeepOpenFile.__iter__)rnrorpr$rurtrRr0rUrer%rvrwrrkr[rxryrmrrrrrzs rzTF)messager{nlerrcolorrcCs|dur&|rt}nt}|dur&dS|durHt|tttfsHt|}n|}|rt|pVd}t|trl|d7}n|d7}|s|dSt|ttfrt|}|dur||||dSnDt |}t ||rt |}n(t rt durt ||}n|st |}|||dS)aPrint a message and newline to stdout or a file. This should be used instead of :func:`print` because it provides better support for different data, files, and environments. Compared to :func:`print`, this does the following: - Ensures that the output encoding is not misconfigured on Linux. - Supports Unicode in the Windows console. - Supports writing to binary outputs, and supports writing bytes to text outputs. - Supports colors and styles on Windows. - Removes ANSI color and style codes if the output does not look like an interactive terminal. - Always flushes the output. :param message: The string or bytes to output. Other objects are converted to strings. :param file: The file to write to. Defaults to ``stdout``. :param err: Write to ``stderr`` instead of ``stdout``. :param nl: Print a newline after the message. Enabled by default. :param color: Force showing or hiding colors and other styles. By default Click will remove color if the output does not look like an interactive terminal. .. versionchanged:: 6.0 Support Unicode output on the Windows console. Click does not modify ``sys.stdout``, so ``sys.stdout.write()`` and ``print()`` will still not support Unicode. .. versionchanged:: 4.0 Added the ``color`` parameter. .. versionadded:: 3.0 Added the ``err`` parameter. .. versionchanged:: 2.0 Support colors on Windows if colorama is installed. Nr6  )rrr*r0r+ bytearrayflushrwriterr r rr )r}r{r~rrout binary_filerrrechosD-        rz'te.Literal['stdin', 'stdout', 'stderr']cCs(t|}|dur"td|d|S)zReturns a system stream for byte processing. :param name: the name of the stream to open. Valid names are ``'stdin'``, ``'stdout'`` and ``'stderr'`` NUnknown standard stream '')r get TypeError)ropenerrrrget_binary_streamBs rrD)rrHrIrcCs,t|}|dur"td|d|||S)aReturns a system stream for text processing. This usually returns a wrapped stream around a binary stream returned from :func:`get_binary_stream` but it also can take shortcuts for already correctly configured streams. :param name: the name of the stream to open. Valid names are ``'stdin'``, ``'stdout'`` and ``'stderr'`` :param encoding: overrides the detected default encoding. :param errors: overrides the default error mode. Nrr)rrr)rrHrIrrrrget_text_streamNs rrCrE)rFrGrHrIlazyrJrc Cs\|r&ttjtjt|||||dSt|||||d\}}|sXttjtjt|}|S)a^Open a file, with extra behavior to handle ``'-'`` to indicate a standard stream, lazy open on write, and atomic write. Similar to the behavior of the :class:`~click.File` param type. If ``'-'`` is given to open ``stdout`` or ``stdin``, the stream is wrapped so that using it in a context manager will not close it. This makes it possible to use the function without accidentally closing a standard stream: .. code-block:: python with open_file(filename) as f: ... :param filename: The name or Path of the file to open, or ``'-'`` for ``stdin``/``stdout``. :param mode: The mode in which to open the file. :param encoding: The encoding to decode or encode a file opened in text mode. :param errors: The error handling mode. :param lazy: Wait to open the file until it is accessed. For read mode, the file is temporarily opened to raise access errors early, then closed until it is read again. :param atomic: Write to a temporary file and replace the given file on close. .. versionadded:: 3.0 r\)r$castrurtrBr rz)rFrGrHrIrrJfrNrrr open_filecs$rz9t.Union[str, bytes, os.PathLike[str], os.PathLike[bytes]])rFshortenrcCsP|rtj|}n t|}t|tr8|td}n| dddd}|S)uFormat a filename as a string for display. Ensures the filename can be displayed by replacing any invalid bytes or surrogate escapes in the name with the replacement character ``�``. Invalid bytes or surrogate escapes will raise an error when written to a stream with ``errors="strict"``. This will typically happen with ``stdout`` when the locale is something like ``en_GB.UTF-8``. Many scenarios *are* safe to write surrogates though, due to PEP 538 and PEP 540, including: - Writing to ``stderr``, which uses ``errors="backslashreplace"``. - The system has ``LANG=C.UTF-8``, ``C``, or ``POSIX``. Python opens stdout and stderr with ``errors="surrogateescape"``. - None of ``LANG/LC_*`` are set. Python assumes ``LANG=C.UTF-8``. - Python is started in UTF-8 mode with ``PYTHONUTF8=1`` or ``-X utf8``. Python opens stdout and stderr with ``errors="surrogateescape"``. :param filename: formats a filename for UI display. This will also convert the filename into unicode without failing. :param shorten: this optionally shortens the filename to strip of the path that leads up to it. r)r(surrogateescape) rKpathbasenamerLr*r+r,r-r.encode)rFrrrrrYs   rY)app_nameroaming force_posixrcCstr>|r dnd}tj|}|dur0tjd}tj||S|r`tjtjdt|Stj dkrtjtjd|Stjtjdtjd t|S) aReturns the config folder for the application. The default behavior is to return whatever is most appropriate for the operating system. To give you an idea, for an app called ``"Foo Bar"``, something like the following folders could be returned: Mac OS X: ``~/Library/Application Support/Foo Bar`` Mac OS X (POSIX): ``~/.foo-bar`` Unix: ``~/.config/foo-bar`` Unix (POSIX): ``~/.foo-bar`` Windows (roaming): ``C:\Users\\AppData\Roaming\Foo Bar`` Windows (not roaming): ``C:\Users\\AppData\Local\Foo Bar`` .. versionadded:: 2.0 :param app_name: the application name. This should be properly capitalized and can contain whitespace. :param roaming: controls if the folder should be roaming or not on Windows. Has no effect otherwise. :param force_posix: if this is set to `True` then on any POSIX system the folder will be stored in the home folder with a leading dot instead of the XDG config home or darwin's application support folder. APPDATA LOCALAPPDATAN~z~/.darwinz~/Library/Application SupportXDG_CONFIG_HOMEz ~/.config) rrKenvironrr expanduserrrr-platform)rrrkeyfolderrrr get_app_dirs      rc@sHeZdZdZejejddddZddddZe ejd d d Z dS) PacifyFlushWrapperaThis wrapper is used to catch and suppress BrokenPipeErrors resulting from ``.flush()`` being called on broken pipe during the shutdown/final-GC of the Python interpreter. Notably ``.flush()`` is always called on ``sys.stdout`` and ``sys.stderr``. So as to have minimal impact on any other cleanup code, and the case where the underlying file is not a broken pipe, all calls and attributes are proxied. N)wrappedrcCs ||_dSr )r)rQrrrrrRszPacifyFlushWrapper.__init__rVc CsNz|jWn:tyH}z"ddl}|j|jkr4WYd}~n d}~00dS)Nr)rrr_errnoEPIPE)rQrcrrrrrs  zPacifyFlushWrapper.flush)attrrcCs t|j|Sr )rSr)rQrrrrrUszPacifyFlushWrapper.__getattr__) rnrorprqr$rurtrRrr0rUrrrrrs r)r_mainrcCs|durtjd}|s tjd}t|dddvsbtjdkrn|jdkrntj|sntj|drntj |St t |j}tj tj |d}|dkr|d |}d |d S) a:Determine the command used to run the program, for use in help text. If a file or entry point was executed, the file name is returned. If ``python -m`` was used to execute a module or package, ``python -m name`` is returned. This doesn't try to be too precise, the goal is to give a concise name for help text. Files are only shown as their name without the path. ``python`` is only shown for modules, and the full path to ``sys.executable`` is not shown. :param path: The Python file being executed. Python puts this in ``sys.argv[0]``, which is used by default. :param _main: The ``__main__`` module. This should only be passed during internal testing. .. versionadded:: 8.0 Based on command args detection in the Werkzeug reloader. :meta private: N__main__r __package__>Nr6ntr6z.exer8z python -m )r-modulesargvrSrKrrrexistsrr$rr0splitextlstrip)rrZ py_modulerrrr_detect_program_names&    r)userenvglob_recursive)rrrrrc Csddlm}g}|D]h}|r(tj|}|r8tj|}z|||d}Wntjy`g}Yn0|sr||q||q|S)aSimulate Unix shell expansion with Python functions. See :func:`glob.glob`, :func:`os.path.expanduser`, and :func:`os.path.expandvars`. This is intended for use on Windows, where the shell does not do any expansion. It may not exactly match what a Unix shell would do. :param args: List of command line arguments to expand. :param user: Expand user home directory. :param env: Expand environment variables. :param glob_recursive: ``**`` matches directories recursively. .. versionchanged:: 8.1 Invalid glob patterns are treated as empty expansions rather than raising an error. .. versionadded:: 8.0 :meta private: r)glob) recursive) rrKrr expandvarsreerrorappendextend)rrrrrrargmatchesrrr _expand_args?s      r)r2)NNTFN)NrD)rCNrDFF)F)TF)NN)8rKrr-typingr$ functoolsrtypesrrZ_compatrrrr r r r r rrglobalsr TYPE_CHECKINGtyping_extensionste ParamSpecrTypeVarrr0rr&rtr1intrArBrzr%rursrBinaryIOrTextIOrrrrrYrrrIterableListrrrrrs                  2X  g   3 *1 :