Exemple #1
0
 def __call__(self, environ, start_response):
     global wsgilib
     if wsgilib is None:
         import pkg_resources
         pkg_resources.require('Paste')
         from paste import wsgilib
     popped_config = None
     if 'paste.config' in environ:
         popped_config = environ['paste.config']        
     conf = environ['paste.config'] = self.config.copy()
     app_iter = None
     CONFIG.push_thread_config(conf)
     try:
         app_iter = self.application(environ, start_response)
     finally:
         if app_iter is None:
             # An error occurred...
             CONFIG.pop_thread_config(conf)
             if popped_config is not None:
                 environ['paste.config'] = popped_config
     if type(app_iter) in (list, tuple):
         # Because it is a concrete iterator (not a generator) we
         # know the configuration for this thread is no longer
         # needed:
         CONFIG.pop_thread_config(conf)
         if popped_config is not None:
             environ['paste.config'] = popped_config
         return app_iter
     else:
         def close_config():
             CONFIG.pop_thread_config(conf)
         new_app_iter = wsgilib.add_close(app_iter, close_config)
         return new_app_iter
Exemple #2
0
def test_add_close_unicode():
    global close_func_called

    close_func_called = False
    lst = []
    app_iterable = app_iterable_func_unicode()

    obj = add_close(app_iterable, close_func)
    for x in obj:
        lst.append(x)
    obj.close()

    assert lst == ['a', 'b', 'c']
    assert close_func_called
    assert obj._closed
Exemple #3
0
def test_add_close(app_iterable_func, expected):
    global close_func_called

    close_func_called = False
    lst = []
    app_iterable = app_iterable_func()

    obj = add_close(app_iterable, close_func)
    for x in obj:
        lst.append(x)
    obj.close()

    assert lst == expected
    assert close_func_called
    assert obj._closed
Exemple #4
0
    def __call__(self, environ, start_response):
        service = flup_session.SessionService(
            self.store, environ, cookieName=self.cookie_name,
            fieldName=self.cookie_name)
        environ['paste.flup_session_service'] = service

        def cookie_start_response(status, headers, exc_info=None):
            service.addCookie(headers)
            return start_response(status, headers, exc_info)

        try:
            app_iter = self.application(environ, cookie_start_response)
        except httpexceptions.HTTPException as e:
            headers = (e.headers or {}).items()
            service.addCookie(headers)
            e.headers = dict(headers)
            service.close()
            raise
        except:
            service.close()
            raise

        return wsgilib.add_close(app_iter, service.close)
Exemple #5
0
    def __call__(self, environ, start_response):
        service = flup_session.SessionService(self.store,
                                              environ,
                                              cookieName=self.cookie_name,
                                              fieldName=self.cookie_name)
        environ['paste.flup_session_service'] = service

        def cookie_start_response(status, headers, exc_info=None):
            service.addCookie(headers)
            return start_response(status, headers, exc_info)

        try:
            app_iter = self.application(environ, cookie_start_response)
        except httpexceptions.HTTPException as e:
            headers = (e.headers or {}).items()
            service.addCookie(headers)
            e.headers = dict(headers)
            service.close()
            raise
        except:
            service.close()
            raise

        return wsgilib.add_close(app_iter, service.close)
Exemple #6
0
            service.addCookie(headers)
            return start_response(status, headers, exc_info)

        try:
            app_iter = self.application(environ, cookie_start_response)
        except httpexceptions.HTTPException, e:
            headers = (e.headers or {}).items()
            service.addCookie(headers)
            e.headers = dict(headers)
            service.close()
            raise
        except:
            service.close()
            raise

        return wsgilib.add_close(app_iter, service.close)
            
def make_session_middleware(app, global_conf,
                            session_type=NoDefault,
                            cookie_name=NoDefault,
                            **store_config):
    """
    Wraps the application in a session-managing middleware.
    The session service can then be found in
    ``environ['paste.flup_session_service']``
    """
    return SessionMiddleware(
        app, global_conf=global_conf,
        session_type=session_type, cookie_name=cookie_name,
        **store_config)