annotate MoinMoin/wsgiapp.py @ 4164:0be4fb46e492

Moved even more attributes into (lazy) properties
author Florian Krupicka <florian.krupicka@googlemail.com>
date Wed, 11 Jun 2008 18:36:54 +0200
parents 67f0fc696d97
children 500c58d0269b
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
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
13 from MoinMoin.web.contexts import HTTPContext, RenderContext
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
4160
1ea1d69b28e8 Factored out surge protection and forbidden checks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4158
diff changeset
16 from MoinMoin.web.utils import check_surge_protect, handle_auth_form
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
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
25 from MoinMoin.util.clock import Clock
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
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
28 def _request_init(request):
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
29 request.clock = Clock()
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
30 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
31 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
32
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 user_obj = request.cfg.session_handler.start(request, request.cfg.session_id_handler)
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
34 request.user = handle_auth_form(user_obj, 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
35
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
36 request.cfg.session_handler.after_auth(request, request.cfg.session_id_handler, request.user)
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
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
38 if not request.user:
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
39 request.user = user.User(request, auth_method='request:invalid')
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
40
4161
67f0fc696d97 Factored out setuid-code
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4160
diff changeset
41 check_setuid(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
42
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
43 request = RenderContext(request)
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
44
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
45 if request.action != 'xmlrpc':
4160
1ea1d69b28e8 Factored out surge protection and forbidden checks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4158
diff changeset
46 check_forbidden(request)
1ea1d69b28e8 Factored out surge protection and forbidden checks
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4158
diff changeset
47 check_surge_protect(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
48
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
49 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
50
4156
40501b3e2176 Moved some attributes on Request into RenderContext
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4155
diff changeset
51 request.clock.stop('base__init__')
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
52 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
53
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
54 def application(environ, start_response):
4152
ddcd459c3255 Restructured contexts classes for wrapping contexts in each other
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4151
diff changeset
55 request = Request(environ)
ddcd459c3255 Restructured contexts classes for wrapping contexts in each other
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4151
diff changeset
56 request = HTTPContext(request)
4164
0be4fb46e492 Moved even more attributes into (lazy) properties
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4161
diff changeset
57 request = _request_init(request)
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
58 request.run()
4134
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
59
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
60 response = Response(status=request.status,
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
61 headers=request.headers)
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
62
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
63 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
64 # 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
65 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
66 return iter(lambda: fileobj.read(bufsize), '')
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
67 file_wrapper = environ.get('wsgi.file_wrapper', simple_wrapper)
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
68 response.response = file_wrapper(request._send_file, request._send_bufsize)
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
69 else:
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
70 response.response = request.output()
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
71 return response
719256a8db51 Initial code to track down the use of request objects in MoinMoin
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
72
4138
6bbc4beed793 Started with the HTTPContext (currently a reimplementation of request_wsgi with werkzeug)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4134
diff changeset
73 application = responder(application)
4151
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4149
diff changeset
74 application = HTTPExceptionsMiddleware(application)