New in version 1.1.0.
Data serialization
Represent arbitrary bytes.
Actual storage of the bytes.
| Type: | str |
|---|
A serializers registry.
Can be accessed like a dictionary:
>>> reg = Registry()
>>> # (register some serializers here)
>>> reg[3]
<class MySerializer ...
>>> MySerializer in reg
True
>>> for serializer in reg:
... print serializer
<class Serializer1 ...
<class Serializer2 ...
First registered serializer.
| Type: | Serializer |
|---|---|
| Value: | None |
Media type-to-Serializer map.
| Type: | dict |
|---|---|
| Value: | {} |
Filename extension-to-Serializer map.
| Type: | dict |
|---|---|
| Value: | {} |
List of available serializers.
| Type: | list |
|---|---|
| Value: | [] |
Iterate serializers able to read, or unserialize, data.
for ser in reg.readers:
print ser
| Return type: | generator |
|---|
Iterate serializers able to write, or serialize, data.
for ser in reg.writers:
print ser
| Return type: | generator |
|---|
Register a new Serializer.
serializer should be the class of the serializer to register, not an instance.
Find a Serializer associated with a media type or an extension.
| Return type: | Serializer |
|---|---|
| Returns: | None if not found. |
Abstract baseclass for serializers.
All members described here are class members (serializers are never instantiated).
A human readable short and descriptive name of the serializer.
| Type: | str |
|---|---|
| Value: | “Untitled serializer” |
Filename extensions this serializer can handle.
Must contain at least one item. The first item will be used as the primary extension.
| Type: | collection |
|---|---|
| Value: | tuple() |
Media types this serializer can handle.
Must contain at least one item. The first item will be used as the primary media type.
| Type: | collection |
|---|---|
| Value: | tuple() |
Preferred character encoding.
If the value is None the serializer is considered “binary”.
| Type: | str |
|---|---|
| Value: | None |
How to handle unicode conversions.
Possible values: "strict", "ignore", "replace", "xmlcharrefreplace", "backslashreplace"
| Type: | str |
|---|---|
| Value: | “strict” |
If enabled, serialize() will be called even when leafs does not generate a response body. (i.e. params=None passed to serialize())
Some serialization formats does not allow empty responses (RPC-variants for instance) in which case this feature come in handy.
| Type: | bool |
|---|---|
| Value: | False |
Declares where there or not this serializer can write/encode/serialize data.
New in version 1.1.3.
| Type: | bool |
|---|---|
| Value: | False |
Declares where there or not this serializer can read/decode/unserialize data.
New in version 1.1.3.
| Type: | bool |
|---|---|
| Value: | False |
Serialize the data structure params with the user/outside-prefered character encoding charset.
If the serializer is binary; the first item in the tuple returned should be None. If the serializer is textual; the character encoding actually used should be the first item of the tuple returned. It is constructed this way to allow serializers only to accept a few character encodings or to be able to enforce a specific one at the same time as some serializers strictly follow the charset requested by the user/outside.
| Parameters: |
|
|---|---|
| Returns: | Tuple of (str charset, str data) where charset is the name of the actual charset used and might be None if binary or unknown. data must be a str. |
| Return type: | tuple |
Unserialize bytes representing some kind of data structure.
| Parameters: |
|
|---|---|
| Returns: | Tuple of (list args, dict params). args and params might be None. |
| Return type: | tuple |
Encode an error.
Returning None indicates that someone else should handle the error encoding. (Normally this means that smisk.mvc.Application.error() serializes the error using best guess).
“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: |
|
|---|---|
| Returns: | Tuple of (str charset, str data) where charset is the name of the actual charset used and might be None if binary or unknown. |
| Return type: | tuple |
List of possible directions, or read/write capabilities.
| Returns: | ["read", "write"], ["read"], ["write"] or [] |
|---|---|
| Return type: | list |
Called when this serializer has been successfully registered in a Registry (the registry instance is passed as the registry argument).
Default implementation does nothing. This is meant to be overridden in subclasses to allow a kind of initialization routine, setting up the serializer if needed.
| Parameters: |
|
|---|---|
| Return type: | None |
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 tear-down routine, finalizing the serializer if needed.
| Parameters: |
|
|---|---|
| Return type: | None |