-
Notifications
You must be signed in to change notification settings - Fork 4
/
python-2.6-update-bsddb3-4.8.patch
3446 lines (3212 loc) · 112 KB
/
python-2.6-update-bsddb3-4.8.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Nupr Python-2.6.4.orig/Lib/bsddb/dbobj.py Python-2.6.4/Lib/bsddb/dbobj.py
--- Python-2.6.4.orig/Lib/bsddb/dbobj.py 2008-07-23 07:38:42.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/dbobj.py 2009-12-04 07:36:00.000000000 -0500
@@ -110,15 +110,17 @@ class DBEnv:
def log_stat(self, *args, **kwargs):
return apply(self._cobj.log_stat, args, kwargs)
- if db.version() >= (4,1):
- def dbremove(self, *args, **kwargs):
- return apply(self._cobj.dbremove, args, kwargs)
- def dbrename(self, *args, **kwargs):
- return apply(self._cobj.dbrename, args, kwargs)
- def set_encrypt(self, *args, **kwargs):
- return apply(self._cobj.set_encrypt, args, kwargs)
+ def dbremove(self, *args, **kwargs):
+ return apply(self._cobj.dbremove, args, kwargs)
+ def dbrename(self, *args, **kwargs):
+ return apply(self._cobj.dbrename, args, kwargs)
+ def set_encrypt(self, *args, **kwargs):
+ return apply(self._cobj.set_encrypt, args, kwargs)
if db.version() >= (4,4):
+ def fileid_reset(self, *args, **kwargs):
+ return self._cobj.fileid_reset(*args, **kwargs)
+
def lsn_reset(self, *args, **kwargs):
return apply(self._cobj.lsn_reset, args, kwargs)
@@ -229,9 +231,8 @@ class DB(MutableMapping):
def set_get_returns_none(self, *args, **kwargs):
return apply(self._cobj.set_get_returns_none, args, kwargs)
- if db.version() >= (4,1):
- def set_encrypt(self, *args, **kwargs):
- return apply(self._cobj.set_encrypt, args, kwargs)
+ def set_encrypt(self, *args, **kwargs):
+ return apply(self._cobj.set_encrypt, args, kwargs)
class DBSequence:
diff -Nupr Python-2.6.4.orig/Lib/bsddb/dbtables.py Python-2.6.4/Lib/bsddb/dbtables.py
--- Python-2.6.4.orig/Lib/bsddb/dbtables.py 2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/dbtables.py 2009-12-04 07:36:00.000000000 -0500
@@ -15,7 +15,7 @@
# This provides a simple database table interface built on top of
# the Python Berkeley DB 3 interface.
#
-_cvsid = '$Id: dbtables.py 66088 2008-08-31 14:00:51Z jesus.cea $'
+_cvsid = '$Id: dbtables.py 58758 2007-11-01 21:15:36Z gregory.p.smith $'
import re
import sys
@@ -659,6 +659,13 @@ class bsdTableDB :
a = atuple[1]
b = btuple[1]
if type(a) is type(b):
+
+ # Needed for python 3. "cmp" vanished in 3.0.1
+ def cmp(a, b) :
+ if a==b : return 0
+ if a<b : return -1
+ return 1
+
if isinstance(a, PrefixCond) and isinstance(b, PrefixCond):
# longest prefix first
return cmp(len(b.prefix), len(a.prefix))
diff -Nupr Python-2.6.4.orig/Lib/bsddb/dbutils.py Python-2.6.4/Lib/bsddb/dbutils.py
--- Python-2.6.4.orig/Lib/bsddb/dbutils.py 2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/dbutils.py 2009-12-04 07:36:00.000000000 -0500
@@ -61,7 +61,7 @@ def DeadlockWrap(function, *_args, **_kw
"""
sleeptime = _deadlock_MinSleepTime
max_retries = _kwargs.get('max_retries', -1)
- if _kwargs.has_key('max_retries'):
+ if 'max_retries' in _kwargs:
del _kwargs['max_retries']
while True:
try:
diff -Nupr Python-2.6.4.orig/Lib/bsddb/__init__.py Python-2.6.4/Lib/bsddb/__init__.py
--- Python-2.6.4.orig/Lib/bsddb/__init__.py 2008-09-05 14:33:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/__init__.py 2009-12-04 07:36:00.000000000 -0500
@@ -33,7 +33,7 @@
#----------------------------------------------------------------------
-"""Support for Berkeley DB 4.0 through 4.7 with a simple interface.
+"""Support for Berkeley DB 4.1 through 4.8 with a simple interface.
For the full featured object oriented interface use the bsddb.db module
instead. It mirrors the Oracle Berkeley DB C API.
@@ -42,12 +42,6 @@ instead. It mirrors the Oracle Berkeley
import sys
absolute_import = (sys.version_info[0] >= 3)
-if sys.py3kwarning:
- import warnings
- warnings.warnpy3k("in 3.x, bsddb has been removed; "
- "please use the pybsddb project instead",
- DeprecationWarning, 2)
-
try:
if __name__ == 'bsddb3':
# import _pybsddb binary as it should be the more recent version from
@@ -442,8 +436,10 @@ def _checkflag(flag, file):
# Berkeley DB was too.
try:
- import thread
- del thread
+ # 2to3 automatically changes "import thread" to "import _thread"
+ import thread as T
+ del T
+
except ImportError:
db.DB_THREAD = 0
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_all.py Python-2.6.4/Lib/bsddb/test/test_all.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_all.py 2008-09-03 18:07:11.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_all.py 2009-12-04 07:36:00.000000000 -0500
@@ -203,6 +203,16 @@ if sys.version_info[0] >= 3 :
k = bytes(k, charset)
return self._db.has_key(k, txn=txn)
+ def set_re_delim(self, c) :
+ if isinstance(c, str) : # We can use a numeric value byte too
+ c = bytes(c, charset)
+ return self._db.set_re_delim(c)
+
+ def set_re_pad(self, c) :
+ if isinstance(c, str) : # We can use a numeric value byte too
+ c = bytes(c, charset)
+ return self._db.set_re_pad(c)
+
def put(self, key, value, txn=None, flags=0, dlen=-1, doff=-1) :
if isinstance(key, str) :
key = bytes(key, charset)
@@ -221,6 +231,11 @@ if sys.version_info[0] >= 3 :
key = bytes(key, charset)
return self._db.get_size(key)
+ def exists(self, key, *args, **kwargs) :
+ if isinstance(key, str) :
+ key = bytes(key, charset)
+ return self._db.exists(key, *args, **kwargs)
+
def get(self, key, default="MagicCookie", txn=None, flags=0, dlen=-1, doff=-1) :
if isinstance(key, str) :
key = bytes(key, charset)
@@ -288,13 +303,21 @@ if sys.version_info[0] >= 3 :
key = key.decode(charset)
data = data.decode(charset)
key = self._callback(key, data)
- if (key != bsddb._db.DB_DONOTINDEX) and isinstance(key,
- str) :
- key = bytes(key, charset)
+ if (key != bsddb._db.DB_DONOTINDEX) :
+ if isinstance(key, str) :
+ key = bytes(key, charset)
+ elif isinstance(key, list) :
+ key2 = []
+ for i in key :
+ if isinstance(i, str) :
+ i = bytes(i, charset)
+ key2.append(i)
+ key = key2
return key
return self._db.associate(secondarydb._db,
- associate_callback(callback).callback, flags=flags, txn=txn)
+ associate_callback(callback).callback, flags=flags,
+ txn=txn)
def cursor(self, txn=None, flags=0) :
return cursor_py3k(self._db, txn=txn, flags=flags)
@@ -310,6 +333,12 @@ if sys.version_info[0] >= 3 :
def __getattr__(self, v) :
return getattr(self._dbenv, v)
+ def get_data_dirs(self) :
+ # Have to use a list comprehension and not
+ # generators, because we are supporting Python 2.3.
+ return tuple(
+ [i.decode(charset) for i in self._dbenv.get_data_dirs()])
+
class DBSequence_py3k(object) :
def __init__(self, db, *args, **kwargs) :
self._db=db
@@ -332,7 +361,10 @@ if sys.version_info[0] >= 3 :
bsddb._db.DBEnv_orig = bsddb._db.DBEnv
bsddb._db.DB_orig = bsddb._db.DB
- bsddb._db.DBSequence_orig = bsddb._db.DBSequence
+ if bsddb.db.version() <= (4, 3) :
+ bsddb._db.DBSequence_orig = None
+ else :
+ bsddb._db.DBSequence_orig = bsddb._db.DBSequence
def do_proxy_db_py3k(flag) :
flag2 = do_proxy_db_py3k.flag
@@ -481,6 +513,7 @@ def suite(module_prefix='', timing_check
test_modules = [
'test_associate',
'test_basics',
+ 'test_dbenv',
'test_compare',
'test_compat',
'test_cursor_pget_bug',
@@ -489,6 +522,7 @@ def suite(module_prefix='', timing_check
'test_dbtables',
'test_distributed_transactions',
'test_early_close',
+ 'test_fileid',
'test_get_none',
'test_join',
'test_lock',
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_associate.py Python-2.6.4/Lib/bsddb/test/test_associate.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_associate.py 2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_associate.py 2009-12-04 07:36:00.000000000 -0500
@@ -148,12 +148,8 @@ class AssociateTestCase(unittest.TestCas
self.secDB = None
self.primary = db.DB(self.env)
self.primary.set_get_returns_none(2)
- if db.version() >= (4, 1):
- self.primary.open(self.filename, "primary", self.dbtype,
- db.DB_CREATE | db.DB_THREAD | self.dbFlags, txn=txn)
- else:
- self.primary.open(self.filename, "primary", self.dbtype,
- db.DB_CREATE | db.DB_THREAD | self.dbFlags)
+ self.primary.open(self.filename, "primary", self.dbtype,
+ db.DB_CREATE | db.DB_THREAD | self.dbFlags, txn=txn)
def closeDB(self):
if self.cur:
@@ -169,12 +165,7 @@ class AssociateTestCase(unittest.TestCas
return self.primary
- def test01_associateWithDB(self):
- if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_associateWithDB..." % \
- self.__class__.__name__
-
+ def _associateWithDB(self, getGenre):
self.createDB()
self.secDB = db.DB(self.env)
@@ -182,19 +173,21 @@ class AssociateTestCase(unittest.TestCas
self.secDB.set_get_returns_none(2)
self.secDB.open(self.filename, "secondary", db.DB_BTREE,
db.DB_CREATE | db.DB_THREAD | self.dbFlags)
- self.getDB().associate(self.secDB, self.getGenre)
+ self.getDB().associate(self.secDB, getGenre)
self.addDataToDB(self.getDB())
self.finish_test(self.secDB)
-
- def test02_associateAfterDB(self):
+ def test01_associateWithDB(self):
if verbose:
print '\n', '-=' * 30
- print "Running %s.test02_associateAfterDB..." % \
+ print "Running %s.test01_associateWithDB..." % \
self.__class__.__name__
+ return self._associateWithDB(self.getGenre)
+
+ def _associateAfterDB(self, getGenre) :
self.createDB()
self.addDataToDB(self.getDB())
@@ -204,10 +197,35 @@ class AssociateTestCase(unittest.TestCas
db.DB_CREATE | db.DB_THREAD | self.dbFlags)
# adding the DB_CREATE flag will cause it to index existing records
- self.getDB().associate(self.secDB, self.getGenre, db.DB_CREATE)
+ self.getDB().associate(self.secDB, getGenre, db.DB_CREATE)
self.finish_test(self.secDB)
+ def test02_associateAfterDB(self):
+ if verbose:
+ print '\n', '-=' * 30
+ print "Running %s.test02_associateAfterDB..." % \
+ self.__class__.__name__
+
+ return self._associateAfterDB(self.getGenre)
+
+ if db.version() >= (4, 6):
+ def test03_associateWithDB(self):
+ if verbose:
+ print '\n', '-=' * 30
+ print "Running %s.test03_associateWithDB..." % \
+ self.__class__.__name__
+
+ return self._associateWithDB(self.getGenreList)
+
+ def test04_associateAfterDB(self):
+ if verbose:
+ print '\n', '-=' * 30
+ print "Running %s.test04_associateAfterDB..." % \
+ self.__class__.__name__
+
+ return self._associateAfterDB(self.getGenreList)
+
def finish_test(self, secDB, txn=None):
# 'Blues' should not be in the secondary database
@@ -277,6 +295,12 @@ class AssociateTestCase(unittest.TestCas
else:
return genre
+ def getGenreList(self, priKey, PriData) :
+ v = self.getGenre(priKey, PriData)
+ if type(v) == type("") :
+ v = [v]
+ return v
+
#----------------------------------------------------------------------
@@ -322,10 +346,7 @@ class AssociateBTreeTxnTestCase(Associat
self.secDB.set_get_returns_none(2)
self.secDB.open(self.filename, "secondary", db.DB_BTREE,
db.DB_CREATE | db.DB_THREAD, txn=txn)
- if db.version() >= (4,1):
- self.getDB().associate(self.secDB, self.getGenre, txn=txn)
- else:
- self.getDB().associate(self.secDB, self.getGenre)
+ self.getDB().associate(self.secDB, self.getGenre, txn=txn)
self.addDataToDB(self.getDB(), txn=txn)
except:
@@ -426,8 +447,7 @@ def test_suite():
suite.addTest(unittest.makeSuite(AssociateBTreeTestCase))
suite.addTest(unittest.makeSuite(AssociateRecnoTestCase))
- if db.version() >= (4, 1):
- suite.addTest(unittest.makeSuite(AssociateBTreeTxnTestCase))
+ suite.addTest(unittest.makeSuite(AssociateBTreeTxnTestCase))
suite.addTest(unittest.makeSuite(ShelveAssociateHashTestCase))
suite.addTest(unittest.makeSuite(ShelveAssociateBTreeTestCase))
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_basics.py Python-2.6.4/Lib/bsddb/test/test_basics.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_basics.py 2009-07-02 11:37:21.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_basics.py 2009-12-04 07:36:00.000000000 -0500
@@ -33,6 +33,7 @@ class VersionTestCase(unittest.TestCase)
class BasicTestCase(unittest.TestCase):
dbtype = db.DB_UNKNOWN # must be set in derived class
+ cachesize = (0, 1024*1024, 1)
dbopenflags = 0
dbsetflags = 0
dbmode = 0660
@@ -43,6 +44,13 @@ class BasicTestCase(unittest.TestCase):
_numKeys = 1002 # PRIVATE. NOTE: must be an even value
+ import sys
+ if sys.version_info[:3] < (2, 4, 0):
+ def assertTrue(self, expr, msg=None):
+ self.failUnless(expr,msg=msg)
+ def assertFalse(self, expr, msg=None):
+ self.failIf(expr,msg=msg)
+
def setUp(self):
if self.useEnv:
self.homeDir=get_new_environment_path()
@@ -50,7 +58,8 @@ class BasicTestCase(unittest.TestCase):
self.env = db.DBEnv()
self.env.set_lg_max(1024*1024)
self.env.set_tx_max(30)
- self.env.set_tx_timestamp(int(time.time()))
+ self._t = int(time.time())
+ self.env.set_tx_timestamp(self._t)
self.env.set_flags(self.envsetflags, 1)
self.env.open(self.homeDir, self.envflags | db.DB_CREATE)
self.filename = "test"
@@ -64,6 +73,15 @@ class BasicTestCase(unittest.TestCase):
# create and open the DB
self.d = db.DB(self.env)
+ if not self.useEnv :
+ if db.version() >= (4, 2) :
+ self.d.set_cachesize(*self.cachesize)
+ cachesize = self.d.get_cachesize()
+ self.assertEqual(cachesize[0], self.cachesize[0])
+ self.assertEqual(cachesize[2], self.cachesize[2])
+ # Berkeley DB expands the cache 25% accounting overhead,
+ # if the cache is small.
+ self.assertEqual(125, int(100.0*cachesize[1]/self.cachesize[1]))
self.d.set_flags(self.dbsetflags)
if self.dbname:
self.d.open(self.filename, self.dbname, self.dbtype,
@@ -74,6 +92,10 @@ class BasicTestCase(unittest.TestCase):
dbtype = self.dbtype,
flags = self.dbopenflags|db.DB_CREATE)
+ if not self.useEnv:
+ self.assertRaises(db.DBInvalidArgError,
+ self.d.set_cachesize, *self.cachesize)
+
self.populateDB()
@@ -131,7 +153,7 @@ class BasicTestCase(unittest.TestCase):
self.assertEqual(d.get('0321'), '0321-0321-0321-0321-0321')
- # By default non-existent keys return None...
+ # By default non-existant keys return None...
self.assertEqual(d.get('abcd'), None)
# ...but they raise exceptions in other situations. Call
@@ -276,6 +298,21 @@ class BasicTestCase(unittest.TestCase):
pprint(values[:10])
+ #----------------------------------------
+
+ def test02b_SequenceMethods(self):
+ d = self.d
+
+ for key in ['0002', '0101', '0401', '0701', '0998']:
+ data = d[key]
+ self.assertEqual(data, self.makeData(key))
+ if verbose:
+ print data
+
+ self.assertTrue(hasattr(d, "__contains__"))
+ self.assertTrue("0401" in d)
+ self.assertFalse("1234" in d)
+
#----------------------------------------
@@ -509,6 +546,15 @@ class BasicTestCase(unittest.TestCase):
self.assertEqual(old, 1)
self.test03_SimpleCursorStuff(get_raises_error=0, set_raises_error=0)
+ if db.version() >= (4, 6):
+ def test03d_SimpleCursorPriority(self) :
+ c = self.d.cursor()
+ c.set_priority(db.DB_PRIORITY_VERY_LOW) # Positional
+ self.assertEqual(db.DB_PRIORITY_VERY_LOW, c.get_priority())
+ c.set_priority(priority=db.DB_PRIORITY_HIGH) # Keyword
+ self.assertEqual(db.DB_PRIORITY_HIGH, c.get_priority())
+ c.close()
+
#----------------------------------------
def test04_PartialGetAndPut(self):
@@ -562,7 +608,7 @@ class BasicTestCase(unittest.TestCase):
d = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test99_Truncate..." % self.__class__.__name__
+ print "Running %s.test06_Truncate..." % self.__class__.__name__
d.put("abcde", "ABCDE");
num = d.truncate()
@@ -582,6 +628,33 @@ class BasicTestCase(unittest.TestCase):
#----------------------------------------
+ if db.version() >= (4, 6):
+ def test08_exists(self) :
+ self.d.put("abcde", "ABCDE")
+ self.assert_(self.d.exists("abcde") == True,
+ "DB->exists() returns wrong value")
+ self.assert_(self.d.exists("x") == False,
+ "DB->exists() returns wrong value")
+
+ #----------------------------------------
+
+ if db.version() >= (4, 7):
+ def test_compact(self) :
+ d = self.d
+ self.assertEqual(0, d.compact(flags=db.DB_FREELIST_ONLY))
+ self.assertEqual(0, d.compact(flags=db.DB_FREELIST_ONLY))
+ d.put("abcde", "ABCDE");
+ d.put("bcde", "BCDE");
+ d.put("abc", "ABC");
+ d.put("monty", "python");
+ d.delete("abc")
+ d.delete("bcde")
+ d.compact(start='abcde', stop='monty', txn=None,
+ compact_fillpercent=42, compact_pages=1,
+ compact_timeout=50000000,
+ flags=db.DB_FREELIST_ONLY|db.DB_FREE_SPACE)
+
+ #----------------------------------------
#----------------------------------------------------------------------
@@ -611,13 +684,13 @@ class BasicWithEnvTestCase(BasicTestCase
#----------------------------------------
- def test08_EnvRemoveAndRename(self):
+ def test09_EnvRemoveAndRename(self):
if not self.env:
return
if verbose:
print '\n', '-=' * 30
- print "Running %s.test08_EnvRemoveAndRename..." % self.__class__.__name__
+ print "Running %s.test09_EnvRemoveAndRename..." % self.__class__.__name__
# can't rename or remove an open DB
self.d.close()
@@ -626,10 +699,6 @@ class BasicWithEnvTestCase(BasicTestCase
self.env.dbrename(self.filename, None, newname)
self.env.dbremove(newname)
- # dbremove and dbrename are in 4.1 and later
- if db.version() < (4,1):
- del test08_EnvRemoveAndRename
-
#----------------------------------------
class BasicBTreeWithEnvTestCase(BasicWithEnvTestCase):
@@ -729,11 +798,25 @@ class BasicTransactionTestCase(BasicTest
#----------------------------------------
- def test08_TxnTruncate(self):
+ if db.version() >= (4, 6):
+ def test08_exists(self) :
+ txn = self.env.txn_begin()
+ self.d.put("abcde", "ABCDE", txn=txn)
+ txn.commit()
+ txn = self.env.txn_begin()
+ self.assert_(self.d.exists("abcde", txn=txn) == True,
+ "DB->exists() returns wrong value")
+ self.assert_(self.d.exists("x", txn=txn) == False,
+ "DB->exists() returns wrong value")
+ txn.abort()
+
+ #----------------------------------------
+
+ def test09_TxnTruncate(self):
d = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test08_TxnTruncate..." % self.__class__.__name__
+ print "Running %s.test09_TxnTruncate..." % self.__class__.__name__
d.put("abcde", "ABCDE");
txn = self.env.txn_begin()
@@ -746,7 +829,7 @@ class BasicTransactionTestCase(BasicTest
#----------------------------------------
- def test09_TxnLateUse(self):
+ def test10_TxnLateUse(self):
txn = self.env.txn_begin()
txn.abort()
try:
@@ -766,6 +849,39 @@ class BasicTransactionTestCase(BasicTest
raise RuntimeError, "DBTxn.commit() called after DB_TXN no longer valid w/o an exception"
+ #----------------------------------------
+
+
+ if db.version() >= (4, 4):
+ def test_txn_name(self) :
+ txn=self.env.txn_begin()
+ self.assertEqual(txn.get_name(), "")
+ txn.set_name("XXYY")
+ self.assertEqual(txn.get_name(), "XXYY")
+ txn.set_name("")
+ self.assertEqual(txn.get_name(), "")
+ txn.abort()
+
+ #----------------------------------------
+
+
+ def test_txn_set_timeout(self) :
+ txn=self.env.txn_begin()
+ txn.set_timeout(1234567, db.DB_SET_LOCK_TIMEOUT)
+ txn.set_timeout(2345678, flags=db.DB_SET_TXN_TIMEOUT)
+ txn.abort()
+
+ #----------------------------------------
+
+ if db.version() >= (4, 2) :
+ def test_get_tx_max(self) :
+ self.assertEqual(self.env.get_tx_max(), 30)
+
+ def test_get_tx_timestamp(self) :
+ self.assertEqual(self.env.get_tx_timestamp(), self._t)
+
+
+
class BTreeTransactionTestCase(BasicTransactionTestCase):
dbtype = db.DB_BTREE
@@ -780,11 +896,11 @@ class BTreeRecnoTestCase(BasicTestCase):
dbtype = db.DB_BTREE
dbsetflags = db.DB_RECNUM
- def test08_RecnoInBTree(self):
+ def test09_RecnoInBTree(self):
d = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test08_RecnoInBTree..." % self.__class__.__name__
+ print "Running %s.test09_RecnoInBTree..." % self.__class__.__name__
rec = d.get(200)
self.assertEqual(type(rec), type(()))
@@ -814,11 +930,11 @@ class BTreeRecnoWithThreadFlagTestCase(B
class BasicDUPTestCase(BasicTestCase):
dbsetflags = db.DB_DUP
- def test09_DuplicateKeys(self):
+ def test10_DuplicateKeys(self):
d = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test09_DuplicateKeys..." % \
+ print "Running %s.test10_DuplicateKeys..." % \
self.__class__.__name__
d.put("dup0", "before")
@@ -887,11 +1003,11 @@ class BasicMultiDBTestCase(BasicTestCase
else:
return db.DB_BTREE
- def test10_MultiDB(self):
+ def test11_MultiDB(self):
d1 = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test10_MultiDB..." % self.__class__.__name__
+ print "Running %s.test11_MultiDB..." % self.__class__.__name__
d2 = db.DB(self.env)
d2.open(self.filename, "second", self.dbtype,
@@ -1032,11 +1148,12 @@ class CrashAndBurn(unittest.TestCase) :
# # See http://bugs.python.org/issue3307
# self.assertRaises(db.DBInvalidArgError, db.DB, None, 65535)
- def test02_DBEnv_dealloc(self):
- # http://bugs.python.org/issue3885
- import gc
- self.assertRaises(db.DBInvalidArgError, db.DBEnv, ~db.DB_RPCCLIENT)
- gc.collect()
+ if db.version() < (4, 8) :
+ def test02_DBEnv_dealloc(self):
+ # http://bugs.python.org/issue3885
+ import gc
+ self.assertRaises(db.DBInvalidArgError, db.DBEnv, ~db.DB_RPCCLIENT)
+ gc.collect()
#----------------------------------------------------------------------
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_compare.py Python-2.6.4/Lib/bsddb/test/test_compare.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_compare.py 2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_compare.py 2009-12-04 07:36:00.000000000 -0500
@@ -12,6 +12,12 @@ from test_all import db, dbshelve, test_
get_new_environment_path, get_new_database_path
+# Needed for python 3. "cmp" vanished in 3.0.1
+def cmp(a, b) :
+ if a==b : return 0
+ if a<b : return -1
+ return 1
+
lexical_cmp = cmp
def lowercase_cmp(left, right):
@@ -26,6 +32,10 @@ _expected_lexical_test_data = ['', 'CCCP
_expected_lowercase_test_data = ['', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf', 'CCCP']
class ComparatorTests (unittest.TestCase):
+ if sys.version_info[:3] < (2, 4, 0):
+ def assertTrue(self, expr, msg=None):
+ self.failUnless(expr,msg=msg)
+
def comparator_test_helper (self, comparator, expected_data):
data = expected_data[:]
@@ -47,7 +57,7 @@ class ComparatorTests (unittest.TestCase
data2.append(i)
data = data2
- self.failUnless (data == expected_data,
+ self.assertTrue (data == expected_data,
"comparator `%s' is not right: %s vs. %s"
% (comparator, expected_data, data))
def test_lexical_comparator (self):
@@ -65,6 +75,10 @@ class AbstractBtreeKeyCompareTestCase (u
env = None
db = None
+ if sys.version_info[:3] < (2, 4, 0):
+ def assertTrue(self, expr, msg=None):
+ self.failUnless(expr,msg=msg)
+
def setUp (self):
self.filename = self.__class__.__name__ + '.db'
self.homeDir = get_new_environment_path()
@@ -115,14 +129,14 @@ class AbstractBtreeKeyCompareTestCase (u
rec = curs.first ()
while rec:
key, ignore = rec
- self.failUnless (index < len (expected),
+ self.assertTrue(index < len (expected),
"to many values returned from cursor")
- self.failUnless (expected[index] == key,
+ self.assertTrue(expected[index] == key,
"expected value `%s' at %d but got `%s'"
% (expected[index], index, key))
index = index + 1
rec = curs.next ()
- self.failUnless (index == len (expected),
+ self.assertTrue(index == len (expected),
"not enough values returned from cursor")
finally:
curs.close ()
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_compat.py Python-2.6.4/Lib/bsddb/test/test_compat.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_compat.py 2009-07-02 11:37:21.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_compat.py 2009-12-04 07:36:00.000000000 -0500
@@ -133,7 +133,7 @@ class CompatibilityTestCase(unittest.Tes
except KeyError:
pass
else:
- self.fail("set_location on non-existent key did not raise KeyError")
+ self.fail("set_location on non-existant key did not raise KeyError")
f.sync()
f.close()
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_dbenv.py Python-2.6.4/Lib/bsddb/test/test_dbenv.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_dbenv.py 1969-12-31 19:00:00.000000000 -0500
+++ Python-2.6.4/Lib/bsddb/test/test_dbenv.py 2009-12-04 07:36:00.000000000 -0500
@@ -0,0 +1,148 @@
+import unittest
+import os, glob
+
+from test_all import db, test_support, get_new_environment_path, \
+ get_new_database_path
+
+#----------------------------------------------------------------------
+
+class DBEnv(unittest.TestCase):
+ def setUp(self):
+ self.homeDir = get_new_environment_path()
+ self.env = db.DBEnv()
+
+ def tearDown(self):
+ del self.env
+ test_support.rmtree(self.homeDir)
+
+ if db.version() >= (4, 2) :
+ def test_setget_data_dirs(self) :
+ dirs = ("a", "b", "c", "d")
+ for i in dirs :
+ self.env.set_data_dir(i)
+ self.assertEqual(dirs, self.env.get_data_dirs())
+
+ def test_setget_cachesize(self) :
+ cachesize = (0, 512*1024*1024, 3)
+ self.env.set_cachesize(*cachesize)
+ self.assertEqual(cachesize, self.env.get_cachesize())
+
+ cachesize = (0, 1*1024*1024, 5)
+ self.env.set_cachesize(*cachesize)
+ cachesize2 = self.env.get_cachesize()
+ self.assertEqual(cachesize[0], cachesize2[0])
+ self.assertEqual(cachesize[2], cachesize2[2])
+ # Berkeley DB expands the cache 25% accounting overhead,
+ # if the cache is small.
+ self.assertEqual(125, int(100.0*cachesize2[1]/cachesize[1]))
+
+ # You can not change configuration after opening
+ # the environment.
+ self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
+ cachesize = (0, 2*1024*1024, 1)
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.set_cachesize, *cachesize)
+ self.assertEqual(cachesize2, self.env.get_cachesize())
+
+ def test_set_cachesize_dbenv_db(self) :
+ # You can not configure the cachesize using
+ # the database handle, if you are using an environment.
+ d = db.DB(self.env)
+ self.assertRaises(db.DBInvalidArgError,
+ d.set_cachesize, 0, 1024*1024, 1)
+
+ def test_setget_shm_key(self) :
+ shm_key=137
+ self.env.set_shm_key(shm_key)
+ self.assertEqual(shm_key, self.env.get_shm_key())
+ self.env.set_shm_key(shm_key+1)
+ self.assertEqual(shm_key+1, self.env.get_shm_key())
+
+ # You can not change configuration after opening
+ # the environment.
+ self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
+ # If we try to reconfigure cache after opening the
+ # environment, core dump.
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.set_shm_key, shm_key)
+ self.assertEqual(shm_key+1, self.env.get_shm_key())
+
+ if db.version() >= (4, 4) :
+ def test_mutex_setget_max(self) :
+ v = self.env.mutex_get_max()
+ v2 = v*2+1
+
+ self.env.mutex_set_max(v2)
+ self.assertEqual(v2, self.env.mutex_get_max())
+
+ self.env.mutex_set_max(v)
+ self.assertEqual(v, self.env.mutex_get_max())
+
+ # You can not change configuration after opening
+ # the environment.
+ self.env.open(self.homeDir, db.DB_CREATE)
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.mutex_set_max, v2)
+
+ def test_mutex_setget_increment(self) :
+ v = self.env.mutex_get_increment()
+ v2 = 127
+
+ self.env.mutex_set_increment(v2)
+ self.assertEqual(v2, self.env.mutex_get_increment())
+
+ self.env.mutex_set_increment(v)
+ self.assertEqual(v, self.env.mutex_get_increment())
+
+ # You can not change configuration after opening
+ # the environment.
+ self.env.open(self.homeDir, db.DB_CREATE)
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.mutex_set_increment, v2)
+
+ def test_mutex_setget_tas_spins(self) :
+ self.env.mutex_set_tas_spins(0) # Default = BDB decides
+ v = self.env.mutex_get_tas_spins()
+ v2 = v*2+1
+
+ self.env.mutex_set_tas_spins(v2)
+ self.assertEqual(v2, self.env.mutex_get_tas_spins())
+
+ self.env.mutex_set_tas_spins(v)
+ self.assertEqual(v, self.env.mutex_get_tas_spins())
+
+ # In this case, you can change configuration
+ # after opening the environment.
+ self.env.open(self.homeDir, db.DB_CREATE)
+ self.env.mutex_set_tas_spins(v2)
+
+ def test_mutex_setget_align(self) :
+ v = self.env.mutex_get_align()
+ v2 = 64
+ if v == 64 :
+ v2 = 128
+
+ self.env.mutex_set_align(v2)
+ self.assertEqual(v2, self.env.mutex_get_align())
+
+ # Requires a nonzero power of two
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.mutex_set_align, 0)
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.mutex_set_align, 17)
+
+ self.env.mutex_set_align(2*v2)
+ self.assertEqual(2*v2, self.env.mutex_get_align())
+
+ # You can not change configuration after opening
+ # the environment.
+ self.env.open(self.homeDir, db.DB_CREATE)
+ self.assertRaises(db.DBInvalidArgError,
+ self.env.mutex_set_align, v2)
+
+
+def test_suite():
+ return unittest.makeSuite(DBEnv)
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_dbtables.py Python-2.6.4/Lib/bsddb/test/test_dbtables.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_dbtables.py 2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_dbtables.py 2009-12-04 07:36:00.000000000 -0500
@@ -18,13 +18,17 @@
#
# -- Gregory P. Smith <[email protected]>
#
-# $Id: test_dbtables.py 66088 2008-08-31 14:00:51Z jesus.cea $
+# $Id: test_dbtables.py 58532 2007-10-18 07:56:54Z gregory.p.smith $
-import os, re
-try:
- import cPickle
- pickle = cPickle
-except ImportError:
+import os, re, sys
+
+if sys.version_info[0] < 3 :
+ try:
+ import cPickle
+ pickle = cPickle
+ except ImportError:
+ import pickle
+else :
import pickle
import unittest
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_distributed_transactions.py Python-2.6.4/Lib/bsddb/test/test_distributed_transactions.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_distributed_transactions.py 2008-08-31 10:00:51.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_distributed_transactions.py 2009-12-04 07:36:00.000000000 -0500
@@ -35,9 +35,9 @@ class DBTxn_distributed(unittest.TestCas
db.DB_INIT_TXN | db.DB_INIT_LOG | db.DB_INIT_MPOOL |
db.DB_INIT_LOCK, 0666)
self.db = db.DB(self.dbenv)
- self.db.set_re_len(db.DB_XIDDATASIZE)
+ self.db.set_re_len(db.DB_GID_SIZE)
if must_open_db :
- if db.version() > (4,1) :
+ if db.version() >= (4,2) :
txn=self.dbenv.txn_begin()
self.db.open(self.filename,
db.DB_QUEUE, db.DB_CREATE | db.DB_THREAD, 0666,
@@ -76,7 +76,7 @@ class DBTxn_distributed(unittest.TestCas
# let them be garbage collected.
for i in xrange(self.num_txns) :
txn = self.dbenv.txn_begin()
- gid = "%%%dd" %db.DB_XIDDATASIZE
+ gid = "%%%dd" %db.DB_GID_SIZE
gid = adapt(gid %i)
self.db.put(i, gid, txn=txn, flags=db.DB_APPEND)
txns.add(gid)
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_early_close.py Python-2.6.4/Lib/bsddb/test/test_early_close.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_early_close.py 2008-09-08 20:49:16.000000000 -0400
+++ Python-2.6.4/Lib/bsddb/test/test_early_close.py 2009-12-04 07:36:00.000000000 -0500
@@ -155,11 +155,8 @@ class DBEnvClosedEarlyCrash(unittest.Tes
db.DB_INIT_LOG | db.DB_CREATE)
d = db.DB(dbenv)
txn = dbenv.txn_begin()
- if db.version() < (4,1) :
- d.open(self.filename, dbtype = db.DB_HASH, flags = db.DB_CREATE)
- else :
- d.open(self.filename, dbtype = db.DB_HASH, flags = db.DB_CREATE,
- txn=txn)
+ d.open(self.filename, dbtype = db.DB_HASH, flags = db.DB_CREATE,
+ txn=txn)
d.put("XXX", "yyy", txn=txn)
txn.commit()
txn = dbenv.txn_begin()
@@ -168,9 +165,9 @@ class DBEnvClosedEarlyCrash(unittest.Tes
self.assertEquals(("XXX", "yyy"), c1.first())
import warnings
# Not interested in warnings about implicit close.
- with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- txn.commit()
+ warnings.simplefilter("ignore")
+ txn.commit()
+ warnings.resetwarnings()
self.assertRaises(db.DBCursorClosedError, c2.first)
if db.version() > (4,3,0) :
diff -Nupr Python-2.6.4.orig/Lib/bsddb/test/test_fileid.py Python-2.6.4/Lib/bsddb/test/test_fileid.py
--- Python-2.6.4.orig/Lib/bsddb/test/test_fileid.py 1969-12-31 19:00:00.000000000 -0500
+++ Python-2.6.4/Lib/bsddb/test/test_fileid.py 2009-12-04 07:36:00.000000000 -0500
@@ -0,0 +1,63 @@
+"""TestCase for reseting File ID.
+"""
+
+import os
+import shutil
+import unittest
+
+from test_all import db, test_support, get_new_environment_path, get_new_database_path
+
+class FileidResetTestCase(unittest.TestCase):
+ def setUp(self):
+ self.db_path_1 = get_new_database_path()
+ self.db_path_2 = get_new_database_path()
+ self.db_env_path = get_new_environment_path()
+
+ def test_fileid_reset(self):
+ # create DB 1
+ self.db1 = db.DB()
+ self.db1.open(self.db_path_1, dbtype=db.DB_HASH, flags=(db.DB_CREATE|db.DB_EXCL))
+ self.db1.put('spam', 'eggs')
+ self.db1.close()
+
+ shutil.copy(self.db_path_1, self.db_path_2)
+
+ self.db2 = db.DB()