-
Notifications
You must be signed in to change notification settings - Fork 0
/
rq_handler.py
41 lines (29 loc) · 1014 Bytes
/
rq_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from os import path as px
def process_req(req):
query_parameters = params_from_req(req)
file_bytes, filename = process_file_req(req, query_parameters)
return file_bytes, filename
def process_req_glasnik(req):
query_parameters = params_from_req(req)
return query_parameters["text"]
def params_from_req(req):
query_parameters = req.args
if len(query_parameters) == 0:
query_parameters = req.form
return query_parameters
def process_file_req(req, query_parameters):
if "file" in req.files:
file_bytes = req.files["file"].read()
filename = req.files["file"].filename
if filename != "":
return file_bytes, filename
filename = query_parameters.get('file')
file_bytes = filepath2file(filename)
return file_bytes, filename
def filepath2file(filepath):
if px.exists(filepath):
with open(filepath, "rb") as f:
file_bytes = f.read()
return file_bytes
else:
return None