Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.support.werkzeug.contrib.sessions.SessionMiddleware Class Reference

List of all members.

Public Member Functions

def __init__
def __call__

Public Attributes

 app
 store
 cookie_name
 cookie_age
 cookie_expires
 cookie_path
 cookie_domain
 cookie_secure
 cookie_httponly
 environ_key

Detailed Description

A simple middleware that puts the session object of a store provided
into the WSGI environ.  It automatically sets cookies and restores
sessions.

However a middleware is not the preferred solution because it won't be as
fast as sessions managed by the application itself and will put a key into
the WSGI environment only relevant for the application which is against
the concept of WSGI.

The cookie parameters are the same as for the :func:`~werkzeug.dump_cookie`
function just prefixed with ``cookie_``.  Additionally `max_age` is
called `cookie_age` and not `cookie_max_age` because of backwards
compatibility.

Definition at line 230 of file sessions.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.contrib.sessions.SessionMiddleware.__init__ (   self,
  app,
  store,
  cookie_name = 'session_id',
  cookie_age = None,
  cookie_expires = None,
  cookie_path = '/',
  cookie_domain = None,
  cookie_secure = None,
  cookie_httponly = False,
  environ_key = 'werkzeug.session' 
)

Definition at line 249 of file sessions.py.

00249 
00250                  cookie_httponly=False, environ_key='werkzeug.session'):
00251         self.app = app
00252         self.store = store
00253         self.cookie_name = cookie_name
00254         self.cookie_age = cookie_age
00255         self.cookie_expires = cookie_expires
00256         self.cookie_path = cookie_path
00257         self.cookie_domain = cookie_domain
00258         self.cookie_secure = cookie_secure
00259         self.cookie_httponly = cookie_httponly
00260         self.environ_key = environ_key


Member Function Documentation

def MoinMoin.support.werkzeug.contrib.sessions.SessionMiddleware.__call__ (   self,
  environ,
  start_response 
)

Definition at line 261 of file sessions.py.

00261 
00262     def __call__(self, environ, start_response):
00263         cookie = parse_cookie(environ.get('HTTP_COOKIE', ''))
00264         sid = cookie.get(self.cookie_name, None)
00265         if sid is None:
00266             session = self.store.new()
00267         else:
00268             session = self.store.get(sid)
00269         environ[self.environ_key] = session
00270 
00271         def injecting_start_response(status, headers, exc_info=None):
00272             if session.should_save:
00273                 self.store.save(session)
00274                 headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
00275                                 session.sid, self.cookie_age,
00276                                 self.cookie_expires, self.cookie_path,
00277                                 self.cookie_domain, self.cookie_secure,
00278                                 self.cookie_httponly)))
00279             return start_response(status, headers, exc_info)
00280         return ClosingIterator(self.app(environ, injecting_start_response),
00281                                lambda: self.store.save_if_modified(session))

Here is the call graph for this function:


Member Data Documentation

Definition at line 250 of file sessions.py.

Definition at line 253 of file sessions.py.

Definition at line 256 of file sessions.py.

Definition at line 254 of file sessions.py.

Definition at line 258 of file sessions.py.

Definition at line 252 of file sessions.py.

Definition at line 255 of file sessions.py.

Definition at line 257 of file sessions.py.

Definition at line 259 of file sessions.py.

Definition at line 251 of file sessions.py.


The documentation for this class was generated from the following file: