unpod()¶
- picopod.unpod(pod, *, type=None, encoding='p8scii')¶
Deserialize a Picotron pod into a Python object.
Pods compressed with LZ4 and/or encoded with Base64 are detected and unpacked automatically. Whitespace and Lua comments inside the pod are ignored.
Unlike Picotron, which stops as soon as it reads a valid value, the entire input must be consumed or this will raise a
ParserError.- Parameters:
pod (str|Buffer) –
The pod to decode, as either a string or bytes.
If this is a string, it will be automatically encoded to bytes using the selected encoding (P8SCII by default).
type (type, optional) –
The expected result type. If the pod deserializes to a different type, it will be converted to this type if supported (see below) or else a
TypeErrorwill be raised.Supported automatic conversions:
int,float, andboolwill all convert to each other.strwill convert to/frombytesusing the selected encoding.listwill convert todictwith the indexes as keys (starting from 1).dictcannot be converted tolist.
encoding (str, optional) – The encoding to decode byte strings with.
- Returns:
The deserialized object. This may be an
int,float,bool,str,bytes,list,dict,Userdata, orNonedepending on the type of data in the pod. Use thetypeparameter to constrain this.Nonewill only be returned if the input decodes to nil. Invalid pods raise aParserErrorinstead of returningNone.- Raises:
ParserError – An error occurred trying to parse the pod.
TypeError – The result did not match the required type.