This commit is contained in:
Benoit Masson 2017-01-09 16:52:23 +00:00 committed by GitHub
commit 234aab49d8
4 changed files with 4361 additions and 4 deletions

4350
bottle.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -83,9 +83,11 @@ class SQLitePlugin(object):
if bottle.__version__.startswith('0.9'): if bottle.__version__.startswith('0.9'):
config = route['config'] config = route['config']
_callback = route['callback'] _callback = route['callback']
argspec = inspect.getargspec(_callback).args
else: else:
config = route.config config = route.config
_callback = route.callback _callback = route.callback
argspec = route.get_callback_args()
# Override global configuration with route-specific values. # Override global configuration with route-specific values.
if "sqlite" in config: if "sqlite" in config:
@ -100,10 +102,7 @@ class SQLitePlugin(object):
keyword = g('keyword', self.keyword) keyword = g('keyword', self.keyword)
text_factory = g('keyword', self.text_factory) text_factory = g('keyword', self.text_factory)
# Test if the original callback accepts a 'db' keyword. if keyword not in argspec:
# Ignore it if it does not need a database handle.
argspec = inspect.getargspec(_callback)
if keyword not in argspec.args:
return callback return callback
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):

View File

@ -28,6 +28,13 @@ class SQLiteTest(unittest.TestCase):
def tearDown(self): def tearDown(self):
os.unlink(self.plugin.dbfile) 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): def test_with_keyword(self):
@self.app.get('/') @self.app.get('/')
def test(db): def test(db):

1
views/test_view.tpl Normal file
View File

@ -0,0 +1 @@
test_view