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:
ambreenn
2026-04-15 10:24:41 -04:00
parent fdca338c67
commit 9d2b381fea
7 changed files with 86 additions and 2 deletions

20
text_codecs/ascii7.py Normal file → Executable file
View 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