Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the new get_callback_args() from route to find keyword #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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