forked from libremir/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·55 lines (47 loc) · 1.14 KB
/
run.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
import os
import socket
import sys
import conf
import core
from addons import dreams
from addons import dreams_test
from addons import needs
from addons import needs_test
from addons import projects
from addons import projects_test
from addons import time
from addons import time_test
from addons import waves
from addons import waves_addresses
from addons import waves_test
# Static addon must be the last. If previous addons have not processed the request, then search in static files.
from addons import static
# ==== functions ====
def Parse(conn, addr):
data = b""
while not b"\r\n" in data: # waiting for the first line
tmp = conn.recv(1024)
if not tmp: # socket closed, empty object
break
else:
data += tmp
if not data: # data did not come
return # do not process
core.handleRecv(conn, addr, data)
# ==== main ====
sock = socket.socket()
sock.bind((conf.HOST, conf.PORT))
sock.listen(5)
try:
while 1:
conn, addr = sock.accept()
try:
Parse(conn, addr)
except Exception as e:
core.sendAnswer(conn, "500 Internal Server Error")
print(e)
finally:
conn.close()
finally:
sock.close()