pibootctl.userstr¶
The pibootctl.userstr
module provides the UserStr
class which
represents unparsed user input on the command line.
The module also provides a variety of functions for converting input (either
from JSON, YAML, or other structured formats, or from unparsed
UserStr
) into common types (to_bool()
, to_int()
,
to_str()
, etc).
-
class
pibootctl.userstr.
UserStr
[source]¶ Type used to represent a value expressed as a string on the command line. In other words, any value bearing this type is a string representation of some other type (possibly
str
,int
,None
, etc.)Primarily used by various conversion routines (
to_bool()
,to_str()
, etc.) to determine whether a value is a string parsed from some serialization format (like JSON or YAML) which should be treated as a string literal.
-
pibootctl.userstr.
to_bool
(s)[source]¶ Converts the
UserStr
(or other type) s to abool
. Various “typical” string representations of true and false are accepted including “true”, “yes”, and “on”, along with their counter-parts “false”, “no”, and “off”. LiteralNone
passes through unchanged, and a blankUserStr
will convert toNone
.
-
pibootctl.userstr.
to_int
(s)[source]¶ Converts the
UserStr
(or other type) s to aint
. As with allUserStr
conversions, blank string inputs are converted toNone
, and literalNone
passes through unchanged. Otherwise, decimal integers and hexi-decimal integers prefixed with “0x” are accepted.
-
pibootctl.userstr.
to_float
(s)[source]¶ Converts the
UserStr
(or other type) s to afloat
. As with allUserStr
conversions, blank string inputs are converted toNone
, and literalNone
passes through unchanged. Otherwise, typical floating point values (optionally prefixed with sign, optionally suffixed with an exponent) are accepted.
-
pibootctl.userstr.
to_str
(s)[source]¶ Converts the
UserStr
(or other type) s to astr
. BlankUserStr
are converted toNone
, and literalNone
passes through unchanged. Everything else is simply passed to thestr
constructor.
-
pibootctl.userstr.
to_list
(s, sep=', ')[source]¶ Converts the
UserStr
(or other type) s to alist
based on the separator character sep (which defaults to “,”). BlankUserStr
are converted toNone
, and literalNone
passes through unchanged. Everything else is passed to thelist
constructor. This ensures that the result is always a unique reference.