-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update more of the documentation for Asphalt 5
- Loading branch information
Showing
5 changed files
with
45 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
Writing new serializer backends | ||
=============================== | ||
|
||
If you wish to implement an alternate method of serialization, you can do so by subclassing | ||
the :class:`~asphalt.serialization.api.Serializer` class. | ||
There are three methods implementors must override: | ||
.. py:currentmodule:: asphalt.serialization | ||
* :meth:`~asphalt.serialization.api.Serializer.serialize` | ||
* :meth:`~asphalt.serialization.api.Serializer.deserialize` | ||
* :meth:`~asphalt.serialization.api.Serializer.mimetype` | ||
If you wish to implement an alternate method of serialization, you can do so by | ||
subclassing the :class:`~Serializer` class. There are three methods implementors must | ||
override: | ||
|
||
The ``mimetype`` method is a ``@property`` that simply returns the MIME type appropriate for the | ||
serialization scheme. This property is used by certain other components. If you cannot find an | ||
applicable MIME type, you can use ``application/octet-stream``. | ||
* :meth:`~Serializer.serialize` | ||
* :meth:`~Serializer.deserialize` | ||
* :meth:`~Serializer.mimetype` | ||
|
||
The ``mimetype`` method is a ``@property`` that simply returns the MIME type appropriate | ||
for the serialization scheme. This property is used by certain other components. If you | ||
cannot find an applicable MIME type, you can use ``application/octet-stream``. | ||
|
||
.. note:: Serializers must always serialize to bytes; never serialize to strings! | ||
|
||
If you want your serializer to be available as a backend for | ||
:class:`~asphalt.serialization.component.SerializationComponent`, you need to add the corresponding | ||
entry point for it. Suppose your serializer class is named ``AwesomeSerializer``, lives in the | ||
package ``foo.bar.awesome`` and you want to give it the alias ``awesome``, add this line to your | ||
project's ``setup.py`` under the ``entry_points`` argument in the | ||
``asphalt.serialization.serializers`` namespace: | ||
|
||
.. code-block:: python | ||
setup( | ||
# (...other arguments...) | ||
entry_points={ | ||
'asphalt.serialization.serializers': [ | ||
'awesome = foo.bar.awesome:AwesomeSerializer' | ||
] | ||
} | ||
) | ||
:class:`~asphalt.serialization.SerializationComponent`, you need to add the | ||
corresponding entry point for it. Suppose your serializer class is named | ||
``AwesomeSerializer``, lives in the package ``foo.bar.awesome`` and you want to give it | ||
the alias ``awesome``, add this line to your project's ``pyproject.toml`` under the | ||
``entry_points`` argument in the ``asphalt.serialization.serializers`` namespace: | ||
|
||
.. code-block:: toml | ||
[project.entry-points."asphalt.serialization.serializers"] | ||
awesome = "foo.bar.awesome:AwesomeSerializer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters