U a@I @sddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZejrddlZejdejdejfdZeedddZeedddZejedddZ dHee!eddd Z"Gd!d"d"Z#Gd#d$d$Z$dIej%ejej%ej&e'e'ej%e'dd'd(d)Z(d*ej)dd+d,Z*dJd*ej%eej%eej+d.d/d0Z,dKeeej%eej%ee'e'ej&d2d3d4Z-ej.ed5d6d7Z/dLej0ee1ej2fe'ed8d9d:Z3dMee'e'ed;dd?d?Z5dej6d@fej%eeedAdBdCZ7d%d%d%dDej8ee'e'e'ej9edEdFdGZ:dS)NN)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)rrLC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-s9fh6ldx\click\utils.py _posixifysr)funcrcsfdd}ttt|S)z0Wraps a function so that it swallows exceptions.cs&z ||WStk r YnXdSN) Exception)argskwargsrrrwrapper!s zsafecall..wrapper)rtcastr)rr#rr"rsafecalls r&)valuercCsBt|tr:z|tWStk r8|ddYSXt|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_help4s4           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|krXt|| d|_d|_dS)NrrAT) rrDrErFrGr _f should_closeopenclose)selfrCrDrErFrGrrr__init__mszLazyFile.__init__rcCst||Sr)getattrrJrLrrrr __getattr__szLazyFile.__getattr__rcCs*|jdk rt|jSd|jd|jdS)Nz)rHreprrrDrLrrr__repr__s  zLazyFile.__repr__c Cs|jdk r|jSz&t|j|j|j|j|jd\}|_Wn>tk rt}z ddl m }||j|j dW5d}~XYnX||_|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|jdk r|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@fs(  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 |dkr|rt}nt}|dk rt |}t ||rt |}n"t rt dk rt |}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|}|dkr"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|}|dkr"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)aThis is similar to how the :class:`File` works but for manual usage. Files are opened non lazy by default. This can open regular files as well as stdin/stdout if ``'-'`` is passed. If stdin/stdout is returned the stream is wrapped so that the context manager will not close the stream accidentally. This makes it possible to always use the function like this without having to worry to accidentally close a standard stream:: with open_file(filename) as f: ... .. versionadded:: 3.0 :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 use. :param errors: the error handling for this file. :param lazy: can be flipped to true to open the file lazily. :param atomic: in atomic mode writes go into a temporary file and it's moved on close. rV)r$r%rnr@r rq)rCrDrErFrrGfrIrrr open_fileOs rrQcCs&ddl}|jdtddtjddS)zReturns the argument part of ``sys.argv``, removing the first value which is the name of the script. .. deprecated:: 8.0 Will be removed in Click 8.1. Access ``sys.argv[1:]`` directly instead. rNze'get_os_args' is deprecated and will be removed in Click 8.1. Access 'sys.argv[1:]' directly instead.) stacklevelr)warningswarnDeprecationWarningsysargv)rrrr get_os_argsusr)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|}|dkr0tjd}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 expanduserrrrplatform)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 CsLz|jWn8tk rF}zddl}|j|jkr6W5d}~XYnXdS)Nr)rr{rYerrnoEPIPE)rLr]rrrrr{s  zPacifyFlushWrapper.flush)attrrcCs t|j|Sr)rNr)rLrrrrrPszPacifyFlushWrapper.__getattr__) rgrhrirjr$rnrMr{r-rmrPrrrrrs r__main__)r_mainrcCs|stjd}t|dddksPtjdkr\|jdkr\tj|s\tj|dr\tj|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: r __package__Nntr3z.exerr5z python -m )rrrNrrrrexistsrr$r%r-splitextlstrip)rrZ py_modulerrrr_detect_program_names"   r)userenvglob_recursive)r rrrrcCsdddlm}g}|D]J}|r(tj|}|r8tj|}|||d}|sT||q||q|S)a)Simulate Unix shell expansion with Python functions. See :func:`glob.glob`, :func:`os.path.expanduser`, and :func:`os.path.expandvars`. This 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. .. versionadded:: 8.0 :meta private: r)glob) recursive)rrrr expandvarsappendextend)r rrrrr}argmatchesrrr _expand_argss      r)r/)NNTFN)NrB)rANrBFF)F)TF);rrtypingr$ functoolsrtypesr_compatrrrrr r r r r rrglobalsr TYPE_CHECKINGZtyping_extensionsteTypeVarCallablermrr-rr&r.intr?r@rqrkrnrlrBinaryIOrTextIOrrSequencerUnionr*PathLikerrrmodulesrIterableListrrrrrs                2R   b  & 1 6