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.Note
The blank
UserStris special in that it always representsNonein conversions.
-
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”. LiteralNonepasses through unchanged, and a blankUserStrwill convert toNone.
-
pibootctl.userstr.to_int(s)[source]¶ Converts the
UserStr(or other type) s to aint. As with allUserStrconversions, blank string inputs are converted toNone, and literalNonepasses 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 allUserStrconversions, blank string inputs are converted toNone, and literalNonepasses 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. BlankUserStrare converted toNone, and literalNonepasses through unchanged. Everything else is simply passed to thestrconstructor.
-
pibootctl.userstr.to_list(s, sep=',')[source]¶ Converts the
UserStr(or other type) s to alistbased on the separator character sep (which defaults to “,”). BlankUserStrare converted toNone, and literalNonepasses through unchanged. Everything else is passed to thelistconstructor. This ensures that the result is always a unique reference.