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/alphanumeric.py Normal file → Executable file
View File

@@ -1,10 +1,28 @@
import string
import codecs
from custom_codecs.register import register_codec
#from text_codecs.register import register_codec
from easybits import Bits
allowed_characters = string.ascii_letters + string.digits
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):
"""A (very) lossy encoder which only saves ASCII letters, numbers, and spaces.
Everything else is discarded. All whitespace (e.g. tabs) is converted into spaces.