Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding support for response object as well

  • Loading branch information...
commit dc4c22043cfafe44bbcb1cbfd46b4f58d6415133 1 parent 2cd9687
@turtlebender authored
Showing with 10 additions and 6 deletions.
  1. +7 −4 bottle_request.py
  2. +1 −1  setup.py
  3. +2 −1  test.py
View
11 bottle_request.py
@@ -6,22 +6,25 @@
it can be easily swapped.
"""
import inspect
-from bottle import request
+from bottle import request, response
def inject_request(callback):
"""
Wrap the function in a decorator which adds the request parameter if
necessary.
"""
- args = inspect.getargspec(callback)[0]
- if 'request' not in args:
+ callback_args = inspect.getargspec(callback)[0]
+ if 'request' not in callback_args and 'response' not in callback_args:
return callback
def wrapper(*args, **kwargs):
"""
Pass request object as a function parameter if signature contains
"request" as a parameter.
"""
- kwargs['request'] = request
+ if 'request' in callback_args:
+ kwargs['request'] = request
+ if 'response' in callback_args:
+ kwargs['response'] = response
return callback(*args, **kwargs)
return wrapper
View
2  setup.py
@@ -2,7 +2,7 @@
setup(
name="bottle-request",
- version="0.1.0",
+ version="0.2.0",
url="http://github.com/turtlebender/bottle-request/",
description="Plugin to give bottle a 'stateless' request object",
author="Tom Howe",
View
3  test.py
@@ -11,8 +11,9 @@ def test_with_keyword(self):
self.plugin = self.app.install(bottle_request.Plugin)
@self.app.get('/')
- def test(request):
+ def test(request, response):
self.assertEqual(bottle.request, request)
+ self.assertEqual(bottle.response, response)
self.app({'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}, lambda x, y: None)
def test_without_keyword(self):
Please sign in to comment.
Something went wrong with that request. Please try again.