annotate MoinMoin/wsgiapp.py @ 4239:db15f98e3228

Split up wsgiapp.init and wsgiapp.run into smaller chunks
author Florian Krupicka <florian.krupicka@googlemail.com>
date Tue, 22 Jul 2008 20:35:16 +0200
parents d9b3c6585585
children 2b21ec54a5c9
rev   line source
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
2 """
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
3 MoinMoin - WSGI application
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
4
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
5 @copyright: 2003-2008 MoinMoin:ThomasWaldmann,
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
6 2008-2008 MoinMoin:FlorianKrupicka
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
8 """
4227
b459b036f263 Changed some setHttpHeader-calls to new header API
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4225
diff changeset
9 from werkzeug.http import HeaderSet
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
10 from werkzeug.exceptions import HTTPException
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
11
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
12 from MoinMoin.web.contexts import AllContext, Context, XMLRPCContext
4152
ddcd459c3255 Restructured contexts classes for wrapping contexts in each other
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4151
diff changeset
13 from MoinMoin.web.request import Request
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
14 from MoinMoin.web.utils import check_forbidden, check_setuid, check_surge_protect
4144
0a62a439d81b Trying to port some of RequestBase.__init__ to a WSGI app (very crude right now)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4141
diff changeset
15
0a62a439d81b Trying to port some of RequestBase.__init__ to a WSGI app (very crude right now)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4141
diff changeset
16 from MoinMoin.Page import Page
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
17 from MoinMoin import auth, i18n, user, wikiutil, xmlrpc
4144
0a62a439d81b Trying to port some of RequestBase.__init__ to a WSGI app (very crude right now)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4141
diff changeset
18 from MoinMoin.action import get_names, get_available_actions
0a62a439d81b Trying to port some of RequestBase.__init__ to a WSGI app (very crude right now)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4141
diff changeset
19
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
20 from MoinMoin import log
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
21 logging = log.getLogger(__name__)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
22
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
23 def init(request):
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
24 """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
25 Wraps an incoming WSGI request in a Context object and initializes
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
26 several important attributes.
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
27 """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
28 context = AllContext(request)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
29 context.clock.start('total')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
30 context.clock.start('init')
4144
0a62a439d81b Trying to port some of RequestBase.__init__ to a WSGI app (very crude right now)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4141
diff changeset
31
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
32 context.lang = setup_i18n_preauth(context)
4144
0a62a439d81b Trying to port some of RequestBase.__init__ to a WSGI app (very crude right now)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4141
diff changeset
33
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
34 context.session = context.cfg.session_service.get_session(request)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
35
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
36 userobj = setup_user(context, context.session)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
37 userobj, olduser = check_setuid(context, userobj)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
38
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
39 if not userobj:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
40 userobj = user.User(context, auth_method='request:invalid')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
41
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
42 context.user = userobj
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
43 context._setuid_realuser = olduser
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
44
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
45 context.lang = setup_i18n_postauth(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
46
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
47 context.reset()
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
48
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
49 context.clock.stop('init')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
50 return context
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
51
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
52 def run(context):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
53 """ Run a context trough the application. """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
54 context.clock.start('run')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
55 request = context.request
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
56
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
57 # preliminary access checks (forbidden, bots, surge protection)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
58 check_forbidden(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
59 check_surge_protect(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
60
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
61 action_name = context.action
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
62
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
63 # handle XMLRPC calls
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
64 if action_name == 'xmlrpc':
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
65 response = xmlrpc.xmlrpc(XMLRPCContext(request))
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
66 elif action_name == 'xmlrpc2':
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
67 response = xmlrpc.xmlrpc2(XMLRPCContext(request))
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
68 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
69 response = dispatch(request, context, action_name)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
70 context.cfg.session_service.finalize(context, context.session)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
71 context.clock.stop('run')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
72 return response
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
73
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
74 def remove_prefix(path, prefix=None):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
75 """ Remove an url prefix from the path info and return shortened path. """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
76 # we can have all action URLs like this: /action/ActionName/PageName?action=ActionName&...
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
77 # this is just for robots.txt being able to forbid them for crawlers
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
78 if prefix is not None:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
79 prefix = '/%s/' % prefix # e.g. '/action/'
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
80 if path.startswith(prefix):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
81 # remove prefix and action name
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
82 path = path[len(prefix):]
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
83 action, path = (path.split('/', 1) + ['', ''])[:2]
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
84 path = '/' + path
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
85 return path
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
86
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
87 def dispatch(request, context, action_name='show'):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
88 cfg = context.cfg
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
89
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
90 # The last component in path_info is the page name, if any
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
91 path = remove_prefix(request.path, cfg.url_prefix_action)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
92
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
93 if path.startswith('/'):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
94 pagename = wikiutil.normalize_pagename(path, cfg)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
95 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
96 pagename = None
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
97
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
98 # need to inform caches that content changes based on:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
99 # * cookie (even if we aren't sending one now)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
100 # * User-Agent (because a bot might be denied and get no content)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
101 # * Accept-Language (except if moin is told to ignore browser language)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
102 hs = HeaderSet(('Cookie', 'User-Agent'))
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
103 if not cfg.language_ignore_browser:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
104 hs.add('Accept-Language')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
105 request.headers.add('Vary', str(hs))
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
106
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
107 # Handle request. We have these options:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
108 # 1. jump to page where user left off
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
109 if not pagename and context.user.remember_last_visit and action_name == 'show':
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
110 response = handle_last_visit(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
111 # 2. handle action
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
112 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
113 response = handle_action(context, pagename, action_name)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
114 if isinstance(response, Context):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
115 response = response.request
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
116 return response
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
117
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
118 def handle_action(context, pagename, action_name='show'):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
119 """ Actual dispatcher function for non-XMLRPC actions.
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
120
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
121 Also sets up the Page object for this request, normalizes and
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
122 redirects to canonical pagenames and checks for non-allowed
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
123 actions.
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
124 """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
125 _ = context.getText
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
126 cfg = context.cfg
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
127
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
128 # pagename could be empty after normalization e.g. '///' -> ''
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
129 # Use localized FrontPage if pagename is empty
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
130 if not pagename:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
131 context.page = wikiutil.getFrontPage(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
132 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
133 context.page = Page(context, pagename)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
134 if '_' in pagename and not context.page.exists():
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
135 pagename = pagename.replace('_', ' ')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
136 page = Page(context, pagename)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
137 if page.exists():
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
138 url = page.url(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
139 return abort(redirect(url))
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
140
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
141 msg = None
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
142 # Complain about unknown actions
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
143 if not action_name in get_names(cfg):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
144 msg = _("Unknown action %(action_name)s.") % {
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
145 'action_name': wikiutil.escape(action_name), }
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
146
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
147 # Disallow non available actions
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
148 elif action_name[0].isupper() and not action_name in \
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
149 get_available_actions(cfg, context.page, context.user):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
150 msg = _("You are not allowed to do %(action_name)s on this page.") % {
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
151 'action_name': wikiutil.escape(action_name), }
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
152 if not context.user.valid:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
153 # Suggest non valid user to login
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
154 msg += " " + _("Login and try again.")
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
155
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
156 if msg:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
157 context.theme.add_msg(msg, "error")
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
158 context.page.send_page()
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
159 # Try action
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
160 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
161 from MoinMoin import action
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
162 handler = action.getHandler(cfg, action_name)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
163 if handler is None:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
164 msg = _("You are not allowed to do %(action_name)s on this page.") % {
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
165 'action_name': wikiutil.escape(action_name), }
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
166 if not context.user.valid:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
167 # Suggest non valid user to login
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
168 msg += " " + _("Login and try again.")
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
169 context.theme.add_msg(msg, "error")
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
170 context.page.send_page()
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
171 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
172 handler(context.page.page_name, context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
173
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
174 return context
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
175
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
176 def setup_user(context, session):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
177 """ Try to retrieve a valid user object from the request, be it
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
178 either through the session or through a login. """
4194
9c80451df643 Setup user from stored session
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4193
diff changeset
179 # first try setting up from session
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
180 userobj = auth.setup_from_session(context, session)
4194
9c80451df643 Setup user from stored session
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4193
diff changeset
181
4198
988b2b672219 Fix tests: source code (indentation, whitespace) mostly
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4197
diff changeset
182 # then handle login/logout forms
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
183 form = context.request.values
4193
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
184
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
185 if 'login' in form:
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
186 params = {
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
187 'username': form.get('name'),
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
188 'password': form.get('password'),
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
189 'attended': True,
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
190 'openid_identifier': form.get('openid_identifier'),
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
191 'stage': form.get('stage')
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
192 }
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
193 userobj = auth.handle_login(context, userobj, **params)
4193
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
194 elif 'logout' in form:
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
195 userobj = auth.handle_logout(context, userobj)
4193
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
196 else:
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
197 userobj = auth.handle_request(context, userobj)
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
198
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
199 return userobj
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
200
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
201 def setup_i18n_preauth(context):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
202 """ Determine language for the request in absence of any user info. """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
203 if i18n.languages is None:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
204 i18n.i18n_init(context)
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
205
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
206 cfg = context.cfg
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
207 lang = None
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
208 if i18n.languages and not cfg.language_ignore_browser:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
209 for l in context.request.accept_languages:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
210 if l in i18n.languages:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
211 lang = l
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
212 break
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
213 if lang is None and cfg.language_default in i18n.languages:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
214 lang = cfg.language_default
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
215 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
216 lang = 'en'
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
217 return lang
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
218
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
219 def setup_i18n_postauth(context):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
220 """ Determine language for the request after user-id is established. """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
221 user = context.user
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
222 if user and user.valid and user.language:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
223 return user.language
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
224 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
225 return context.lang
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
226
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
227 def handle_last_visit(request, context):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
228 """ Redirect to last visited page (or frontpage) on missing pagename. """
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
229 pagetrail = context.user.getTrail()
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
230 if pagetrail:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
231 # Redirect to last page visited
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
232 last_visited = pagetrail[-1]
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
233 wikiname, pagename = wikiutil.split_interwiki(last_visited)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
234 if wikiname != 'Self':
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
235 wikitag, wikiurl, wikitail, error = wikiutil.resolve_interwiki(context, wikiname, pagename)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
236 url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
237 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
238 url = Page(context, pagename).url(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
239 else:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
240 # Or to localized FrontPage
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
241 url = wikiutil.getFrontPage(context).url(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
242 return abort(redirect(url))
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
243
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
244 def application(environ, start_response):
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
245 try:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
246 request = Request(environ)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
247 context = init(request)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
248 response = run(context)
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
249 except HTTPException, e:
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
250 context.clock.stop('run')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
251 context.clock.stop('total')
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
252 response = e
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
253
4239
db15f98e3228 Split up wsgiapp.init and wsgiapp.run into smaller chunks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4228
diff changeset
254 return response(environ, start_response)
4228
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
255
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
256 def run_server(config):
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
257 from os import path
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
258 from MoinMoin.config import url_prefix_static
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
259 from werkzeug.serving import run_simple
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
260 from werkzeug.utils import SharedDataMiddleware
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
261
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
262 shared = {url_prefix_static: config.docs,
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
263 '/favicon.ico': path.join(config.docs, 'favicon.ico'),
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
264 '/robots.txt': path.join(config.docs, 'robots.txt')}
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
265
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
266 app = SharedDataMiddleware(application, shared)
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
267
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
268 params = {}
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
269 params['use_debugger'] = config.traceback_show
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
270 params['threaded'] = True
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
271 params['use_reloader'] = config.reload_server
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
272
d9b3c6585585 First implementation of standalone server using werkzeug.serving.run_simple
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4227
diff changeset
273 run_simple(config.interface, config.port, app, **params)