コード例 #1
0
def test_shared_data_middleware(tmpdir):
    def null_application(environ, start_response):
        start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
        yield b'NOT FOUND'

    test_dir = str(tmpdir)
    with open(path.join(test_dir, to_native(u'äöü', 'utf-8')),
              'w') as test_file:
        test_file.write(u'FOUND')

    app = wsgi.SharedDataMiddleware(
        null_application, {
            '/': path.join(path.dirname(__file__), 'res'),
            '/sources': path.join(path.dirname(__file__), 'res'),
            '/pkg': ('werkzeug.debug', 'shared'),
            '/foo': test_dir
        })

    for p in '/test.txt', '/sources/test.txt', '/foo/äöü':
        app_iter, status, headers = run_wsgi_app(app, create_environ(p))
        assert status == '200 OK'
        with closing(app_iter) as app_iter:
            data = b''.join(app_iter).strip()
        assert data == b'FOUND'

    app_iter, status, headers = run_wsgi_app(
        app, create_environ('/pkg/debugger.js'))
    with closing(app_iter) as app_iter:
        contents = b''.join(app_iter)
    assert b'$(function() {' in contents

    app_iter, status, headers = run_wsgi_app(app, create_environ('/missing'))
    assert status == '404 NOT FOUND'
    assert b''.join(app_iter).strip() == b'NOT FOUND'
コード例 #2
0
    def test_shared_data_middleware(self):
        def null_application(environ, start_response):
            start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
            yield b'NOT FOUND'

        app = wsgi.SharedDataMiddleware(
            null_application, {
                '/': path.join(path.dirname(__file__), 'res'),
                '/sources': path.join(path.dirname(__file__), 'res'),
                '/pkg': ('werkzeug.debug', 'shared')
            })

        for p in '/test.txt', '/sources/test.txt':
            app_iter, status, headers = run_wsgi_app(app, create_environ(p))
            self.assert_equal(status, '200 OK')
            with closing(app_iter) as app_iter:
                data = b''.join(app_iter).strip()
            self.assert_equal(data, b'FOUND')

        app_iter, status, headers = run_wsgi_app(
            app, create_environ('/pkg/debugger.js'))
        with closing(app_iter) as app_iter:
            contents = b''.join(app_iter)
        self.assert_in(b'$(function() {', contents)

        app_iter, status, headers = run_wsgi_app(app,
                                                 create_environ('/missing'))
        self.assert_equal(status, '404 NOT FOUND')
        self.assert_equal(b''.join(app_iter).strip(), b'NOT FOUND')
コード例 #3
0
 def WSGIHandler(self):
     return werkzeug_wsgi.SharedDataMiddleware(
         self, {
             "/static": config.CONFIG["AdminUI.document_root"],
             "/local/static": config.CONFIG["AdminUI.local_document_root"],
             "/local/help": config.CONFIG["AdminUI.help_root"]
         })
コード例 #4
0
    def _app(self):
        if self.__app is None:
            url_map = routing.Map([
                routing.Rule('/', endpoint='route_index'),
                routing.Rule('/api/<endpoint>', endpoint='route_api'),
                routing.Rule('/auth', endpoint='route_auth'),
                routing.Rule('/cookie', endpoint='route_cookie'),
                routing.Rule('/edit/<path:path>', endpoint='route_edit'),
                routing.Rule('/version', endpoint='route_version'),
            ])

            @wrappers.Request.application
            def app(request):
                adapter = url_map.bind_to_environ(request.environ)
                endpoint, values = adapter.match()
                response = getattr(self, endpoint)(request=request, **values)
                if isinstance(response, str):
                    response = wrappers.Response(
                        response,
                        mimetype='text/plain',
                    )
                return response

            app = wsgi.SharedDataMiddleware(app, {
                '/static': ('whim', 'static'),
            })
            self.__app = app
        return self.__app
コード例 #5
0
    def test_shared_data_middleware(self):
        def null_application(environ, start_response):
            start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
            yield 'NOT FOUND'

        app = wsgi.SharedDataMiddleware(
            null_application, {
                '/': path.join(path.dirname(__file__), 'res'),
                '/sources': path.join(path.dirname(__file__), 'res'),
                '/pkg': ('werkzeug.debug', 'shared')
            })

        for p in '/test.txt', '/sources/test.txt':
            app_iter, status, headers = run_wsgi_app(app, create_environ(p))
            assert status == '200 OK'
            assert ''.join(app_iter).strip() == 'FOUND'

        app_iter, status, headers = run_wsgi_app(
            app, create_environ('/pkg/debugger.js'))
        contents = ''.join(app_iter)
        assert '$(function() {' in contents

        app_iter, status, headers = run_wsgi_app(app,
                                                 create_environ('/missing'))
        assert status == '404 NOT FOUND'
        assert ''.join(app_iter).strip() == 'NOT FOUND'
コード例 #6
0
ファイル: main.py プロジェクト: rsau/grow
def create_wsgi_app(pod, host, port, debug=False):
    podserver_app = PodServer(pod, host, port, debug=debug)
    assets_path = os.path.join(utils.get_grow_dir(), 'ui', 'admin', 'assets')
    ui_path = os.path.join(utils.get_grow_dir(), 'ui', 'dist')
    return wsgi.SharedDataMiddleware(podserver_app, {
        '/_grow/ui': ui_path,
        '/_grow/assets': assets_path,
    })
コード例 #7
0
def create_wsgi_app(pod, debug=False):
    if pod.use_reroute:
        podserver_app = PodServerReRoute(pod, debug=debug)
    else:
        podserver_app = PodServer(pod, debug=debug)
    assets_path = os.path.join(utils.get_grow_dir(), 'ui', 'assets')
    ui_path = os.path.join(utils.get_grow_dir(), 'ui', 'dist')
    return wsgi.SharedDataMiddleware(podserver_app, {
        '/_grow/ui': ui_path,
        '/_grow/assets': assets_path,
    })
コード例 #8
0
 def WSGIHandler(self):
   """Returns GRR's WSGI handler."""
   sdm = werkzeug_wsgi.SharedDataMiddleware(self, {
       "/": config.CONFIG["AdminUI.document_root"],
   })
   # Use DispatcherMiddleware to make sure that SharedDataMiddleware is not
   # used at all if the URL path doesn't start with "/static". This is a
   # workaround for cases when unicode URLs are used on systems with
   # non-unicode filesystems (as detected by Werkzeug). In this case
   # SharedDataMiddleware may fail early while trying to convert the
   # URL into the file path and not dispatch the call further to our own
   # WSGI handler.
   return werkzeug_wsgi.DispatcherMiddleware(self, {
       "/static": sdm,
   })
コード例 #9
0
def test_shareddatamiddleware_get_file_loader():
    app = wsgi.SharedDataMiddleware(None, {})
    assert callable(app.get_file_loader('foo'))
コード例 #10
0
ファイル: mavelous_server.py プロジェクト: regaleagle/SQUID
import os
import os.path
import threading
import types

from cherrypy import wsgiserver
import flask
from werkzeug import wsgi

logger = logging.getLogger(__name__)

app = flask.Flask(__name__)

DOC_DIR = os.path.join(os.path.dirname(__file__), 'mavelous_web')

app.wsgi_app = wsgi.SharedDataMiddleware(app.wsgi_app, {'/': DOC_DIR})


class Error(Exception):
    pass


@app.route('/')
def index_view():
    return flask.redirect('/index.html')


@app.route('/mavlink/<msgtypes>')
def mavlink_view(msgtypes):
    # Treat '*' as a wildcard.
    if msgtypes == '*':