-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.txt
69 lines (46 loc) · 1.88 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
.. contents::
Installation
============
Install the distribution from source::
$ python setup.py install
Or install with ``easy_install``::
$ easy_install fnord.easycodec
Usage
=====
This package can be used to easily create and register codecs.
Use the decorator ``encoder`` to create an encode-function::
>>> from fnord.easycodec import encoder
>>> @encoder("my_codec")
... def my_encode(message):
... ...
(``my_codec`` is the name of the codec.)
Use the decorator ``decoder`` to create a decode-function::
>>> from fnord.easycodec import decoder
>>> @decoder("my_codec")
... def my_decode(message):
... ...
Use the factory ``CodecRegistration`` to create an object that can be
returned by a codec's search-function::
>>> from fnord.easycodec import CodecRegistration, AUTO
>>> registration = CodecRegistration(
... "my_codec", my_encode, my_decode,
... streamwriter=AUTO, streamreader=AUTO)
This factory takes the following parameters:
:``name``: The name of the codec. Required.
:``encode``: The encode-function. Required.
:``decode``: The decode-function. Required.
:``incrementalencoder``: The incremental encoder. Optional.
:``incrementaldecoder``: The incremental decoder. Optional.
:``streamwriter``: The stream-writer. Optional.
:``streamreader``: The stream-reader. Optional.
If one of the optional parameters has the value ``AUTO`` assigned, an
appropriate object will be generated and used.
Use the factory ``CodecSearch`` to create a search-function for a codec. The
parameters are the same as for ``CodecRegistration``::
>>> from fnord.easycodec import CodecSearch
>>> search = CodecSearch(
... "my_codec", my_encode, my_decode,
... streamwriter=AUTO, streamreader=AUTO)
This function can then be used to register the codec::
>>> import codecs
>>> codecs.register(search)