a cH @s~ddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl m Z ddl m Z dd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddlmZejrddlZejdejdejfdZeedddZeedddZ ejedddZ!dDee"eddd Z#Gd!d"d"Z$Gd#d$d$Z%dEej&ejej&ej'eje(e(ej&e(dd'd(d)Z)d*ej*dd+d,Z+dFd*ej&eej&eej,d.d/d0Z-dGeeej&eej&ee(e(ej'd2d3d4Z.dHej/ee0ej1fe(ed5d6d7Z2dIee(e(ed8d9d:Z3Gd;d<d<Z4dJej&eej&eed=d>d?Z5d%d%d%d@ej6ee(e(e(ej7edAdBdCZ8dS)KN)update_wrapper) ModuleType)_default_text_stderr)_default_text_stdout)_find_binary_writer)auto_wrap_for_ansi)binary_streams)get_filesystem_encoding) open_stream)should_strip_ansi) strip_ansi) text_streams)WIN)resolve_color_defaultF.)boundnamereturncCsd|S)N-)joinsplitlower)rrX/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/click/utils.py _posixifysr)funcrcsfdd}ttt|S)z0Wraps a function so that it swallows exceptions.cs(z|i|WSty"Yn0dSN) Exception)argskwargsrrrwrapper"s zsafecall..wrapper)rtcastr)rr#rr"rsafecalls r&)valuercCs@t|tr8z|tWSty6|ddYS0t|S)z%Converts a value into a valid string.zutf-8replace) isinstancebytesdecoder UnicodeErrorstr)r'rrrmake_str+s   r.-)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)r0r1Z paragraph_endwords total_length last_indexiwordrrrmake_default_short_help5s4           r?c@seZdZdZdeeejeejeedddZeej d d d Z ed d dZ ej d ddZ dd ddZdd ddZdd ddZddZejejd 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. rNstrictF)filenamemodeencodingerrorsatomiccCsh||_||_||_||_||_||dkrBt||||\|_|_n"d|vrXt|| d|_d|_dS)NrrAT) rrDrErFrGr _f should_closeopenclose)selfrCrDrErFrGrrr__init__nszLazyFile.__init__rcCst||Sr)getattrrJrLrrrr __getattr__szLazyFile.__getattr__rcCs*|jdurt|jSd|jd|jdS)Nz)rHreprrrDrLrrr__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. NrGr) FileError)hint) rHr rrDrErFrGrIOSError exceptionsrWstrerror)rLrverWrrrrJs  (z LazyFile.opencCs|jdur|jdS)z+Closes the underlying file, no matter what.N)rHrKrTrrrrKs 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)rIrKrTrrrclose_intelligentlyszLazyFile.close_intelligentlycCs|SrrrTrrr __enter__szLazyFile.__enter__cCs |dSr)r^rLexc_type exc_valuetbrrr__exit__szLazyFile.__exit__cCs|t|jSr)rJiterrHrTrrr__iter__szLazyFile.__iter__)rANrBF)__name__ __module__ __qualname____doc__r-r$OptionalboolrMAnyrPrUIOrJrKr^r_rdIteratorAnyStrrfrrrrr@gs(  r@c@sjeZdZejddddZeejdddZddd d Z d d Z edd dZ ej ej dddZdS) KeepOpenFileN)filercCs ||_dSr)_file)rLrrrrrrMszKeepOpenFile.__init__rcCs t|j|Sr)rNrsrOrrrrPszKeepOpenFile.__getattr__rQcCs|SrrrTrrrr_szKeepOpenFile.__enter__cCsdSrrr`rrrrdszKeepOpenFile.__exit__cCs t|jSr)rSrsrTrrrrUszKeepOpenFile.__repr__cCs t|jSr)rersrTrrrrfszKeepOpenFile.__iter__)rgrhrir$rnrMr-rmrPr_rdrUrorprfrrrrrqs rqTF)messagerrnlerrcolorrcCs |dur|rt}nt}|durt |}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. Nr3  )rrr)r-r* bytearrayflushrwriterr r rr)rtrrrurvrwout binary_filerrrechos@-        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_stream/s rrB)rrErFrcCs,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)rrErFrrrrget_text_stream;s rrA)rCrDrErFlazyrGrc CsP|r ttjt|||||dSt|||||d\}}|sLttjt|}|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 rV)r$r%rnr@r rq)rCrDrErFrrGfrIrrr open_filePs $r)rCshortenrcCs|rtj|}t|S)aKFormats a filename for user display. The main purpose of this function is to ensure that the filename can be displayed at all. This will decode the filename to unicode if necessary in a way that it will not fail. Optionally, it can shorten the filename to not include the full path to the filename. :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. )ospathbasenamefsdecode)rCrrrrformat_filenames r)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 affect 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) rrenvironrr expanduserrrsysplatform)rrrkeyfolderrrr get_app_dirs      rc@sBeZdZdZejddddZddddZeej d 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)rLrrrrrMszPacifyFlushWrapper.__init__rQc CsNz|jWn:tyH}z"ddl}|j|jkr4WYd}~n d}~00dS)Nr)rr{rYerrnoEPIPE)rLr]rrrrr{s  zPacifyFlushWrapper.flush)attrrcCs t|j|Sr)rNr)rLrrrrrPszPacifyFlushWrapper.__getattr__) rgrhrirjr$rnrMr{r-rmrPrrrrrs r)r_mainrcCs|durtjd}|s tjd}t|dddusbtjdkrn|jdkrntj|sntj|drntj |St t |j}tj tj |d}|dkr|d|}d |dS) 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__ntr3z.exer5z python -m )rmodulesargvrNrrrrexistsrr$r%r-splitextlstrip)rrZ py_modulerrrr_detect_program_names&    r)userenvglob_recursive)r rrrrc 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) rrrr expandvarsreerrorappendextend)r rrrrr}argmatchesrrr _expand_argss      r)r/)NNTFN)NrB)rANrBFF)F)TF)NN)9rrrtypingr$ functoolsrtypesr_compatrrrrr r r r r rrglobalsr TYPE_CHECKINGZtyping_extensionsteTypeVarCallablermrr-rr&r.intr?r@rqrkrnrlrBinaryIOrTextIOrrUnionr*PathLikerrrrIterableListrrrrrs                2R  b  0 1 9