diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-14 19:22:17 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2009-08-14 19:22:17 +0200 |
commit | f1eee621cf0f4991fa04902f9b447de73cb41dd3 (patch) | |
tree | 8bd90a748031a64121156f1e3d3501537f8c78ec /portato/eix | |
parent | 82f6e37bdd112d223580abdbe788442a6bb22666 (diff) | |
download | portato-f1eee621cf0f4991fa04902f9b447de73cb41dd3.tar.gz portato-f1eee621cf0f4991fa04902f9b447de73cb41dd3.tar.bz2 portato-f1eee621cf0f4991fa04902f9b447de73cb41dd3.zip |
Make the EixReader support the context manager protocol
Diffstat (limited to '')
-rw-r--r-- | portato/eix/__init__.py | 9 |
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. |