generated from mwc/lab_compression
I created a text codec ascii5 similar to ascii7
but with differnt characters included. This reads/encodes with 5 bits instead of the original 7.
This commit is contained in:
20
text_codecs/ascii7.py
Normal file → Executable file
20
text_codecs/ascii7.py
Normal file → Executable file
@@ -1,6 +1,24 @@
|
||||
from custom_codecs.register import register_codec
|
||||
#from text_codecs.register import register_codec
|
||||
from easybits import Bits
|
||||
|
||||
import codecs
|
||||
|
||||
def register_codec(encode, decode, name):
|
||||
"""Registers a codec so that it can later be used to encode
|
||||
or decode strings and bytes.
|
||||
"""
|
||||
def encode_wrapper(text):
|
||||
return encode(text), len(text)
|
||||
|
||||
def decode_wrapper(data):
|
||||
return decode(data), len(data)
|
||||
|
||||
def search_for_codec(query):
|
||||
if query == name:
|
||||
return codecs.CodecInfo(encode_wrapper, decode_wrapper, name=name)
|
||||
|
||||
codecs.register(search_for_codec)
|
||||
|
||||
def encode(text):
|
||||
"""An encoder which only handles ASCII: non-ASCII characters
|
||||
are replaced with '?'. Once all the characters are ASCII, this encoder
|
||||
|
||||
Reference in New Issue
Block a user