mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Allow make_dsn to take no parameter
The behaviour of connect() is unchanged: either dsn or params must be specified.
This commit is contained in:
parent
7aab934ae5
commit
c9fd828f8a
|
@ -497,11 +497,8 @@ Other functions
|
|||
|
||||
Put together the arguments in *kwargs* into a connection string. If *dsn*
|
||||
is specified too, merge the arguments coming from both the sources. If the
|
||||
same argument is specified in both the sources, the *kwargs* version
|
||||
overrides the *dsn* version.
|
||||
|
||||
At least one parameter is required (either *dsn* or any keyword). Note
|
||||
that the empty string is a valid connection string.
|
||||
same argument name is specified in both the sources, the *kwargs* value
|
||||
overrides the *dsn* value.
|
||||
|
||||
The input arguments are validated: the output should always be a valid
|
||||
connection string (as far as `parse_dsn()` is concerned). If not raise
|
||||
|
|
|
@ -116,6 +116,9 @@ def connect(dsn=None, connection_factory=None, cursor_factory=None,
|
|||
library: the list of supported parameters depends on the library version.
|
||||
|
||||
"""
|
||||
if dsn is None and not kwargs:
|
||||
raise TypeError('missing dsn and no parameters')
|
||||
|
||||
dsn = _ext.make_dsn(dsn, **kwargs)
|
||||
conn = _connect(dsn, connection_factory=connection_factory, async=async)
|
||||
if cursor_factory is not None:
|
||||
|
|
|
@ -158,7 +158,7 @@ class NoneAdapter(object):
|
|||
def make_dsn(dsn=None, **kwargs):
|
||||
"""Convert a set of keywords into a connection strings."""
|
||||
if dsn is None and not kwargs:
|
||||
raise TypeError('missing dsn and no parameters')
|
||||
return ''
|
||||
|
||||
# If no kwarg is specified don't mung the dsn, but verify it
|
||||
if not kwargs:
|
||||
|
|
|
@ -381,8 +381,8 @@ class MakeDsnTestCase(ConnectingTestCase):
|
|||
def assertDsnEqual(self, dsn1, dsn2):
|
||||
self.assertEqual(set(dsn1.split()), set(dsn2.split()))
|
||||
|
||||
def test_there_has_to_be_something(self):
|
||||
self.assertRaises(TypeError, ext.make_dsn)
|
||||
def test_empty_arguments(self):
|
||||
self.assertEqual(ext.make_dsn(), '')
|
||||
|
||||
def test_empty_string(self):
|
||||
dsn = ext.make_dsn('')
|
||||
|
|
Loading…
Reference in New Issue
Block a user