First commit after changed file framework

这个提交包含在:
2023-03-14 18:52:04 +08:00
父节点 e23318c8f1
当前提交 79a6a31dc7
共修改 34 个文件,包含 5751 行新增和 0 行删除
+32
查看文件
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from _ctypes import PyObj_FromPtr
import json, re
class NoIndent(object):
""" Value wrapper. """
def __init__(self, value):
self.value = value
class MyEncoder(json.JSONEncoder):
FORMAT_SPEC = '@@{}@@'
regex = re.compile(FORMAT_SPEC.format(r'(\d+)'))
def __init__(self, **kwargs):
super(MyEncoder, self).__init__(**kwargs)
def default(self, obj):
return (self.FORMAT_SPEC.format(id(obj)) if isinstance(obj, NoIndent)
else super(MyEncoder, self).default(obj))
def encode(self, obj):
format_spec = self.FORMAT_SPEC # Local var to expedite access.
json_repr = super(MyEncoder, self).encode(obj) # Default JSON.
for match in self.regex.finditer(json_repr):
id = int(match.group(1))
no_indent = PyObj_FromPtr(id)
json_obj_repr = json.dumps(no_indent.value)
json_repr = json_repr.replace(
'"{}"'.format(format_spec.format(id)), json_obj_repr)
return json_repr