pyfarm.core.utility module¶
Utilities¶
General utility functions that are not specific to individual components of PyFarm.
-
class
pyfarm.core.utility.ImmutableDict(iterable=None, **kwargs)¶ Bases:
dictA basic immutable dictionary that’s built on top of Python’s standard
dictclass. Once__init__()has been run the contents of the instance can no longer be modified-
clear(*args, **kwargs)¶
-
pop(*args, **kwargs)¶
-
popitem(*args, **kwargs)¶
-
setdefault(*args, **kwargs)¶
-
update(*args, **kwargs)¶
-
-
class
pyfarm.core.utility.PyFarmJSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶ Bases:
json.encoder.JSONEncoder-
encode(o)¶
-
-
class
pyfarm.core.utility.convert¶ Bases:
objectNamespace containing various static methods for converting data.
Some staticmethods are named the same as builtin types. The name indicates the expected result but the staticmethod may not behave the same as the equivalently named Python object. Read the documentation for each staticmethod to learn the differences, expected input and output.
-
static
bool(value)¶ Converts
valueinto a boolean object. This function mainly exits so human-readable booleans such as ‘yes’ or ‘y’ can be handled in a single location. Internally it does not usebool()and instead checksvalueagainstpyfarm.core.enums.BOOLEAN_TRUEandpyfarm.core.enums.BOOLEAN_FALSE.Parameters: value – The value to attempt to convert to a boolean. If this value is a string it will be run through .lower().strip()first.Raises: ValueError – Raised if we can’t convert valueto a true boolean object
-
static
bytetomb(value)¶ Convert bytes to megabytes
>>> convert.bytetomb(10485760) 10.0
-
static
list(value, sep=', ', strip=True, filter_empty=True)¶ Converts
valueinto a list object by splitting onsep.Parameters: - value (str) – The string we should convert into a list
- sep (str) – The string that we should split
valueby. - strip (bool) – If
True, strip extra whitespace from the results so'foo, bar'becomes['foo', 'bar'] - filter_empty (bool) – If
True, any result that evaluates toFalsewill be removed so'foo,,'would become['foo']
-
static
mbtogb(value)¶ Convert megabytes to gigabytes
>>> convert.mbtogb(2048) 2.0
-
static
none(value)¶ Converts
valueintoNone. This function mainly exits so human-readable values such as ‘None’ or ‘null’ can be handled in a single location. Internally this checksvalueagainstpyfarm.core.enums.NONEParameters: value – The value to attempt to convert to None. If this value is a string it will be run through.lower().strip()first.Raises: ValueError – Raised if we can’t convert valuetoNone
-
static
ston(value, types=(<class 'int'>, <class 'float'>, <class 'complex'>))¶ Converts a string to an integer or fails with a useful error message
Parameters: value (string) – The value to convert to an integer
Raises: - ValueError – Raised if
valuecould not be converted usingliterval_eval() - TypeError – Raised if
valuewas not converted to a float, integer, or long
- ValueError – Raised if
-
static