KERI Help API
keri.help.helping
keri.help.helping module
- class keri.help.helping.NonStringIterable[source]
Allows isinstance check for iterable that is not a string if isinstance(x, NonStringIterable):
- class keri.help.helping.NonStringSequence[source]
Allows isinstance check for sequence that is not a string if isinstance(x, NonStringSequence):
- keri.help.helping.codeB2ToB64(b, l)[source]
Convert l sextets from base2 b to base64
- Returns:
conversion (encode) of l Base2 sextets from front of b to Base64 chars.
- Return type:
cs (bytes)
One char for each of l sextets from front (left) of b. This is useful for encoding as code characters, sextets from the front of a Base2 bytes (byte string). Must provide l because of ambiguity between l=3 and l=4. Both require 3 bytes in b. Trailing pad bits are removed so returned sextets as characters are right aligned .
- Parameters:
b (bytes | str) – target from which to nab sextets
l (int) – number of sextets to convert from front of b
- keri.help.helping.codeB64ToB2(s)[source]
Convert Base64 chars in s to B2 bytes
- Returns:
conversion (decode) of s Base64 chars to Base2 bytes. Where the number of total bytes returned is equal to the minimun number of chars (octet) sufficient to hold the total converted concatenated chars from s, with one sextet per each Base64 char of s. Assumes no pad chars in s.
- Return type:
bs (bytes)
Sextets are left aligned with pad bits in last (rightmost) byte to support mid padding of code portion with respect to rest of primitive. This is useful for decoding as bytes, code characters from the front of a Base64 encoded string of characters.
- Parameters:
s (str | bytes) – Base64 str or bytes to convert
- keri.help.helping.datify(cls, d)[source]
Returns instance of dataclass cls converted from dict d. If the dataclass cls or any nested dataclasses contains a _der method, the use it instead of default fieldtypes conversion.
Parameters: cls is dataclass class d is dict
- keri.help.helping.dictify(val: dataclass)[source]
Returns a serializable dict represention of a dataclass. If the dataclass contains a _ser method, use it instead of asdict
- Parameters:
dict. (val the dataclass instance to turn into a)
- keri.help.helping.extractElementValues(element, values)[source]
Recusive depth first search that recursively extracts value(s) from element and appends to values list
Assumes that extracted values are str
- Parameters:
from (element is some element to extract values)
nonStringIterables (values is list of values from elements that are not)
- IF element is mapping or sequence (nonStringIterable) then
recusively extractValues from the items of that element
- Else
append element to values list
return
- keri.help.helping.extractValues(ked, labels)[source]
Returns list of depth first recursively extracted values from elements of key event dict ked whose labels are in labels list
- Parameters:
dict (ked is key event)
values (labels is list of element labels in ked from which to extract)
- keri.help.helping.fromIso8601(dts)[source]
Returns datetime object from RFC-3339 profile of ISO 8601 format str or bytes. Converts dts from ISO 8601 format to datetime object
YYYY-MM-DDTHH:MM:SS.ffffff+HH:MM[:SS[.ffffff]] .strftime(‘%Y-%m-%dT%H:%M:%S.%f%z’) ‘2020-08-22T17:50:09.988921+00:00’ Assumes TZ aware For nanosecond use instead attotime or datatime64 in pandas or numpy
- keri.help.helping.intToB64(i, l=1)[source]
Returns conversion of int i to Base64 str l is min number of b64 digits left padded with Base64 0 == “A” char
- keri.help.helping.intToB64b(i, l=1)[source]
Returns conversion of int i to Base64 bytes l is min number of b64 digits left padded with Base64 0 == “A” char
- keri.help.helping.isNonStringIterable(obj)[source]
- Returns:
True if obj is non-string iterable, False otherwise
- Return type:
(bool)
Future proof way that is compatible with both Python3 and Python2 to check for non string iterables.
Faster way that is less future proof return (hasattr(x, ‘__iter__’) and not isinstance(x, (str, bytes)))
- keri.help.helping.isNonStringSequence(obj)[source]
Returns: True if obj is non-string sequence, False otherwise
Future proof way that is compatible with both Python3 and Python2 to check for non string sequences.
- keri.help.helping.isign(i)[source]
Integer sign function :returns: 1 if i > 0, -1 if i < 0, 0 otherwise :rtype: (int)
- keri.help.helping.key64uToKey(key64u)[source]
Returns bytes Convert and return unicode base64 url-file safe key64u to bytes key
- keri.help.helping.keyToKey64u(key)[source]
Returns 64u Convert and return bytes key to unicode base64 url-file safe version
- keri.help.helping.klasify(sers: Iterable, klases: Iterable, args: Iterable = None)[source]
Convert each qb64 serialization ser in sers to instance of corresponding klas in klases modified by corresponding arg in args. Useful for converting iterable of CESR serializations to associated iterable of CESR subclass instances. When klas in klases is None then return corresponding ser without conversion
- Parameters:
sers (Iterable) – of serialized CESR subclass, str .qb64 or bytes .qb64b
klases (Iterable) – of class reference of CESR subclass
- keri.help.helping.nabSextets(b, l)[source]
Nab l sextets from front of b
- Returns:
- first l sextets from front (left) of b as bytes
(byte string). Length of bytes returned is minimum sufficient to hold all l sextets. Last byte returned is right bit padded with zeros which is compatible with mid padded codes on front of primitives
- Return type:
sextets (bytes)
- Parameters:
b (bytes | str) – target from which to nab sextets
l (int) – number of sextets to nab from front of b
- keri.help.helping.nowIso8601()[source]
Returns time now in RFC-3339 profile of ISO 8601 format. use now(timezone.utc)
YYYY-MM-DDTHH:MM:SS.ffffff+HH:MM[:SS[.ffffff]] .strftime(‘%Y-%m-%dT%H:%M:%S.%f%z’) ‘2020-08-22T17:50:09.988921+00:00’ Assumes TZ aware For nanosecond use instead attotime or datatime64 in pandas or numpy
- keri.help.helping.nowUTC()[source]
Returns timezone aware datetime of current UTC time Convenience function that allows monkeypatching in tests to mock time
- keri.help.helping.sceil(r)[source]
Symmetric ceiling function :returns: value that is symmetric ceiling of r away from zero :rtype: sceil (int)
- Because int() provides a symmetric floor towards zero, just inc int(r) by:
1 when r - int(r) > 0 (r positive)
- -1 when r - int(r) < 0 (r negative)
0 when r - int(r) == 0 (r integral already)
abs(r) > abs(int(r) or 0 when abs(r)
- keri.help.helping.toIso8601(dt=None)[source]
Returns str datetime dt in RFC-3339 profile of ISO 8601 format. Converts datetime object dt to ISO 8601 formt If dt is missing use now(timezone.utc)
YYYY-MM-DDTHH:MM:SS.ffffff+HH:MM[:SS[.ffffff]] .strftime(‘%Y-%m-%dT%H:%M:%S.%f%z’) ‘2020-08-22T17:50:09.988921+00:00’ Assumes TZ aware For nanosecond use instead attotime or datatime64 in pandas or numpy