File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77def 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
Original file line number Diff line number Diff line change @@ -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
Original file line number Diff line number Diff line change 88class 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
Original file line number Diff line number Diff line change 11Version history
22===============
33
4+ * `Version 2.3.0 <https://github.com/dw/python-pure-cdb/releases/tag/v2.3.0 >`_
5+ * Added `python-cdb ` compatibility module.
46* `Version 2.2.0 <https://github.com/dw/python-pure-cdb/releases/tag/v2.2.0 >`_
57 * Added non-`strict ` mode for convenience when using non-binary keys.
68 * API docs are now available at ReadTheDocs.
Original file line number Diff line number Diff 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' )
You can’t perform that action at this time.
0 commit comments