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 TypeError will be raised.

    Supported automatic conversions:

    • int, float, and bool will all convert to each other.

    • str will convert to/from bytes using the selected encoding.

    • list will convert to dict with the indexes as keys (starting from 1). dict cannot be converted to list.

  • 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, or None depending on the type of data in the pod. Use the type parameter to constrain this.

None will only be returned if the input decodes to nil. Invalid pods raise a ParserError instead of returning None.

Raises:
  • ParserError – An error occurred trying to parse the pod.

  • TypeError – The result did not match the required type.