Implemented new tool in backend
This commit is contained in:
		| @@ -1,16 +1,22 @@ | ||||
| from lxml import etree | ||||
|  | ||||
|  | ||||
| def prettify(source: str) -> str: | ||||
|     xml = etree.XML(source) | ||||
|     return etree.tostring(xml, pretty_print=True) | ||||
|  | ||||
| def minimize(source: str) -> str: | ||||
|     xml = etree.XML(source) | ||||
|     return etree.tostring(xml, pretty_print=False) | ||||
|  | ||||
|  | ||||
| def xpath(source: str, xpath: str) -> str: | ||||
|     """ | ||||
|     Method used to get nodes from XML string using XPath | ||||
|  | ||||
|     :param source: XML string used for selection | ||||
|     :type source: str | ||||
|     :param xpath: XPath query used for selection | ||||
|     :type xpath: str | ||||
|     :return: Nodes selected using XPath | ||||
|     :rtype: str | ||||
|     """ | ||||
|  | ||||
|      | ||||
| @@ -34,11 +40,8 @@ def xsd(source: str, xsd: str) -> bool: | ||||
|     """ | ||||
|     Method used to validate XML string against XSD schema | ||||
|     :param source: XML string used for validation | ||||
|     :type source: str | ||||
|     :param xsd: XSD schema to validate XML against | ||||
|     :type xsd: str | ||||
|     :return: Message saying, if the validation was successful or not | ||||
|     :rtype: str | ||||
|     """ | ||||
|     xml_schema = etree.XMLSchema(etree.XML(xsd)) | ||||
|  | ||||
| @@ -54,11 +57,8 @@ def xslt(source: str, xslt: str) -> str: | ||||
|     Method used to transformate XML string using XSLT | ||||
|  | ||||
|     :param source: XML string to transform | ||||
|     :type source: str | ||||
|     :param xslt: XSLT string used to transformate XML | ||||
|     :type xslt: str | ||||
|     :return: Result of transformation | ||||
|     :rtype: str | ||||
|     """ | ||||
|     xslt_transform = etree.XSLT(etree.XML(xslt)) | ||||
|  | ||||
|   | ||||
| @@ -19,12 +19,9 @@ def process_xml(request: request, type: str) -> str: | ||||
|     """Function to process  | ||||
|  | ||||
|     :param request: Received request | ||||
|     :type request: request | ||||
|     :param type: Type of needed processing: xsd, xslt or xpath | ||||
|     :type type: str | ||||
|     :raises ValueError: is raised when type is different than those provided above | ||||
|     :return: response JSON converted to string and response code | ||||
|     :rtype: str, int | ||||
|     """ | ||||
|     start = time.time_ns() | ||||
|     code = 200 | ||||
| @@ -70,5 +67,10 @@ def xsd(): | ||||
| def xslt(): | ||||
|     return process_xml(request, "xslt") | ||||
|  | ||||
| @app.route("/prettifypost", methods=["POST"]) | ||||
| def prettify(): | ||||
|     request_data = json.loads(request.get_data(as_text=True)) | ||||
|     return Parser.prettify(request_data['data']) | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     app.run() | ||||
		Reference in New Issue
	
	Block a user