示例#1
0
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)

        for script_type in ('dev', 'debug', 'normal'):
            scripts = self.__scripts[script_type]['scripts']
            for pattern in scripts:
                if not request.lookup_path.startswith(pattern):
                    continue

                filepath = scripts[pattern]
                if isinstance(filepath, tuple):
                    filepath = filepath[0]

                path = filepath + request.lookup_path[len(pattern):]

                if not os.path.isfile(path):
                    continue

                log.debug('Serving path: %s', path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader(b'content-type', mime_type[0])
                with open(path, 'rb') as _file:
                    data = _file.read()
                return compress(data, request)

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return compress(template.render(), request)
示例#2
0
文件: server.py 项目: newfyle/deluge
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)
        lookup_path = request.lookup_path.decode()
        for script_type in ('dev', 'debug', 'normal'):
            scripts = self.__scripts[script_type]['scripts']
            for pattern in scripts:
                if not lookup_path.startswith(pattern):
                    continue

                filepath = scripts[pattern]
                if isinstance(filepath, tuple):
                    filepath = filepath[0]

                path = filepath + lookup_path[len(pattern):]

                if not os.path.isfile(path):
                    continue

                log.debug('Serving path: %s', path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader(b'content-type', mime_type[0].encode())
                with open(path, 'rb') as _file:
                    data = _file.read()
                return compress(data, request)

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return compress(template.render(), request)
示例#3
0
    def render(self, request):
        """
        Saves all uploaded files to the disk and returns a list of filenames,
        each on a new line.
        """

        # Block all other HTTP methods.
        if request.method != 'POST':
            request.setResponseCode(http.NOT_ALLOWED)
            return ''

        if 'file' not in request.args:
            request.setResponseCode(http.OK)
            return json.dumps({
                'success': True,
                'files': []
            })

        tempdir = tempfile.mkdtemp(prefix='delugeweb-')
        log.debug('uploading files to %s', tempdir)

        filenames = []
        for upload in request.args.get('file'):
            fd, fn = tempfile.mkstemp('.torrent', dir=tempdir)
            os.write(fd, upload)
            os.close(fd)
            filenames.append(fn)
        log.debug('uploaded %d file(s)', len(filenames))

        request.setHeader(b'content-type', b'text/html')
        request.setResponseCode(http.OK)
        return compress(json.dumps({
            'success': True,
            'files': filenames
        }), request)
示例#4
0
    def render(self, request):
        """
        Saves all uploaded files to the disk and returns a list of filenames,
        each on a new line.
        """

        # Block all other HTTP methods.
        if request.method != "POST":
            request.setResponseCode(http.NOT_ALLOWED)
            return ""

        if "file" not in request.args:
            request.setResponseCode(http.OK)
            return common.json.dumps({
                'success': True,
                'files': []
            })

        tempdir = tempfile.mkdtemp(prefix="delugeweb-")
        log.debug("uploading files to %s", tempdir)

        filenames = []
        for upload in request.args.get("file"):
            fd, fn = tempfile.mkstemp('.torrent', dir=tempdir)
            os.write(fd, upload)
            os.close(fd)
            filenames.append(fn)
        log.debug("uploaded %d file(s)", len(filenames))

        request.setHeader("content-type", "text/html")
        request.setResponseCode(http.OK)
        return compress(common.json.dumps({
            'success': True,
            'files': filenames
        }), request)
示例#5
0
    def render(self, request):
        log.debug("Requested path: '%s'", request.lookup_path)

        for type in ("dev", "debug", "normal"):
            scripts = self.__scripts[type]["scripts"]
            for pattern in scripts:
                if not request.lookup_path.startswith(pattern):
                    continue

                filepath = scripts[pattern]
                if isinstance(filepath, tuple):
                    filepath = filepath[0]

                path = filepath + request.lookup_path[len(pattern):]

                if not os.path.isfile(path):
                    continue

                log.debug("Serving path: '%s'", path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader("content-type", mime_type[0])
                return compress(open(path, "rb").read(), request)

        request.setResponseCode(http.NOT_FOUND)
        return "<h1>404 - Not Found</h1>"
示例#6
0
文件: test_core.py 项目: Ashod/Deluge
 def render(self, request):
     data = open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")).read()
     request.setHeader("Content-Type", len(data))
     request.setHeader("Content-Type", "application/x-bittorrent")
     if request.requestHeaders.hasHeader("accept-encoding"):
         return compress(data, request)
     return data
示例#7
0
文件: server.py 项目: newfyle/deluge
    def render(self, request):
        """
        Saves all uploaded files to the disk and returns a list of filenames,
        each on a new line.
        """

        # Block all other HTTP methods.
        if request.method != b'POST':
            request.setResponseCode(http.NOT_ALLOWED)
            return ''

        print(request.args)
        if b'file' not in request.args:
            request.setResponseCode(http.OK)
            return json.dumps({'success': True, 'files': []})

        tempdir = tempfile.mkdtemp(prefix='delugeweb-')
        log.debug('uploading files to %s', tempdir)

        filenames = []
        for upload in request.args.get('file'):
            fd, fn = tempfile.mkstemp('.torrent', dir=tempdir)
            os.write(fd, upload)
            os.close(fd)
            filenames.append(fn)
        log.debug('uploaded %d file(s)', len(filenames))

        request.setHeader(b'content-type', b'text/html')
        request.setResponseCode(http.OK)
        return compress(json.dumps({
            'success': True,
            'files': filenames
        }), request)
示例#8
0
    def render(self, request):
        """
        Saves all uploaded files to the disk and returns a list of filenames,
        each on a new line.
        """

        # Block all other HTTP methods.
        if request.method != "POST":
            request.setResponseCode(http.NOT_ALLOWED)
            return ""

        if "file" not in request.args:
            request.setResponseCode(http.OK)
            return common.json.dumps({'success': True, 'files': []})

        tempdir = tempfile.mkdtemp(prefix="delugeweb-")
        log.debug("uploading files to %s", tempdir)

        filenames = []
        for upload in request.args.get("file"):
            fd, fn = tempfile.mkstemp('.torrent', dir=tempdir)
            os.write(fd, upload)
            os.close(fd)
            filenames.append(fn)
        log.debug("uploaded %d file(s)", len(filenames))

        request.setHeader("content-type", "text/html")
        request.setResponseCode(http.OK)
        return compress(
            common.json.dumps({
                'success': True,
                'files': filenames
            }), request)
示例#9
0
 def render(self, request):
     data = open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")).read()
     request.setHeader("Content-Type", len(data))
     request.setHeader("Content-Type", "application/x-bittorrent")
     if request.requestHeaders.hasHeader("accept-encoding"):
         return compress(data, request)
     return data
示例#10
0
    def render(self, request):
        log.debug("Requested path: '%s'", request.lookup_path)

        for type in ("dev", "debug", "normal"):
            scripts = self.__scripts[type]["scripts"]
            for pattern in scripts:
                if not request.lookup_path.startswith(pattern):
                    continue

                filepath = scripts[pattern]
                if isinstance(filepath, tuple):
                    filepath = filepath[0]

                path = filepath + request.lookup_path[len(pattern):]

                if not os.path.isfile(path):
                    continue

                log.debug("Serving path: '%s'", path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader("content-type", mime_type[0])
                return compress(open(path, "rb").read(), request)

        request.setResponseCode(http.NOT_FOUND)
        return "<h1>404 - Not Found</h1>"
示例#11
0
 def render(self, request):
     with open(common.get_test_data_file('ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file:
         data = _file.read()
     request.setHeader(b'Content-Type', len(data))
     request.setHeader(b'Content-Type', b'application/x-bittorrent')
     if request.requestHeaders.hasHeader('accept-encoding'):
         return compress(data, request)
     return data
示例#12
0
 def _send_response(self, request, response):
     if request._disconnected:
         return ''
     response = json.dumps(response)
     request.setHeader(b'content-type', b'application/x-json')
     request.write(compress(response, request))
     request.finish()
     return server.NOT_DONE_YET
示例#13
0
 def _send_response(self, request, response):
     if request._disconnected:
         return ''
     response = json.dumps(response)
     request.setHeader(b'content-type', b'application/x-json')
     request.write(compress(response, request))
     request.finish()
     return server.NOT_DONE_YET
示例#14
0
    def render(self, request):
        if not hasattr(request, "render_file"):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ""

        filename = os.path.join("render", request.render_file)
        template = Template(filename=rpath(filename))
        request.setHeader("content-type", "text/html")
        request.setResponseCode(http.OK)
        return compress(template.render(), request)
示例#15
0
 def render(self, request):
     with open(
             common.get_test_data_file(
                 'ubuntu-9.04-desktop-i386.iso.torrent'), 'rb') as _file:
         data = _file.read()
     request.setHeader(b'Content-Type', len(data))
     request.setHeader(b'Content-Type', b'application/x-bittorrent')
     if request.requestHeaders.hasHeader('accept-encoding'):
         return compress(data, request)
     return data
示例#16
0
    def render(self, request):
        if not hasattr(request, "render_file"):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ""

        filename = os.path.join("render", request.render_file)
        template = Template(filename=rpath(filename))
        request.setHeader("content-type", "text/html")
        request.setResponseCode(http.OK)
        return compress(template.render(), request)
示例#17
0
文件: server.py 项目: newfyle/deluge
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)
        path = os.path.dirname(request.lookup_path).decode()

        if path in self.__paths:
            filename = os.path.basename(request.path).decode()
            for directory in self.__paths[path]:
                if os.path.join(directory, filename):
                    path = os.path.join(directory, filename)
                    log.debug('Serving path: %s', path)
                    mime_type = mimetypes.guess_type(path)
                    request.setHeader(b'content-type', mime_type[0].encode())
                    with open(path, 'rb') as _file:
                        data = _file.read()
                    return compress(data, request)

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return compress(template.render(), request)
示例#18
0
    def render(self, request):
        log.debug('Requested path: %s', request.lookup_path)
        path = os.path.dirname(request.lookup_path)

        if path in self.__paths:
            filename = os.path.basename(request.path)
            for directory in self.__paths[path]:
                if os.path.join(directory, filename):
                    path = os.path.join(directory, filename)
                    log.debug('Serving path: %s', path)
                    mime_type = mimetypes.guess_type(path)
                    request.setHeader(b'content-type', mime_type[0])
                    with open(path, 'rb') as _file:
                        data = _file.read()
                    return compress(data, request)

        request.setResponseCode(http.NOT_FOUND)
        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(os.path.join('render', '404.html')))
        return compress(template.render(), request)
示例#19
0
    def render(self, request):
        if not hasattr(request, 'render_file'):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ''

        if request.render_file in self.template_files:
            request.setResponseCode(http.OK)
            filename = os.path.join('render', request.render_file)
        else:
            request.setResponseCode(http.NOT_FOUND)
            filename = os.path.join('render', '404.html')

        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(filename))
        return compress(template.render(), request)
示例#20
0
    def render(self, request):
        if not hasattr(request, 'render_file'):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ''

        if request.render_file in self.template_files:
            request.setResponseCode(http.OK)
            filename = os.path.join('render', request.render_file)
        else:
            request.setResponseCode(http.NOT_FOUND)
            filename = os.path.join('render', '404.html')

        request.setHeader(b'content-type', b'text/html')
        template = Template(filename=rpath(filename))
        return compress(template.render(), request)
示例#21
0
文件: server.py 项目: newfyle/deluge
    def render(self, request):
        log.debug('Render template file: %s', request.render_file)
        if not hasattr(request, 'render_file'):
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            return ''

        request.setHeader(b'content-type', b'text/html')

        tpl_file = request.render_file.decode()
        if tpl_file in self.template_files:
            request.setResponseCode(http.OK)
        else:
            request.setResponseCode(http.NOT_FOUND)
            tpl_file = '404.html'

        template = Template(filename=rpath(os.path.join('render', tpl_file)))
        return compress(template.render(), request)
示例#22
0
    def render(self, request):
        log.debug("Requested path: '%s'", request.lookup_path)
        path = os.path.dirname(request.lookup_path)

        if path not in self.__paths:
            request.setResponseCode(http.NOT_FOUND)
            return "<h1>404 - Not Found</h1>"

        filename = os.path.basename(request.path)
        for directory in self.__paths[path]:
            if os.path.join(directory, filename):
                path = os.path.join(directory, filename)
                log.debug("Serving path: '%s'", path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader("content-type", mime_type[0])
                return compress(open(path, "rb").read(), request)

        request.setResponseCode(http.NOT_FOUND)
        return "<h1>404 - Not Found</h1>"
示例#23
0
    def render(self, request):
        log.debug("Requested path: '%s'", request.lookup_path)
        path = os.path.dirname(request.lookup_path)

        if path not in self.__paths:
            request.setResponseCode(http.NOT_FOUND)
            return "<h1>404 - Not Found</h1>"

        filename = os.path.basename(request.path)
        for directory in self.__paths[path]:
            if os.path.join(directory, filename):
                path = os.path.join(directory, filename)
                log.debug("Serving path: '%s'", path)
                mime_type = mimetypes.guess_type(path)
                request.setHeader("content-type", mime_type[0])
                return compress(open(path, "rb").read(), request)

        request.setResponseCode(http.NOT_FOUND)
        return "<h1>404 - Not Found</h1>"
示例#24
0
 def render(self, request):
     request.setHeader(b'content-type', b'text/javascript; encoding=utf-8')
     template = Template(filename=rpath('js', 'gettext.js'))
     return compress(template.render(), request)
示例#25
0
 def render(self, request):
     request.setHeader("content-type", "text/javascript; encoding=utf-8")
     template = Template(filename=rpath("gettext.js"))
     return compress(template.render(), request)
 def render(self, request):
     message = request.args.get('msg', ['EFFICIENCY!'])[0]
     request.setHeader(b'Content-Type', b'text/plain')
     return compress(message, request)
示例#27
0
文件: json_api.py 项目: laanwj/deluge
 def _send_response(self, request, response):
     response = json.dumps(response)
     request.setHeader("content-type", "application/x-json")
     request.write(compress(response, request))
     request.finish()
示例#28
0
 def render(self, request):
     message = request.args.get('msg', ['EFFICIENCY!'])[0]
     request.setHeader(b'Content-Type', b'text/plain')
     return compress(message, request)
示例#29
0
 def render(self, request):
     message = request.args.get("msg", ["EFFICIENCY!"])[0]
     request.setHeader("Content-Type", "text/plain")
     return compress(message, request)
示例#30
0
文件: server.py 项目: newfyle/deluge
 def render(self, request):
     request.setHeader(b'content-type', b'text/javascript; encoding=utf-8')
     data = b'function _(string) { return string; }'
     return compress(data, request)
示例#31
0
文件: server.py 项目: newfyle/deluge
 def render(self, request):
     request.setHeader(b'content-type', b'text/javascript; encoding=utf-8')
     template = Template(filename=rpath('js', 'gettext.js'))
     return compress(template.render(), request)
示例#32
0
 def render(self, request):
     request.setHeader("content-type", "text/javascript; encoding=utf-8")
     template = Template(filename=rpath("gettext.js"))
     return compress(template.render(), request)
示例#33
0
 def render(self, request):
     message = request.args.get("msg", ["EFFICIENCY!"])[0]
     request.setHeader("Content-Type", "text/plain")
     return compress(message, request)
示例#34
0
 def _send_response(self, request, response):
     response = json.dumps(response)
     request.setHeader("content-type", "application/x-json")
     request.write(compress(response, request))
     request.finish()