From adc9902252ed2c94d0f0e2c5bc8fe8da929cd04c Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Tue, 22 Jul 2008 19:24:57 +0000 Subject: [PATCH] mime-type guessing for /template/render/ --- deluge/ui/webui/pages.py | 5 +++-- deluge/ui/webui/utils.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/deluge/ui/webui/pages.py b/deluge/ui/webui/pages.py index aaff59de4..1612bcc7a 100644 --- a/deluge/ui/webui/pages.py +++ b/deluge/ui/webui/pages.py @@ -392,8 +392,9 @@ route("/template/static/(.*)", template_static) class template_render: "render anything in /render/ dir" - @deco.deluge_page + def GET(self, name): + web.header("Content-type",utils.guess_mime_type(name)) #security : assumes config.get('template') returns a safe subdir. basepath = os.path.normpath(os.path.join(os.path.dirname(__file__), 'templates/%s/render' % config.get('template'))) @@ -402,7 +403,7 @@ class template_render: #hack detected? raise Exception("File to render is not located in %s" % basepath) - return web.template.Template(open(filename).read(), filename=filename)() + print web.template.Template(open(filename).read(), filename=filename)() route("/template/render/(.*)", template_render) class template_style: diff --git a/deluge/ui/webui/utils.py b/deluge/ui/webui/utils.py index 610c8a52d..6804f4237 100644 --- a/deluge/ui/webui/utils.py +++ b/deluge/ui/webui/utils.py @@ -297,3 +297,17 @@ class WebUiError(Exception): class UnknownTorrentError(WebUiError): pass +#mime-type guessing : +def guess_mime_type(path): + import posixpath + from mimetypes import types_map as extensions_map + base, ext = posixpath.splitext(path) + if ext in extensions_map: + return extensions_map[ext] + ext = ext.lower() + if ext in extensions_map: + return extensions_map[ext] + else: + return 'application/octet-stream' + +