implemented ecoding/decoding in commonchars.py

This commit is contained in:
owengavi2
2026-04-07 18:37:03 -04:00
parent 96add86f83
commit 999aae570f
6 changed files with 146 additions and 4 deletions

View File

@@ -72,4 +72,20 @@ if args.encodings:
print(tabulate(results, headers="keys"))
if args.inspect:
print(inspect_encoded_text(args.inspect, args.text))
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)
codecs.register(search_for_codec)