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
361ed153
Commit
361ed153
authored
Aug 23, 2007
by
Gregory P. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require strict bytes objects for all bsddb.db input values.
parent
e5a8dc68
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
77 deletions
+80
-77
Lib/bsddb/test/test_dbtables.py
Lib/bsddb/test/test_dbtables.py
+53
-53
Lib/bsddb/test/test_lock.py
Lib/bsddb/test/test_lock.py
+2
-2
Lib/bsddb/test/test_queue.py
Lib/bsddb/test/test_queue.py
+12
-12
Lib/bsddb/test/test_recno.py
Lib/bsddb/test/test_recno.py
+7
-7
Modules/_bsddb.c
Modules/_bsddb.c
+6
-3
No files found.
Lib/bsddb/test/test_dbtables.py
View file @
361ed153
...
...
@@ -88,9 +88,9 @@ class TableDBTestCase(unittest.TestCase):
col1
=
'but can it fly?'
col2
=
'Species'
testinfo
=
[
{
col0
:
pickle
.
dumps
(
8
,
1
),
col1
:
'no'
,
col2
:
'Penguin'
},
{
col0
:
pickle
.
dumps
(
-
1
,
1
),
col1
:
'no'
,
col2
:
'Turkey'
},
{
col0
:
pickle
.
dumps
(
9
,
1
),
col1
:
'yes'
,
col2
:
'SR-71A Blackbird'
}
{
col0
:
pickle
.
dumps
(
8
,
1
),
col1
:
b'no'
,
col2
:
b
'Penguin'
},
{
col0
:
pickle
.
dumps
(
-
1
,
1
),
col1
:
b'no'
,
col2
:
b
'Turkey'
},
{
col0
:
pickle
.
dumps
(
9
,
1
),
col1
:
b'yes'
,
col2
:
b
'SR-71A Blackbird'
}
]
try
:
...
...
@@ -150,22 +150,22 @@ class TableDBTestCase(unittest.TestCase):
pass
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
'42'
,
'b'
:
"bad"
,
'c'
:
"meep"
,
'e'
:
'Fuzzy wuzzy was a bear'
})
{
'a'
:
b
'42'
,
'b'
:
b'bad'
,
'c'
:
b'meep'
,
'e'
:
b
'Fuzzy wuzzy was a bear'
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
'581750'
,
'b'
:
"good"
,
'd'
:
"bla"
,
'c'
:
"black"
,
'e'
:
'fuzzy was here'
})
{
'a'
:
b
'581750'
,
'b'
:
b'good'
,
'd'
:
b'bla'
,
'c'
:
b'black'
,
'e'
:
b
'fuzzy was here'
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
'800000'
,
'b'
:
"good"
,
'd'
:
"bla"
,
'c'
:
"black"
,
'e'
:
'Fuzzy wuzzy is a bear'
})
{
'a'
:
b
'800000'
,
'b'
:
b'good'
,
'd'
:
b'bla'
,
'c'
:
b'black'
,
'e'
:
b
'Fuzzy wuzzy is a bear'
})
if
verbose
:
self
.
tdb
.
_db_print
()
...
...
@@ -202,19 +202,19 @@ class TableDBTestCase(unittest.TestCase):
try
:
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
""
,
{
'a'
:
b
""
,
'e'
:
pickle
.
dumps
([{
4
:
5
,
6
:
7
},
'foo'
],
1
),
'f'
:
"Zero"
})
'f'
:
b
"Zero"
})
self
.
fail
(
"exception not raised"
)
except
dbtables
.
TableDBError
:
pass
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
"A"
,
'b'
:
"B"
,
'c'
:
"C"
,
'd'
:
"D
"
,
'
e'
:
"E"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
"-A"
,
'b'
:
"-B"
,
'c'
:
"-C"
,
'd'
:
"-D
"
,
'
e'
:
"-E"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
"A-"
,
'b'
:
"B-"
,
'c'
:
"C-"
,
'd'
:
"D
-"
,
'
e'
:
"E-"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
b"A"
,
'b'
:
b"B"
,
'c'
:
b"C
"
,
'
d'
:
b"D"
,
'e'
:
b
"E"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
b"-A"
,
'b'
:
b"-B"
,
'c'
:
b"-C
"
,
'
d'
:
b"-D"
,
'e'
:
b
"-E"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
b"A-"
,
'b'
:
b"B-"
,
'c'
:
b"C
-"
,
'
d'
:
b"D-"
,
'e'
:
b
"E-"
})
if
verbose
:
self
.
tdb
.
_db_print
()
...
...
@@ -239,9 +239,9 @@ class TableDBTestCase(unittest.TestCase):
tabname
,
[
'name'
,
'taste'
,
'filling'
,
'alcohol content'
,
'price'
])
try
:
self
.
tdb
.
Insert
(
tabname
,
{
'taste'
:
'crap'
,
'filling'
:
'no'
,
'is it Guinness?'
:
'no'
})
{
'taste'
:
b
'crap'
,
'filling'
:
b
'no'
,
'is it Guinness?'
:
b
'no'
})
self
.
fail
(
"Insert should've failed due to bad column name"
)
except
:
pass
...
...
@@ -249,11 +249,11 @@ class TableDBTestCase(unittest.TestCase):
[
'name'
,
'taste'
,
'is it Guinness?'
])
# these should both succeed as the table should contain the union of both sets of columns.
self
.
tdb
.
Insert
(
tabname
,
{
'taste'
:
'crap'
,
'filling'
:
'no'
,
'is it Guinness?'
:
'no'
})
self
.
tdb
.
Insert
(
tabname
,
{
'taste'
:
'great'
,
'filling'
:
'yes'
,
'is it Guinness?'
:
'yes'
,
'name'
:
'Guinness'
})
self
.
tdb
.
Insert
(
tabname
,
{
'taste'
:
b'crap'
,
'filling'
:
b
'no'
,
'is it Guinness?'
:
b
'no'
})
self
.
tdb
.
Insert
(
tabname
,
{
'taste'
:
b'great'
,
'filling'
:
b
'yes'
,
'is it Guinness?'
:
b
'yes'
,
'name'
:
b
'Guinness'
})
def
test_CondObjs
(
self
):
...
...
@@ -261,17 +261,17 @@ class TableDBTestCase(unittest.TestCase):
self
.
tdb
.
CreateTable
(
tabname
,
[
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'p'
])
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
"the letter A"
,
'b'
:
"the letter B"
,
'c'
:
"is for cookie"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
"is for aardvark"
,
'e'
:
"the letter E"
,
'c'
:
"is for cookie"
,
'd'
:
"is for dog"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
"the letter A"
,
'e'
:
"the letter E"
,
'c'
:
"is for cookie"
,
'p'
:
"is for Python"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
b
"the letter A"
,
'b'
:
b
"the letter B"
,
'c'
:
b
"is for cookie"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
b
"is for aardvark"
,
'e'
:
b
"the letter E"
,
'c'
:
b
"is for cookie"
,
'd'
:
b
"is for dog"
})
self
.
tdb
.
Insert
(
tabname
,
{
'a'
:
b
"the letter A"
,
'e'
:
b
"the letter E"
,
'c'
:
b
"is for cookie"
,
'p'
:
b
"is for Python"
})
values
=
self
.
tdb
.
Select
(
tabname
,
[
'p'
,
'e'
],
...
...
@@ -309,8 +309,8 @@ class TableDBTestCase(unittest.TestCase):
# fail if it encountered any rows that did not have values in
# every column.
# Hunted and Squashed by <Donwulff> (Jukka Santala - donwulff@nic.fi)
self
.
tdb
.
Insert
(
tabname
,
{
'x'
:
'X1'
,
'y'
:
'Y1'
})
self
.
tdb
.
Insert
(
tabname
,
{
'x'
:
'X2'
,
'y'
:
'Y2'
,
'z'
:
'Z2'
})
self
.
tdb
.
Insert
(
tabname
,
{
'x'
:
b'X1'
,
'y'
:
b
'Y1'
})
self
.
tdb
.
Insert
(
tabname
,
{
'x'
:
b'X2'
,
'y'
:
b'Y2'
,
'z'
:
b
'Z2'
})
self
.
tdb
.
Delete
(
tabname
,
conditions
=
{
'x'
:
dbtables
.
PrefixCond
(
'X'
)})
values
=
self
.
tdb
.
Select
(
tabname
,
[
'y'
],
...
...
@@ -321,18 +321,18 @@ class TableDBTestCase(unittest.TestCase):
tabname
=
"test_Modify"
self
.
tdb
.
CreateTable
(
tabname
,
[
'Name'
,
'Type'
,
'Access'
])
self
.
tdb
.
Insert
(
tabname
,
{
'Name'
:
'Index to MP3 files.doc'
,
'Type'
:
'Word'
,
'Access'
:
'8'
})
self
.
tdb
.
Insert
(
tabname
,
{
'Name'
:
'Nifty.MP3'
,
'Access'
:
'1'
})
self
.
tdb
.
Insert
(
tabname
,
{
'Type'
:
'Unknown'
,
'Access'
:
'0'
})
self
.
tdb
.
Insert
(
tabname
,
{
'Name'
:
b
'Index to MP3 files.doc'
,
'Type'
:
b'Word'
,
'Access'
:
b
'8'
})
self
.
tdb
.
Insert
(
tabname
,
{
'Name'
:
b'Nifty.MP3'
,
'Access'
:
b
'1'
})
self
.
tdb
.
Insert
(
tabname
,
{
'Type'
:
b'Unknown'
,
'Access'
:
b
'0'
})
def
set_type
(
type
):
if
type
==
None
:
return
'MP3'
return
b
'MP3'
return
type
def
increment_access
(
count
):
return
str
(
int
(
count
)
+
1
)
return
bytes
(
str
(
int
(
count
)
+
1
)
)
def
remove_value
(
value
):
return
None
...
...
@@ -350,7 +350,7 @@ class TableDBTestCase(unittest.TestCase):
try
:
self
.
tdb
.
Modify
(
tabname
,
conditions
=
{
'Name'
:
dbtables
.
LikeCond
(
'%'
)},
mappings
=
{
'Access'
:
'What is your quest?'
})
mappings
=
{
'Access'
:
b
'What is your quest?'
})
except
TypeError
:
# success, the string value in mappings isn't callable
pass
...
...
Lib/bsddb/test/test_lock.py
View file @
361ed153
...
...
@@ -55,7 +55,7 @@ class LockingTestCase(unittest.TestCase):
anID
=
self
.
env
.
lock_id
()
if
verbose
:
print
(
"locker ID: %s"
%
anID
)
lock
=
self
.
env
.
lock_get
(
anID
,
"some locked thing"
,
db
.
DB_LOCK_WRITE
)
lock
=
self
.
env
.
lock_get
(
anID
,
b
"some locked thing"
,
db
.
DB_LOCK_WRITE
)
if
verbose
:
print
(
"Aquired lock: %s"
%
lock
)
time
.
sleep
(
1
)
...
...
@@ -115,7 +115,7 @@ class LockingTestCase(unittest.TestCase):
if
verbose
:
print
(
"%s: locker ID: %s"
%
(
name
,
anID
))
lock
=
self
.
env
.
lock_get
(
anID
,
"some locked thing"
,
lockType
)
lock
=
self
.
env
.
lock_get
(
anID
,
b
"some locked thing"
,
lockType
)
if
verbose
:
print
(
"%s: Aquired %s lock: %s"
%
(
name
,
lt
,
lock
))
...
...
Lib/bsddb/test/test_queue.py
View file @
361ed153
...
...
@@ -47,14 +47,14 @@ class SimpleQueueTestCase(unittest.TestCase):
pprint
(
d
.
stat
())
for
x
in
letters
:
d
.
append
(
x
*
40
)
d
.
append
(
bytes
(
x
)
*
40
)
assert
len
(
d
)
==
52
d
.
put
(
100
,
"some more data"
)
d
.
put
(
101
,
"and some more "
)
d
.
put
(
75
,
"out of order"
)
d
.
put
(
1
,
"replacement data"
)
d
.
put
(
100
,
b
"some more data"
)
d
.
put
(
101
,
b
"and some more "
)
d
.
put
(
75
,
b
"out of order"
)
d
.
put
(
1
,
b
"replacement data"
)
assert
len
(
d
)
==
55
...
...
@@ -71,7 +71,7 @@ class SimpleQueueTestCase(unittest.TestCase):
print
(
"after open"
+
'-'
*
30
)
pprint
(
d
.
stat
())
d
.
append
(
"one more"
)
d
.
append
(
b
"one more"
)
c
=
d
.
cursor
()
if
verbose
:
...
...
@@ -119,14 +119,14 @@ class SimpleQueueTestCase(unittest.TestCase):
pprint
(
d
.
stat
())
for
x
in
letters
:
d
.
append
(
x
*
40
)
d
.
append
(
bytes
(
x
)
*
40
)
assert
len
(
d
)
==
52
d
.
put
(
100
,
"some more data"
)
d
.
put
(
101
,
"and some more "
)
d
.
put
(
75
,
"out of order"
)
d
.
put
(
1
,
"replacement data"
)
d
.
put
(
100
,
b
"some more data"
)
d
.
put
(
101
,
b
"and some more "
)
d
.
put
(
75
,
b
"out of order"
)
d
.
put
(
1
,
b
"replacement data"
)
assert
len
(
d
)
==
55
...
...
@@ -144,7 +144,7 @@ class SimpleQueueTestCase(unittest.TestCase):
print
(
"after open"
+
'-'
*
30
)
pprint
(
d
.
stat
())
d
.
append
(
"one more"
)
d
.
append
(
b
"one more"
)
if
verbose
:
print
(
"after append"
+
'-'
*
30
)
...
...
Lib/bsddb/test/test_recno.py
View file @
361ed153
...
...
@@ -41,7 +41,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
d
.
open
(
self
.
filename
,
db
.
DB_RECNO
,
db
.
DB_CREATE
)
for
x
in
letters
:
recno
=
d
.
append
(
x
*
60
)
recno
=
d
.
append
(
bytes
(
x
)
*
60
)
assert
type
(
recno
)
==
type
(
0
)
assert
recno
>=
1
if
verbose
:
...
...
@@ -219,7 +219,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
data
=
"The quick brown fox jumped over the lazy dog"
.
split
()
for
datum
in
data
:
d
.
append
(
datum
)
d
.
append
(
bytes
(
datum
)
)
d
.
sync
()
d
.
close
()
...
...
@@ -238,8 +238,8 @@ class SimpleRecnoTestCase(unittest.TestCase):
d
.
set_re_source
(
source
)
d
.
open
(
self
.
filename
,
db
.
DB_RECNO
)
d
[
3
]
=
'reddish-brown'
d
[
8
]
=
'comatose'
d
[
3
]
=
b
'reddish-brown'
d
[
8
]
=
b
'comatose'
d
.
sync
()
d
.
close
()
...
...
@@ -261,12 +261,12 @@ class SimpleRecnoTestCase(unittest.TestCase):
d
.
open
(
self
.
filename
,
db
.
DB_RECNO
,
db
.
DB_CREATE
)
for
x
in
letters
:
d
.
append
(
x
*
35
)
# These will be padded
d
.
append
(
bytes
(
x
)
*
35
)
# These will be padded
d
.
append
(
'.'
*
40
)
# this one will be exact
d
.
append
(
b
'.'
*
40
)
# this one will be exact
try
:
# this one will fail
d
.
append
(
'bad'
*
20
)
d
.
append
(
b
'bad'
*
20
)
except
db
.
DBInvalidArgError
as
val
:
assert
val
.
args
[
0
]
==
db
.
EINVAL
if
verbose
:
print
(
val
)
...
...
Modules/_bsddb.c
View file @
361ed153
...
...
@@ -380,11 +380,13 @@ static int make_dbt(PyObject* obj, DBT* dbt)
if
(
obj
==
Py_None
)
{
/* no need to do anything, the structure has already been zeroed */
}
else
if
(
!
Py
Arg_Parse
(
obj
,
"s#"
,
&
dbt
->
data
,
&
dbt
->
size
))
{
else
if
(
!
Py
Bytes_Check
(
obj
))
{
PyErr_SetString
(
PyExc_TypeError
,
"Data values must be of type
string
or None."
);
"Data values must be of type
bytes
or None."
);
return
0
;
}
dbt
->
data
=
PyBytes_AS_STRING
(
obj
);
dbt
->
size
=
PyBytes_GET_SIZE
(
obj
);
return
1
;
}
...
...
@@ -4737,7 +4739,7 @@ DBTxn_prepare(DBTxnObject* self, PyObject* args)
char
*
gid
=
NULL
;
int
gid_size
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"
s
#:prepare"
,
&
gid
,
&
gid_size
))
if
(
!
PyArg_ParseTuple
(
args
,
"
y
#:prepare"
,
&
gid
,
&
gid_size
))
return
NULL
;
if
(
gid_size
!=
DB_XIDDATASIZE
)
{
...
...
@@ -5915,6 +5917,7 @@ PyMODINIT_FUNC init_bsddb(void)
#if (DBVER >= 33)
ADD_INT
(
d
,
DB_DONOTINDEX
);
ADD_INT
(
d
,
DB_XIDDATASIZE
);
#endif
#if (DBVER >= 41)
...
...
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