diff --git a/bottle_sqlite.py b/bottle_sqlite.py index c4014a9..944876a 100755 --- a/bottle_sqlite.py +++ b/bottle_sqlite.py @@ -83,9 +83,11 @@ def apply(self, callback, route): if bottle.__version__.startswith('0.9'): config = route['config'] _callback = route['callback'] + argspec = inspect.getargspec(_callback).args else: config = route.config _callback = route.callback + argspec = route.get_callback_args() # Override global configuration with route-specific values. if "sqlite" in config: @@ -100,10 +102,7 @@ def apply(self, callback, route): keyword = g('keyword', self.keyword) text_factory = g('keyword', self.text_factory) - # Test if the original callback accepts a 'db' keyword. - # Ignore it if it does not need a database handle. - argspec = inspect.getargspec(_callback) - if keyword not in argspec.args: + if keyword not in argspec: return callback def wrapper(*args, **kwargs): diff --git a/test.py b/test.py index 681a79e..f91f4bc 100644 --- a/test.py +++ b/test.py @@ -28,6 +28,13 @@ def setUp(self): def tearDown(self): os.unlink(self.plugin.dbfile) + def test_with_view(self): + @self.app.get('/') + @bottle.view('test_view') + def test(db): + self.assertEqual(type(db), type(sqlite3.connect(':memory:'))) + self._request('/') + def test_with_keyword(self): @self.app.get('/') def test(db): diff --git a/views/test_view.tpl b/views/test_view.tpl new file mode 100644 index 0000000..bbba0a0 --- /dev/null +++ b/views/test_view.tpl @@ -0,0 +1 @@ +test_view \ No newline at end of file