Ejemplo n.º 1
0
def app(environ, start_response):
    import re
    path = environ.get('PATH_INFO', '').lstrip('/')
    for regex, callback in urls:
        match = re.search(regex, path)
        if match is not None:
            return callback(environ, start_response, *match.groups())
    return views.not_found(environ, start_response)
Ejemplo n.º 2
0
def app(environ, start_response):
    import re
    path = environ.get('PATH_INFO', '').lstrip('/')
    for regex, callback in urls:
        match = re.search(regex, path)
        if match is not None:
            return callback(environ, start_response, *match.groups())
    return views.not_found(environ, start_response)
Ejemplo n.º 3
0
def application(environ, start_response):
    path = environ.get('PATH_INFO', '').lstrip('/')
    for regex, callback in urls.URLS:
        match = re.search(regex, path)
        if match is not None:
            environ[views.URLARG] = match.groups()
            return callback(environ, start_response)
    return views.not_found(environ, start_response)
Ejemplo n.º 4
0
 def handle_request(self, request):
     url_adapter = url_map.bind_to_environ(request.environ)
     local.request.session['last'] = request.base_url
     try:
         endpoint, values = url_adapter.match()
         route = getattr(views, endpoint)
         response = route(request, **values)
     except NotFound, e:
         response = views.not_found(request)
Ejemplo n.º 5
0
def application(environ, start_response):
    path = environ.get('PATH_INFO', '').lstrip('/')
    for regex, callback in urls:
        match = re.search(regex, path)
        if not match:
            continue
        environ['URL_ARGS'] = match.groups()
        return callback(environ, start_response)()
    return not_found(environ, start_response)
Ejemplo n.º 6
0
    def __call__(self, environ, start_response):
        pprint(environ)

        request = self.request_init(environ)
        if request['PATH'] in self.urls:
            for item in middleware:
                item(request)
            code, page = urls[request['PATH']](request)
        else:
            code, page = not_found(request)

        print("request: ")
        pprint(request)

        start_response(code, [('Content-Type', 'text/html')])
        return [page.encode(encoding='utf-8')]
Ejemplo n.º 7
0
    def dispatch(self, environ, start_response):
        local.application = self
        request = Request(environ)
        local.url_adapter = adapter = url_map.bind_to_environ(environ)

        try:
            endpoint, values = adapter.match()
            handler = getattr(views, endpoint)
            response = handler(request, **values)
        except NotFound as e:
            response = views.not_found(request)
            response.status_code = 404
        except HTTPException as e:
            response = e
        return ClosingIterator(response(environ, start_response),
                               [local_manager.cleanup])