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
b7de61bf
Commit
b7de61bf
authored
Oct 09, 2007
by
Gregory P. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the highest cPickle protocol in bsddb.dbshelve. This comes from
sourceforge pybsddb patch 1551443 by w_barnes.
parent
10bed54a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
14 deletions
+28
-14
Lib/bsddb/dbshelve.py
Lib/bsddb/dbshelve.py
+28
-14
No files found.
Lib/bsddb/dbshelve.py
View file @
b7de61bf
...
...
@@ -30,12 +30,21 @@ storage.
#------------------------------------------------------------------------
import
cPickle
try
:
import
db
import
sys
#At version 2.3 cPickle switched to using protocol instead of bin and
#DictMixin was added
if
sys
.
version_info
[:
3
]
>=
(
2
,
3
,
0
):
HIGHEST_PROTOCOL
=
cPickle
.
HIGHEST_PROTOCOL
def
_dumps
(
object
,
protocol
):
return
cPickle
.
dumps
(
object
,
protocol
=
protocol
)
from
UserDict
import
DictMixin
except
ImportError
:
# DictMixin is new in Python 2.3
else
:
HIGHEST_PROTOCOL
=
None
def
_dumps
(
object
,
protocol
):
return
cPickle
.
dumps
(
object
,
bin
=
protocol
)
class
DictMixin
:
pass
import
db
#------------------------------------------------------------------------
...
...
@@ -81,7 +90,10 @@ class DBShelf(DictMixin):
"""
def
__init__
(
self
,
dbenv
=
None
):
self
.
db
=
db
.
DB
(
dbenv
)
self
.
binary
=
1
if
HIGHEST_PROTOCOL
:
self
.
protocol
=
HIGHEST_PROTOCOL
else
:
self
.
protocol
=
1
def
__del__
(
self
):
...
...
@@ -108,7 +120,7 @@ class DBShelf(DictMixin):
def
__setitem__
(
self
,
key
,
value
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
self
.
db
[
key
]
=
data
...
...
@@ -146,7 +158,7 @@ class DBShelf(DictMixin):
# Other methods
def
__append
(
self
,
value
,
txn
=
None
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
return
self
.
db
.
append
(
data
,
txn
)
def
append
(
self
,
value
,
txn
=
None
):
...
...
@@ -177,19 +189,19 @@ class DBShelf(DictMixin):
# so it doesn't need unpickled.
def
get_both
(
self
,
key
,
value
,
txn
=
None
,
flags
=
0
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
data
=
self
.
db
.
get
(
key
,
data
,
txn
,
flags
)
return
cPickle
.
loads
(
data
)
def
cursor
(
self
,
txn
=
None
,
flags
=
0
):
c
=
DBShelfCursor
(
self
.
db
.
cursor
(
txn
,
flags
))
c
.
binary
=
self
.
binary
c
.
protocol
=
self
.
protocol
return
c
def
put
(
self
,
key
,
value
,
txn
=
None
,
flags
=
0
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
return
self
.
db
.
put
(
key
,
data
,
txn
,
flags
)
...
...
@@ -225,11 +237,13 @@ class DBShelfCursor:
#----------------------------------------------
def
dup
(
self
,
flags
=
0
):
return
DBShelfCursor
(
self
.
dbc
.
dup
(
flags
))
c
=
DBShelfCursor
(
self
.
dbc
.
dup
(
flags
))
c
.
protocol
=
self
.
protocol
return
c
def
put
(
self
,
key
,
value
,
flags
=
0
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
return
self
.
dbc
.
put
(
key
,
data
,
flags
)
...
...
@@ -247,7 +261,7 @@ class DBShelfCursor:
return
self
.
_extract
(
rec
)
def
get_3
(
self
,
key
,
value
,
flags
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
rec
=
self
.
dbc
.
get
(
key
,
flags
)
return
self
.
_extract
(
rec
)
...
...
@@ -264,7 +278,7 @@ class DBShelfCursor:
def
get_both
(
self
,
key
,
value
,
flags
=
0
):
data
=
cPickle
.
dumps
(
value
,
self
.
binary
)
data
=
_dumps
(
value
,
self
.
protocol
)
rec
=
self
.
dbc
.
get_both
(
key
,
flags
)
return
self
.
_extract
(
rec
)
...
...
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