Skip to content

Commit 77c877d

Browse files
author
r.inyakin
committed
dbapi: implementation dsn
Added support for DSN strings in the dbapi `connect` method. The following format is supported: `[scheme://][user[:password]@]host:port[?option=value&...]`. Support for Python 3.9 and earlier was dropped to enable the use of generic aliases. Closes #170
1 parent 5003558 commit 77c877d

8 files changed

Lines changed: 691 additions & 21 deletions

File tree

‎.github/workflows/testing.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
- '3.3'
3232
- 'master'
3333
python:
34-
- '3.9'
3534
- '3.10'
3635
- '3.11'
3736
msgpack-deps:
@@ -152,7 +151,7 @@ jobs:
152151
path: 'release/linux/x86_64/2.11/'
153152
- bundle: 'sdk-gc64-3.3.1-0-r55.linux.x86_64'
154153
path: 'release/linux/x86_64/3.3/'
155-
python: ['3.9', '3.11']
154+
python: ['3.10', '3.11']
156155

157156
steps:
158157
- name: Clone the connector

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Added
10+
- Support for a DSN in `tarantool.dbapi.connect()`. The expected format
11+
is `[scheme://][user[:password]@]host:port[?option=value&...]`, where
12+
a Unix socket address is either `unix/:path` or an absolute path, and
13+
an IPv6 address is enclosed in `[]`. The scheme, if any, is ignored,
14+
as Tarantool itself ignores it. Allowed options are the Tarantool URI
15+
parameters: `transport`, `ssl_key_file`, `ssl_cert_file`,
16+
`ssl_ca_file`, `ssl_ciphers`, `ssl_password`, `ssl_password_file` and
17+
`auth_type`. Parameters set explicitly take precedence over the ones
18+
from the DSN (PR #351).
1019

1120
### Changed
21+
- Drop Python 3.9 and below support (PR #351).
1222

1323
### Fixed
1424

‎requirements-test.txt‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
git+https://github.com/baztian/dbapi-compliance.git@ea7cb1b4#egg=dbapi-compliance
22
pyyaml >= 6.0.2
3-
importlib-metadata >= 1.0 ; python_version < '3.8'
43
packaging >= 20.0
5-
pylint == 3.3.0 ; python_version >= '3.9'
6-
pylint == 3.2.7 ; python_version == '3.8'
7-
pylint == 2.17.7 ; python_version == '3.7'
8-
flake8 == 6.1.0 ; python_version >= '3.8'
9-
flake8 == 5.0.4 ; python_version < '3.8'
10-
codespell == 2.3.0 ; python_version >= '3.8'
11-
codespell == 2.2.5 ; python_version < '3.8'
4+
pylint == 3.3.0
5+
flake8 == 6.1.0
6+
codespell == 2.3.0
127
setuptools >= 75.3.2

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ def get_dependencies(filename):
114114
setup_requires=[
115115
'setuptools_scm==7.1.0',
116116
],
117-
python_requires='>=3.7',
117+
python_requires='>=3.10',
118118
)

‎tarantool/dbapi.py‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
# pylint: disable=fixme,unused-import,bad-option-value,no-self-use
77
# flake8: noqa: F401
88

9+
import typing
10+
911
from tarantool.connection import Connection as BaseConnection
1012
from tarantool.error import (
13+
ConfigurationError,
1114
Error,
1215
InterfaceError,
1316
DatabaseError,
@@ -17,6 +20,7 @@
1720
ProgrammingError,
1821
NotSupportedError,
1922
)
23+
from tarantool.utils import parse_dsn
2024

2125
Warning = Warning # pylint: disable=redefined-builtin,self-assigning-variable
2226

@@ -400,9 +404,10 @@ def connect(dsn=None, host=None, port=None,
400404
"""
401405
Constructor for creating a connection to the database.
402406
403-
:param dsn: **Not implemented**. Tarantool server URI:
404-
``[[[username[:password]@]host:]port``.
405-
:type dsn: :obj:`str`
407+
:param dsn: Tarantool server DSN, refer to
408+
:func:`~tarantool.utils.parse_dsn`. Parameters set explicitly
409+
take precedence over the ones from the DSN.
410+
:type dsn: :obj:`str`, optional
406411
407412
:param host: Refer to :paramref:`~tarantool.Connection.params.host`.
408413
@@ -415,14 +420,18 @@ def connect(dsn=None, host=None, port=None,
415420
416421
:rtype: :class:`~tarantool.Connection`
417422
418-
:raise: :exc:`~NotImplementedError`,
423+
:raise: :exc:`~tarantool.error.InterfaceError`,
419424
:class:`~tarantool.Connection` exceptions
420425
"""
421426

427+
params: dict[str, typing.Any] = {}
428+
422429
if dsn:
423-
raise NotImplementedError("dsn param is not implemented in"
424-
"this version of dbapi module")
425-
params = {}
430+
try:
431+
params = parse_dsn(dsn)
432+
except ConfigurationError as exc:
433+
raise InterfaceError(str(exc)) from exc
434+
426435
if host:
427436
params["host"] = host
428437
if port:
@@ -432,6 +441,6 @@ def connect(dsn=None, host=None, port=None,
432441
if password:
433442
params["password"] = password
434443

435-
kwargs.update(params)
444+
params.update(kwargs)
436445

437-
return Connection(**kwargs)
446+
return Connection(**params)

0 commit comments

Comments
 (0)