From 73065214abdff535154bb9399f241dc75248fb14 Mon Sep 17 00:00:00 2001 From: Charles Leifer Date: Fri, 12 Jul 2024 11:20:30 -0500 Subject: [PATCH] Remove python 2.6-specific workaround in db_url. Replaces #2915 --- playhouse/db_url.py | 9 +++------ tests/db_url.py | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/playhouse/db_url.py b/playhouse/db_url.py index 7176c806d..8d57990d7 100644 --- a/playhouse/db_url.py +++ b/playhouse/db_url.py @@ -39,13 +39,10 @@ def parseresult_to_dict(parsed, unquote_password=False): # urlparse in python 2.6 is broken so query will be empty and instead # appended to path complete with '?' - path_parts = parsed.path[1:].split('?') - try: - query = path_parts[1] - except IndexError: - query = parsed.query + path = parsed.path[1:] # Ignore leading '/'. + query = parsed.query - connect_kwargs = {'database': path_parts[0]} + connect_kwargs = {'database': path} if parsed.username: connect_kwargs['user'] = parsed.username if parsed.password: diff --git a/tests/db_url.py b/tests/db_url.py index bdfbfb9d9..7d8bc6b51 100644 --- a/tests/db_url.py +++ b/tests/db_url.py @@ -65,6 +65,12 @@ def test_db_url(self): self.assertTrue(isinstance(db, SqliteDatabase)) self.assertEqual(db.database, ':memory:') + db = connect('sqlite:///test.db?p1=1?a&p2=22&p3=xyz') + self.assertTrue(isinstance(db, SqliteDatabase)) + self.assertEqual(db.database, 'test.db') + self.assertEqual(db.connect_params, { + 'p1': '1?a', 'p2': 22, 'p3': 'xyz'}) + def test_bad_scheme(self): def _test_scheme(): connect('missing:///')