From 6ee205018af2f5d13f2606f16d82564d5877b589 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 8 Aug 2011 19:15:49 +0200 Subject: Implemented session, send play notification. --- app.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'app.py') diff --git a/app.py b/app.py index 1da175f..9120ea4 100755 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import os, mimetypes, json, cgi, recode, time, urllib, events, threading from config import config from directory import Directory, File +from session import Session class Application(object): # Application handlers @@ -58,28 +59,17 @@ class Application(object): encoder = args.getvalue('encoder') if 'encoder' in args else None f = File(path) - t = threading.Thread(target = f.recode, args = (decoder, encoder)) + t = threading.Thread(target = f.recode, args = (decoder, encoder, environ['sessionid'])) t.start() start_response('200 OK', [('Content-Type', 'text/plain')]) return [] - def json_is_cached(self, environ, start_response, path): - args = cgi.FieldStorage(environ = environ) - path = args.getvalue('path') if 'path' in args else None - - cache_file = os.path.join(config.get('cache_dir'), path) - cache_file = os.path.splitext(cache_file)[0] + '.mp3' - - start_response('200 OK', [('Content-Type', 'text/plain')]) - return json.dumps(os.path.exists(cache_file)) - handlers = { 'files': files, 'static': static, 'list': json_list, 'cache': json_cache, - 'is_cached': json_is_cached, 'events': events.EventSubscriber, } @@ -94,7 +84,7 @@ class Application(object): path = ['static', 'index.html'] if module in self.handlers: - return self.handlers[module](self, environ, start_response, path) + return Session(self.handlers[module])(self, environ, start_response, path) start_response('404 Not Found', [('Content-Type', 'text/plain')]) return [str(path)] -- cgit v1.2.3