FileList raise exception if write failse

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
Steven Armstrong 2011-10-13 17:59:23 +02:00
parent 6271e27eb5
commit 589b5a68b9

View file

@ -49,6 +49,7 @@ class FileList(collections.MutableSequence):
def __read(self): def __read(self):
lines = [] lines = []
# if file does not exist return empty list
try: try:
with open(self.path) as fd: with open(self.path) as fd:
for line in fd: for line in fd:
@ -59,13 +60,9 @@ class FileList(collections.MutableSequence):
return lines return lines
def __write(self, lines): def __write(self, lines):
try: with open(self.path, 'w') as fd:
with open(self.path, 'w') as fd: for line in lines:
for line in lines: fd.write(str(line) + '\n')
fd.write(str(line) + '\n')
except EnvironmentError as e:
# error ignored
raise
def __repr__(self): def __repr__(self):
return repr(list(self)) return repr(list(self))