API Reference

hipack

This module provide a pythonic way to handle HiPack messages.

exception hipack.ParseError(line, column, message)

Use to signal an error when parsing a HiPack message.

Attribute line:Input line where the error occurred.
Attribute column:
 Input column where the error occured.
Attribute message:
 Textual description of the error.
class hipack.Parser(stream, cast=<function cast>)

Parses HiPack messages and converts them to Python objects.

Parameters:
  • stream – A file-like object with a .read(n) method.
  • cast (callable) – Function called after each value has been parsed successfully, which can perform additional conversions on the data. The cast function is passed the set of annotations associated with the value, the bytes representation before converting a simple literal value (that is, all except lists and dictionaries, for which None is passed instead), and the converted value.
messages()

Parses and yields each message contained in the input stream.

For an input stream which contains a single, unframed message, the method yields exactly once. For an input with multiple, framed messages, each message is yield in the same order as they are in the input stream.

parse_message()

Parses a single message from the input stream. If the stream contains multiple messages delimited by braces, each subsequent calls will return the following message.

hipack.cast(annotations, bytestring, value)

Default “cast” function.

hipack.dump(obj, stream, indent=True, value=<function value>)

Writes Python objects to a writable stream as a HiPack message.

Parameters:
  • obj – Object to be serialized and written.
  • stream – A file-like object with a .write(b) method.
  • indent (bool) – Whether to pretty-print and indent the written message, instead of writing the whole message in single line. (Default: False).
  • value (callable) – Function called before writing each value, which can perform additional conversions to support direct serialization of values other than those supported by HiPack. The function is passed a Python object, and it must return an object that can be represented as a HiPack value.
hipack.dumps(obj, indent=True, value=<function value>)

Serializes a Python object into a string in HiPack format.

Parameters:
  • obj – Object to be serialized and written.
  • indent (bool) – Whether to pretty-print and indent the written message, instead of writing the whole message in single line. (Default: False).
  • value (callable) – A Python object conversion function, see dump() for details.
hipack.load(stream, cast=<function cast>)

Parses a single message from an input stream.

Parameters:
  • stream – A file-like object with a .read(n) method.
  • cast (callable) – A value conversion function, see Parser for details.
hipack.loads(bytestring, cast=<function cast>)

Parses a single message contained in a string.

Parameters:
  • bytestring – Input string. It is valid to pass any of str, unicode, and bytes objects as input.
  • cast (callable) – A value conversion function, see Parser for details.
hipack.value(obj)

Default “value” function.

hipack.Parser

class hipack.Parser(stream, cast=<function cast>)

Parses HiPack messages and converts them to Python objects.

Parameters:
  • stream – A file-like object with a .read(n) method.
  • cast (callable) – Function called after each value has been parsed successfully, which can perform additional conversions on the data. The cast function is passed the set of annotations associated with the value, the bytes representation before converting a simple literal value (that is, all except lists and dictionaries, for which None is passed instead), and the converted value.
messages()

Parses and yields each message contained in the input stream.

For an input stream which contains a single, unframed message, the method yields exactly once. For an input with multiple, framed messages, each message is yield in the same order as they are in the input stream.

parse_message()

Parses a single message from the input stream. If the stream contains multiple messages delimited by braces, each subsequent calls will return the following message.