Utils Module

Utils for input types

author:

Doug Skrypa

class cli_command_parser.inputs.utils.InputParam(default: T)[source]

Bases: Generic[T]

default
name
class cli_command_parser.inputs.utils.StatMode(*values)[source]

Bases: FixedFlag

mode: int | None
friendly_name: str
DIR = 1
FILE = 2
CHARACTER = 4
BLOCK = 8
FIFO = 16
SOCKET = 64
ANY = 127
matches(mode: int) bool[source]
class cli_command_parser.inputs.utils.FileWrapper(path: Path, mode: OpenTextMode = 'r', *, encoding: OptStr = None, errors: OptStr = None, parents: Bool = False)[source]
class cli_command_parser.inputs.utils.FileWrapper(path: Path, mode: OpenBinaryMode, *, encoding: OptStr = None, errors: OptStr = None, parents: Bool = False)
class cli_command_parser.inputs.utils.FileWrapper(path: Path, mode: OpenAnyMode = 'r', *, encoding: OptStr = None, errors: OptStr = None, parents: Bool = False)

Bases: Generic

read() AnyStr[source]
write(data: AnyStr) None[source]
close()[source]
class cli_command_parser.inputs.utils.SerializedFileWrapper(path: Path, mode: OpenAnyMode, serializer: AnySerializer[AnyStr], *, encoding: OptStr = None, errors: OptStr = None, parents: Bool = False)[source]

Bases: FileWrapper

serializer: AnySerializer[AnyStr]
read() Any[source]
write(data: Any) None[source]
class cli_command_parser.inputs.utils.JsonSerializer(wrap_errors: Bool = True)[source]

Bases: FileSerializer[str]

static dump(obj, fp, *, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw)

Serialize obj as a JSON formatted stream to fp (a .write()-supporting file-like object).

If skipkeys is true then dict keys that are not basic types (str, int, float, bool, None) will be skipped instead of raising a TypeError.

If ensure_ascii is false, then the strings written to fp can contain non-ASCII and non-printable characters if they appear in strings contained in obj. Otherwise, all such characters are escaped in JSON strings.

If check_circular is false, then the circular reference check for container types will be skipped and a circular reference will result in an RecursionError (or worse).

If allow_nan is false, then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (NaN, Infinity, -Infinity).

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (', ', ': ') if indent is None and (',', ': ') otherwise. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.

If sort_keys is true (default: False), then the output of dictionaries will be sorted by key.

To use a custom JSONEncoder subclass (e.g. one that overrides the .default() method to serialize additional types), specify it with the cls kwarg; otherwise JSONEncoder is used.

wrap_errors
load(fp: SupportsRead[str]) Any[source]
cli_command_parser.inputs.utils.allows_write(mode: str, strict: bool = False) bool[source]
cli_command_parser.inputs.utils.fix_windows_path(path: Path) Path[source]

Attempts to resolve issues related to inconsistencies between the way the version of Bash that is distributed with Git handles paths in some situations and the way that Python handles paths.

The use case that this function currently handles is when the given Path does not exist, and it was auto-completed by Git Bash to begin with /{drive}/... instead of {drive}:/....

cli_command_parser.inputs.utils.range_str(min_val: Number, max_val: Number, include_min: Bool, include_max: Bool, var: str = 'N') str[source]
class cli_command_parser.inputs.utils.RangeMixin[source]

Bases: object

min: Number
max: Number
include_min: bool
include_max: bool
value_lt_min(value: Number) bool[source]
value_gt_max(value: Number) bool[source]