Skip to content

Instantly share code, notes, and snippets.

@20chan
Created February 5, 2020 16:20
Show Gist options
  • Save 20chan/0c2c890072067fee8475a15a6ee10c42 to your computer and use it in GitHub Desktop.
Save 20chan/0c2c890072067fee8475a15a6ee10c42 to your computer and use it in GitHub Desktop.
python custom codec meta programming post example aheui code
import codecs, io, encodings
from encodings import utf_8
aheui_code = '''
'''
def aheui_decode(input, errors="strict"):
raw = bytes(input).decode("utf-8")
code = "\n".join(raw.splitlines()[1:])
hooked = aheui_code + f'eval("""{code}""")'
return hooked, len(input)
def search_function(encoding):
if encoding != "aheui":
return None
utf8 = encodings.search_function("utf8")
return codecs.CodecInfo(
name="aheui",
encode=utf8.encode,
decode=aheui_decode,
)
codecs.register(search_function)
import register
import script
# coding: aheui
밤밣따빠밣밟따뿌
빠맣파빨받밤뚜뭏
돋밬탕빠맣붏두붇
볻뫃박발뚷투뭏붖
뫃도뫃희멓뭏뭏붘
뫃봌토범더벌뿌뚜
뽑뽀멓멓더벓뻐뚠
뽀덩벐멓뻐덕더벅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment