Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r61395:9b0d6cfc3e39
Date: 2013-02-17 19:56 -0800
http://bitbucket.org/pypy/pypy/changeset/9b0d6cfc3e39/
Log: fix test_dbm/dbm_ndbm
diff --git a/lib_pypy/_dbm.py b/lib_pypy/_dbm.py
--- a/lib_pypy/_dbm.py
+++ b/lib_pypy/_dbm.py
@@ -1,8 +1,9 @@
-from ctypes import Structure, c_char_p, c_int, c_void_p, CDLL, POINTER, c_char
+import os
+import sys
import ctypes.util
-import os, sys
+from ctypes import Structure, c_char, c_char_p, c_int, c_void_p, CDLL, POINTER
-class error(Exception):
+class error(IOError):
def __init__(self, msg):
self.msg = msg
@@ -16,8 +17,11 @@
]
def __init__(self, text):
- if not isinstance(text, str):
- raise TypeError("datum: expected string, not %s" % type(text))
+ if isinstance(text, str):
+ text = text.encode(sys.getdefaultencoding())
+ elif not isinstance(text, bytes):
+ msg = "dbm mapping keys must be a string or bytes object, not {!r}"
+ raise TypeError(msg.format(type(text).__name__))
Structure.__init__(self, text, len(text))
class dbm(object):
@@ -157,9 +161,9 @@
"open a DBM database"
if not isinstance(filename, str):
raise TypeError("expected string")
+ filename = filename.encode(sys.getdefaultencoding())
openflag = 0
-
try:
openflag = {
'r': os.O_RDONLY,
@@ -177,4 +181,3 @@
return dbm(a_db)
__all__ = ('datum', 'dbm', 'error', 'funcs', 'open', 'library')
-
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit