summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--portato/eix/__init__.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/portato/eix/__init__.py b/portato/eix/__init__.py
index aed5855..effac2d 100644
--- a/portato/eix/__init__.py
+++ b/portato/eix/__init__.py
@@ -29,6 +29,8 @@ class EixReader(object):
Note that the file used internally stays open during the whole operation.
So please call `close()` when you are finished.
+ The ``EixReader`` supports the context manager protocol, so you can the ``with ... as ...``.
+
:CVariables:
supported_versions : int[]
@@ -72,6 +74,13 @@ class EixReader(object):
self.close()
raise
+ def __enter__ (self):
+ return self
+
+ def __exit__ (self, exc_type, exc_val, exc_tb):
+ self.close()
+ return True
+
def close (self):
"""
Closes the cache file.