smisk.serialization — Data serialization

New in version 1.1.

Data serialization

class smisk.serialization.Registry
associate(serializer, media_type=None, extension=None, override_existing=True)
Associate a serializer with formats and extensions
find(media_type_or_extension)
Find a serializer associated with a media type or an extension. Returns None if not found.
readers
Iterate serializers able to read, or unserialize, data.
register(serializer)
Register a new Serializer
unregister(serializer=None)
Unregister a previously registered serializer or all registered serializers, if serializer is None.
writers
Iterate serializers able to write, or serialize, data.
exception smisk.serialization.SerializationError
Indicates an encoding error
class smisk.serialization.Serializer

Abstract baseclass for serializers

add_content_type_header
Adds “Content-Type” header if missing
did_register

Called when this serializer has been successfully registered in a Registry.

Default implementation does nothing. This is meant to be overridden in subclasses to allow a kind of initialization routine, setting up cls if needed.

Parameters:
registry : Registry

The registry in which this serializer was just registered

Return type:

None

did_unregister

Called when this serializer has been removed from a Registry.

Default implementation does nothing. This is meant to be overridden in subclasses to allow a kind of initialization routine, tearing down cls if needed.

Parameters:
registry : Registry

The registry from which this serializer was removed

Return type:

None

directions

List of possible directions.

Returns:["read", "write"], ["read"], ["write"] or []
Return type:list
serialize
Parameters:
  • params (dict) – Parameters
  • charset (string) – Destination charset. Might be discarded, so care about the returned charset.
Returns:

Tuple of (charset, string data) where charset is the name of the actual charset used and might be None if binary or unknown.

Return type:

tuple

serialize_error

Encode an error.

Might return None to indicate that someone else should handle the error encoding.

params will always contain:
  • “code”: int Error code. i.e. 123
  • “name”: unicode Name of the error. i.e. “404 Not Found”
  • “description”: unicode Description of the error or the emtpy string.
  • “server”: unicode Short one line description of the server name, port and software.
params might contain:
  • “traceback”: list A list of strings.
Parameters:
  • status (smisk.mvc.http.Status) – HTTP status
  • params (dict) – Parameters
  • charset (string) – Destination charset. Might be discarded, so care about the returned charset.
Returns:

Tuple of (charset, string data) where charset is the name of the actual charset used and might be None if binary or unknown.

Return type:

tuple

unserialize
Parameters:
  • file (object) – A file-like object implementing at least the read() method
  • length (int) –
  • charset (string) –
Returns:

Tuple of (list args, dict params) args and params might be None

Return type:

tuple

exception smisk.serialization.UnserializationError
Indicates an encoding error
class smisk.serialization.data(source)

Represents arbitrary bytes.

decode

Decode data which is a base-64 encoded string.

Parameters:
string : string

Base-64 encoded data

Return type:

data

encode()

Return a base-64 encoded representation of this data.

Return type:string

Modules

Previous topic

smisk.release

Next topic

smisk.serialization.json

This Page

Quick search