Undocumented
Class |
|
Undocumented |
Class |
|
A 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. |
Class |
|
This 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... |
Function | echo |
Print 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. |
Function | format |
Formats 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... |
Function | get |
Returns the config folder for the application. The default behavior is to return whatever is most appropriate for the operating system. |
Function | get |
Returns a system stream for byte processing. |
Function | get |
Returns 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. |
Function | make |
Returns a condensed version of help string. |
Function | make |
Converts a value into a valid string. |
Function | open |
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. |
Function | safecall |
Wraps a function so that it swallows exceptions. |
Constant | F |
Undocumented |
Function | _detect |
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. |
Function | _expand |
Simulate Unix shell expansion with Python functions. |
Function | _posixify |
Undocumented |
Print 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.
Parameters | |
message:t.Optional[ | Undocumented |
file:t.Optional[ | Undocumented |
nl:bool | Undocumented |
err:bool | Undocumented |
color:t.Optional[ | Undocumented |
Formats 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.
Parameters | |
filename:t.Union[ | Undocumented |
shorten:bool | Undocumented |
Returns | |
str | Undocumented |
Returns 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\<user>\AppData\Roaming\Foo Bar`` Windows (not roaming): ``C:\Users\<user>\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.
Parameters | |
appstr | Undocumented |
roaming:bool | Undocumented |
forcebool | Undocumented |
Returns | |
str | Undocumented |
Returns a system stream for byte processing. :param name: the name of the stream to open. Valid names are ``'stdin'``, ``'stdout'`` and ``'stderr'``
Parameters | |
name:te.Literal[ | Undocumented |
Returns | |
t.BinaryIO | Undocumented |
Returns 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.
Parameters | |
name:te.Literal[ | Undocumented |
encoding:t.Optional[ | Undocumented |
errors:t.Optional[ | Undocumented |
Returns | |
t.TextIO | Undocumented |
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 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
Parameters | |
filename:str | Undocumented |
mode:str | Undocumented |
encoding:t.Optional[ | Undocumented |
errors:t.Optional[ | Undocumented |
lazy:bool | Undocumented |
atomic:bool | Undocumented |
Returns | |
t.IO | Undocumented |
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:
Parameters | |
path:t.Optional[ | Undocumented |
_main:t.Optional[ | Undocumented |
Returns | |
str | Undocumented |
Simulate 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:
Parameters | |
args:t.Iterable[ | Undocumented |
user:bool | Undocumented |
env:bool | Undocumented |
globbool | Undocumented |
Returns | |
t.List[ | Undocumented |