Skip to content

value_text

panel_flowdash.value_text

Text for arbitrary values shown to a user or an agent, never an object's own repr.

A param.Parameterized repr lists every parameter, so a data source would show its connection URI with the password, its tokens and the like. Only plain data (strings, numbers, dates and the like) is written out; any other object is named by its type, and a Parameterized by its name too.

RESTRICTED_ERROR_TEXT = 'Restricted: you do not have access to this data.' module-attribute

_BEARER = re.compile('\\b(bearer\\s+)(?=[\\w~+/.-]*(?:\\d|[~+/.][\\w~+/-])|\\w{16})[\\w~+/.-]+=*', re.IGNORECASE) module-attribute

_CONTAINERS = (list, tuple, set, frozenset, dict) module-attribute

_HEADER_WORD = '(?:required|missing|invalid|expired|needed|denied|rejected|failed|empty|header|is|was|not|must)(?![^\\s\\"\',;}&])' module-attribute

_MAX_NAME = 60 module-attribute

_PASSWORD_PLAIN = re.compile('(\\b\\w*?(?:password|passwd|pwd)\\s*:\\s*)(?![*"\'])[^\\s"\',;}&]+(?![^\\s"\',;}&])(?!\\s+(?-i:[a-z]))', re.IGNORECASE) module-attribute

_PLAIN_TYPES = (str, bytes, bool, numbers.Number, dt.date, dt.time, dt.timedelta, decimal.Decimal, fractions.Fraction, uuid.UUID, pathlib.PurePath, enum.Enum) module-attribute

_SAFE_REPR = SafeRepr() module-attribute

_SECRET_HEADER = re.compile(f'''(\\b(?:(?:x-)?api[_-]?key["']?\\s*:|authorization["']?\\s*[:=])\\s*(?:["'](?:(?:bearer|basic|token)\\s+)?|(?:bearer|basic)\\s+|token\\s+(?!{_HEADER_WORD})|(?!(?:bearer|basic|token)\\s)(?!{_HEADER_WORD})))(?![*"'])[^\\s"',;}}&]+''', re.IGNORECASE) module-attribute

_SECRET_KEY = '\\b\\w*?(?:password|passwd|pwd|secret|token|api[_-]?key)' module-attribute

_SECRET_PARAM = re.compile(f'''({_SECRET_KEY}=)[^\\s&;,'\\"]+''', re.IGNORECASE) module-attribute

_SECRET_QUOTED = re.compile(f'''(["']?{_SECRET_KEY}["']?\\s*[:=]\\s*)(["'])(?:\\\\.|(?!\\2).)*?\\2''', re.IGNORECASE) module-attribute

_URL_PASSWORD = re.compile('(\\b[a-zA-Z][\\w+.-]*://[^\\s:/@]*:)[^\\s@/]+@') module-attribute

SafeRepr

Bases: Repr

A reprlib.Repr that writes containers out but names any other object by its label.

repr_instance(x, level)

_auto_name(obj, name)

Whether name is one param generated, like FileSource00012.

_safe_labels(index)

Return a pandas index whose labels and level names that are not plain data show their text.

The index itself is returned when nothing needs to change.

error_text(exc)

Return an exception's message with its credentials masked, to show a user or an agent.

held_table_names(value)

Return the table names a source already holds, never calling get_tables(), which may query it.

is_plain(value)

Whether value is plain data whose text is the data itself, not an object's internals.

is_restricted(error)

Return whether error is a refusal of access: a PermissionError, or one caused by it.

Takes the param.ReactiveError a failed output carries too. A component that wraps a failure of its input in an error of its own keeps the refusal recognisable by raising it from the original; an error raised while handling one with the context suppressed (raise ... from None) is not a refusal. A PermissionError the OS raised, whose errno is a real OS error number (EACCES, EPERM), is a fault of the deployment, such as an unreadable file, and not a refusal either; one whose first argument is some other number, e.g. PermissionError(403, "Forbidden"), is a refusal. An exception group is a refusal when any of its members is.

object_label(value)

Name value by its type, and a Parameterized by its own name too, e.g. FileSource ยท turbines.

redact_secrets(text)

Mask a URL's password, secret keys' values and bearer tokens, e.g. in an error message.

safe_frame(frame)

Return a pandas frame whose objects that are not plain data show their text.

That covers object cells, index values, column labels and level names. The frame is copied only when one of them needs to change, so pass only the rows to show.

safe_repr(value)

Return repr(value) for plain data and containers of it, labelling any other object.

safe_str(value)

Return str(value) for plain data and the object's label for anything else.