Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bottle_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions views/test_view.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_view