annotate MoinMoin/web/apps.py @ 4151:30ac757e72de

Added HTTPException catching middleware
author Florian Krupicka <florian.krupicka@googlemail.com>
date Sun, 08 Jun 2008 18:27:07 +0200
parents 78e6deeadc7e
children b84bcea48523
rev   line source
4148
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
2 """
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
3 MoinMoin - WSGI apps and middlewares
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
4
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
5 @copyright: 2003-2008 MoinMoin:ThomasWaldmann,
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
6 2008-2008 MoinMoin:FlorianKrupicka
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
8 """
4151
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
9 from werkzeug.exceptions import HTTPException
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
10
4148
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
11 from MoinMoin.web.request import Request
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
12 from MoinMoin.web.contexts import XMLRPCContext
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
13
4151
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
14 class HTTPExceptionsMiddleware(object):
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
15 def __init__(self, app):
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
16 self.app = app
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
17
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
18 def __call__(self, environ, start_response):
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
19 try:
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
20 return self.app(environ, start_response)
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
21 except HTTPException, e:
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
22 return e(environ, start_response)
30ac757e72de Added HTTPException catching middleware
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4148
diff changeset
23
4148
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
24 class XMLRPCApp(object):
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
25 """ Handles XML-RPC method calls or dispatches to next layer """
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
26
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
27 def __init__(self, app):
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
28 self.app = app
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
29
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
30 def __call__(self, environ, start_response):
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
31 request = Request(environ)
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
32 action = Request.args.get('action')
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
33
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
34 from MoinMoin import xmlrpc
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
35
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
36 if action == 'xmlrpc':
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
37 return xmlrpc.xmlrpc(XMLRPCContext(environ))
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
38 elif action == 'xmlrpc2':
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
39 return xmlrpc.xmlrpc2(XMLRPCContext(environ))
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
40 else:
78e6deeadc7e Make XML-RPC action call into own WSGI app (draft)
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
41 return self.app(environ, start_response)