예제 #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
파일: server.py 프로젝트: Aniverse/deluge-1
    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
파일: server.py 프로젝트: Aniverse/deluge-1
    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
파일: test_core.py 프로젝트: newfyle/deluge
 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
파일: server.py 프로젝트: Aniverse/deluge-1
    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
파일: server.py 프로젝트: Aniverse/deluge-2
    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
파일: server.py 프로젝트: Aniverse/deluge-1
    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
파일: server.py 프로젝트: Aniverse/deluge-1
 def render(self, request):
     request.setHeader("content-type", "text/javascript; encoding=utf-8")
     template = Template(filename=rpath("gettext.js"))
     return compress(template.render(), request)
예제 #26
0
 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()