Skip to content

Commit f9a0276

Browse files
committedMay 7, 2024
Fix bugs in db_info; use EnvExtendedInterpolation in configs
1 parent 1963ba1 commit f9a0276

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
lines changed
 

Diff for: ‎CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.10.4] - 2024-05-07
8+
9+
### Added
10+
11+
- Support for values fetched from environment variables in configuration files via
12+
EnvExtendedInterpolation provided by firebird-base package v1.8.0.
13+
14+
### Fixed
15+
16+
- Unregistered bug: db info call for CRYPT_KEY, CRYPT_PLUGIN, WIRE_CRYPT, DB_GUID and
17+
DB_FILE_ID returned mangled values.
18+
- Unregistered bug: db info call for FIREBIRD_VERSION or Connection.info.firebird_version
19+
always returned only one string. Now it returns all values returned by server, separated
20+
by newline.
21+
722
## [1.10.3] - 2024-05-03
823

924
### Fixed

Diff for: ‎docs/changelog.txt

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
Changelog
33
#########
44

5+
Version 1.10.4
6+
==============
7+
8+
- Support for values fetched from environment variables in configuration files via
9+
`~firebird.base.config.EnvExtendedInterpolation` provided by firebird-base package v1.8.0.
10+
- Fix: db info call for CRYPT_KEY, CRYPT_PLUGIN, WIRE_CRYPT, DB_GUID and
11+
DB_FILE_ID returned mangled values.
12+
- Fix: db info call for FIREBIRD_VERSION or `.Connection.info.firebird_version`
13+
always returned only one string. Now it returns all values returned by server, separated
14+
by newline.
515

616
Version 1.10.3
717
==============

Diff for: ‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
"Topic :: Database",
3030
]
3131
dependencies = [
32-
"firebird-base>=1.7.0",
32+
"firebird-base>=1.8.0",
3333
"python-dateutil>=2.8",
3434
]
3535

Diff for: ‎src/firebird/driver/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161
Server, Statement)
6262

6363
#: Current driver version, SEMVER string.
64-
__VERSION__ = '1.10.3'
64+
__VERSION__ = '1.10.4'

Diff for: ‎src/firebird/driver/config.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141
from __future__ import annotations
4242
from typing import Dict, Union, Iterable
4343
import os
44-
from configparser import ConfigParser, ExtendedInterpolation
4544
from firebird.base.config import Config, StrOption, IntOption, BoolOption, EnumOption, \
46-
ConfigListOption, ListOption
45+
ConfigListOption, ListOption, ConfigParser, EnvExtendedInterpolation
4746
from .types import NetProtocol, DecfloatRound, DecfloatTraps
4847

4948
class ServerConfig(Config): # pylint: disable=R0902
@@ -218,7 +217,7 @@ def read(self, filenames: Union[str, Iterable], encoding: str=None):
218217
219218
Return list of successfully read files.
220219
"""
221-
parser = ConfigParser(interpolation=ExtendedInterpolation())
220+
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
222221
read_ok = parser.read(filenames, encoding)
223222
if read_ok:
224223
self.load_config(parser)
@@ -228,13 +227,13 @@ def read_file(self, f):
228227
229228
The `f` argument must be iterable, returning one line at a time.
230229
"""
231-
parser = ConfigParser(interpolation=ExtendedInterpolation())
230+
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
232231
parser.read_file(f)
233232
self.load_config(parser)
234233
def read_string(self, string: str) -> None:
235234
"""Read configuration from a given string.
236235
"""
237-
parser = ConfigParser(interpolation=ExtendedInterpolation())
236+
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
238237
parser.read_string(string)
239238
self.load_config(parser)
240239
def read_dict(self, dictionary: Dict) -> None:
@@ -247,7 +246,7 @@ def read_dict(self, dictionary: Dict) -> None:
247246
All types held in the dictionary are converted to strings during
248247
reading, including section names, option names and keys.
249248
"""
250-
parser = ConfigParser(interpolation=ExtendedInterpolation())
249+
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
251250
parser.read_dict(dictionary)
252251
self.load_config(parser)
253252
def get_server(self, name: str) -> ServerConfig:
@@ -282,7 +281,7 @@ def register_server(self, name: str, config: str=None) -> ServerConfig:
282281
srv_config = ServerConfig(name)
283282
self.servers.value.append(srv_config)
284283
if config:
285-
parser = ConfigParser(interpolation=ExtendedInterpolation())
284+
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
286285
parser.read_string(config)
287286
srv_config.load_config(parser, name)
288287
return srv_config
@@ -304,7 +303,7 @@ def register_database(self, name: str, config: str=None) -> DatabaseConfig:
304303
db_config = DatabaseConfig(name)
305304
self.databases.value.append(db_config)
306305
if config:
307-
parser = ConfigParser(interpolation=ExtendedInterpolation())
306+
parser = ConfigParser(interpolation=EnvExtendedInterpolation())
308307
parser.read_string(config)
309308
db_config.load_config(parser, name)
310309
return db_config

Diff for: ‎src/firebird/driver/core.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,8 @@ def __init__(self, connection: Connection):
11161116
DbInfoCode.DB_ID: self.__db_id,
11171117
DbInfoCode.IMPLEMENTATION: self.__implementation,
11181118
DbInfoCode.IMPLEMENTATION_OLD: self.__implementation_old,
1119-
DbInfoCode.VERSION: self._info_string,
1120-
DbInfoCode.FIREBIRD_VERSION: self._info_string,
1119+
DbInfoCode.VERSION: self._version_string,
1120+
DbInfoCode.FIREBIRD_VERSION: self._version_string,
11211121
DbInfoCode.USER_NAMES: self.__user_names,
11221122
DbInfoCode.ACTIVE_TRANSACTIONS: self.__tra_active,
11231123
DbInfoCode.LIMBO: self.__tra_limbo,
@@ -1197,13 +1197,15 @@ def __implementation_old(self) -> Tuple[int, int]:
11971197
impl_number = self.response.read_byte()
11981198
class_number = self.response.read_byte()
11991199
return (impl_number, class_number)
1200-
def _info_string(self) -> str:
1201-
self.response.read_byte() # Cluster length
1202-
self.response.read_short() # number of strings
1203-
return self.response.read_pascal_string()
1200+
def _version_string(self) -> str:
1201+
self.response.read_short() # Cluster length
1202+
result = []
1203+
count = self.response.read_byte() # number of strings
1204+
for _ in range(count):
1205+
result.append(self.response.read_pascal_string())
1206+
return '\n'.join(result)
12041207
def _single_info_string(self) -> str:
1205-
self.response.read_byte() # Cluster length
1206-
return self.response.read_pascal_string()
1208+
return self.response.read_sized_string()
12071209
def __user_names(self) -> Dict[str, str]:
12081210
self.response.rewind() # necessary to process names separated by info tag
12091211
usernames = []

Diff for: ‎tests/test_driver.py

+3
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ def test_db_info(self):
536536
self.assertIsInstance(con.info.get_info(DbInfoCode.ODS_VERSION), int)
537537
self.assertIsInstance(con.info.get_info(DbInfoCode.ODS_MINOR_VERSION), int)
538538
#
539+
self.assertEqual(con.info.get_info(DbInfoCode.CRYPT_KEY), '')
540+
self.assertEqual(con.info.get_info(DbInfoCode.CRYPT_PLUGIN), '')
541+
self.assertEqual(con.info.get_info(DbInfoCode.DB_GUID), '{03EC58E8-865D-4528-A888-130677BEB1CF}')
539542

540543

541544
class TestTransaction(DriverTestBase):

0 commit comments

Comments
 (0)
Please sign in to comment.