Commit ffa926d7 authored by Barry Warsaw's avatar Barry Warsaw

__init__(), save_views(): Catch ValueError along with IOError and

EOFError so any failures in unmarshalling are just ignored.  Use
print>> instead of sys.stderr.write().
parent 698c1493
...@@ -45,6 +45,8 @@ import sys ...@@ -45,6 +45,8 @@ import sys
from types import DictType from types import DictType
import marshal import marshal
class Switchboard: class Switchboard:
def __init__(self, initfile): def __init__(self, initfile):
self.__initfile = initfile self.__initfile = initfile
...@@ -63,11 +65,10 @@ class Switchboard: ...@@ -63,11 +65,10 @@ class Switchboard:
fp = open(initfile) fp = open(initfile)
self.__optiondb = marshal.load(fp) self.__optiondb = marshal.load(fp)
if type(self.__optiondb) <> DictType: if type(self.__optiondb) <> DictType:
sys.stderr.write( print >> sys.stderr, \
'Problem reading options from file: %s\n' % 'Problem reading options from file:', initfile
initfile)
self.__optiondb = {} self.__optiondb = {}
except (IOError, EOFError): except (IOError, EOFError, ValueError):
pass pass
finally: finally:
if fp: if fp:
...@@ -118,8 +119,8 @@ class Switchboard: ...@@ -118,8 +119,8 @@ class Switchboard:
try: try:
fp = open(self.__initfile, 'w') fp = open(self.__initfile, 'w')
except IOError: except IOError:
sys.stderr.write('Cannot write options to file: %s\n' % print >> sys.stderr, 'Cannot write options to file:', \
self.__initfile) self.__initfile
else: else:
marshal.dump(self.__optiondb, fp) marshal.dump(self.__optiondb, fp)
finally: finally:
......
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