Prepared dockerfile
This commit is contained in:
@@ -1,17 +1,69 @@
|
||||
from flask import Flask
|
||||
from flask import request
|
||||
from lxml import etree
|
||||
import json
|
||||
import time
|
||||
import Parser
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
SOURCE = "sample/xslt.xml"
|
||||
XSLT = "sample/sample.xslt"
|
||||
app = Flask(__name__)
|
||||
|
||||
file = open(SOURCE, "r")
|
||||
xml = file.read()
|
||||
file.close()
|
||||
@app.route("/xpath", methods=["POST"])
|
||||
def xpath():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xpath = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xpath(xml, xpath)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
|
||||
file = open(XSLT, "r")
|
||||
xslt = file.read()
|
||||
print(Parser.xslt(xml, xslt))
|
||||
@app.route("/xsd", methods=["POST"])
|
||||
def xsd():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xsd = request_data['process']
|
||||
|
||||
file.close()
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xsd(xml, xsd)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
|
||||
@app.route("/xslt", methods=["POST"])
|
||||
def xslt():
|
||||
request_data = request.get_json()
|
||||
xml = request_data['data']
|
||||
xslt = request_data['process']
|
||||
|
||||
response = dict()
|
||||
start = time.time_ns()
|
||||
try:
|
||||
response['result'] = Parser.xslt(xml, xslt)
|
||||
response['status'] = "OK"
|
||||
except BaseException as e:
|
||||
response['result'] = str(e)
|
||||
response['status'] = "ERR"
|
||||
finally:
|
||||
exec_time = (time.time_ns() - start) / 10**6
|
||||
response['time'] = f"{exec_time:.03f}"
|
||||
response['processor'] = "libxml2 over lxml"
|
||||
return json.dumps(response)
|
||||
Reference in New Issue
Block a user