summaryrefslogtreecommitdiffstats
path: root/Lib/whichdb.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-23 20:51:02 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-23 20:51:02 (GMT)
commit6252e10ed906eb419a75b310f7c0d6696a4eeb46 (patch)
treeb6b46cf0e5d1528d736cde47d1089aefc46bbf05 /Lib/whichdb.py
parent517bcfeb6be448f47804900ac75c804d8f70a20e (diff)
downloadcpython-6252e10ed906eb419a75b310f7c0d6696a4eeb46.zip
cpython-6252e10ed906eb419a75b310f7c0d6696a4eeb46.tar.gz
cpython-6252e10ed906eb419a75b310f7c0d6696a4eeb46.tar.bz2
Make gdbm and dumbdbm use byte strings. Updated their tests.
Diffstat (limited to 'Lib/whichdb.py')
-rw-r--r--Lib/whichdb.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/Lib/whichdb.py b/Lib/whichdb.py
index 4d7a560..752bbb1 100644
--- a/Lib/whichdb.py
+++ b/Lib/whichdb.py
@@ -1,6 +1,7 @@
# !/usr/bin/env python
"""Guess which db package to use to open a db file."""
+import io
import os
import struct
import sys
@@ -29,18 +30,18 @@ def whichdb(filename):
# Check for dbm first -- this has a .pag and a .dir file
try:
- f = open(filename + os.extsep + "pag", "rb")
+ f = io.open(filename + os.extsep + "pag", "rb")
f.close()
# dbm linked with gdbm on OS/2 doesn't have .dir file
if not (dbm.library == "GNU gdbm" and sys.platform == "os2emx"):
- f = open(filename + os.extsep + "dir", "rb")
+ f = io.open(filename + os.extsep + "dir", "rb")
f.close()
return "dbm"
except IOError:
# some dbm emulations based on Berkeley DB generate a .db file
# some do not, but they should be caught by the dbhash checks
try:
- f = open(filename + os.extsep + "db", "rb")
+ f = io.open(filename + os.extsep + "db", "rb")
f.close()
# guarantee we can actually open the file using dbm
# kind of overkill, but since we are dealing with emulations
@@ -60,9 +61,9 @@ def whichdb(filename):
# dumbdbm files with no keys are empty
if size == 0:
return "dumbdbm"
- f = open(filename + os.extsep + "dir", "rb")
+ f = io.open(filename + os.extsep + "dir", "rb")
try:
- if f.read(1) in ("'", '"'):
+ if f.read(1) in (b"'", b'"'):
return "dumbdbm"
finally:
f.close()
@@ -71,7 +72,7 @@ def whichdb(filename):
# See if the file exists, return None if not
try:
- f = open(filename, "rb")
+ f = io.open(filename, "rb")
except IOError:
return None