annotate MoinMoin/wsgiapp.py @ 4193:1e954e802ed2

Start to make auth work again with the new session layer
author Florian Krupicka <florian.krupicka@googlemail.com>
date Fri, 27 Jun 2008 18:38:29 +0200
parents 105c5469ac05
children 9c80451df643
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 """
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
9 from werkzeug.utils import responder
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
10 from werkzeug.wrappers import Response
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
11 from werkzeug.exceptions import NotFound
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
12
4185
68bcf39ae1d3 General cleanups
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4182
diff changeset
13 from MoinMoin.web.contexts import HTTPContext, RenderContext, AllContext
4152
ddcd459c3255 Restructured contexts classes for wrapping contexts in each other
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4151
diff changeset
14 from MoinMoin.web.request import Request
4161
67f0fc696d97 Factored out setuid-code
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4160
diff changeset
15 from MoinMoin.web.utils import check_spider, check_forbidden, check_setuid
4193
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
16 from MoinMoin.web.utils import check_surge_protect
4151
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4149
diff changeset
17 from MoinMoin.web.apps import HTTPExceptionsMiddleware
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
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 from MoinMoin.Page import Page
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
20 from MoinMoin import config, wikiutil, user, caching, error
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
21 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
22 from MoinMoin.config import multiconfig
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
23 from MoinMoin.support.python_compatibility import set
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
24 from MoinMoin.util import IsWin9x
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
25 from MoinMoin.request import MoinMoinFinish, RemoteClosedConnection
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
26 from MoinMoin import auth
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
27
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
28 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
29 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
30
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
31 def init(request):
4185
68bcf39ae1d3 General cleanups
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4182
diff changeset
32 request = AllContext(request)
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 request.clock.start('total')
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
34 request.clock.start('base__init__')
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
35
4192
105c5469ac05 Use session service in the WSGI app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4185
diff changeset
36 request.session = request.cfg.session_service.get_session(request)
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
37
4193
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
38 # auth & user handling
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
39 userobj = None
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
40 form = request.form
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
41
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
42 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
43 params = {
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
44 '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
45 '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
46 'attended': True,
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
47 '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
48 '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
49 }
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
50 userobj = auth.handle_login(request, userobj, **params)
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
51 elif 'logout' in form:
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
52 userobj = auth.handle_logout(request, userobj)
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
53 else:
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
54 userobj = auth.handle_request(request, userobj)
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
55
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
56 userobj, olduser = check_setuid(request, userobj)
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
57
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
58 if not userobj:
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
59 userobj = user.User(request, auth_method='request:invalid')
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
60
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
61 request.user = userobj
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
62 request._setuid_real_user = olduser
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
63
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
64 # preliminary access control
1e954e802ed2 Start to make auth work again with the new session layer
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4192
diff changeset
65 # check against spiders, blacklists and request-spam
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
66 check_forbidden(request)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
67 check_surge_protect(request)
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
68
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
69 request.reset()
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
70
4156
40501b3e2176 Moved some attributes on Request into RenderContext
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4155
diff changeset
71 request.clock.stop('base__init__')
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
72 return request
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
73
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
74 def run(request):
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
75
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
76 _ = request.getText
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
77 request.clock.start('run')
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
78
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
79 request.initTheme()
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
80
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
81 action_name = request.action
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
82 if request.cfg.log_timing:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
83 request.timing_log(True, action_name)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
84
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
85 # parse request data
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
86 try:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
87 # The last component in path_info is the page name, if any
4181
eacb4c9e83e5 Reflect changes to Context-model and Request/Response in wsgiapp
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4166
diff changeset
88 path = request.path
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
89
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
90 # we can have all action URLs like this: /action/ActionName/PageName?action=ActionName&...
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
91 # this is just for robots.txt being able to forbid them for crawlers
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
92 prefix = request.cfg.url_prefix_action
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
93 if prefix is not None:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
94 prefix = '/%s/' % prefix # e.g. '/action/'
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
95 if path.startswith(prefix):
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
96 # remove prefix and action name
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
97 path = path[len(prefix):]
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
98 action, path = (path.split('/', 1) + ['', ''])[:2]
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
99 path = '/' + path
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
100
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
101 if path.startswith('/'):
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
102 pagename = wikiutil.normalize_pagename(path, request.cfg)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
103 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
104 pagename = None
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
105
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
106 # need to inform caches that content changes based on:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
107 # * cookie (even if we aren't sending one now)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
108 # * User-Agent (because a bot might be denied and get no content)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
109 # * Accept-Language (except if moin is told to ignore browser language)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
110 if request.cfg.language_ignore_browser:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
111 request.setHttpHeader("Vary: Cookie,User-Agent")
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
112 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
113 request.setHttpHeader("Vary: Cookie,User-Agent,Accept-Language")
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
114
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
115 # Handle request. We have these options:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
116 # 1. jump to page where user left off
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
117 if not pagename and request.user.remember_last_visit and action_name == 'show':
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
118 pagetrail = request.user.getTrail()
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
119 if pagetrail:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
120 # Redirect to last page visited
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
121 last_visited = pagetrail[-1]
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
122 wikiname, pagename = wikiutil.split_interwiki(last_visited)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
123 if wikiname != 'Self':
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
124 wikitag, wikiurl, wikitail, error = wikiutil.resolve_interwiki(request, wikiname, pagename)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
125 url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
126 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
127 url = Page(request, pagename).url(request)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
128 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
129 # Or to localized FrontPage
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
130 url = wikiutil.getFrontPage(request).url(request)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
131 return abort(redirect(url))
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
132
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
133 # 2. handle action
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
134 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
135 # pagename could be empty after normalization e.g. '///' -> ''
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
136 # Use localized FrontPage if pagename is empty
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
137 if not pagename:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
138 request.page = wikiutil.getFrontPage(request)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
139 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
140 request.page = Page(request, pagename)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
141 if '_' in pagename and not request.page.exists():
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
142 pagename = pagename.replace('_', ' ')
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
143 page = Page(request, pagename)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
144 if page.exists():
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
145 url = page.url(request)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
146 return abort(redirect(url))
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
147
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
148 msg = None
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
149 # Complain about unknown actions
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
150 if not action_name in get_names(request.cfg):
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
151 msg = _("Unknown action %(action_name)s.") % {
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
152 'action_name': wikiutil.escape(action_name), }
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
153
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
154 # Disallow non available actions
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
155 elif action_name[0].isupper() and not action_name in request.getAvailableActions(request.page):
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
156 msg = _("You are not allowed to do %(action_name)s on this page.") % {
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
157 'action_name': wikiutil.escape(action_name), }
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
158 if not request.user.valid:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
159 # Suggest non valid user to login
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
160 msg += " " + _("Login and try again.")
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
161
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
162 if msg:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
163 request.theme.add_msg(msg, "error")
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
164 request.page.send_page()
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
165 # Try action
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
166 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
167 from MoinMoin import action
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
168 handler = action.getHandler(request, action_name)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
169 if handler is None:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
170 msg = _("You are not allowed to do %(action_name)s on this page.") % {
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
171 'action_name': wikiutil.escape(action_name), }
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
172 if not request.user.valid:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
173 # Suggest non valid user to login
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
174 msg += " " + _("Login and try again.")
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
175 request.theme.add_msg(msg, "error")
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
176 request.page.send_page()
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
177 else:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
178 handler(request.page.page_name, request)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
179
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
180 # every action that didn't use to raise MoinMoinFinish must call this now:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
181 # request.theme.send_closing_html()
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
182
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
183 except MoinMoinFinish:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
184 pass
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
185 except RemoteClosedConnection:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
186 # at least clean up
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
187 pass
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
188 except SystemExit:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
189 raise # fcgi uses this to terminate a thread
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
190
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
191 if request.cfg.log_timing:
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
192 request.timing_log(False, action_name)
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
193
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
194 #return request.finish()
4192
105c5469ac05 Use session service in the WSGI app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4185
diff changeset
195 request.cfg.session_service.finalize(request, request.session)
4185
68bcf39ae1d3 General cleanups
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4182
diff changeset
196 return request
4166
500c58d0269b Port RequestBase.run() into a function for use in wsgi-app
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4164
diff changeset
197
4181
eacb4c9e83e5 Reflect changes to Context-model and Request/Response in wsgiapp
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4166
diff changeset
198 def application(request):
4185
68bcf39ae1d3 General cleanups
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4182
diff changeset
199 run(init(request))
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
200
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
201 if getattr(request, '_send_file', None) is not None:
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
202 # moin wants to send a file (e.g. AttachFile.do_get)
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
203 def simple_wrapper(fileobj, bufsize):
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
204 return iter(lambda: fileobj.read(bufsize), '')
4185
68bcf39ae1d3 General cleanups
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4182
diff changeset
205 file_wrapper = request.environ.get('wsgi.file_wrapper', simple_wrapper)
68bcf39ae1d3 General cleanups
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4182
diff changeset
206 request.response = file_wrapper(request._send_file, request._send_bufsize)
4181
eacb4c9e83e5 Reflect changes to Context-model and Request/Response in wsgiapp
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4166
diff changeset
207 return request
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
208
4181
eacb4c9e83e5 Reflect changes to Context-model and Request/Response in wsgiapp
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4166
diff changeset
209 application = Request.application(application)
4151
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4149
diff changeset
210 application = HTTPExceptionsMiddleware(application)