未验证 提交 0975664e 编写于 作者: C chenjian 提交者: GitHub

[Bug] Fix autofilling FD client (#1202)

* fix autofilling fd client

* robust pattern for auto filling fd client
上级 36808ca4
......@@ -258,93 +258,293 @@ def create_app(args): # noqa: C901
content = content.decode()
try:
if request_args.get('lang', 'zh') == 'en':
default_server_addr = re.search(
'"label": {}.*?"value": "".*?}}'.format(
json.dumps(
"server ip", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
server_addr_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("server ip",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not server_addr_match or server_addr_match.group(
0).count('"label"') >= 2:
server_addr_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("server ip",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_server_addr = server_addr_match.group(0)
cur_server_addr = default_server_addr.replace(
'"value": ""', '"value": "localhost"')
default_http_port = re.search(
'"label": {}.*?"value": "".*?}}'.format(
json.dumps(
"server port", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
cur_server_addr = default_server_addr.replace(
'"value":""', '"value": "localhost"')
content = content.replace(default_server_addr,
cur_server_addr)
http_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("server port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not http_port_match or http_port_match.group(
0).count('"label"') >= 2:
http_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"server port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_http_port = http_port_match.group(0)
cur_http_port = default_http_port.replace(
'"value": ""', '"value": "{}"'.format(http_port))
default_metrics_port = re.search(
'"label": {}.*?"value": "".*?}}'.format(
json.dumps(
"metrics port", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
cur_http_port = default_http_port.replace(
'"value":""', '"value": "{}"'.format(http_port))
if http_port:
content = content.replace(default_http_port,
cur_http_port)
metrics_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("metrics port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not metrics_port_match or metrics_port_match.group(
0).count('"label"') >= 2:
metrics_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"metrics port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_metrics_port = metrics_port_match.group(0)
cur_metrics_port = default_metrics_port.replace(
'"value": ""',
'"value": "{}"'.format(metrics_port))
default_model_name = re.search(
'"label": {}.*?"value": "".*?}}'.format(
json.dumps(
"model name", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
cur_metrics_port = default_metrics_port.replace(
'"value":""', '"value": "{}"'.format(metrics_port))
if metrics_port:
content = content.replace(default_metrics_port,
cur_metrics_port)
model_name_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("model name",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_name_match or model_name_match.group(
0).count('"label"') >= 2:
model_name_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"model name",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_model_name = model_name_match.group(0)
cur_model_name = default_model_name.replace(
'"value": ""', '"value": "{}"'.format(model_name))
default_model_version = re.search(
'"label": {}.*?"value": "".*?}}'.format(
cur_model_name = default_model_name.replace(
'"value":""', '"value": "{}"'.format(model_name))
if model_name:
content = content.replace(default_model_name,
cur_model_name)
model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("model version",
ensure_ascii=True).replace(
'\\', '\\\\')),
content).group(0)
'\\', '\\\\')), content)
if not model_version_match or model_version_match.group(
0).count('"label"') >= 2:
model_version_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"model version",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_model_version = model_version_match.group(0)
cur_model_version = default_model_version.replace(
'"value": ""', '"value": "{}"'.format('1'))
content = content.replace(default_server_addr,
cur_server_addr)
cur_model_version = default_model_version.replace(
'"value":""', '"value": "{}"'.format('1'))
content = content.replace(default_model_version,
cur_model_version)
else:
default_server_addr = re.search(
'"label": {}.*?"value": "".*?}}'.format(
server_addr_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("服务ip", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
'\\', '\\\\')), content)
if not server_addr_match or server_addr_match.group(
0).count('"label"') >= 2:
server_addr_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("服务ip",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not server_addr_match:
server_addr_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps("服务ip",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
if not server_addr_match or server_addr_match.group(
0).count('"label"') >= 2:
server_addr_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"服务ip",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
default_server_addr = server_addr_match.group(0)
cur_server_addr = default_server_addr.replace(
'"value": ""', '"value": "localhost"')
default_http_port = re.search(
'"label": {}.*?"value": "".*?}}'.format(
json.dumps(
"推理服务端口", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
cur_server_addr = default_server_addr.replace(
'"value":""', '"value": "localhost"')
content = content.replace(default_server_addr,
cur_server_addr)
http_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("推理服务端口",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not http_port_match or http_port_match.group(
0).count('"label"') >= 2:
http_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("推理服务端口",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not http_port_match:
http_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"推理服务端口",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
if not http_port_match or http_port_match.group(
0).count('"label"') >= 2:
http_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"推理服务端口",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
default_http_port = http_port_match.group(0)
cur_http_port = default_http_port.replace(
'"value": ""', '"value": "{}"'.format(http_port))
default_metrics_port = re.search(
'"label": {}.*?"value": "".*?}}'.format(
json.dumps(
"性能服务端口", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
cur_http_port = default_http_port.replace(
'"value":""', '"value": "{}"'.format(http_port))
if http_port:
content = content.replace(default_http_port,
cur_http_port)
metrics_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("性能服务端口",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not metrics_port_match or metrics_port_match.group(
0).count('"label"') >= 2:
metrics_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("性能服务端口",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not metrics_port_match:
metrics_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"性能服务端口",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
if not metrics_port_match or metrics_port_match.group(
0).count('"label"') >= 2:
metrics_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"性能服务端口",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
default_metrics_port = metrics_port_match.group(0)
cur_metrics_port = default_metrics_port.replace(
'"value": ""',
'"value": "{}"'.format(metrics_port))
default_model_name = re.search(
'"label": {}.*?"value": "".*?}}'.format(
cur_metrics_port = default_metrics_port.replace(
'"value":""', '"value": "{}"'.format(metrics_port))
if metrics_port:
content = content.replace(default_metrics_port,
cur_metrics_port)
model_name_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("模型名称", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
'\\', '\\\\')), content)
if not model_name_match or model_name_match.group(
0).count('"label"') >= 2:
model_name_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("模型名称",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_name_match:
model_name_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps("模型名称",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
if not model_name_match or model_name_match.group(
0).count('"label"') >= 2:
model_name_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"模型名称",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
default_model_name = model_name_match.group(0)
cur_model_name = default_model_name.replace(
'"value": ""', '"value": "{}"'.format(model_name))
default_model_version = re.search(
'"label": {}.*?"value": "".*?}}'.format(
cur_model_name = default_model_name.replace(
'"value":""', '"value": "{}"'.format(model_name))
if model_name:
content = content.replace(default_model_name,
cur_model_name)
model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("模型版本", ensure_ascii=True).replace(
'\\', '\\\\')), content).group(0)
'\\', '\\\\')), content)
if not model_version_match or model_version_match.group(
0).count('"label"') >= 2:
model_version_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("模型版本",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_version_match:
model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps("模型版本",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
if not model_version_match or model_version_match.group(
0).count('"label"') >= 2:
model_version_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"模型版本",
ensure_ascii=False).replace(
'\\', '\\\\')), content)
default_model_version = model_version_match.group(0)
cur_model_version = default_model_version.replace(
'"value": ""', '"value": "{}"'.format('1'))
content = content.replace(default_server_addr,
cur_server_addr)
if http_port:
content = content.replace(default_http_port,
cur_http_port)
if metrics_port:
content = content.replace(default_metrics_port,
cur_metrics_port)
if model_name:
content = content.replace(default_model_name,
cur_model_name)
content = content.replace(default_model_version,
cur_model_version)
cur_model_version = default_model_version.replace(
'"value":""', '"value": "{}"'.format('1'))
content = content.replace(default_model_version,
cur_model_version)
except Exception:
pass
finally:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册