Make it work with two plugins.

bottle>=0.10 changed behaviour to replace plugins with the same name,
so I have to patch the name if a plugin with the same name already
exists.
This commit is contained in:
Iuri de Silvio 2014-03-29 10:57:02 -03:00
parent b5fe085f96
commit e0d85fbc44
2 changed files with 15 additions and 1 deletions

View File

@ -67,6 +67,8 @@ class SQLitePlugin(object):
if other.keyword == self.keyword:
raise PluginError("Found another sqlite plugin with "\
"conflicting settings (non-unique keyword).")
elif other.name == self.name:
self.name += '_%s' % self.keyword
def apply(self, callback, route):
# hack to support bottle v0.9.x

14
test.py
View File

@ -28,6 +28,18 @@ class SQLiteTest(unittest.TestCase):
def test(**kw):
self.assertFalse('db' in kw)
self.app({'PATH_INFO':'/2', 'REQUEST_METHOD':'GET'}, lambda x, y: None)
def test_install_conflicts(self):
self.app.install(sqlite.Plugin())
self.app.install(sqlite.Plugin(keyword='db2'))
@self.app.get('/')
def test(db, db2):
pass
# I have two plugins working with different names
self.app({'PATH_INFO': '/', 'REQUEST_METHOD': 'GET'}, lambda x, y: None)
if __name__ == '__main__':
unittest.main()