upsies.utils.types
CLI argument types
All types return normalized values and raise ValueError for invalid values.
Functions
- upsies.utils.types.Choice(options, *, empty_ok=False, case_sensitive=True)[source]
Return
strsubclass that can only have instances that are equal to an item of options- Parameters:
- Raises:
ValueError – if instantiation is attempted with a value that is not in options
- upsies.utils.types.Imagehost(allowed=None, disallowed=None)[source]
Return new
Choicesubclass that only accepts allowed image host names- Parameters:
allowed – Sequence of allowed image host names or None to allow all supported image host names
disallowed – Sequence of disallowed image host names or None to allow all supported image host names
- upsies.utils.types.Integer(min=None, max=None)[source]
Return
intsubclass with minimum and maximum value>>> i = Integer(min=0, max=10) >>> i(100) >>> ValueError: Maximum is 10
- upsies.utils.types.ListOf(item_type, separator=None)[source]
Return immutable sequence type that can only contain item_type objects
- Parameters:
item_type – Any callable that returns a valid object for any items added to the list or raises
ValueErrororTypeError- Raises:
ValueError – if any invalid value is added to the list
- Returns:
subclass of
Sequence
Classes
- class upsies.utils.types.Bool(value)[source]
Bases:
strstrsubclass with boolean valueTruthy strings:
true,yes,on,1Falsy strings:false,no,off,0- truthy = ('true', 'yes', '1', 'on', 'aye')
Valid True values (case-insensitive)
- falsy = ('false', 'no', '0', 'off', 'nay')
Valid False values (case-insensitive)
- class upsies.utils.types.Bytes(value)[source]
Bases:
intintsubclass with binary or decimal unit prefix- format(*, prefix='shortest', decimal_places=2, trailing_zeros=False)[source]
Return human-readable string
- Parameters:
prefix (str) – Unit prefix, must be one of
binary(1000 -> “1 kB”),decimal(1024 -> “1 KiB”) orshortest(automatically pick the string representation with the fewest decimal places)decimal_places (int) – How many decimal places to include
trailing_zeros (bool) – Whether to remove zeros on the right of the decimal places
- class upsies.utils.types.PathTranslation(string)[source]
Bases:
objectTranslate beginning of path
- Parameters:
string (str) – Translation in the form of
/from/path -> /to/path
Windows paths are detected by a single ASCII letter followed by a colon (e.g.
c:) at the beginning of a path. All other paths are interpreted as POSIX.~is interpreted viaos.path.expanduser()for local paths.- property local
pathlib.PurePathinstance of the first/source path
- property remote
pathlib.PurePathinstance of the second/target path
- class upsies.utils.types.PathTranslations(items=())[source]
Bases:
ListOfPathTranslationListOfPathTranslationinstances- translate(path)[source]
Use the first matching
PathTranslationto translate pathReturn path unmodified by default.
- class upsies.utils.types.Regex(pattern)[source]
Bases:
objectSpecial class that behaves like
re.Pattern(return value ofre.compile()) but more intuitivelyIts string representation is
re.Pattern.patterninstead ofre.compile('<pattern>').Instead of raising
re.error, it raisesValueErroron invalid regular expressions.- Raises:
ValueError – instead of
re.error
- class upsies.utils.types.ReleaseType(value)[source]
Bases:
EnumEnum with the values
movie,season,episodeandunknownseriesis an alias forseason.All values are truthy except for
unknown.
- class upsies.utils.types.ReleaseYear(year)[source]
Bases:
intintwithin a reasonable range- Raises:
ValueError – if year cannot be converted to int or is not reasonable
- class upsies.utils.types.SceneCheckResult(value)[source]
Bases:
EnumEnum with the values
true,false,renamed,alteredandunknownAll values are falsy except for
true.
- class upsies.utils.types.Timestamp(seconds)[source]
Bases:
floatSubclass of
floatthat can parse and format timestamp/duration strings- Parameters:
seconds (int or float or "[[H+:]M+:]S+") – Number of seconds or hours, minutes and seconds as “:”-separated string
- Raises:
ValueError – if seconds is not a valid timestamp
- classmethod from_string(string)[source]
Parse string of the format “[[H+:]MM:]SS”
- Parameters:
string (str) – Hours, minutes and seconds as “:”-separated string or number of seconds
- Raises:
ValueError – if string has an invalid format