代码拉取完成,页面将自动刷新
import re
import sys
import base64
from io import BytesIO
from PIL import Image
def cmdParser(command: str) -> list[str]:
command = re.sub(r'\\\n\s*', '', command)
command = re.sub(r'#.*$', '', command)
pattern = r'''
(?: "(?:\\.|[^"\\])*" | # 双引号字符串
'(?:\\.|[^'\\])*' | # 单引号字符串
[^\s"']+ # 非空白字符
)
'''
matches = re.findall(pattern, command, re.VERBOSE)
def unquote(s:str):
# 处理转义字符
if s.startswith('"') and s.endswith('"'):
s = s[1:-1]
# 双引号内处理转义字符
s = re.sub(r'\\(["\\abfnrtv])', _replace_escape, s)
elif s.startswith("'") and s.endswith("'"):
s = s[1:-1]
# 单引号内只允许转义单引号和反斜杠
s = re.sub(r'\\([\'\\])', _replace_escape, s)
return s
def _replace_escape(match: re.Match) -> str:
esc = match.group(1)
escape_map = {
'a': '\a', # 响铃
'b': '\b', # 退格
'f': '\f', # 换页
'n': '\n', # 换行
'r': '\r', # 回车
't': '\t', # 制表符
'v': '\v', # 垂直制表符
'"': '"', # 双引号
"'": "'", # 单引号
'\\': '\\', # 反斜杠
}
return escape_map.get(esc, esc) # 如果找不到,返回原字符
return [unquote(m) for m in matches if m.strip()]
def fileSelector(remote: bool = False) -> bytes:
if not remote:
file_path = input("请输入图片文件地址:")
try:
with open(file_path, 'rb') as f:
data = f.read()
return data
except FileNotFoundError:
print("[fileSelector] 文件打开失败!请检查文件路径。")
else:
sys.stdout.write("__!fileSelector()_called!__")
data = sys.stdin.readline().strip()
data = base64.b64decode(data)
return data
def showImage(data: bytes, remote: bool = False):
if not remote:
Image.open(BytesIO(data)).show()
else:
sys.stdout.write("__!showImage()_called!__")
data = base64.b64encode(data).decode()
sys.stdout.write(data)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。