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.
register(serializer)
Register a new Serializer
unregister(serializer=None)
Unregister a previously registered serializer or all registered serializers, if serializer is None.
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:
  • “name”: string Name of the error. i.e. “Not Found”
  • “code”: int Error code. i.e. 404
  • “description”: string Description of the error.
  • “traceback”: object A list of strings or None if not available.
  • “server”: string Short one line description of the server name, port and software.
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