Kaydet (Commit) da72d937 authored tarafından Skip Montanaro's avatar Skip Montanaro

try to avoid gross incompatibilities with older versions of Python

üst 7c1274d8
...@@ -33,7 +33,7 @@ except ImportError: ...@@ -33,7 +33,7 @@ except ImportError:
prog = sys.argv[0] prog = sys.argv[0]
def usage(): def usage():
print >> sys.stderr, __doc__ % globals() sys.stderr.write(__doc__ % globals())
def main(args): def main(args):
try: try:
...@@ -52,9 +52,9 @@ def main(args): ...@@ -52,9 +52,9 @@ def main(args):
else: else:
dbfile = args[0] dbfile = args[0]
try: try:
pfile = file(args[1], 'wb') pfile = open(args[1], 'wb')
except IOError: except IOError:
print >> sys.stderr, "Unable to open", args[1] sys.stderr.write("Unable to open %s\n" % args[1])
return 1 return 1
dbopen = None dbopen = None
...@@ -63,36 +63,36 @@ def main(args): ...@@ -63,36 +63,36 @@ def main(args):
try: try:
dbopen = bsddb.hashopen dbopen = bsddb.hashopen
except AttributeError: except AttributeError:
print >> sys.stderr, "bsddb module unavailable." sys.stderr.write("bsddb module unavailable.\n")
return 1 return 1
elif opt in ("-b", "--btree"): elif opt in ("-b", "--btree"):
try: try:
dbopen = bsddb.btopen dbopen = bsddb.btopen
except AttributeError: except AttributeError:
print >> sys.stderr, "bsddb module unavailable." sys.stderr.write("bsddb module unavailable.\n")
return 1 return 1
elif opt in ("-r", "--recno"): elif opt in ("-r", "--recno"):
try: try:
dbopen = bsddb.rnopen dbopen = bsddb.rnopen
except AttributeError: except AttributeError:
print >> sys.stderr, "bsddb module unavailable." sys.stderr.write("bsddb module unavailable.\n")
return 1 return 1
elif opt in ("-a", "--anydbm"): elif opt in ("-a", "--anydbm"):
try: try:
dbopen = anydbm.open dbopen = anydbm.open
except AttributeError: except AttributeError:
print >> sys.stderr, "anydbm module unavailable." sys.stderr.write("anydbm module unavailable.\n")
return 1 return 1
elif opt in ("-d", "--dbm"): elif opt in ("-d", "--dbm"):
try: try:
dbopen = dbm.open dbopen = dbm.open
except AttributeError: except AttributeError:
print >> sys.stderr, "dbm module unavailable." sys.stderr.write("dbm module unavailable.\n")
return 1 return 1
if dbopen is None: if dbopen is None:
if bsddb is None: if bsddb is None:
print >> sys.stderr, "bsddb module unavailable -" sys.stderr.write("bsddb module unavailable - ")
print >> sys.stderr, "must specify dbtype." sys.stderr.write("must specify dbtype.\n")
return 1 return 1
else: else:
dbopen = bsddb.hashopen dbopen = bsddb.hashopen
...@@ -100,8 +100,8 @@ def main(args): ...@@ -100,8 +100,8 @@ def main(args):
try: try:
db = dbopen(dbfile, 'r') db = dbopen(dbfile, 'r')
except bsddb.error: except bsddb.error:
print >> sys.stderr, "Unable to open", dbfile, sys.stderr.write("Unable to open %s. " % dbfile)
print >> sys.stderr, "Check for format or version mismatch." sys.stderr.write("Check for format or version mismatch.\n")
return 1 return 1
for k in db.keys(): for k in db.keys():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment