DdJOrddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddlmZej.rddlZej4dZej8dZdedefdZdCdZ dejBdefdZ"dDdede#defdZ$GddZ%GddZ& dEd!ejNejBd"ejNejPejBd#e)d$e)d%ejNe)ddf d&Z*dd'dejVfd(Z, dFdd'd)ejNed*ejNedejZfd+Z. dGd,ed-ed)ejNed*ejNed.e)d/e)dejPejBfd0Z/ dHd,d1d2e)defd3Z0dId4ed5e)d6e)defd7Z1Gd8d9Z2 dJd:ejNed;ejNedefd<Z3d d d d=d>ejhed?e)d@e)dAe)dejjef dBZ6y)KN)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_defaultPRnamereturnc\dj|jjS)N-)joinsplitlower)rs -/usr/lib/python3/dist-packages/click/utils.py _posixifyrs 88DJJL ! ' ' ))c^dddddtjtffd }t|S)z0Wraps a function so that it swallows exceptions.argszP.argskwargszP.kwargsrc4 |i|S#t$rYywxYwN) Exception)rr funcs rwrapperzsafecall..wrapper$s- (( (   s  )tOptionalrr)r$r%s` rsafecallr(!s4x:!**Q- '4 ((rvaluect|tr$ |jtjSt |S#t $r|jddcYSwxYw)z%Converts a value into a valid string.utf-8replace) isinstancebytesdecodesysgetfilesystemencoding UnicodeErrorstr)r)s rmake_strr4.sW% 4<< 9 9 ;< < u: 4<<3 3 4s"AAAhelp max_lengthc|jd}|dk7r|d|}|j}|sy|ddk(r|dd}d}t|dz }t|D]N\}}|t||dkDzz }||kDrnA|ddk(rd j |d|dzcS||k(sH||k7sNnd j |S|td z }|dkDr(|t|||dkDzz}||krn |dz}|dkDr(d j |d|d zS) z+Returns a condensed version of help string.z Nrr. z...)findrlen enumerater)r5r6 paragraph_endwords total_length last_indexiwords rmake_default_short_helprF8sPIIf%MN]# JJLE  Qx4ab LUaJU# 4D QU++ * $  8s?88E'AEN+ + : %!z/  xxCJL a%E!H Q// : %  Q a% 88E"1I  &&rc eZdZdZ ddej edfdedejedejedef d Z d ed ejfd Z d efd Z d ejejfdZddZddZddZdejej$edejedejed dfdZd ej,ej.fdZy)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. Nfilenamezos.PathLike[str]modeencodingerrorsatomicc&tj||_||_||_||_||_|||jdk(rt||||\|_|_ yd|vrt||jd|_d|_ y)NrrT) osfspathrrJrKrLrMr _f should_closeopenclose)selfrIrJrKrLrMs r__init__zLazyFile.__init__qs8,        99 )4XtXv)V &DGT&d{Xt$**,DG $D rrrc6t|j|Sr")getattrrTrVrs r __getattr__zLazyFile.__getattr__styy{D))rc|jt|jSdt|jd|jdS)Nz)rRreprformat_filenamerrJrVs r__repr__zLazyFile.__repr__s= 77 = !/$))" ?sA A-- B 6%BB cR|j|jjyy)z+Closes the underlying file, no matter what.N)rRrUr`s rrUzLazyFile.closes 77  GGMMO rc>|jr|jyy)zThis function only closes the file if it was opened by the lazy file wrapper. For instance this will never close stdin. N)rSrUr`s rclose_intelligentlyzLazyFile.close_intelligentlys    JJL rc|Sr"r`s r __enter__zLazyFile.__enter__ rexc_type exc_valuetbc$|jyr")rmrVrrrsrts r__exit__zLazyFile.__exit__s   "rcL|jt|jSr")rTiterrRr`s r__iter__zLazyFile.__iter__s DGG}r)rONstrictFrN)rrH)__name__ __module__ __qualname____doc__r&Unionr3r'boolrWAnyr[raIOrTrUrmrpType BaseExceptionrrwIteratorAnyStrrzrorrrHrHjs$("* %''#112%%**S/ %  3 %  %6***M#M add155k$ #**QVVM23#::m,# JJ} % #  #!**QXX.rrHc<eZdZdejej ddfdZdedej fdZddZ dejeje d eje d eje ddfd Zdefd Zdej ej"fd Zy) KeepOpenFilefilerNc||_yr")_file)rVrs rrWzKeepOpenFile.__init__s "& rrc.t|j|Sr")rYrrZs rr[zKeepOpenFile.__getattr__stzz4((rc|Sr"ror`s rrpzKeepOpenFile.__enter__rqrrrrsrtcyr"rorvs rrwzKeepOpenFile.__exit__s rc,t|jSr")r^rr`s rrazKeepOpenFile.__repr__DJJrc,t|jSr")ryrr`s rrzzKeepOpenFile.__iter__rr)rr)r}r~rr&rrrWr3r[rpr'rrrrwrarrrzrorrrrs'QTT!%%['T'))) **QVVM23 ::m,  JJ} %     #  !**QXX. rrTmessagernlerrcolorcz||r t}n t}|y|'t|ttt fs t|}n|}|r!|xsd}t|tr|dz }n|dz }|s|j yt|tt fr?t|}|z|j |j||j yt|}t||r t|}n%trt t|}n |s t|}|j||j y)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. Nr9  )rrr-r3r. bytearrayflushr writerr rrr )rrrrrout binary_files rechorsZ | ')D')D < :gUI7N#O/27| iR c3  4KC 5LC   #y)*)$/  " JJL   c "      &e, T5 )S/C !-)$/ oJJsOJJLrz'te.Literal['stdin', 'stdout', 'stderr']c\tj|}|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'`` Unknown standard stream '')r get TypeError)ropeners rget_binary_streamrBs5    %F ~3D6;<< 8OrrKrLc`tj|}|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. rr)rrr)rrKrLrs rget_text_streamrNs;  d #F ~3D6;<< (F ##rrIrJlazyrMc 6|rCtjtjtjt |||||St |||||\}}|s>tjtjtjt |}|S)aVOpen 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 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 rc)r&castrrrHr r)rIrJrKrLrrMfrSs r open_filercswH vv DDK(D(F6R  "(D(F6ROA|  FF144; Q 0 Hrz9t.Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]shortenc$|r tjj|}ntj|}t |t r&|j tjd}|S|jddj dd}|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) rPpathbasenamerQr-r.r/r0r1encode)rIrs rr_r_s}677##H-99X&(E"??3#<#<#> J O ??7,=>EE Y  Orapp_nameroaming force_posixctrf|rdnd}tjj|}|tjj d}tjj ||S|rHtjj tjj dt|Stjdk(r=tjj tjj d|Stjj tjjdtjj dt|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 LOCALAPPDATA~z~/.darwinz~/Library/Application SupportXDG_CONFIG_HOMEz ~/.config) rrPenvironrr expanduserrrr0platform)rrrkeyfolders r get_app_dirrs> "i$ >WW'',Fww||FH--ww||BGG..Yx5H4I/JKLL ||xww|| GG  > ?   77<< ("''*<*<[*IJ( rczeZdZdZdej ej ddfdZd dZde dej fdZ y) 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. wrappedrNc||_yr")r)rVrs rrWzPacifyFlushWrapper.__init__s  rc |jjy#t$r(}ddl}|j|jk7rYd}~yd}~wwxYw)Nr)rrrferrnoEPIPE)rVrjrs rrzPacifyFlushWrapper.flushsB  LL     ww%++%& s AA  Aattrc.t|j|Sr")rYr)rVrs rr[zPacifyFlushWrapper.__getattr__st||T**rr|) r}r~rrr&rrrWrr3r[rorrrrsBQUU +++rrr_mainc~|tjd}|stjd}t|dddvsctj dk(ro|j dk(r`tjj|sAtjj|drtjj|Stjt|j }tjjtjj|d}|dk7r|d |}d |jd 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__>Nr9ntr9z.exer;z python -m )r0modulesargvrYrPrrrexistsrr&rr3splitextlstrip)rr py_modulers r_detect_program_namers. } J' xx{ umT*j8 4    #t$ GGNNdV4= )ww%% sE--.I 77  BGG,,T2 3A 6D z k4&)  ((-. //r)userenvglob_recursiverrrrc>ddlm}g}|D]t}|rtjj|}|rtjj |} |||}|s|j|d|j|v|S#t j $rg}Y@wxYw)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) rrPrr expandvarsreerrorappendextend)rrrrrrargmatchess r _expand_argsr?s8 C  ''$$S)C ''$$S)C 3.9G JJsO JJw  " Jxx G s BBB)r$zt.Callable[P, R]rzt.Callable[P, t.Optional[R]])-)NNTFN)Nr{)rONr{FF)F)TF)NN)7rPrr0typingr& functoolsrtypesrr_compatrrr r r r r rrrglobalsr TYPE_CHECKINGtyping_extensionste ParamSpecrTypeVarrr3rr(rr4intrFrHrr'rrrBinaryIOrTextIOrrr_rrrIterableListrrorrrs $))('# &!*??" SA AIIcN*C*C* )AEEc/'#/'3/'/'dUUp  4"&$(" d ZZ d **QTT!%%[ !d d  d ::d  d  dN E !** !%&$ 3$jjo$ JJsO$XX $. $& . . . jjo.  JJsO .  .  . TT!%%[. f'I' ' 'T.#..$.SV.b++4CG40 **S/40)*J)?4040t 1 **S/1 1  1  1 VVC[ 1r