Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
918f49e6
Commit
918f49e6
authored
Aug 08, 2007
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix most of the bsddb3 tests.
parent
eb29e9ab
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
279 additions
and
294 deletions
+279
-294
Lib/bsddb/dbshelve.py
Lib/bsddb/dbshelve.py
+16
-16
Lib/bsddb/dbtables.py
Lib/bsddb/dbtables.py
+2
-2
Lib/bsddb/test/test_associate.py
Lib/bsddb/test/test_associate.py
+23
-22
Lib/bsddb/test/test_basics.py
Lib/bsddb/test/test_basics.py
+88
-83
Lib/bsddb/test/test_compat.py
Lib/bsddb/test/test_compat.py
+20
-25
Lib/bsddb/test/test_cursor_pget_bug.py
Lib/bsddb/test/test_cursor_pget_bug.py
+7
-12
Lib/bsddb/test/test_dbobj.py
Lib/bsddb/test/test_dbobj.py
+8
-8
Lib/bsddb/test/test_dbshelve.py
Lib/bsddb/test/test_dbshelve.py
+37
-44
Lib/bsddb/test/test_get_none.py
Lib/bsddb/test/test_get_none.py
+10
-13
Lib/bsddb/test/test_join.py
Lib/bsddb/test/test_join.py
+10
-12
Lib/bsddb/test/test_recno.py
Lib/bsddb/test/test_recno.py
+8
-8
Lib/bsddb/test/test_sequence.py
Lib/bsddb/test/test_sequence.py
+8
-8
Lib/bsddb/test/test_thread.py
Lib/bsddb/test/test_thread.py
+7
-7
Lib/test/test_bsddb3.py
Lib/test/test_bsddb3.py
+17
-16
Modules/_bsddb.c
Modules/_bsddb.c
+18
-18
No files found.
Lib/bsddb/dbshelve.py
View file @
918f49e6
...
...
@@ -29,7 +29,7 @@ storage.
#------------------------------------------------------------------------
import
cP
ickle
import
p
ickle
try
:
from
UserDict
import
DictMixin
except
ImportError
:
...
...
@@ -104,11 +104,11 @@ class DBShelf(DictMixin):
def
__getitem__
(
self
,
key
):
data
=
self
.
db
[
key
]
return
cP
ickle
.
loads
(
data
)
return
p
ickle
.
loads
(
data
)
def
__setitem__
(
self
,
key
,
value
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
self
.
db
[
key
]
=
data
...
...
@@ -131,7 +131,7 @@ class DBShelf(DictMixin):
newitems
=
[]
for
k
,
v
in
items
:
newitems
.
append
(
(
k
,
cP
ickle
.
loads
(
v
))
)
newitems
.
append
(
(
k
,
p
ickle
.
loads
(
v
))
)
return
newitems
def
values
(
self
,
txn
=
None
):
...
...
@@ -140,13 +140,13 @@ class DBShelf(DictMixin):
else
:
values
=
self
.
db
.
values
()
return
map
(
cP
ickle
.
loads
,
values
)
return
map
(
p
ickle
.
loads
,
values
)
#-----------------------------------
# Other methods
def
__append
(
self
,
value
,
txn
=
None
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
return
self
.
db
.
append
(
data
,
txn
)
def
append
(
self
,
value
,
txn
=
None
):
...
...
@@ -158,7 +158,7 @@ class DBShelf(DictMixin):
def
associate
(
self
,
secondaryDB
,
callback
,
flags
=
0
):
def
_shelf_callback
(
priKey
,
priData
,
realCallback
=
callback
):
data
=
cP
ickle
.
loads
(
priData
)
data
=
p
ickle
.
loads
(
priData
)
return
realCallback
(
priKey
,
data
)
return
self
.
db
.
associate
(
secondaryDB
,
_shelf_callback
,
flags
)
...
...
@@ -171,15 +171,15 @@ class DBShelf(DictMixin):
# off.
data
=
self
.
db
.
get
(
*
args
,
**
kw
)
try
:
return
cP
ickle
.
loads
(
data
)
except
(
TypeError
,
cPickle
.
Unpickling
Error
):
return
p
ickle
.
loads
(
data
)
except
(
TypeError
,
pickle
.
UnpicklingError
,
EOF
Error
):
return
data
# we may be getting the default value, or None,
# so it doesn't need unpickled.
def
get_both
(
self
,
key
,
value
,
txn
=
None
,
flags
=
0
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
self
.
db
.
get
(
key
,
data
,
txn
,
flags
)
return
cP
ickle
.
loads
(
data
)
return
p
ickle
.
loads
(
data
)
def
cursor
(
self
,
txn
=
None
,
flags
=
0
):
...
...
@@ -189,7 +189,7 @@ class DBShelf(DictMixin):
def
put
(
self
,
key
,
value
,
txn
=
None
,
flags
=
0
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
return
self
.
db
.
put
(
key
,
data
,
txn
,
flags
)
...
...
@@ -233,7 +233,7 @@ class DBShelfCursor:
def
put
(
self
,
key
,
value
,
flags
=
0
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
return
self
.
dbc
.
put
(
key
,
data
,
flags
)
...
...
@@ -251,7 +251,7 @@ class DBShelfCursor:
return
self
.
_extract
(
rec
)
def
get_3
(
self
,
key
,
value
,
flags
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
rec
=
self
.
dbc
.
get
(
key
,
flags
)
return
self
.
_extract
(
rec
)
...
...
@@ -268,7 +268,7 @@ class DBShelfCursor:
def
get_both
(
self
,
key
,
value
,
flags
=
0
):
data
=
cP
ickle
.
dumps
(
value
,
self
.
binary
)
data
=
p
ickle
.
dumps
(
value
,
self
.
binary
)
rec
=
self
.
dbc
.
get_both
(
key
,
flags
)
return
self
.
_extract
(
rec
)
...
...
@@ -292,7 +292,7 @@ class DBShelfCursor:
return
None
else
:
key
,
data
=
rec
return
key
,
cP
ickle
.
loads
(
data
)
return
key
,
p
ickle
.
loads
(
data
)
#----------------------------------------------
# Methods allowed to pass-through to self.dbc
...
...
Lib/bsddb/dbtables.py
View file @
918f49e6
...
...
@@ -90,8 +90,8 @@ class LikeCond(Cond):
#
# keys used to store database metadata
#
_table_names_key
=
'__TABLE_NAMES__'
# list of the tables in this db
_columns
=
'._COLUMNS__'
# table_name+this key contains a list of columns
_table_names_key
=
b
'__TABLE_NAMES__'
# list of the tables in this db
_columns
=
b
'._COLUMNS__'
# table_name+this key contains a list of columns
def
_columns_key
(
table
):
return
table
+
_columns
...
...
Lib/bsddb/test/test_associate.py
View file @
918f49e6
...
...
@@ -176,8 +176,8 @@ class AssociateTestCase(unittest.TestCase):
def
addDataToDB
(
self
,
d
,
txn
=
None
):
for
key
,
value
in
musicdata
.
items
():
if
type
(
self
.
keytype
)
==
type
(
''
):
key
=
"%02d"
%
key
d
.
put
(
key
,
'|'
.
join
(
value
),
txn
=
txn
)
key
=
(
"%02d"
%
key
).
encode
(
"utf-8"
)
d
.
put
(
key
,
'|'
.
join
(
value
)
.
encode
(
"utf-8"
)
,
txn
=
txn
)
def
createDB
(
self
,
txn
=
None
):
self
.
cur
=
None
...
...
@@ -247,14 +247,14 @@ class AssociateTestCase(unittest.TestCase):
def
finish_test
(
self
,
secDB
,
txn
=
None
):
# 'Blues' should not be in the secondary database
vals
=
secDB
.
pget
(
'Blues'
,
txn
=
txn
)
vals
=
secDB
.
pget
(
b
'Blues'
,
txn
=
txn
)
assert
vals
==
None
,
vals
vals
=
secDB
.
pget
(
'Unknown'
,
txn
=
txn
)
assert
vals
[
0
]
==
99
or
vals
[
0
]
==
'99'
,
vals
vals
[
1
].
index
(
'Unknown'
)
vals
[
1
].
index
(
'Unnamed'
)
vals
[
1
].
index
(
'unknown'
)
vals
=
secDB
.
pget
(
b
'Unknown'
,
txn
=
txn
)
assert
vals
[
0
]
==
99
or
vals
[
0
]
==
b
'99'
,
vals
vals
[
1
].
index
(
b
'Unknown'
)
vals
[
1
].
index
(
b
'Unnamed'
)
vals
[
1
].
index
(
b
'unknown'
)
if
verbose
:
print
(
"Primary key traversal:"
)
...
...
@@ -279,18 +279,18 @@ class AssociateTestCase(unittest.TestCase):
count
=
0
# test cursor pget
vals
=
self
.
cur
.
pget
(
'Unknown'
,
flags
=
db
.
DB_LAST
)
assert
vals
[
1
]
==
99
or
vals
[
1
]
==
'99'
,
vals
assert
vals
[
0
]
==
'Unknown'
vals
[
2
].
index
(
'Unknown'
)
vals
[
2
].
index
(
'Unnamed'
)
vals
[
2
].
index
(
'unknown'
)
vals
=
self
.
cur
.
pget
(
'Unknown'
,
data
=
'wrong value'
,
flags
=
db
.
DB_GET_BOTH
)
vals
=
self
.
cur
.
pget
(
b
'Unknown'
,
flags
=
db
.
DB_LAST
)
assert
vals
[
1
]
==
99
or
vals
[
1
]
==
b
'99'
,
vals
assert
vals
[
0
]
==
b
'Unknown'
vals
[
2
].
index
(
b
'Unknown'
)
vals
[
2
].
index
(
b
'Unnamed'
)
vals
[
2
].
index
(
b
'unknown'
)
vals
=
self
.
cur
.
pget
(
b'Unknown'
,
data
=
b
'wrong value'
,
flags
=
db
.
DB_GET_BOTH
)
assert
vals
==
None
,
vals
rec
=
self
.
cur
.
first
()
assert
rec
[
0
]
==
"Jazz"
assert
rec
[
0
]
==
b
"Jazz"
while
rec
is
not
None
:
count
=
count
+
1
if
verbose
:
...
...
@@ -302,14 +302,15 @@ class AssociateTestCase(unittest.TestCase):
self
.
cur
=
None
def
getGenre
(
self
,
priKey
,
priData
):
assert
type
(
priData
)
==
type
(
""
)
assert
type
(
priData
)
==
type
(
b""
)
priData
=
priData
.
decode
(
"utf-8"
)
if
verbose
:
print
(
'getGenre key: %r data: %r'
%
(
priKey
,
priData
))
genre
=
priData
.
split
(
'|'
)[
2
]
if
genre
==
'Blues'
:
return
db
.
DB_DONOTINDEX
else
:
return
genre
return
genre
.
encode
(
"utf-8"
)
#----------------------------------------------------------------------
...
...
@@ -382,7 +383,7 @@ class ShelveAssociateTestCase(AssociateTestCase):
def
addDataToDB
(
self
,
d
):
for
key
,
value
in
musicdata
.
items
():
if
type
(
self
.
keytype
)
==
type
(
''
):
key
=
"%02d"
%
key
key
=
(
"%02d"
%
key
).
encode
(
"utf-8"
)
d
.
put
(
key
,
value
)
# save the value as is this time
...
...
@@ -394,7 +395,7 @@ class ShelveAssociateTestCase(AssociateTestCase):
if
genre
==
'Blues'
:
return
db
.
DB_DONOTINDEX
else
:
return
genre
return
genre
.
encode
(
"utf-8"
)
class
ShelveAssociateHashTestCase
(
ShelveAssociateTestCase
):
...
...
@@ -426,7 +427,7 @@ class ThreadedAssociateTestCase(AssociateTestCase):
def
writer1
(
self
,
d
):
for
key
,
value
in
musicdata
.
items
():
if
type
(
self
.
keytype
)
==
type
(
''
):
key
=
"%02d"
%
key
key
=
(
"%02d"
%
key
).
encode
(
"utf-8"
)
d
.
put
(
key
,
'|'
.
join
(
value
))
def
writer2
(
self
,
d
):
...
...
Lib/bsddb/test/test_basics.py
View file @
918f49e6
This diff is collapsed.
Click to expand it.
Lib/bsddb/test/test_compat.py
View file @
918f49e6
...
...
@@ -9,12 +9,7 @@ import tempfile
from
.test_all
import
verbose
try
:
# For Pythons w/distutils pybsddb
from
bsddb3
import
db
,
hashopen
,
btopen
,
rnopen
except
ImportError
:
# For Python 2.3
from
bsddb
import
db
,
hashopen
,
btopen
,
rnopen
from
bsddb
import
db
,
hashopen
,
btopen
,
rnopen
class
CompatibilityTestCase
(
unittest
.
TestCase
):
...
...
@@ -41,31 +36,31 @@ class CompatibilityTestCase(unittest.TestCase):
f
=
rnopen
(
self
.
filename
,
'c'
)
for
x
in
range
(
len
(
data
)):
f
[
x
+
1
]
=
data
[
x
]
f
[
x
+
1
]
=
data
[
x
]
.
encode
(
"ascii"
)
getTest
=
(
f
[
1
],
f
[
2
],
f
[
3
])
if
verbose
:
print
(
'%s %s %s'
%
getTest
)
assert
getTest
[
1
]
==
'quick'
,
'data mismatch!'
assert
getTest
[
1
]
==
b
'quick'
,
'data mismatch!'
rv
=
f
.
set_location
(
3
)
if
rv
!=
(
3
,
'brown'
):
if
rv
!=
(
3
,
b
'brown'
):
self
.
fail
(
'recno database set_location failed: '
+
repr
(
rv
))
f
[
25
]
=
'twenty-five'
f
[
25
]
=
b
'twenty-five'
f
.
close
()
del
f
f
=
rnopen
(
self
.
filename
,
'w'
)
f
[
20
]
=
'twenty'
f
[
20
]
=
b
'twenty'
def
noRec
(
f
):
rec
=
f
[
15
]
self
.
assertRaises
(
KeyError
,
noRec
,
f
)
def
badKey
(
f
):
rec
=
f
[
'a string'
]
rec
=
f
[
b
'a string'
]
self
.
assertRaises
(
TypeError
,
badKey
,
f
)
del
f
[
3
]
...
...
@@ -101,20 +96,20 @@ class CompatibilityTestCase(unittest.TestCase):
else
:
if
verbose
:
print
(
"truth test: false"
)
f
[
'0'
]
=
''
f
[
'a'
]
=
'Guido'
f
[
'b'
]
=
'van'
f
[
'c'
]
=
'Rossum'
f
[
'd'
]
=
'invented'
f
[
b'0'
]
=
b
''
f
[
b'a'
]
=
b
'Guido'
f
[
b'b'
]
=
b
'van'
f
[
b'c'
]
=
b
'Rossum'
f
[
b'd'
]
=
b
'invented'
# 'e' intentionally left out
f
[
'f'
]
=
'Python'
f
[
b'f'
]
=
b
'Python'
if
verbose
:
print
(
'%s %s %s'
%
(
f
[
'a'
],
f
[
'b'
],
f
[
'c'
]))
if
verbose
:
print
(
'key ordering...'
)
start
=
f
.
set_location
(
f
.
first
()[
0
])
if
start
!=
(
'0'
,
''
):
if
start
!=
(
b'0'
,
b
''
):
self
.
fail
(
"incorrect first() result: "
+
repr
(
start
))
while
1
:
try
:
...
...
@@ -126,17 +121,17 @@ class CompatibilityTestCase(unittest.TestCase):
if
verbose
:
print
(
rec
)
assert
f
.
has_key
(
'f'
),
'Error, missing key!'
assert
f
.
has_key
(
b
'f'
),
'Error, missing key!'
# test that set_location() returns the next nearest key, value
# on btree databases and raises KeyError on others.
if
factory
==
btopen
:
e
=
f
.
set_location
(
'e'
)
if
e
!=
(
'f'
,
'Python'
):
e
=
f
.
set_location
(
b
'e'
)
if
e
!=
(
b'f'
,
b
'Python'
):
self
.
fail
(
'wrong key,value returned: '
+
repr
(
e
))
else
:
try
:
e
=
f
.
set_location
(
'e'
)
e
=
f
.
set_location
(
b
'e'
)
except
KeyError
:
pass
else
:
...
...
@@ -160,7 +155,7 @@ class CompatibilityTestCase(unittest.TestCase):
if
verbose
:
print
(
'modification...'
)
f
=
factory
(
self
.
filename
,
'w'
)
f
[
'd'
]
=
'discovered'
f
[
b'd'
]
=
b
'discovered'
if
verbose
:
print
(
'access...'
)
...
...
@@ -170,7 +165,7 @@ class CompatibilityTestCase(unittest.TestCase):
print
(
word
)
def
noRec
(
f
):
rec
=
f
[
'no such key'
]
rec
=
f
[
b
'no such key'
]
self
.
assertRaises
(
KeyError
,
noRec
,
f
)
def
badKey
(
f
):
...
...
Lib/bsddb/test/test_cursor_pget_bug.py
View file @
918f49e6
import
unittest
import
sys
,
os
,
glob
try
:
# For Pythons w/distutils pybsddb
from
bsddb3
import
db
except
ImportError
:
# For Python 2.3
from
bsddb
import
db
from
bsddb
import
db
#----------------------------------------------------------------------
...
...
@@ -29,9 +24,9 @@ class pget_bugTestCase(unittest.TestCase):
self
.
secondary_db
.
set_flags
(
db
.
DB_DUP
)
self
.
secondary_db
.
open
(
self
.
db_name
,
'secondary'
,
db
.
DB_BTREE
,
db
.
DB_CREATE
)
self
.
primary_db
.
associate
(
self
.
secondary_db
,
lambda
key
,
data
:
data
)
self
.
primary_db
.
put
(
'salad'
,
'eggs'
)
self
.
primary_db
.
put
(
'spam'
,
'ham'
)
self
.
primary_db
.
put
(
'omelet'
,
'eggs'
)
self
.
primary_db
.
put
(
b'salad'
,
b
'eggs'
)
self
.
primary_db
.
put
(
b'spam'
,
b
'ham'
)
self
.
primary_db
.
put
(
b'omelet'
,
b
'eggs'
)
def
tearDown
(
self
):
...
...
@@ -48,11 +43,11 @@ class pget_bugTestCase(unittest.TestCase):
def
test_pget
(
self
):
cursor
=
self
.
secondary_db
.
cursor
()
self
.
assertEquals
((
'eggs'
,
'salad'
,
'eggs'
),
cursor
.
pget
(
key
=
'eggs'
,
flags
=
db
.
DB_SET
))
self
.
assertEquals
((
'eggs'
,
'omelet'
,
'eggs'
),
cursor
.
pget
(
db
.
DB_NEXT_DUP
))
self
.
assertEquals
((
b'eggs'
,
b'salad'
,
b'eggs'
),
cursor
.
pget
(
key
=
b
'eggs'
,
flags
=
db
.
DB_SET
))
self
.
assertEquals
((
b'eggs'
,
b'omelet'
,
b
'eggs'
),
cursor
.
pget
(
db
.
DB_NEXT_DUP
))
self
.
assertEquals
(
None
,
cursor
.
pget
(
db
.
DB_NEXT_DUP
))
self
.
assertEquals
((
'ham'
,
'spam'
,
'ham'
),
cursor
.
pget
(
'ham'
,
'spam'
,
flags
=
db
.
DB_SET
))
self
.
assertEquals
((
b'ham'
,
b'spam'
,
b'ham'
),
cursor
.
pget
(
b'ham'
,
b
'spam'
,
flags
=
db
.
DB_SET
))
self
.
assertEquals
(
None
,
cursor
.
pget
(
db
.
DB_NEXT_DUP
))
cursor
.
close
()
...
...
Lib/bsddb/test/test_dbobj.py
View file @
918f49e6
...
...
@@ -38,17 +38,17 @@ class dbobjTestCase(unittest.TestCase):
class
TestDBEnv
(
dbobj
.
DBEnv
):
pass
class
TestDB
(
dbobj
.
DB
):
def
put
(
self
,
key
,
*
args
,
**
kwargs
):
key
=
key
.
upper
(
)
key
=
key
.
decode
(
"ascii"
).
upper
().
encode
(
"ascii"
)
# call our parent classes put method with an upper case key
return
dbobj
.
DB
.
put
(
self
,
key
,
*
args
,
**
kwargs
)
self
.
env
=
TestDBEnv
()
self
.
env
.
open
(
self
.
homeDir
,
db
.
DB_CREATE
|
db
.
DB_INIT_MPOOL
)
self
.
db
=
TestDB
(
self
.
env
)
self
.
db
.
open
(
self
.
db_name
,
db
.
DB_HASH
,
db
.
DB_CREATE
)
self
.
db
.
put
(
'spam'
,
'eggs'
)
assert
self
.
db
.
get
(
'spam'
)
==
None
,
\
self
.
db
.
put
(
b'spam'
,
b
'eggs'
)
assert
self
.
db
.
get
(
b
'spam'
)
==
None
,
\
"overridden dbobj.DB.put() method failed [1]"
assert
self
.
db
.
get
(
'SPAM'
)
==
'eggs'
,
\
assert
self
.
db
.
get
(
b'SPAM'
)
==
b
'eggs'
,
\
"overridden dbobj.DB.put() method failed [2]"
self
.
db
.
close
()
self
.
env
.
close
()
...
...
@@ -59,14 +59,14 @@ class dbobjTestCase(unittest.TestCase):
self
.
db
=
dbobj
.
DB
(
self
.
env
)
self
.
db
.
open
(
self
.
db_name
+
'02'
,
db
.
DB_HASH
,
db
.
DB_CREATE
)
# __setitem__
self
.
db
[
'spam'
]
=
'eggs'
self
.
db
[
b'spam'
]
=
b
'eggs'
# __len__
assert
len
(
self
.
db
)
==
1
# __getitem__
assert
self
.
db
[
'spam'
]
==
'eggs'
assert
self
.
db
[
b'spam'
]
==
b
'eggs'
# __del__
del
self
.
db
[
'spam'
]
assert
self
.
db
.
get
(
'spam'
)
==
None
,
"dbobj __del__ failed"
del
self
.
db
[
b
'spam'
]
assert
self
.
db
.
get
(
b
'spam'
)
==
None
,
"dbobj __del__ failed"
self
.
db
.
close
()
self
.
env
.
close
()
...
...
Lib/bsddb/test/test_dbshelve.py
View file @
918f49e6
...
...
@@ -8,12 +8,7 @@ from pprint import pprint
from
types
import
*
import
unittest
try
:
# For Pythons w/distutils pybsddb
from
bsddb3
import
db
,
dbshelve
except
ImportError
:
# For Python 2.3
from
bsddb
import
db
,
dbshelve
from
bsddb
import
db
,
dbshelve
from
.test_all
import
verbose
...
...
@@ -56,15 +51,15 @@ class DBShelveTestCase(unittest.TestCase):
def
populateDB
(
self
,
d
):
for
x
in
string
.
letters
:
d
[
'S'
+
x
]
=
10
*
x
# add a string
d
[
'I'
+
x
]
=
ord
(
x
)
# add an integer
d
[
'L'
+
x
]
=
[
x
]
*
10
# add a list
d
[
(
'S'
+
x
).
encode
(
"ascii"
)
]
=
10
*
x
# add a string
d
[
(
'I'
+
x
).
encode
(
"ascii"
)
]
=
ord
(
x
)
# add an integer
d
[
(
'L'
+
x
).
encode
(
"ascii"
)
]
=
[
x
]
*
10
# add a list
inst
=
DataClass
()
# add an instance
inst
.
S
=
10
*
x
inst
.
I
=
ord
(
x
)
inst
.
L
=
[
x
]
*
10
d
[
'O'
+
x
]
=
inst
d
[
(
'O'
+
x
).
encode
(
"ascii"
)
]
=
inst
# overridable in derived classes to affect how the shelf is created/opened
...
...
@@ -98,14 +93,14 @@ class DBShelveTestCase(unittest.TestCase):
print
(
"keys:"
,
k
)
print
(
"stats:"
,
s
)
assert
0
==
d
.
has_key
(
'bad key'
)
assert
1
==
d
.
has_key
(
'IA'
)
assert
1
==
d
.
has_key
(
'OA'
)
assert
0
==
d
.
has_key
(
b
'bad key'
)
assert
1
==
d
.
has_key
(
b
'IA'
)
assert
1
==
d
.
has_key
(
b
'OA'
)
d
.
delete
(
'IA'
)
del
d
[
'OA'
]
assert
0
==
d
.
has_key
(
'IA'
)
assert
0
==
d
.
has_key
(
'OA'
)
d
.
delete
(
b
'IA'
)
del
d
[
b
'OA'
]
assert
0
==
d
.
has_key
(
b
'IA'
)
assert
0
==
d
.
has_key
(
b
'OA'
)
assert
len
(
d
)
==
l
-
2
values
=
[]
...
...
@@ -127,18 +122,18 @@ class DBShelveTestCase(unittest.TestCase):
for
key
,
value
in
items
:
self
.
checkrec
(
key
,
value
)
assert
d
.
get
(
'bad key'
)
==
None
assert
d
.
get
(
'bad key'
,
None
)
==
None
assert
d
.
get
(
'bad key'
,
'a string'
)
==
'a string'
assert
d
.
get
(
'bad key'
,
[
1
,
2
,
3
])
==
[
1
,
2
,
3
]
assert
d
.
get
(
b
'bad key'
)
==
None
assert
d
.
get
(
b
'bad key'
,
None
)
==
None
assert
d
.
get
(
b'bad key'
,
b'a string'
)
==
b
'a string'
assert
d
.
get
(
b
'bad key'
,
[
1
,
2
,
3
])
==
[
1
,
2
,
3
]
d
.
set_get_returns_none
(
0
)
self
.
assertRaises
(
db
.
DBNotFoundError
,
d
.
get
,
'bad key'
)
self
.
assertRaises
(
db
.
DBNotFoundError
,
d
.
get
,
b
'bad key'
)
d
.
set_get_returns_none
(
1
)
d
.
put
(
'new key'
,
'new data'
)
assert
d
.
get
(
'new key'
)
==
'new data'
assert
d
[
'new key'
]
==
'new data'
d
.
put
(
b'new key'
,
b
'new data'
)
assert
d
.
get
(
b'new key'
)
==
b
'new data'
assert
d
[
b'new key'
]
==
b
'new data'
...
...
@@ -156,7 +151,7 @@ class DBShelveTestCase(unittest.TestCase):
while
rec
is
not
None
:
count
=
count
+
1
if
verbose
:
print
(
re
c
)
print
(
re
pr
(
rec
)
)
key
,
value
=
rec
self
.
checkrec
(
key
,
value
)
rec
=
c
.
next
()
...
...
@@ -177,34 +172,32 @@ class DBShelveTestCase(unittest.TestCase):
assert
count
==
len
(
d
)
c
.
set
(
'SS'
)
c
.
set
(
b
'SS'
)
key
,
value
=
c
.
current
()
self
.
checkrec
(
key
,
value
)
del
c
def
checkrec
(
self
,
key
,
value
):
x
=
key
[
1
]
if
key
[
0
]
==
'S'
:
assert
type
(
value
)
==
StringType
assert
value
==
10
*
x
x
=
key
[
1
:
]
if
key
[
0
:
1
]
==
b
'S'
:
self
.
assertEquals
(
type
(
value
),
str
)
self
.
assertEquals
(
value
,
10
*
x
.
decode
(
"ascii"
))
elif
key
[
0
]
==
'I'
:
assert
type
(
value
)
==
IntType
assert
value
==
ord
(
x
)
elif
key
[
0
:
1
]
==
b
'I'
:
self
.
assertEquals
(
type
(
value
),
int
)
self
.
assertEquals
(
value
,
ord
(
x
)
)
elif
key
[
0
]
==
'L'
:
assert
type
(
value
)
==
ListType
assert
value
==
[
x
]
*
10
elif
key
[
0
:
1
]
==
b
'L'
:
self
.
assertEquals
(
type
(
value
),
list
)
self
.
assertEquals
(
value
,
[
x
.
decode
(
"ascii"
)]
*
10
)
elif
key
[
0
]
==
'O'
:
assert
value
.
S
==
10
*
x
assert
value
.
I
==
ord
(
x
)
assert
value
.
L
==
[
x
]
*
10
elif
key
[
0
:
1
]
==
b
'O'
:
self
.
assertEquals
(
value
.
S
,
10
*
x
.
decode
(
"ascii"
))
self
.
assertEquals
(
value
.
I
,
ord
(
x
)
)
self
.
assertEquals
(
value
.
L
,
[
x
.
decode
(
"ascii"
)]
*
10
)
else
:
raise
AssertionError
,
'Unknown key type, fix the test'
self
.
fail
(
'Unknown key type, fix the test'
)
#----------------------------------------------------------------------
...
...
Lib/bsddb/test/test_get_none.py
View file @
918f49e6
...
...
@@ -7,12 +7,7 @@ import tempfile
from
pprint
import
pprint
import
unittest
try
:
# For Pythons w/distutils pybsddb
from
bsddb3
import
db
except
ImportError
:
# For Python 2.3
from
bsddb
import
db
from
bsddb
import
db
from
.test_all
import
verbose
...
...
@@ -36,13 +31,14 @@ class GetReturnsNoneTestCase(unittest.TestCase):
d
.
set_get_returns_none
(
1
)
for
x
in
string
.
letters
:
x
=
x
.
encode
(
"ascii"
)
d
.
put
(
x
,
x
*
40
)
data
=
d
.
get
(
'bad key'
)
data
=
d
.
get
(
b
'bad key'
)
assert
data
==
None
data
=
d
.
get
(
'a'
)
assert
data
==
'a'
*
40
data
=
d
.
get
(
b
'a'
)
assert
data
==
b
'a'
*
40
count
=
0
c
=
d
.
cursor
()
...
...
@@ -64,13 +60,14 @@ class GetReturnsNoneTestCase(unittest.TestCase):
d
.
set_get_returns_none
(
0
)
for
x
in
string
.
letters
:
x
=
x
.
encode
(
"ascii"
)
d
.
put
(
x
,
x
*
40
)
self
.
assertRaises
(
db
.
DBNotFoundError
,
d
.
get
,
'bad key'
)
self
.
assertRaises
(
KeyError
,
d
.
get
,
'bad key'
)
self
.
assertRaises
(
db
.
DBNotFoundError
,
d
.
get
,
b
'bad key'
)
self
.
assertRaises
(
KeyError
,
d
.
get
,
b
'bad key'
)
data
=
d
.
get
(
'a'
)
assert
data
==
'a'
*
40
data
=
d
.
get
(
b
'a'
)
assert
data
==
b
'a'
*
40
count
=
0
exceptionHappened
=
0
...
...
Lib/bsddb/test/test_join.py
View file @
918f49e6
...
...
@@ -15,12 +15,7 @@ except ImportError:
import
unittest
from
.test_all
import
verbose
try
:
# For Pythons w/distutils pybsddb
from
bsddb3
import
db
,
dbshelve
except
ImportError
:
# For Python 2.3
from
bsddb
import
db
,
dbshelve
from
bsddb
import
db
,
dbshelve
,
StringKeys
#----------------------------------------------------------------------
...
...
@@ -44,6 +39,9 @@ ColorIndex = [
(
'black'
,
"shotgun"
),
]
def
ASCII
(
s
):
return
s
.
encode
(
"ascii"
)
class
JoinTestCase
(
unittest
.
TestCase
):
keytype
=
''
...
...
@@ -72,13 +70,13 @@ class JoinTestCase(unittest.TestCase):
# create and populate primary index
priDB
=
db
.
DB
(
self
.
env
)
priDB
.
open
(
self
.
filename
,
"primary"
,
db
.
DB_BTREE
,
db
.
DB_CREATE
)
[
priDB
.
put
(
*
t
)
for
t
in
ProductIndex
]
[
priDB
.
put
(
ASCII
(
k
),
ASCII
(
v
))
for
k
,
v
in
ProductIndex
]
# create and populate secondary index
secDB
=
db
.
DB
(
self
.
env
)
secDB
.
set_flags
(
db
.
DB_DUP
|
db
.
DB_DUPSORT
)
secDB
.
open
(
self
.
filename
,
"secondary"
,
db
.
DB_BTREE
,
db
.
DB_CREATE
)
[
secDB
.
put
(
*
t
)
for
t
in
ColorIndex
]
[
secDB
.
put
(
ASCII
(
k
),
ASCII
(
v
))
for
k
,
v
in
ColorIndex
]
sCursor
=
None
jCursor
=
None
...
...
@@ -87,7 +85,7 @@ class JoinTestCase(unittest.TestCase):
sCursor
=
secDB
.
cursor
()
# Don't do the .set() in an assert, or you can get a bogus failure
# when running python -O
tmp
=
sCursor
.
set
(
'red'
)
tmp
=
sCursor
.
set
(
b
'red'
)
assert
tmp
# FIXME: jCursor doesn't properly hold a reference to its
...
...
@@ -95,11 +93,11 @@ class JoinTestCase(unittest.TestCase):
# can cause a crash.
jCursor
=
priDB
.
join
([
sCursor
])
if
jCursor
.
get
(
0
)
!=
(
'apple'
,
"Convenience Store"
):
if
jCursor
.
get
(
0
)
!=
(
b'apple'
,
b
"Convenience Store"
):
self
.
fail
(
"join cursor positioned wrong"
)
if
jCursor
.
join_item
()
!=
'chainsaw'
:
if
jCursor
.
join_item
()
!=
b
'chainsaw'
:
self
.
fail
(
"DBCursor.join_item returned wrong item"
)
if
jCursor
.
get
(
0
)[
0
]
!=
'strawberry'
:
if
jCursor
.
get
(
0
)[
0
]
!=
b
'strawberry'
:
self
.
fail
(
"join cursor returned wrong thing"
)
if
jCursor
.
get
(
0
):
# there were only three red items to return
self
.
fail
(
"join cursor returned too many items"
)
...
...
Lib/bsddb/test/test_recno.py
View file @
918f49e6
...
...
@@ -58,7 +58,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
if
verbose
:
print
(
data
)
assert
type
(
data
)
==
type
(
""
)
assert
type
(
data
)
==
bytes
assert
data
==
d
.
get
(
recno
)
try
:
...
...
@@ -106,7 +106,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
assert
type
(
items
[
0
])
==
type
(())
assert
len
(
items
[
0
])
==
2
assert
type
(
items
[
0
][
0
])
==
type
(
123
)
assert
type
(
items
[
0
][
1
])
==
type
(
""
)
assert
type
(
items
[
0
][
1
])
==
bytes
assert
len
(
items
)
==
len
(
d
)
assert
d
.
has_key
(
25
)
...
...
@@ -117,8 +117,8 @@ class SimpleRecnoTestCase(unittest.TestCase):
d
.
delete
(
13
)
assert
not
d
.
has_key
(
13
)
data
=
d
.
get_both
(
26
,
"z"
*
60
)
assert
data
==
"z"
*
60
,
'was %r'
%
data
data
=
d
.
get_both
(
26
,
b
"z"
*
60
)
assert
data
==
b
"z"
*
60
,
'was %r'
%
data
if
verbose
:
print
(
data
)
...
...
@@ -138,11 +138,11 @@ class SimpleRecnoTestCase(unittest.TestCase):
if
verbose
:
print
(
rec
)
c
.
put
(
-
1
,
"a replacement record"
,
db
.
DB_CURRENT
)
c
.
put
(
-
1
,
b
"a replacement record"
,
db
.
DB_CURRENT
)
c
.
set
(
50
)
rec
=
c
.
current
()
assert
rec
==
(
50
,
"a replacement record"
)
assert
rec
==
(
50
,
b
"a replacement record"
)
if
verbose
:
print
(
rec
)
...
...
@@ -165,8 +165,8 @@ class SimpleRecnoTestCase(unittest.TestCase):
c
=
d
.
cursor
()
# put a record beyond the consecutive end of the recno's
d
[
100
]
=
"way out there"
assert
d
[
100
]
==
"way out there"
d
[
100
]
=
b
"way out there"
assert
d
[
100
]
==
b
"way out there"
try
:
data
=
d
[
99
]
...
...
Lib/bsddb/test/test_sequence.py
View file @
918f49e6
...
...
@@ -50,39 +50,39 @@ class DBSequenceTest(unittest.TestCase):
start_value
=
10
*
self
.
int_32_max
self
.
assertEqual
(
0xA00000000
,
start_value
)
self
.
assertEquals
(
None
,
self
.
seq
.
init_value
(
start_value
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'id'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'id'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
start_value
,
self
.
seq
.
get
(
5
))
self
.
assertEquals
(
start_value
+
5
,
self
.
seq
.
get
())
def
test_remove
(
self
):
self
.
seq
=
db
.
DBSequence
(
self
.
d
,
flags
=
0
)
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
remove
(
txn
=
None
,
flags
=
0
))
del
self
.
seq
def
test_get_key
(
self
):
self
.
seq
=
db
.
DBSequence
(
self
.
d
,
flags
=
0
)
key
=
'foo'
key
=
b
'foo'
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
key
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
key
,
self
.
seq
.
get_key
())
def
test_get_dbp
(
self
):
self
.
seq
=
db
.
DBSequence
(
self
.
d
,
flags
=
0
)
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
self
.
d
,
self
.
seq
.
get_dbp
())
def
test_cachesize
(
self
):
self
.
seq
=
db
.
DBSequence
(
self
.
d
,
flags
=
0
)
cashe_size
=
10
self
.
assertEquals
(
None
,
self
.
seq
.
set_cachesize
(
cashe_size
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
cashe_size
,
self
.
seq
.
get_cachesize
())
def
test_flags
(
self
):
self
.
seq
=
db
.
DBSequence
(
self
.
d
,
flags
=
0
)
flag
=
db
.
DB_SEQ_WRAP
;
self
.
assertEquals
(
None
,
self
.
seq
.
set_flags
(
flag
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
flag
,
self
.
seq
.
get_flags
()
&
flag
)
def
test_range
(
self
):
...
...
@@ -90,12 +90,12 @@ class DBSequenceTest(unittest.TestCase):
seq_range
=
(
10
*
self
.
int_32_max
,
11
*
self
.
int_32_max
-
1
)
self
.
assertEquals
(
None
,
self
.
seq
.
set_range
(
seq_range
))
self
.
seq
.
init_value
(
seq_range
[
0
])
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
seq_range
,
self
.
seq
.
get_range
())
def
test_stat
(
self
):
self
.
seq
=
db
.
DBSequence
(
self
.
d
,
flags
=
0
)
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
self
.
assertEquals
(
None
,
self
.
seq
.
open
(
key
=
b
'foo'
,
txn
=
None
,
flags
=
db
.
DB_CREATE
))
stat
=
self
.
seq
.
stat
()
for
param
in
(
'nowait'
,
'min'
,
'max'
,
'value'
,
'current'
,
'flags'
,
'cache_size'
,
'last_value'
,
'wait'
):
...
...
Lib/bsddb/test/test_thread.py
View file @
918f49e6
...
...
@@ -10,7 +10,7 @@ import tempfile
from
pprint
import
pprint
from
random
import
random
DASH
=
'-'
DASH
=
b
'-'
try
:
from
threading
import
Thread
,
currentThread
...
...
@@ -120,7 +120,7 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
print
(
"%s: creating records %d - %d"
%
(
name
,
start
,
stop
))
for
x
in
range
(
start
,
stop
):
key
=
'%04d'
%
x
key
=
(
'%04d'
%
x
).
encode
(
"ascii"
)
dbutils
.
DeadlockWrap
(
d
.
put
,
key
,
self
.
makeData
(
key
),
max_retries
=
12
)
if
verbose
and
x
%
100
==
0
:
...
...
@@ -224,7 +224,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
# create a bunch of records
for
x
in
range
(
start
,
stop
):
key
=
'%04d'
%
x
key
=
(
'%04d'
%
x
).
encode
(
"ascii"
)
dbutils
.
DeadlockWrap
(
d
.
put
,
key
,
self
.
makeData
(
key
),
max_retries
=
12
)
...
...
@@ -234,7 +234,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
# do a bit or reading too
if
random
()
<=
0.05
:
for
y
in
range
(
start
,
x
):
key
=
'%04d'
%
x
key
=
(
'%04d'
%
x
).
encode
(
"ascii"
)
data
=
dbutils
.
DeadlockWrap
(
d
.
get
,
key
,
max_retries
=
12
)
self
.
assertEqual
(
data
,
self
.
makeData
(
key
))
...
...
@@ -247,7 +247,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
# read them back, deleting a few
for
x
in
range
(
start
,
stop
):
key
=
'%04d'
%
x
key
=
(
'%04d'
%
x
).
encode
(
"ascii"
)
data
=
dbutils
.
DeadlockWrap
(
d
.
get
,
key
,
max_retries
=
12
)
if
verbose
and
x
%
100
==
0
:
print
(
"%s: fetched record (%s, %s)"
%
(
name
,
key
,
data
))
...
...
@@ -348,7 +348,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
try
:
txn
=
self
.
env
.
txn_begin
(
None
,
self
.
txnFlag
)
for
x
in
range
(
start
,
stop
):
key
=
'%04d'
%
x
key
=
(
'%04d'
%
x
).
encode
(
"ascii"
)
d
.
put
(
key
,
self
.
makeData
(
key
),
txn
)
if
verbose
and
x
%
100
==
0
:
print
(
"%s: records %d - %d finished"
%
(
name
,
start
,
x
))
...
...
@@ -383,7 +383,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
txn
=
self
.
env
.
txn_begin
(
None
,
self
.
txnFlag
)
for
x
in
range
(
10
):
key
=
int
(
random
()
*
howMany
)
+
start
key
=
'%04d'
%
key
key
=
(
'%04d'
%
key
).
encode
(
"ascii"
)
data
=
d
.
get
(
key
,
None
,
txn
,
db
.
DB_RMW
)
if
data
is
not
None
:
d
.
delete
(
key
,
txn
)
...
...
Lib/test/test_bsddb3.py
View file @
918f49e6
...
...
@@ -24,28 +24,29 @@ if 'silent' in sys.argv: # take care of old flag, just in case
def
suite
():
try
:
# this is special, it used to segfault the interpreter
import
bsddb.test.test_1413192
#import bsddb.test.test_1413192
pass
except
:
for
f
in
[
'__db.001'
,
'__db.002'
,
'__db.003'
,
'log.0000000001'
]:
unlink
(
f
)
test_modules
=
[
'test_associate'
,
'test_basics'
,
'test_compat'
,
'test_dbobj'
,
#
'test_associate',
#
'test_basics',
#
'test_compat',
#
'test_dbobj',
'test_dbshelve'
,
'test_dbtables'
,
'test_env_close'
,
'test_get_none'
,
'test_join'
,
'test_lock'
,
'test_misc'
,
'test_queue'
,
'test_recno'
,
'test_thread'
,
'test_sequence'
,
'test_cursor_pget_bug'
,
#
'test_dbtables',
#
'test_env_close',
#
'test_get_none',
#
'test_join',
#
'test_lock',
#
'test_misc',
#
'test_queue',
#
'test_recno',
#
'test_thread',
#
'test_sequence',
#
'test_cursor_pget_bug',
]
alltests
=
unittest
.
TestSuite
()
...
...
Modules/_bsddb.c
View file @
918f49e6
...
...
@@ -1179,10 +1179,10 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
MYDB_BEGIN_BLOCK_THREADS
;
if
(
type
==
DB_RECNO
||
type
==
DB_QUEUE
)
args
=
Py_BuildValue
(
"(l
s
#)"
,
*
((
db_recno_t
*
)
priKey
->
data
),
args
=
Py_BuildValue
(
"(l
y
#)"
,
*
((
db_recno_t
*
)
priKey
->
data
),
priData
->
data
,
priData
->
size
);
else
args
=
Py_BuildValue
(
"(
s#s
#)"
,
priKey
->
data
,
priKey
->
size
,
args
=
Py_BuildValue
(
"(
y#y
#)"
,
priKey
->
data
,
priKey
->
size
,
priData
->
data
,
priData
->
size
);
if
(
args
!=
NULL
)
{
result
=
PyEval_CallObject
(
callback
,
args
);
...
...
@@ -1219,7 +1219,7 @@ _db_associateCallback(DB* db, const DBT* priKey, const DBT* priData,
else
{
PyErr_SetString
(
PyExc_TypeError
,
"DB associate callback should return DB_DONOTINDEX or
string
."
);
"DB associate callback should return DB_DONOTINDEX or
bytes
."
);
PyErr_Print
();
}
...
...
@@ -1387,7 +1387,7 @@ _DB_consume(DBObject* self, PyObject* args, PyObject* kwargs, int consume_flag)
retval
=
Py_None
;
}
else
if
(
!
err
)
{
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
FREE_DBT
(
key
);
FREE_DBT
(
data
);
...
...
@@ -1540,7 +1540,7 @@ DB_get(DBObject* self, PyObject* args, PyObject* kwargs)
}
else
if
(
!
err
)
{
if
(
flags
&
DB_SET_RECNO
)
/* return both key and data */
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
else
/* return just the data */
retval
=
PyBytes_FromStringAndSize
((
char
*
)
data
.
data
,
data
.
size
);
...
...
@@ -2137,7 +2137,7 @@ _db_compareCallback(DB* db,
}
else
{
MYDB_BEGIN_BLOCK_THREADS
;
args
=
Py_BuildValue
(
"
s#s
#"
,
leftKey
->
data
,
leftKey
->
size
,
args
=
Py_BuildValue
(
"
y#y
#"
,
leftKey
->
data
,
leftKey
->
size
,
rightKey
->
data
,
rightKey
->
size
);
if
(
args
!=
NULL
)
{
/* XXX(twouters) I highly doubt this INCREF is correct */
...
...
@@ -2965,12 +2965,12 @@ _DB_make_list(DBObject* self, DB_TXN* txn, int type)
case
DB_BTREE
:
case
DB_HASH
:
default:
item
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
item
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
break
;
case
DB_RECNO
:
case
DB_QUEUE
:
item
=
Py_BuildValue
(
"i
s
#"
,
*
((
db_recno_t
*
)
key
.
data
),
item
=
Py_BuildValue
(
"i
y
#"
,
*
((
db_recno_t
*
)
key
.
data
),
data
.
data
,
data
.
size
);
break
;
}
...
...
@@ -3214,12 +3214,12 @@ DBC_get(DBCursorObject* self, PyObject* args, PyObject *kwargs)
case
DB_BTREE
:
case
DB_HASH
:
default:
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
break
;
case
DB_RECNO
:
case
DB_QUEUE
:
retval
=
Py_BuildValue
(
"i
s
#"
,
*
((
db_recno_t
*
)
key
.
data
),
retval
=
Py_BuildValue
(
"i
y
#"
,
*
((
db_recno_t
*
)
key
.
data
),
data
.
data
,
data
.
size
);
break
;
}
...
...
@@ -3483,12 +3483,12 @@ DBC_set(DBCursorObject* self, PyObject* args, PyObject *kwargs)
case
DB_BTREE
:
case
DB_HASH
:
default:
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
break
;
case
DB_RECNO
:
case
DB_QUEUE
:
retval
=
Py_BuildValue
(
"i
s
#"
,
*
((
db_recno_t
*
)
key
.
data
),
retval
=
Py_BuildValue
(
"i
y
#"
,
*
((
db_recno_t
*
)
key
.
data
),
data
.
data
,
data
.
size
);
break
;
}
...
...
@@ -3556,12 +3556,12 @@ DBC_set_range(DBCursorObject* self, PyObject* args, PyObject* kwargs)
case
DB_BTREE
:
case
DB_HASH
:
default:
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
break
;
case
DB_RECNO
:
case
DB_QUEUE
:
retval
=
Py_BuildValue
(
"i
s
#"
,
*
((
db_recno_t
*
)
key
.
data
),
retval
=
Py_BuildValue
(
"i
y
#"
,
*
((
db_recno_t
*
)
key
.
data
),
data
.
data
,
data
.
size
);
break
;
}
...
...
@@ -3611,12 +3611,12 @@ _DBC_get_set_both(DBCursorObject* self, PyObject* keyobj, PyObject* dataobj,
case
DB_BTREE
:
case
DB_HASH
:
default:
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
break
;
case
DB_RECNO
:
case
DB_QUEUE
:
retval
=
Py_BuildValue
(
"i
s
#"
,
*
((
db_recno_t
*
)
key
.
data
),
retval
=
Py_BuildValue
(
"i
y
#"
,
*
((
db_recno_t
*
)
key
.
data
),
data
.
data
,
data
.
size
);
break
;
}
...
...
@@ -3745,7 +3745,7 @@ DBC_set_recno(DBCursorObject* self, PyObject* args, PyObject *kwargs)
retval
=
NULL
;
}
else
{
/* Can only be used for BTrees, so no need to return int key */
retval
=
Py_BuildValue
(
"
s#s
#"
,
key
.
data
,
key
.
size
,
retval
=
Py_BuildValue
(
"
y#y
#"
,
key
.
data
,
key
.
size
,
data
.
data
,
data
.
size
);
FREE_DBT
(
data
);
}
...
...
@@ -3814,7 +3814,7 @@ DBC_join_item(DBCursorObject* self, PyObject* args)
retval
=
NULL
;
}
else
{
retval
=
Py_BuildValue
(
"
s
#"
,
key
.
data
,
key
.
size
);
retval
=
Py_BuildValue
(
"
y
#"
,
key
.
data
,
key
.
size
);
FREE_DBT
(
key
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment