author | Lennard de Rijk <ljvderijk@gmail.com> |
Sun, 04 Oct 2009 21:25:52 +0200 | |
changeset 3008 | 525c65b0a320 |
parent 2910 | 60d56cf01b54 |
permissions | -rw-r--r-- |
2903
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
2 |
# |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
4 |
# |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
8 |
# |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
10 |
# |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
16 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
17 |
"""Middleware to set up and empty the value store. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
18 |
""" |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
19 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
21 |
'"Sverre Rabbelier" <sverre@rabbelier.nl>', |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
22 |
] |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
23 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
24 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
25 |
from soc.modules import callback |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
26 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
27 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
28 |
class ValueStoreMiddleware(object): |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
29 |
"""Middleware class to set up and empty the value store. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
30 |
""" |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
31 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
32 |
def start(self, request): |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
33 |
"""Sets up the value store. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
34 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
35 |
Args: |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
36 |
request: a Django HttpRequest object |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
37 |
""" |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
38 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
39 |
core = callback.getCore() |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
40 |
core.startNewRequest(request) |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
41 |
|
2910
60d56cf01b54
Use the new optional argument to endRequest in the middleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2906
diff
changeset
|
42 |
def end(self, request, optional): |
2903
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
43 |
"""Empties the value store. |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
44 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
45 |
Args: |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
46 |
request: a Django HttpRequest object |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
47 |
""" |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
48 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
49 |
core = callback.getCore() |
2910
60d56cf01b54
Use the new optional argument to endRequest in the middleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2906
diff
changeset
|
50 |
core.endRequest(request, optional) |
2903
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
51 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
52 |
def process_request(self, request): |
2906
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
53 |
"""Called when a request is made. |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
54 |
|
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
55 |
See the Django middleware documentation for an explanation of |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
56 |
the method signature. |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
57 |
""" |
2903
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
58 |
self.start(request) |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
59 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
60 |
def process_response(self, request, response): |
2906
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
61 |
"""Called when a response is returned. |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
62 |
|
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
63 |
See the Django middleware documentation for an explanation of |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
64 |
the method signature. |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
65 |
""" |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
66 |
|
2910
60d56cf01b54
Use the new optional argument to endRequest in the middleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2906
diff
changeset
|
67 |
self.end(request, True) |
2903
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
68 |
return response |
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
69 |
|
bf17c6a843dd
Add ValueStoreMiddleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff
changeset
|
70 |
def process_exception(self, request, exception): |
2906
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
71 |
"""Called when an uncaught exception is raised. |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
72 |
|
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
73 |
See the Django middleware documentation for an explanation of |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
74 |
the method signature. |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
75 |
""" |
6fb53ed7aff4
Add docstring to middleware hooks
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2903
diff
changeset
|
76 |
|
2910
60d56cf01b54
Use the new optional argument to endRequest in the middleware
Sverre Rabbelier <srabbelier@gmail.com>
parents:
2906
diff
changeset
|
77 |
self.end(request, False) |