Changeset - 7c5197d0d935
[Not reviewed]
Kirill - 9 months ago 2021-02-01 07:31:00
anikinkirill94@yandex.ru
Added ability for mounting apps to prefix
1 file changed with 10 insertions and 2 deletions:
0 comments (0 inline, 0 general)
serpens.py
Show inline comments
 
@@ -72,6 +72,7 @@ class SerpensRequest(object):
 
class Serpens(object):
 
    def __init__(self):
 
        self.routes = []
 
        self.subapps = {}
 
 
    def route(self, rule):
 
        def wrapper(callback):
 
@@ -88,6 +89,8 @@ class Serpens(object):
 
                return callback(request, **kwargs)
 
        return None
 
 
    def mount(self, prefix, application)
 
 
    def wsgi(self, environ, start_response):
 
        request = SerpensRequest(
 
            environ['QUERY_STRING'],
 
@@ -96,7 +99,12 @@ class Serpens(object):
 
            environ['SERVER_NAME'],
 
            environ['SERVER_PORT']
 
        )
 
        response = self.dispatch(request, environ['PATH_INFO'])
 
        response = None
 
        for prefix in self.subapps:
 
            if environ['PATH_INFO'].startswith(prefix):
 
                response = self.subapps[prefix](environ, start_response)
 
        if response is None:
 
            response = self.dispatch(request, environ['PATH_INFO'])
 
        if response is None:
 
            start_response(51, 'Not found')
 
            return
 
@@ -120,4 +128,4 @@ def error(message, status=40):
 
    return SerpensResponse(None, status, message)
 
 
def input_required(prompt):
 
    return SerpensResponse(None, 10, prompt)
 
\ No newline at end of file
 
    return SerpensResponse(None, 10, prompt)
0 comments (0 inline, 0 general)