generated from mwc/lab_compression
this was hard, lol
This commit is contained in:
0
text_codecs/custom_codecs/__init__.py
Normal file
0
text_codecs/custom_codecs/__init__.py
Normal file
22
text_codecs/custom_codecs/register.py
Normal file
22
text_codecs/custom_codecs/register.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import codecs
|
||||
|
||||
def register_codec(name, encode, decode):
|
||||
class Codec(codecs.Codec):
|
||||
def encode(self, input, errors="strict"):
|
||||
return encode(input), len(input)
|
||||
|
||||
def decode(self, input, errors="strict"):
|
||||
return decode(input), len(input)
|
||||
|
||||
def search_function(encoding):
|
||||
if encoding == name:
|
||||
return codecs.CodecInfo(
|
||||
name=name,
|
||||
encode=Codec().encode,
|
||||
decode=Codec().decode
|
||||
)
|
||||
return None
|
||||
|
||||
codecs.register(search_function)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user