mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Make AtomicFile support context managers.
This commit is contained in:
parent
e42a3dd6ac
commit
5f582e3f52
@ -156,13 +156,19 @@ class AtomicFile(object):
|
|||||||
# self.__parent = super(AtomicFile, self)
|
# self.__parent = super(AtomicFile, self)
|
||||||
self._fd = open(self.tempFilename, mode)
|
self._fd = open(self.tempFilename, mode)
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
if exc_type:
|
||||||
|
self.rollback()
|
||||||
|
else:
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def closed(self):
|
def closed(self):
|
||||||
return self._fd.closed
|
return self._fd.closed
|
||||||
|
|
||||||
def close(self):
|
|
||||||
return self._fd.close()
|
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
return self._fd.write(data)
|
return self._fd.write(data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user