Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffa926d

Browse files
committed
__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().
1 parent 698c149 commit ffa926d

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

Tools/pynche/Switchboard.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
from types import DictType
4646
import marshal
4747

48+
49+
4850
class Switchboard:
4951
def __init__(self, initfile):
5052
self.__initfile = initfile
@@ -63,11 +65,10 @@ def __init__(self, initfile):
6365
fp = open(initfile)
6466
self.__optiondb = marshal.load(fp)
6567
if type(self.__optiondb) <> DictType:
66-
sys.stderr.write(
67-
'Problem reading options from file: %s\n' %
68-
initfile)
68+
print >> sys.stderr, \
69+
'Problem reading options from file:', initfile
6970
self.__optiondb = {}
70-
except (IOError, EOFError):
71+
except (IOError, EOFError, ValueError):
7172
pass
7273
finally:
7374
if fp:
@@ -118,8 +119,8 @@ def save_views(self):
118119
try:
119120
fp = open(self.__initfile, 'w')
120121
except IOError:
121-
sys.stderr.write('Cannot write options to file: %s\n' %
122-
self.__initfile)
122+
print >> sys.stderr, 'Cannot write options to file:', \
123+
self.__initfile
123124
else:
124125
marshal.dump(self.__optiondb, fp)
125126
finally:

0 commit comments

Comments
 (0)