2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

pyon: add doc

This commit is contained in:
Sebastien Bourdeauducq 2014-10-27 12:54:59 +08:00
parent 47c0352505
commit 27fc19e415
3 changed files with 37 additions and 0 deletions

View File

@ -1,3 +1,23 @@
"""
This module provide serialization and deserialization functions for Python
objects. Its main features are:
* Human-readable format compatible with the Python syntax.
* Each object is serialized on a single line, with only ASCII characters.
* Supports all basic Python data structures: None, booleans, integers,
floats, strings, tuples, lists, dictionaries.
* Those data types are accurately reconstructed (unlike JSON where e.g. tuples
become lists, and dictionary keys are turned into strings).
* Supports Numpy arrays.
The main rationale for this new custom serializer (instead of using JSON) is
that JSON does not support Numpy and more generally cannot be extended with
other data types while keeping a concise syntax. Here we can use the Python
function call syntax to mark special data types.
"""
import base64
import numpy
@ -69,6 +89,10 @@ _encode_map = {
def encode(x):
"""Serializes a Python object and returns the corresponding string in
Python syntax.
"""
return _encode_map[type(x)](x)
@ -78,4 +102,8 @@ def _nparray(shape, dtype, data):
def decode(s):
"""Parses a string in the Python syntax, reconstructs the corresponding
object, and returns it.
"""
return eval(s, {"__builtins__": None, "nparray": _nparray}, {})

View File

@ -10,3 +10,4 @@ Contents:
tutorial
core_reference
drivers_reference
management_reference

View File

@ -0,0 +1,8 @@
Management reference
====================
:mod:`artiq.management.pyon` module
------------------------------------
.. automodule:: artiq.management.pyon
:members: