Skip to content

Commit 094eb25

Browse files
authored
Merge pull request #28 from dw/version-3.0.0
Version 3.0.0
2 parents 75bf270 + f0f4d88 commit 094eb25

6 files changed

Lines changed: 19 additions & 13 deletions

File tree

cdblib/cdbdump.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66

77
def cdbdump(parsed_args, **kwargs):
88
# Read binary data from stdin by default
9-
stdin = kwargs.get('stdin')
10-
if stdin is None:
11-
stdin = sys.stdin.buffer
9+
stdin = kwargs.get('stdin', sys.stdin.buffer)
1210

1311
# Print text data to stdout by default
14-
stdout = kwargs.get('stdout')
15-
if stdout is None:
16-
stdout = sys.stdout.buffer
12+
stdout = kwargs.get('stdout', sys.stdout.buffer)
1713

1814
# Consume stdin and parse the cdb file
1915
reader_cls = cdblib.Reader64 if parsed_args['64'] else cdblib.Reader

cdblib/cdblib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
# Structs for 32-bit databases
1414
read_2_le4 = Struct('<LL').unpack
15-
read_2_le8 = Struct('<QQ').unpack
15+
write_2_le4 = Struct('<LL').pack
1616

1717
# Structs for 64-bit databases
18-
write_2_le4 = Struct('<LL').pack
18+
read_2_le8 = Struct('<QQ').unpack
1919
write_2_le8 = Struct('<QQ').pack
2020

2121
# Encoders for keys
@@ -72,7 +72,7 @@ class Reader(_CDBBase):
7272
def __init__(self, data, **kwargs):
7373
'''Create an instance reading from a sequence and using hashfn to hash
7474
keys.'''
75-
if len(data) < 2048:
75+
if len(data) < (self.pair_size * 256):
7676
raise IOError('CDB too small')
7777

7878
self.data = data

cdblib/cdbmake.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
class CDBMaker(object):
99
def __init__(self, parsed_args, **kwargs):
1010
# Read binary data from stdin and write errors to stderr (by default)
11-
self.stdin = kwargs.get('stdin')
12-
if self.stdin is None:
13-
self.stdin = sys.stdin.buffer
11+
self.stdin = kwargs.get('stdin', sys.stdin.buffer)
1412

1513
self.stderr = kwargs.get('stderr', sys.stderr)
1614

docs/versions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Version history
22
===============
33

4+
* `Version 3.0.0 <https://github.com/dw/python-pure-cdb/releases/tag/v2.3.0>`_
5+
* This package now supports Python 3 only. For a version that works with Python 2, see `this older release <https://github.com/dw/python-pure-cdb/releases/tag/v2.2.0>`
6+
* Added the `python-cdb` compatibility module
47
* `Version 2.2.0 <https://github.com/dw/python-pure-cdb/releases/tag/v2.2.0>`_
58
* Added non-`strict` mode for convenience when using non-binary keys.
69
* API docs are now available at ReadTheDocs.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
keywords='cdb file format appengine database db',
2525
license='MIT',
2626
name='pure-cdb',
27-
version='4.0.0',
27+
version='3.0.0',
2828
packages=find_packages(include=['cdblib']),
2929
ext_modules=ext_modules,
3030
install_requires=[],

tests/cdblib_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ def setUp(self):
166166
sio.seek(0)
167167
self.reader = self.reader_cls(sio.getvalue(), hashfn=self.HASHFN)
168168

169+
def test_min_size(self):
170+
with io.BytesIO() as f:
171+
with self.writer_cls(f, hashfn=self.HASHFN) as writer:
172+
pass
173+
data = f.getvalue()
174+
175+
with self.assertRaises(OSError):
176+
reader = self.reader_cls(data[:-1], hashfn=self.HASHFN)
177+
169178
def test_insertion_order(self):
170179
keys = [b'dave'] * 10
171180
keys.append(b'dave_no_dups')

0 commit comments

Comments
 (0)