From f1eee621cf0f4991fa04902f9b447de73cb41dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Fri, 14 Aug 2009 19:22:17 +0200 Subject: Make the EixReader support the context manager protocol --- portato/eix/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'portato/eix') 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. -- cgit v1.2.3