From 8c4df5d465053fbb8d00ea0a571ec1b3d549b59f Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Wed, 9 May 2007 04:57:05 +0000 Subject: [PATCH] Merged revisions 193 via svnmerge from http://svn.armooo.net/pyTivo/trunk This was commited to the trunk when it should have been with the branck with the rest of the files ........ r193 | KRKeegan | 2007-05-08 22:16:35 -0500 (Tue, 08 May 2007) | 4 lines ##MAJOR Code Change - Huge hack to allow 8.3 to work, affects all four files - Added hack83 as a server key in config file default true - Modified config.py to work with linux ........ --- Config.py | 19 ++++++++++++++++++- httpserver.py | 47 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Config.py b/Config.py index 97bcb33..646800c 100644 --- a/Config.py +++ b/Config.py @@ -37,6 +37,16 @@ def getDebug(): except NoOptionError: return False +def getHack83(): + try: + debug = config.get('Server', 'hack83') + if debug.lower() == 'true': + return True + else: + return False + except NoOptionError: + return True + def get(section, key): return config.get(section, key) @@ -49,7 +59,14 @@ def getValidHeights(): # Return the number in list that is nearest to x # if two values are equidistant, return the larger def nearest(x, list): - return reduce(lambda a, b: a if abs(x-a) < abs(x-b) or (abs(x-a) == abs(x-b)and a>b) else b, list) + return reduce(lambda a, b: closest(x,a,b), list) + +def closest(x,a, b): + if abs(x-a) < abs(x-b) or (abs(x-a) == abs(x-b)and a>b): + return a + else: + return b + def nearestTivoWidth(width): return nearest(width, getValidWidths()) diff --git a/httpserver.py b/httpserver.py index bef0d5b..b567dd3 100644 --- a/httpserver.py +++ b/httpserver.py @@ -4,8 +4,20 @@ from urlparse import urlparse from cgi import parse_qs from Cheetah.Template import Template from plugin import GetPlugin +import Config SCRIPTDIR = os.path.dirname(__file__) +debug = Config.getDebug() +hack83 = Config.getHack83() +def debug_write(data): + if debug: + debug_out = [] + debug_out.append('httpserver.py - ') + for x in data: + debug_out.append(str(x)) + fdebug = open('debug.txt', 'a') + fdebug.write(' '.join(debug_out)) + fdebug.close() class TivoHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): containers = {} @@ -40,7 +52,7 @@ class TivoHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): if not self.path.startswith('/TiVoConnect'): self.infopage() return - + o = urlparse("http://fake.host" + self.path) query = parse_qs(o[4]) @@ -56,8 +68,10 @@ class TivoHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): if query.has_key('Container'): #Dispatch to the container plugin + foundContainer = False for name, container in self.server.containers.items(): if query['Container'][0].startswith(name): + foundContainer = True plugin = GetPlugin(container['type']) if hasattr(plugin,command): method = getattr(plugin, command) @@ -65,6 +79,8 @@ class TivoHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): else: self.unsuported(query) break + if not foundContainer: + self.unsuported(query) else: self.unsuported(query) @@ -86,12 +102,29 @@ class TivoHTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.end_headers() def unsuported(self, query): - self.send_response(404) - self.send_header('Content-type', 'text/html') - self.end_headers() - t = Template(file=os.path.join(SCRIPTDIR,'templates','unsuported.tmpl')) - t.query = query - self.wfile.write(t) + if hack83 and 'Command' in query and 'Filter' in query: + debug_write(['Unsupported request, checking to see if it is video.', '\n']) + command = query['Command'][0] + plugin = plugin = GetPlugin('video') + if "".join(query['Filter']).find('video') >= 0 and hasattr(plugin,command): + debug_write(['Unsupported request, yup it is video send to video plugin for it to sort out.', '\n']) + method = getattr(plugin, command) + method(self, query) + else: + self.send_response(404) + self.send_header('Content-type', 'text/html') + self.end_headers() + t = Template(file=os.path.join(SCRIPTDIR,'templates','unsuported.tmpl')) + t.query = query + self.wfile.write(t) + else: + self.send_response(404) + self.send_header('Content-type', 'text/html') + self.end_headers() + t = Template(file=os.path.join(SCRIPTDIR,'templates','unsuported.tmpl')) + t.query = query + self.wfile.write(t) + if __name__ == '__main__': def start_server(): -- 2.11.4.GIT