module documentation

Undocumented

Class KeepOpenFile Undocumented
Class LazyFile 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 PacifyFlushWrapper 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_filename 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_app_dir Returns the config folder for the application. The default behavior is to return whatever is most appropriate for the operating system.
Function get_binary_stream Returns a system stream for byte processing.
Function get_text_stream 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_default_short_help Returns a condensed version of help string.
Function make_str Converts a value into a valid string.
Function open_file 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_program_name 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_args Simulate Unix shell expansion with Python functions.
Function _posixify Undocumented
def echo(message=None, file=None, nl=True, err=False, color=None): (source)

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[t.Any]Undocumented
file:t.Optional[t.IO[t.Any]]Undocumented
nl:boolUndocumented
err:boolUndocumented
color:t.Optional[bool]Undocumented
def format_filename(filename, shorten=False): (source)

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[str, bytes, os.PathLike]Undocumented
shorten:boolUndocumented
Returns
strUndocumented
def get_app_dir(app_name, roaming=True, force_posix=False): (source)

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
app_name:strUndocumented
roaming:boolUndocumented
force_posix:boolUndocumented
Returns
strUndocumented
def get_binary_stream(name): (source)

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['stdin', 'stdout', 'stderr']Undocumented
Returns
t.BinaryIOUndocumented
def get_text_stream(name, encoding=None, errors='strict'): (source)

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['stdin', 'stdout', 'stderr']Undocumented
encoding:t.Optional[str]Undocumented
errors:t.Optional[str]Undocumented
Returns
t.TextIOUndocumented
def make_default_short_help(help, max_length=45): (source)

Returns a condensed version of help string.

Parameters
help:strUndocumented
max_length:intUndocumented
Returns
strUndocumented
def make_str(value): (source)

Converts a value into a valid string.

Parameters
value:t.AnyUndocumented
Returns
strUndocumented
def open_file(filename, mode='r', encoding=None, errors='strict', lazy=False, atomic=False): (source)

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:strUndocumented
mode:strUndocumented
encoding:t.Optional[str]Undocumented
errors:t.Optional[str]Undocumented
lazy:boolUndocumented
atomic:boolUndocumented
Returns
t.IOUndocumented
def safecall(func): (source)

Wraps a function so that it swallows exceptions.

Parameters
func:FUndocumented
Returns
FUndocumented

Undocumented

Value
t.TypeVar('F',
          bound=t.Callable[..., t.Any])
def _detect_program_name(path=None, _main=None): (source)

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[str]Undocumented
_main:t.Optional[ModuleType]Undocumented
Returns
strUndocumented
def _expand_args(args, *, user=True, env=True, glob_recursive=True): (source)

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[str]Undocumented
user:boolUndocumented
env:boolUndocumented
glob_recursive:boolUndocumented
Returns
t.List[str]Undocumented
def _posixify(name): (source)

Undocumented

Parameters
name:strUndocumented
Returns
strUndocumented