Skip to content

Commit

Permalink
ConfWriter: Reuse ClosableObject for closing
Browse files Browse the repository at this point in the history
  • Loading branch information
sils committed Apr 15, 2015
1 parent c8e5589 commit 5ab485d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions coalib/output/ConfWriter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from coalib.output.ClosableObject import ClosableObject
from coalib.settings.Section import Section


class ConfWriter:
class ConfWriter(ClosableObject):
def __init__(self,
file_name,
key_value_delimiter='=',
Expand All @@ -10,6 +11,7 @@ def __init__(self,
section_name_surrounding_beg='[',
section_name_surrounding_end="]",
unsavable_keys=["save"]):
ClosableObject.__init__(self)
self.__file_name = file_name
self.__file = open(self.__file_name, "w")
self.__key_value_delimiter = key_value_delimiter
Expand All @@ -21,13 +23,8 @@ def __init__(self,
self.__wrote_newline = True
self.__closed = False

def close(self):
if not self.__closed:
self.__file.close()
self.__closed = True

def __del__(self):
assert self.__closed, "ConfWriter needs to be closed!"
def _close(self):
self.__file.close()

def write_sections(self, sections):
assert not self.__closed
Expand Down

1 comment on commit 5ab485d

@fneu
Copy link
Contributor

@fneu fneu commented on 5ab485d Apr 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.