Coverage for /home/mattis/projects/websites/dighl/edictor/src/edictor/server.py: 78%
51 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-07 06:52 +0200
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-07 06:52 +0200
1from http.server import SimpleHTTPRequestHandler
3from edictor.util import (
4 DATA, get_distinct, get_columns,
5 check, configuration,
6 file_type, file_name, file_handler, triples, download,
7 update, serve_base, new_id, modifications, alignments,
8 cognates, patterns, quit
9 )
11CONF = configuration()
14class Handler(SimpleHTTPRequestHandler):
15 """
16 Modified basic class for handling requests in our local server.
17 """
19 def do_POST(s):
20 """
21 Do a POST request.
23 Note:
25 This GIST gave me the tip on how to proceed with POST data.
27 https://gist.github.com/scimad/ae0196afc0bade2ae39d604225084507
28 """
29 content_length = int(s.headers['Content-Length'])
30 post_data_bytes = s.rfile.read(content_length)
32 ft = file_type(s.path)
33 fn = file_name(s.path)
35 if ft in DATA:
36 file_handler(s, ft, fn)
37 return
39 fn = file_name(s.path)
41 if fn == "/triples/triples.py":
42 triples(s, post_data_bytes, "POST", CONF)
43 if fn == "/download.py":
44 download(s, post_data_bytes)
45 if fn == "/check.py":
46 check(s)
47 if fn == "/triples/update.py":
48 update(s, post_data_bytes, "POST", CONF)
49 if fn == "/triples/new_id.py":
50 new_id(s, post_data_bytes, "POST", CONF)
51 if fn == "/triples/modifications.py":
52 modifications(s, post_data_bytes, "POST", CONF)
53 if fn == "/alignments.py":
54 alignments(s, post_data_bytes, "POST")
55 if fn == "/cognates.py":
56 cognates(s, post_data_bytes, "POST")
57 if fn == "/patterns.py":
58 patterns(s, post_data_bytes, "POST")
59 if fn == "/quit.py":
60 quit(s)
62 def do_GET(s):
63 """
64 Do a GET request.
65 """
67 ft = file_type(s.path)
68 fn = file_name(s.path)
70 if fn == "/":
71 serve_base(s, CONF)
73 if ft in DATA:
74 file_handler(s, ft, fn)
75 return
77 if fn == "/triples/triples.py":
78 triples(s, s.path, "GET", CONF)
79 if fn == "/triples/update.py":
80 update(s, s.path, "GET", CONF)
81 if fn == "/triples/new_id.py":
82 new_id(s, s.path, "GET", CONF)
83 if fn == "/triples/modifications.py":
84 modifications(s, s.path, "GET", CONF)
85 if fn == "/quit.py":
86 quit(s)