diff options
Diffstat (limited to 'pyload/webui')
-rw-r--r-- | pyload/webui/__init__.py | 13 | ||||
-rw-r--r-- | pyload/webui/app/__init__.py | 2 | ||||
-rw-r--r-- | pyload/webui/app/pyload.py (renamed from pyload/webui/app/pyloadweb.py) | 2 | ||||
-rw-r--r-- | pyload/webui/app/utils.py | 2 | ||||
-rw-r--r-- | pyload/webui/filters.py | 68 | ||||
-rw-r--r-- | pyload/webui/middlewares.py | 144 |
6 files changed, 8 insertions, 223 deletions
diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py index 472e1a4f7..70928c458 100644 --- a/pyload/webui/__init__.py +++ b/pyload/webui/__init__.py @@ -5,13 +5,12 @@ import os import sys import bottle +import jinja2 import pyload.utils.pylgettext as gettext -from jinja2 import Environment, FileSystemLoader, PrefixLoader, FileSystemBytecodeCache - from pyload.Thread import Server -from pyload.Webui.middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware +from pyload.utils.middlewares import StripPathMiddleware, GZipMiddleWare, PrefixMiddleware from pyload.network.JsEngine import JsEngine from pyload.utils import decode, formatSize @@ -53,14 +52,14 @@ cache = os.path.join("tmp", "jinja_cache") if not os.path.exists(cache): os.makedirs(cache) -bcc = FileSystemBytecodeCache(cache, '%s.cache') +bcc = jinja2.FileSystemBytecodeCache(cache, '%s.cache') -loader = FileSystemLoader([THEME_DIR, os.path.join(THEME_DIR, THEME)]) +loader = jinja2.FileSystemLoader([THEME_DIR, os.path.join(THEME_DIR, THEME)]) -env = Environment(loader=loader, extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'], trim_blocks=True, auto_reload=False, +env = jinja2.Environment(loader=loader, extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'], trim_blocks=True, auto_reload=False, bytecode_cache=bcc) -from filters import quotepath, path_make_relative, path_make_absolute, truncate, date +from pyload.utils.filters import quotepath, path_make_relative, path_make_absolute, truncate, date env.filters['quotepath'] = quotepath env.filters['truncate'] = truncate diff --git a/pyload/webui/app/__init__.py b/pyload/webui/app/__init__.py index 43c9ecbe9..39d0fadd5 100644 --- a/pyload/webui/app/__init__.py +++ b/pyload/webui/app/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from pyload.webui.app import api, cnl, json, pyloadweb +from pyload.webui.app import api, cnl, json, pyload diff --git a/pyload/webui/app/pyloadweb.py b/pyload/webui/app/pyload.py index 27532b86e..58acdf12c 100644 --- a/pyload/webui/app/pyloadweb.py +++ b/pyload/webui/app/pyload.py @@ -15,7 +15,7 @@ from pyload.webui import PYLOAD, PYLOAD_DIR, THEME_DIR, THEME, SETUP, env from pyload.webui.app.utils import render_to_response, parse_permissions, parse_userdata, \ login_required, get_permission, set_permission, permlist, toDict, set_session -from pyload.webui.filters import relpath, unquotepath +from pyload.utils.filters import relpath, unquotepath from pyload.utils import formatSize, fs_join, fs_encode, fs_decode diff --git a/pyload/webui/app/utils.py b/pyload/webui/app/utils.py index 3526f2615..2e7cf76c5 100644 --- a/pyload/webui/app/utils.py +++ b/pyload/webui/app/utils.py @@ -86,10 +86,8 @@ def parse_userdata(session): def login_required(perm=None): - def _dec(func): - def _view(*args, **kwargs): s = request.environ.get('beaker.session') if s.get("name", None) and s.get("authenticated", False): diff --git a/pyload/webui/filters.py b/pyload/webui/filters.py deleted file mode 100644 index 9d4d47c04..000000000 --- a/pyload/webui/filters.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- - -import os - -quotechar = "::/" - -try: - from os.path import relpath -except Exception: - from posixpath import curdir, sep, pardir - - - def os.relpath(path, start=curdir): - """Return a relative version of a path""" - if not path: - raise ValueError("no path specified") - start_list = os.path.abspath(start).split(sep) - path_list = os.path.abspath(path).split(sep) - # Work out how much of the filepath is shared by start and path. - i = len(os.path.commonprefix([start_list, path_list])) - rel_list = [pardir] * (len(start_list) - i) + path_list[i:] - if not rel_list: - return curdir - return os.path.join(*rel_list) - - -def quotepath(path): - try: - return path.replace("../", quotechar) - except AttributeError: - return path - except Exception: - return "" - - -def unquotepath(path): - try: - return path.replace(quotechar, "../") - except AttributeError: - return path - except Exception: - return "" - - -def path_make_absolute(path): - p = os.path.abspath(path) - if p[-1] == os.path.sep: - return p - else: - return p + os.path.sep - - -def path_make_relative(path): - p = os.relpath(path) - if p[-1] == os.path.sep: - return p - else: - return p + os.path.sep - - -def truncate(value, n): - if (n - len(value)) < 3: - return value[:n] + "..." - return value - - -def date(date, format): - return date diff --git a/pyload/webui/middlewares.py b/pyload/webui/middlewares.py deleted file mode 100644 index c3f4952db..000000000 --- a/pyload/webui/middlewares.py +++ /dev/null @@ -1,144 +0,0 @@ -# -*- coding: utf-8 -*- - -import gzip - -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - - -class StripPathMiddleware(object): - - def __init__(self, app): - self.app = app - - - def __call__(self, e, h): - e['PATH_INFO'] = e['PATH_INFO'].rstrip('/') - return self.app(e, h) - - -class PrefixMiddleware(object): - - def __init__(self, app, prefix="/pyload"): - self.app = app - self.prefix = prefix - - - def __call__(self, e, h): - path = e['PATH_INFO'] - if path.startswith(self.prefix): - e['PATH_INFO'] = path.replace(self.prefix, "", 1) - return self.app(e, h) - -# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) -# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php - -# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) -# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php - -# WSGI middleware -# Gzip-encodes the response. - - -class GZipMiddleWare(object): - - def __init__(self, application, compress_level=6): - self.application = application - self.compress_level = int(compress_level) - - - def __call__(self, environ, start_response): - if 'gzip' not in environ.get('HTTP_ACCEPT_ENCODING', ''): - # nothing for us to do, so this middleware will - # be a no-op: - return self.application(environ, start_response) - response = GzipResponse(start_response, self.compress_level) - app_iter = self.application(environ, - response.gzip_start_response) - if app_iter is not None: - response.finish_response(app_iter) - - return response.write() - - -def header_value(headers, key): - for header, value in headers: - if key.lower() == header.lower(): - return value - - -def update_header(headers, key, value): - remove_header(headers, key) - headers.append((key, value)) - - -def remove_header(headers, key): - for header, value in headers: - if key.lower() == header.lower(): - headers.remove((header, value)) - break - - -class GzipResponse(object): - - def __init__(self, start_response, compress_level): - self.start_response = start_response - self.compress_level = compress_level - self.buffer = StringIO() - self.compressible = False - self.content_length = None - self.headers = () - - - def gzip_start_response(self, status, headers, exc_info=None): - self.headers = headers - ct = header_value(headers, 'content-type') - ce = header_value(headers, 'content-encoding') - cl = header_value(headers, 'content-length') - if cl: - cl = int(cl) - else: - cl = 201 - self.compressible = False - if ct and (ct.startswith('text/') or ct.startswith('application/')) and 'zip' not in ct and cl > 200: - self.compressible = True - if ce: - self.compressible = False - if self.compressible: - headers.append(('content-encoding', 'gzip')) - remove_header(headers, 'content-length') - self.headers = headers - self.status = status - return self.buffer.write - - - def write(self): - out = self.buffer - out.seek(0) - s = out.getvalue() - out.close() - return [s] - - - def finish_response(self, app_iter): - if self.compressible: - output = gzip.GzipFile(mode='wb', compresslevel=self.compress_level, fileobj=self.buffer) - else: - output = self.buffer - try: - for s in app_iter: - output.write(s) - if self.compressible: - output.close() - finally: - if hasattr(app_iter, 'close'): - try: - app_iter.close() - except Exception: - pass - - content_length = self.buffer.tell() - update_header(self.headers, "Content-Length", str(content_length)) - self.start_response(self.status, self.headers) |