|
OpenQuizz
Une application de gestion des contenus pédagogiques
|


Public Member Functions | |
| def | __init__ (self, command, parent=None, info_name=None, obj=None, auto_envvar_prefix=None, default_map=None, terminal_width=None, max_content_width=None, resilient_parsing=False, allow_extra_args=None, allow_interspersed_args=None, ignore_unknown_options=None, help_option_names=None, token_normalize_func=None, color=None, show_default=None) |
| def | __enter__ (self) |
| def | __exit__ (self, exc_type, exc_value, tb) |
| def | scope (self, cleanup=True) |
| def | meta (self) |
| def | make_formatter (self) |
| def | call_on_close (self, f) |
| def | close (self) |
| def | command_path (self) |
| def | find_root (self) |
| def | find_object (self, object_type) |
| def | ensure_object (self, object_type) |
| def | lookup_default (self, name) |
| def | fail (self, message) |
| def | abort (self) |
| def | exit (self, code=0) |
| def | get_usage (self) |
| def | get_help (self) |
| def | invoke (*args, **kwargs) |
| def | forward (*args, **kwargs) |
The context is a special internal object that holds state relevant
for the script execution at every single level. It's normally invisible
to commands unless they opt-in to getting access to it.
The context is useful as it can pass internal objects around and can
control special execution features such as reading data from
environment variables.
A context can be used as context manager in which case it will call
:meth:`close` on teardown.
.. versionadded:: 2.0
Added the `resilient_parsing`, `help_option_names`,
`token_normalize_func` parameters.
.. versionadded:: 3.0
Added the `allow_extra_args` and `allow_interspersed_args`
parameters.
.. versionadded:: 4.0
Added the `color`, `ignore_unknown_options`, and
`max_content_width` parameters.
.. versionadded:: 7.1
Added the `show_default` parameter.
:param command: the command class for this context.
:param parent: the parent context.
:param info_name: the info name for this invocation. Generally this
is the most descriptive name for the script or
command. For the toplevel script it is usually
the name of the script, for commands below it it's
the name of the script.
:param obj: an arbitrary object of user data.
:param auto_envvar_prefix: the prefix to use for automatic environment
variables. If this is `None` then reading
from environment variables is disabled. This
does not affect manually set environment
variables which are always read.
:param default_map: a dictionary (like object) with default values
for parameters.
:param terminal_width: the width of the terminal. The default is
inherit from parent context. If no context
defines the terminal width then auto
detection will be applied.
:param max_content_width: the maximum width for content rendered by
Click (this currently only affects help
pages). This defaults to 80 characters if
not overridden. In other words: even if the
terminal is larger than that, Click will not
format things wider than 80 characters by
default. In addition to that, formatters might
add some safety mapping on the right.
:param resilient_parsing: if this flag is enabled then Click will
parse without any interactivity or callback
invocation. Default values will also be
ignored. This is useful for implementing
things such as completion support.
:param allow_extra_args: if this is set to `True` then extra arguments
at the end will not raise an error and will be
kept on the context. The default is to inherit
from the command.
:param allow_interspersed_args: if this is set to `False` then options
and arguments cannot be mixed. The
default is to inherit from the command.
:param ignore_unknown_options: instructs click to ignore options it does
not know and keeps them for later
processing.
:param help_option_names: optionally a list of strings that define how
the default help parameter is named. The
default is ``['--help']``.
:param token_normalize_func: an optional function that is used to
normalize tokens (options, choices,
etc.). This for instance can be used to
implement case insensitive behavior.
:param color: controls if the terminal supports ANSI colors or not. The
default is autodetection. This is only needed if ANSI
codes are used in texts that Click prints which is by
default not the case. This for instance would affect
help output.
:param show_default: if True, shows defaults for all options.
Even if an option is later created with show_default=False,
this command-level setting overrides it.
| def __init__ | ( | self, | |
| command, | |||
parent = None, |
|||
info_name = None, |
|||
obj = None, |
|||
auto_envvar_prefix = None, |
|||
default_map = None, |
|||
terminal_width = None, |
|||
max_content_width = None, |
|||
resilient_parsing = False, |
|||
allow_extra_args = None, |
|||
allow_interspersed_args = None, |
|||
ignore_unknown_options = None, |
|||
help_option_names = None, |
|||
token_normalize_func = None, |
|||
color = None, |
|||
show_default = None |
|||
| ) |
| def __enter__ | ( | self | ) |
| def __exit__ | ( | self, | |
| exc_type, | |||
| exc_value, | |||
| tb | |||
| ) |
| def abort | ( | self | ) |
Aborts the script.
| def call_on_close | ( | self, | |
| f | |||
| ) |
This decorator remembers a function as callback that should be executed when the context tears down. This is most useful to bind resource handling to the script execution. For instance, file objects opened by the :class:`File` type will register their close callbacks here. :param f: the function to execute on teardown.
| def close | ( | self | ) |
Invokes all close callbacks.
| def command_path | ( | self | ) |
The computed command path. This is used for the ``usage`` information on the help page. It's automatically created by combining the info names of the chain of contexts to the root.
| def ensure_object | ( | self, | |
| object_type | |||
| ) |
Like :meth:`find_object` but sets the innermost object to a new instance of `object_type` if it does not exist.
| def exit | ( | self, | |
code = 0 |
|||
| ) |
Exits the application with a given exit code.
| def fail | ( | self, | |
| message | |||
| ) |
Aborts the execution of the program with a specific error message. :param message: the error message to fail with.
| def find_object | ( | self, | |
| object_type | |||
| ) |
Finds the closest object of a given type.
| def find_root | ( | self | ) |
Finds the outermost context.
| def forward | ( | * | args, |
| ** | kwargs | ||
| ) |
Similar to :meth:`invoke` but fills in default keyword arguments from the current context if the other command expects it. This cannot invoke callbacks directly, only other commands.
| def get_help | ( | self | ) |
Helper method to get formatted help page for the current context and command.
| def get_usage | ( | self | ) |
Helper method to get formatted usage string for the current context and command.
| def invoke | ( | * | args, |
| ** | kwargs | ||
| ) |
Invokes a command callback in exactly the way it expects. There
are two ways to invoke this method:
1. the first argument can be a callback and all other arguments and
keyword arguments are forwarded directly to the function.
2. the first argument is a click command object. In that case all
arguments are forwarded as well but proper click parameters
(options and click arguments) must be keyword arguments and Click
will fill in defaults.
Note that before Click 3.2 keyword arguments were not properly filled
in against the intention of this code and no context was created. For
more information about this change and why it was done in a bugfix
release see :ref:`upgrade-to-3.2`.
| def lookup_default | ( | self, | |
| name | |||
| ) |
Looks up the default for a parameter name. This by default looks into the :attr:`default_map` if available.
| def make_formatter | ( | self | ) |
Creates the formatter for the help and usage output.
| def meta | ( | self | ) |
This is a dictionary which is shared with all the contexts
that are nested. It exists so that click utilities can store some
state here if they need to. It is however the responsibility of
that code to manage this dictionary well.
The keys are supposed to be unique dotted strings. For instance
module paths are a good choice for it. What is stored in there is
irrelevant for the operation of click. However what is important is
that code that places data here adheres to the general semantics of
the system.
Example usage::
LANG_KEY = f'{__name__}.lang'
def set_language(value):
ctx = get_current_context()
ctx.meta[LANG_KEY] = value
def get_language():
return get_current_context().meta.get(LANG_KEY, 'en_US')
.. versionadded:: 5.0
| def scope | ( | self, | |
cleanup = True |
|||
| ) |
This helper method can be used with the context object to promote
it to the current thread local (see :func:`get_current_context`).
The default behavior of this is to invoke the cleanup functions which
can be disabled by setting `cleanup` to `False`. The cleanup
functions are typically used for things such as closing file handles.
If the cleanup is intended the context object can also be directly
used as a context manager.
Example usage::
with ctx.scope():
assert get_current_context() is ctx
This is equivalent::
with ctx:
assert get_current_context() is ctx
.. versionadded:: 5.0
:param cleanup: controls if the cleanup functions should be run or
not. The default is to run these functions. In
some situations the context only wants to be
temporarily pushed in which case this can be disabled.
Nested pushes automatically defer the cleanup.
| allow_extra_args |
| allow_interspersed_args |
| args |
| auto_envvar_prefix |
| color |
| command |
| default_map |
| help_option_names |
| ignore_unknown_options |
| info_name |
| invoked_subcommand |
| max_content_width |
| obj |
| params |
| parent |
| protected_args |
| resilient_parsing |
| show_default |
| terminal_width |
| token_normalize_func |