Fixed #94 and done some refactoring #99
@@ -15,43 +15,6 @@ cors = CORS(app, resource={
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
def format_xml(request: request, type: str) -> str:
 | 
			
		||||
    """Function to format XML 
 | 
			
		||||
 | 
			
		||||
    :param request: Received request
 | 
			
		||||
    :param type: Type of needed processing: xsd, xslt or xpath
 | 
			
		||||
    :raises ValueError: is raised when type is different than those provided above
 | 
			
		||||
    :return: response JSON converted to string and response code
 | 
			
		||||
    """
 | 
			
		||||
    start = time.time_ns()
 | 
			
		||||
    code = 200
 | 
			
		||||
    response_json = dict()
 | 
			
		||||
    try:
 | 
			
		||||
        request_data = json.loads(request.get_data(as_text=True))
 | 
			
		||||
        data = request_data['data']
 | 
			
		||||
        process = request_data['process']
 | 
			
		||||
        if (type == "prettify"):
 | 
			
		||||
            response_json['result'] = Parser.xsd(data, process)
 | 
			
		||||
        elif (type == "minimize"):
 | 
			
		||||
            response_json['result'] = Parser.xslt(data, process)
 | 
			
		||||
        else:
 | 
			
		||||
            raise ValueError("Valid operation types are: prettify, minimize")
 | 
			
		||||
 | 
			
		||||
        response_json['status'] = "OK"
 | 
			
		||||
    except KeyError as e:
 | 
			
		||||
        response_json['result'] = "Missing key: " + str(e)
 | 
			
		||||
        response_json['status'] = "ERR"
 | 
			
		||||
        code = 400
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        response_json['result'] = str(e)
 | 
			
		||||
        response_json['status'] = "ERR"
 | 
			
		||||
        code = 400
 | 
			
		||||
    finally:
 | 
			
		||||
        exec_time = (time.time_ns() - start) / 10**6
 | 
			
		||||
        response_json['time'] = f"{exec_time:.03f}"
 | 
			
		||||
        response_json['processor'] = "libxml2 over lxml"
 | 
			
		||||
        return json.dumps(response_json), code
 | 
			
		||||
 | 
			
		||||
def process_xml(request: request, type: str) -> str:
 | 
			
		||||
    """Function to process 
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user