Package ganeti :: Module serializer
[hide private]
[frames] | no frames]

Module serializer

source code

Serializer abstraction module

This module introduces a simple abstraction over the serialization backend (currently json).

Functions [hide private]
(callable, callable)
_GetJsonDumpers(_encoder_class=simplejson.JSONEncoder)
Returns two JSON functions to serialize data.
source code
 
DumpJson(data, indent=True)
Serialize a given object.
source code
 
LoadJson(txt)
Unserialize data from a string.
source code
 
DumpSignedJson(data, key, salt=None, key_selector=None)
Serialize a given object and authenticate it.
source code
tuple of original data, string
LoadSignedJson(txt, key)
Verify that a given message was signed with the given key, and load it.
source code
 
Dump(data, indent=True)
Serialize a given object.
source code
 
Load(txt)
Unserialize data from a string.
source code
 
DumpSigned(data, key, salt=None, key_selector=None)
Serialize a given object and authenticate it.
source code
tuple of original data, string
LoadSigned(txt, key)
Verify that a given message was signed with the given key, and load it.
source code
Variables [hide private]
  _JSON_INDENT = 2
  _RE_EOLSP = re.compile('[ \t]+$', re.MULTILINE)

Imports: simplejson, re, errors, utils


Function Details [hide private]

_GetJsonDumpers(_encoder_class=simplejson.JSONEncoder)

source code 

Returns two JSON functions to serialize data.

Returns: (callable, callable)
The function to generate a compact form of JSON and another one to generate a more readable, indented form of JSON (if supported)

DumpJson(data, indent=True)

source code 

Serialize a given object.

Parameters:
  • data - the data to serialize
  • indent - whether to indent output (depends on simplejson version)
Returns:
the string representation of data

LoadJson(txt)

source code 

Unserialize data from a string.

Parameters:
  • txt - the json-encoded form
Returns:
the original data

DumpSignedJson(data, key, salt=None, key_selector=None)

source code 

Serialize a given object and authenticate it.

Parameters:
  • data - the data to serialize
  • key - shared hmac key
  • key_selector - name/id that identifies the key (in case there are multiple keys in use, e.g. in a multi-cluster environment)
Returns:
the string representation of data signed by the hmac key

LoadSignedJson(txt, key)

source code 

Verify that a given message was signed with the given key, and load it.

Parameters:
  • txt - json-encoded hmac-signed message
  • key - the shared hmac key or a callable taking one argument (the key selector), which returns the hmac key belonging to the key selector. Typical usage is to pass a reference to the get method of a dict.
Returns: tuple of original data, string
original data, salt
Raises:

Dump(data, indent=True)

source code 

Serialize a given object.

Parameters:
  • data - the data to serialize
  • indent - whether to indent output (depends on simplejson version)
Returns:
the string representation of data

Load(txt)

source code 

Unserialize data from a string.

Parameters:
  • txt - the json-encoded form
Returns:
the original data

DumpSigned(data, key, salt=None, key_selector=None)

source code 

Serialize a given object and authenticate it.

Parameters:
  • data - the data to serialize
  • key - shared hmac key
  • key_selector - name/id that identifies the key (in case there are multiple keys in use, e.g. in a multi-cluster environment)
Returns:
the string representation of data signed by the hmac key

LoadSigned(txt, key)

source code 

Verify that a given message was signed with the given key, and load it.

Parameters:
  • txt - json-encoded hmac-signed message
  • key - the shared hmac key or a callable taking one argument (the key selector), which returns the hmac key belonging to the key selector. Typical usage is to pass a reference to the get method of a dict.
Returns: tuple of original data, string
original data, salt
Raises: