423baff73b
- Docker bridge 网络隔离(8000 端口封死) - Gunicorn 4 Worker 多进程 - Alembic 数据库迁移基线 - 日志轮转 20m×3 - JWT 密钥 + DB 密码 + CORS 收紧 - 3-2-1 备份链路(NAS + R740-B 冷备) - 连接池 pool_pre_ping + pool_recycle=3600
44 lines
790 B
Python
44 lines
790 B
Python
# Copyright (c) 2010-2024 openpyxl
|
|
|
|
"""
|
|
OOXML has non-standard escaping for characters < \031
|
|
"""
|
|
|
|
import re
|
|
|
|
|
|
def escape(value):
|
|
r"""
|
|
Convert ASCII < 31 to OOXML: \n == _x + hex(ord(\n)) + _
|
|
"""
|
|
|
|
CHAR_REGEX = re.compile(r"[\001-\031]")
|
|
|
|
def _sub(match):
|
|
"""
|
|
Callback to escape chars
|
|
"""
|
|
return "_x{:0>4x}_".format(ord(match.group(0)))
|
|
|
|
return CHAR_REGEX.sub(_sub, value)
|
|
|
|
|
|
def unescape(value):
|
|
r"""
|
|
Convert escaped strings to ASCIII: _x000a_ == \n
|
|
"""
|
|
|
|
|
|
ESCAPED_REGEX = re.compile("_x([0-9A-Fa-f]{4})_")
|
|
|
|
def _sub(match):
|
|
"""
|
|
Callback to unescape chars
|
|
"""
|
|
return chr(int(match.group(1), 16))
|
|
|
|
if "_x" in value:
|
|
value = ESCAPED_REGEX.sub(_sub, value)
|
|
|
|
return value
|