未验证 提交 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 ...@@ -258,93 +258,293 @@ def create_app(args): # noqa: C901
content = content.decode() content = content.decode()
try: try:
if request_args.get('lang', 'zh') == 'en': if request_args.get('lang', 'zh') == 'en':
default_server_addr = re.search( server_addr_match = re.search(
'"label": {}.*?"value": "".*?}}'.format( '"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps( json.dumps("server ip",
"server ip", ensure_ascii=True).replace( 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("server ip",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_server_addr = server_addr_match.group(0)
cur_server_addr = default_server_addr.replace( cur_server_addr = default_server_addr.replace(
'"value": ""', '"value": "localhost"') '"value": ""', '"value": "localhost"')
default_http_port = re.search( cur_server_addr = default_server_addr.replace(
'"label": {}.*?"value": "".*?}}'.format( '"value":""', '"value": "localhost"')
json.dumps( content = content.replace(default_server_addr,
"server port", ensure_ascii=True).replace( cur_server_addr)
'\\', '\\\\')), content).group(0) 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( cur_http_port = default_http_port.replace(
'"value": ""', '"value": "{}"'.format(http_port)) '"value": ""', '"value": "{}"'.format(http_port))
default_metrics_port = re.search( cur_http_port = default_http_port.replace(
'"label": {}.*?"value": "".*?}}'.format( '"value":""', '"value": "{}"'.format(http_port))
json.dumps( if http_port:
"metrics port", ensure_ascii=True).replace( content = content.replace(default_http_port,
'\\', '\\\\')), content).group(0) 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( cur_metrics_port = default_metrics_port.replace(
'"value": ""', '"value": ""',
'"value": "{}"'.format(metrics_port)) '"value": "{}"'.format(metrics_port))
default_model_name = re.search( cur_metrics_port = default_metrics_port.replace(
'"label": {}.*?"value": "".*?}}'.format( '"value":""', '"value": "{}"'.format(metrics_port))
json.dumps( if metrics_port:
"model name", ensure_ascii=True).replace( content = content.replace(default_metrics_port,
'\\', '\\\\')), content).group(0) 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( cur_model_name = default_model_name.replace(
'"value": ""', '"value": "{}"'.format(model_name)) '"value": ""', '"value": "{}"'.format(model_name))
default_model_version = re.search( cur_model_name = default_model_name.replace(
'"label": {}.*?"value": "".*?}}'.format( '"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", json.dumps("model version",
ensure_ascii=True).replace( ensure_ascii=True).replace(
'\\', '\\\\')), '\\', '\\\\')), content)
content).group(0) 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( cur_model_version = default_model_version.replace(
'"value": ""', '"value": "{}"'.format('1')) '"value": ""', '"value": "{}"'.format('1'))
content = content.replace(default_server_addr, cur_model_version = default_model_version.replace(
cur_server_addr) '"value":""', '"value": "{}"'.format('1'))
content = content.replace(default_model_version,
cur_model_version)
else: else:
default_server_addr = re.search( server_addr_match = re.search(
'"label": {}.*?"value": "".*?}}'.format( '"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("服务ip", ensure_ascii=True).replace( 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( cur_server_addr = default_server_addr.replace(
'"value": ""', '"value": "localhost"') '"value": ""', '"value": "localhost"')
default_http_port = re.search( cur_server_addr = default_server_addr.replace(
'"label": {}.*?"value": "".*?}}'.format( '"value":""', '"value": "localhost"')
json.dumps( content = content.replace(default_server_addr,
"推理服务端口", ensure_ascii=True).replace( cur_server_addr)
'\\', '\\\\')), content).group(0) 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( cur_http_port = default_http_port.replace(
'"value": ""', '"value": "{}"'.format(http_port)) '"value": ""', '"value": "{}"'.format(http_port))
default_metrics_port = re.search( cur_http_port = default_http_port.replace(
'"label": {}.*?"value": "".*?}}'.format( '"value":""', '"value": "{}"'.format(http_port))
json.dumps( if http_port:
"性能服务端口", ensure_ascii=True).replace( content = content.replace(default_http_port,
'\\', '\\\\')), content).group(0) 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( cur_metrics_port = default_metrics_port.replace(
'"value": ""', '"value": ""',
'"value": "{}"'.format(metrics_port)) '"value": "{}"'.format(metrics_port))
default_model_name = re.search( cur_metrics_port = default_metrics_port.replace(
'"label": {}.*?"value": "".*?}}'.format( '"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( 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( cur_model_name = default_model_name.replace(
'"value": ""', '"value": "{}"'.format(model_name)) '"value": ""', '"value": "{}"'.format(model_name))
default_model_version = re.search( cur_model_name = default_model_name.replace(
'"label": {}.*?"value": "".*?}}'.format( '"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( 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( cur_model_version = default_model_version.replace(
'"value": ""', '"value": "{}"'.format('1')) '"value": ""', '"value": "{}"'.format('1'))
content = content.replace(default_server_addr, cur_model_version = default_model_version.replace(
cur_server_addr) '"value":""', '"value": "{}"'.format('1'))
if http_port: content = content.replace(default_model_version,
content = content.replace(default_http_port, cur_model_version)
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)
except Exception: except Exception:
pass pass
finally: finally:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册