Commit 73037e91 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Refactoring: extract get_daemon_connection() from convert().

parent 7d71e4a8
......@@ -90,23 +90,7 @@ def process_request(environ, start_response):
else:
raise NotFound()
def convert(environ, start_response, ph):
if len(ph.op_args()) > 0:
raise NotFound()
if environ["REQUEST_METHOD"] == "GET":
start_response("200 OK",
[('Content-Type', 'text/html;charset=utf-8')])
return ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n"
" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
"<html><head><title>Request conversion</title></head>\n"
"<body><form method=\"POST\" action=\"convert\">\n"
"<button>Confirm conversion to mp3</button>\n"
"</form></body></html>"]
if environ["REQUEST_METHOD"] != "POST":
raise MethodNotAllowed('GET, POST')
def get_daemon_connection():
try:
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
except FileNotFoundError:
......@@ -127,7 +111,26 @@ def convert(environ, start_response, ph):
sys.stderr.write("Connecting to new wav2mp3d.\n")
c = multiprocessing.connection.Client(mp3wavcfg.socketpath, 'AF_UNIX')
sys.stderr.write("Connected to new wav2mp3d.\n")
return c
def convert(environ, start_response, ph):
if len(ph.op_args()) > 0:
raise NotFound()
if environ["REQUEST_METHOD"] == "GET":
start_response("200 OK",
[('Content-Type', 'text/html;charset=utf-8')])
return ["<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n"
" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
"<html><head><title>Request conversion</title></head>\n"
"<body><form method=\"POST\" action=\"convert\">\n"
"<button>Confirm conversion to mp3</button>\n"
"</form></body></html>"]
if environ["REQUEST_METHOD"] != "POST":
raise MethodNotAllowed('GET, POST')
c = get_daemon_connection()
c.send(("encode", ph.rel_base()))
while True:
msg = c.recv()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment