Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.wsgiapp Namespace Reference

Classes

class  Application

Functions

def init
def run
def remove_prefix
def dispatch
def handle_action
def setup_user
def setup_i18n_preauth
def setup_i18n_postauth

Variables

tuple logging = log.getLogger(__name__)
tuple application = Application()

Function Documentation

def MoinMoin.wsgiapp.dispatch (   request,
  context,
  action_name = 'show' 
)

Definition at line 92 of file wsgiapp.py.

00092 
00093 def dispatch(request, context, action_name='show'):
00094     cfg = context.cfg
00095 
00096     # The last component in path_info is the page name, if any
00097     path = remove_prefix(request.path, cfg.url_prefix_action)
00098 
00099     if path.startswith('/'):
00100         pagename = wikiutil.normalize_pagename(path, cfg)
00101     else:
00102         pagename = None
00103 
00104     # need to inform caches that content changes based on:
00105     # * cookie (even if we aren't sending one now)
00106     # * User-Agent (because a bot might be denied and get no content)
00107     # * Accept-Language (except if moin is told to ignore browser language)
00108     hs = HeaderSet(('Cookie', 'User-Agent'))
00109     if not cfg.language_ignore_browser:
00110         hs.add('Accept-Language')
00111     request.headers.add('Vary', str(hs))
00112 
00113     # Handle request. We have these options:
00114     # 1. jump to page where user left off
00115     if not pagename and context.user.remember_last_visit and action_name == 'show':
00116         response = redirect_last_visited(context)
00117     # 2. handle action
00118     else:
00119         response = handle_action(context, pagename, action_name)
00120     if isinstance(response, Context):
00121         response = response.request
00122     return response

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.wsgiapp.handle_action (   context,
  pagename,
  action_name = 'show' 
)
Actual dispatcher function for non-XMLRPC actions.

Also sets up the Page object for this request, normalizes and
redirects to canonical pagenames and checks for non-allowed
actions.

Definition at line 123 of file wsgiapp.py.

00123 
00124 def handle_action(context, pagename, action_name='show'):
00125     """ Actual dispatcher function for non-XMLRPC actions.
00126 
00127     Also sets up the Page object for this request, normalizes and
00128     redirects to canonical pagenames and checks for non-allowed
00129     actions.
00130     """
00131     _ = context.getText
00132     cfg = context.cfg
00133 
00134     # pagename could be empty after normalization e.g. '///' -> ''
00135     # Use localized FrontPage if pagename is empty
00136     if not pagename:
00137         context.page = wikiutil.getFrontPage(context)
00138     else:
00139         context.page = Page(context, pagename)
00140         if '_' in pagename and not context.page.exists():
00141             pagename = pagename.replace('_', ' ')
00142             page = Page(context, pagename)
00143             if page.exists():
00144                 url = page.url(context)
00145                 return context.http_redirect(url)
00146 
00147     msg = None
00148     # Complain about unknown actions
00149     if not action_name in get_names(cfg):
00150         msg = _("Unknown action %(action_name)s.") % {
00151                 'action_name': wikiutil.escape(action_name), }
00152 
00153     # Disallow non available actions
00154     elif action_name[0].isupper() and not action_name in \
00155             get_available_actions(cfg, context.page, context.user):
00156         msg = _("You are not allowed to do %(action_name)s on this page.") % {
00157                 'action_name': wikiutil.escape(action_name), }
00158         if not context.user.valid:
00159             # Suggest non valid user to login
00160             msg += " " + _("Login and try again.")
00161 
00162     if msg:
00163         context.theme.add_msg(msg, "error")
00164         context.page.send_page()
00165     # Try action
00166     else:
00167         from MoinMoin import action
00168         handler = action.getHandler(context, action_name)
00169         if handler is None:
00170             msg = _("You are not allowed to do %(action_name)s on this page.") % {
00171                     'action_name': wikiutil.escape(action_name), }
00172             if not context.user.valid:
00173                 # Suggest non valid user to login
00174                 msg += " " + _("Login and try again.")
00175             context.theme.add_msg(msg, "error")
00176             context.page.send_page()
00177         else:
00178             handler(context.page.page_name, context)
00179 
00180     return context

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.wsgiapp.init (   request)
Wraps an incoming WSGI request in a Context object and initializes
several important attributes.

Definition at line 21 of file wsgiapp.py.

00021 
00022 def init(request):
00023     """
00024     Wraps an incoming WSGI request in a Context object and initializes
00025     several important attributes.
00026     """
00027     if isinstance(request, Context):
00028         context, request = request, request.request
00029     else:
00030         context = AllContext(request)
00031     context.clock.start('total')
00032     context.clock.start('init')
00033 
00034     context.lang = setup_i18n_preauth(context)
00035 
00036     context.session = context.cfg.session_service.get_session(context)
00037 
00038     context.user = setup_user(context, context.session)
00039 
00040     context.lang = setup_i18n_postauth(context)
00041 
00042     def finish():
00043         pass
00044 
00045     context.finish = finish
00046 
00047     context.reset()
00048 
00049     context.clock.stop('init')
00050     return context

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.wsgiapp.remove_prefix (   path,
  prefix = None 
)
Remove an url prefix from the path info and return shortened path. 

Definition at line 79 of file wsgiapp.py.

00079 
00080 def remove_prefix(path, prefix=None):
00081     """ Remove an url prefix from the path info and return shortened path. """
00082     # we can have all action URLs like this: /action/ActionName/PageName?action=ActionName&...
00083     # this is just for robots.txt being able to forbid them for crawlers
00084     if prefix is not None:
00085         prefix = '/%s/' % prefix # e.g. '/action/'
00086         if path.startswith(prefix):
00087             # remove prefix and action name
00088             path = path[len(prefix):]
00089             action, path = (path.split('/', 1) + ['', ''])[:2]
00090             path = '/' + path
00091     return path

Here is the caller graph for this function:

def MoinMoin.wsgiapp.run (   context)
Run a context trough the application. 

Definition at line 51 of file wsgiapp.py.

00051 
00052 def run(context):
00053     """ Run a context trough the application. """
00054     context.clock.start('run')
00055     request = context.request
00056 
00057     # preliminary access checks (forbidden, bots, surge protection)
00058     try:
00059         try:
00060             check_forbidden(context)
00061             check_surge_protect(context)
00062 
00063             action_name = context.action
00064 
00065             # handle XMLRPC calls
00066             if action_name == 'xmlrpc':
00067                 response = xmlrpc.xmlrpc(XMLRPCContext(request))
00068             elif action_name == 'xmlrpc2':
00069                 response = xmlrpc.xmlrpc2(XMLRPCContext(request))
00070             else:
00071                 response = dispatch(request, context, action_name)
00072             context.cfg.session_service.finalize(context, context.session)
00073             return response
00074         except MoinMoinFinish:
00075             return request
00076     finally:
00077         context.finish()
00078         context.clock.stop('run')

Here is the call graph for this function:

Here is the caller graph for this function:

Determine language for the request after user-id is established. 

Definition at line 230 of file wsgiapp.py.

00230 
00231 def setup_i18n_postauth(context):
00232     """ Determine language for the request after user-id is established. """
00233     user = context.user
00234     if user and user.valid and user.language:
00235         return user.language
00236     else:
00237         return context.lang

Here is the caller graph for this function:

Determine language for the request in absence of any user info. 

Definition at line 212 of file wsgiapp.py.

00212 
00213 def setup_i18n_preauth(context):
00214     """ Determine language for the request in absence of any user info. """
00215     if i18n.languages is None:
00216         i18n.i18n_init(context)
00217 
00218     cfg = context.cfg
00219     lang = None
00220     if i18n.languages and not cfg.language_ignore_browser:
00221         for l in context.request.accept_languages:
00222             if l in i18n.languages:
00223                 lang = l
00224                 break
00225     if lang is None and cfg.language_default in i18n.languages:
00226         lang = cfg.language_default
00227     else:
00228         lang = 'en'
00229     return lang

Here is the caller graph for this function:

def MoinMoin.wsgiapp.setup_user (   context,
  session 
)
Try to retrieve a valid user object from the request, be it
either through the session or through a login. 

Definition at line 181 of file wsgiapp.py.

00181 
00182 def setup_user(context, session):
00183     """ Try to retrieve a valid user object from the request, be it
00184     either through the session or through a login. """
00185     # first try setting up from session
00186     userobj = auth.setup_from_session(context, session)
00187     userobj, olduser = auth.setup_setuid(context, userobj)
00188     context._setuid_real_user = olduser
00189 
00190     # then handle login/logout forms
00191     form = context.request.values
00192 
00193     if 'login' in form:
00194         params = {
00195             'username': form.get('name'),
00196             'password': form.get('password'),
00197             'attended': True,
00198             'openid_identifier': form.get('openid_identifier'),
00199             'stage': form.get('stage')
00200         }
00201         userobj = auth.handle_login(context, userobj, **params)
00202     elif 'logout' in form:
00203         userobj = auth.handle_logout(context, userobj)
00204     else:
00205         userobj = auth.handle_request(context, userobj)
00206 
00207     # if we still have no user obj, create a dummy:
00208     if not userobj:
00209         userobj = user.User(context, auth_method='invalid')
00210 
00211     return userobj

Here is the caller graph for this function:


Variable Documentation

Definition at line 269 of file wsgiapp.py.

Definition at line 19 of file wsgiapp.py.