8000 Release v1.3.1 · FirebirdSQL/python3-base@cbb5fc8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbb5fc8

Browse files
committed
Release v1.3.1
1 parent 541ed8d commit cbb5fc8

File tree

8 files changed

+57
-22
lines changed

8 files changed

+57
-22
lines changed

docs/changelog.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
Changelog
33
#########
44

5+
Version 1.3.1
6+
=============
7+
8+
* `~firebird.base.buffer` module:
9+
10+
- Added `.MemoryBuffer.write_sized_string` for symetry with `.read_sized_string`.
11+
- Now `.MemoryBuffer` string functions has also `errors` parameter in addition to `encoding`.
12+
13+
* `~firebird.base.config` module:
14+
15+
- Direct assignment to `.Config` option raises a `ValueError` exception with message
16+
"Cannot assign values to option itself, use `option.value` instead".
17+
518
Version 1.3.0
619
=============
720

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
author = 'Pavel Císař'
2424

2525
# The short X.Y version
26-
version = '1.3.0'
26+
version = '1.3.1'
2727

2828
# The full version, including alpha/beta/rc tags
29-
release = '1.3.0'
29+
release = '1.3.1'
3030

3131

3232
# -- General configuration ---------------------------------------------------

docs/config.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ The framework is based around two classes:
3636
Additionally, the `.ApplicationDirectoryScheme` abstract base class defines set of mostly
3737
used application directories. The function `.get_directory_scheme()` could be then used
3838
to obtain instance that implements platform-specific standards for file-system location
39-
for these directories. Currently, only "Windows" and "Linux" directory schemes are supported.
39+
for these directories. Currently, only "Windows", "Linux" and "MacOS" directory schemes
40+
are supported.
4041

4142
.. note::
4243
You may use `platform.system` call to determine the scheme name suitable for platform

firebird/base/buffer.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,22 @@ def write_bigint(self, value: int) -> None:
220220
"""Write tagged 8 byte number (c_ulonglong).
221221
"""
222222
self.write_number(value, 8)
223-
def write_string(self, value: str, *, encoding='ascii') -> None:
223+
def write_string(self, value: str, *, encoding: str='ascii', errors: str='strict') -> None:
224224
"""Write zero-terminated string.
225225
"""
226-
self.write(value.encode(encoding))
226+
self.write(value.encode(encoding, errors))
227227
self.write_byte(0)
228-
def write_pascal_string(self, value: str, *, encoding='ascii') -> None:
228+
def write_pascal_string(self, value: str, *, encoding: str='ascii', errors: str='strict') -> None:
229229
"""Write tagged Pascal string (2 byte length followed by data).
230230
"""
231-
value = value.encode(encoding)
232-
size = len(value)
233-
self.write_byte(size)
231+
value = value.encode(encoding, errors)
232+
self.write_byte(len(value))
233+
self.write(value)
234+
def write_sized_string(self, value: str, *, encoding: str='ascii', errors: str='strict') -> None:
235+
"""Write string (2 byte length followed by data).
236+
"""
237+
value = value.encode(encoding, errors)
238+
self.write_short(len(value))
234239
self.write(value)
235240
def read(self, size: int=-1) -> bytes:
236241
"""Reads specified number of bytes, or all remaining data.
@@ -248,43 +253,43 @@ def read_number(self, size: int, *, signed=False) -> int:
248253
result = (0).from_bytes(self.raw[self.pos: self.pos + size], self.byteorder.value, signed=signed)
249254
self.pos += size
250255
return result
251-
def read_byte(self, *, signed=False) -> int:
256+
def read_byte(self, *, signed: bool=False) -> int:
252257
"""Read 1 byte number (c_ubyte).
253258
"""
254259
return self.read_number(1, signed=signed)
255-
def read_short(self, *, signed=False) -> int:
260+
def read_short(self, *, signed: bool=False) -> int:
256261
"""Read 2 byte number (c_ushort).
257262
"""
258263
return self.read_number(2, signed=signed)
259-
def read_int(self, *, signed=False) -> int:
264+
def read_int(self, *, signed: bool=False) -> int:
260265
"""Read 4 byte number (c_uint).
261266
"""
262267
return self.read_number(4, signed=signed)
263-
def read_bigint(self, *, signed=False) -> int:
268+
def read_bigint(self, *, signed: bool=False) -> int:
264269
"""Read 8 byte number (c_ulonglong).
265270
"""
266271
return self.read_number(8, signed=signed)
267-
def read_sized_int(self, *, signed=False) -> int:
272+
def read_sized_int(self, *, signed: bool=False) -> int:
268273
"""Read number cluster (2 byte length followed by data).
269274
"""
270275
return self.read_number(self.read_short(), signed=signed)
271-
def read_string(self, *, encoding='ascii') -> str:
276+
def read_string(self, *, encoding: str='ascii', errors: str='strict') -> str:
272277
"""Read null-terminated string.
273278
"""
274279
i = self.pos
275280
while i < self.buffer_size and safe_ord(self.raw[i]) != 0:
276281
i += 1
277-
result = self.read(i - self.pos).decode(encoding)
282+
result = self.read(i - self.pos).decode(encoding, errors)
278283
self.pos += 1
279284
return result
280-
def read_pascal_string(self, *, encoding='ascii') -> str:
285+
def read_pascal_string(self, *, encoding: str='ascii', errors: str='strict') -> str:
281286
"""Read Pascal string (1 byte length followed by string data).
282287
"""
283-
return self.read(self.read_byte()).decode(encoding)
284-
def read_sized_string(self, *, encoding='ascii') -> str:
288+
return self.read(self.read_byte()).decode(encoding, errors)
289+
def read_sized_string(self, *, encoding: str='ascii', errors: str='strict') -> str:
285290
"""Read string (2 byte length followed by data).
286291
"""
287-
return self.read(self.read_short()).decode(encoding)
292+
return self.read(self.read_short()).decode(encoding, errors)
288293
def read_bytes(self) -> bytes:
289294
"""Read content of binary cluster (2 bytes data length followed by data).
290295
"""

firebird/base/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from pathlib import Path
6060
import os
6161
from .config_pb2 import ConfigProto
62-
from .types import Error, MIME, ZMQAddress, PyExpr, PyCode, PyCallable
62+
from .types import Error, UNDEFINED, MIME, ZMQAddress, PyExpr, PyCode, PyCallable
6363
from .strconv import get_convertor, convert_to_str, Convertor
6464

6565
PROTO_CONFIG = 'firebird.base.ConfigProto'
@@ -552,6 +552,11 @@ def __init__(self, name: str, *, optional: bool=False, description: str=None):
552552
self._name: str = name
553553
self._optional: bool = optional
554554
self._description: str = description if description is not None else self.__doc__
555+
def __setattr__(self, name, value):
556+
for attr in vars(self).values():
557+
if isinstance(attr, Option) and attr.name == name:
558+
raise ValueError('Cannot assign values to option itself, use `option.value` instead')
559+
super().__setattr__(name, value)
555560
def validate(self) -> None:
556561
"""Checks whether:
557562
- all required options have value other than None.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all-files=True
55

66
[metadata]
77
name = firebird-base
8-
version = 1.3.0
8+
version = 1.3.1
99
description = Firebird base modules for Python
1010
long_description = file: README.rst
1111
long_description_content_type = text/x-rst; charset=UTF-8

test/test_buffer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def test_write_pascal_string(self):
178178
self.assertEqual(buf.pos, 7)
179179
self.assertBuffer(buf, b'\x06string')
180180
self.assertTrue(buf.is_eof())
181+
def test_write_sized_string(self):
182+
buf = MemoryBuffer(0, factory=self.factory)
183+
buf.write_sized_string('string')
184+
self.assertEqual(buf.pos, 8)
185+
self.assertBuffer(buf, b'\x06\x00string')
186+
self.assertTrue(buf.is_eof())
181187
def test_write_past_size(self):
182188
buf = MemoryBuffer(0, max_size=5, factory=self.factory)
183189
buf.write(b'ABCDE')

test/test_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,11 @@ def test_1_basics(self):
30293029
self.assertIsNone(cfg.backup_db.database.value)
30303030
self.assertEqual(cfg.backup_db.user.value, 'SYSDBA')
30313031
self.assertIsNone(cfg.backup_db.password.value)
3032+
#
3033+
with self.assertRaises(ValueError) as cm:
3034+
cfg.opt_str = 'value'
3035+
self.assertEqual(cm.exception.args,
3036+
('Cannot assign values to option itself, use `option.value` instead',))
30323037
def test_2_load_config(self):
30333038
cfg = SimpleConfig()
30343039
#

0 commit comments

Comments
 (0)
0