summaryrefslogtreecommitdiffstats
path: root/Lib/dumbdbm.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-08-07 05:37:39 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-08-07 05:37:39 (GMT)
commite6568694bbf4702216292588e6438b30ea0b0f61 (patch)
treeeb3569f0a499753a8e3184a1b9f95f019e410b9a /Lib/dumbdbm.py
parent45d569b8232d19b0f6bd1385e8fb624f310d230e (diff)
downloadcpython-e6568694bbf4702216292588e6438b30ea0b0f61.zip
cpython-e6568694bbf4702216292588e6438b30ea0b0f61.tar.gz
cpython-e6568694bbf4702216292588e6438b30ea0b0f61.tar.bz2
Change dumbdbm to use bytes keys.
Diffstat (limited to 'Lib/dumbdbm.py')
-rw-r--r--Lib/dumbdbm.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/dumbdbm.py b/Lib/dumbdbm.py
index aaa1680..6cfda1c 100644
--- a/Lib/dumbdbm.py
+++ b/Lib/dumbdbm.py
@@ -115,6 +115,7 @@ class _Database(UserDict.DictMixin):
sync = _commit
def __getitem__(self, key):
+ key = key.decode("latin-1")
pos, siz = self._index[key] # may raise KeyError
f = _io.open(self._datfile, 'rb')
f.seek(pos)
@@ -159,8 +160,9 @@ class _Database(UserDict.DictMixin):
f.close()
def __setitem__(self, key, val):
- if not isinstance(key, basestring):
- raise TypeError("keys must be strings")
+ if not isinstance(key, bytes):
+ raise TypeError("keys must be bytes")
+ key = key.decode("latin-1") # hashable bytes
if not isinstance(val, (str8, bytes)):
raise TypeError("values must be byte strings")
if key not in self._index:
@@ -188,6 +190,7 @@ class _Database(UserDict.DictMixin):
# (so that _commit() never gets called).
def __delitem__(self, key):
+ key = key.decode("latin-1")
# The blocks used by the associated value are lost.
del self._index[key]
# XXX It's unclear why we do a _commit() here (the code always