ObjectProxy: implement __enter__ and __exit__
authorZac Medico <zmedico@gentoo.org>
Mon, 10 Sep 2012 00:07:18 +0000 (17:07 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 10 Sep 2012 00:07:18 +0000 (17:07 -0700)
pym/portage/proxy/objectproxy.py

index 92b36d111be5e6f0af9631a9bc39c33aeb605893..a755774aefb60a91846914a3f7ab8d60c18c5b62 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2008-2009 Gentoo Foundation
+# Copyright 2008-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import sys
@@ -30,6 +30,13 @@ class ObjectProxy(object):
                result = object.__getattribute__(self, '_get_target')()
                return result(*args, **kwargs)
 
+       def __enter__(self):
+               return object.__getattribute__(self, '_get_target')().__enter__()
+
+       def __exit__(self, exc_type, exc_value, traceback):
+               return object.__getattribute__(self, '_get_target')().__exit__(
+                       exc_type, exc_value, traceback)
+
        def __setitem__(self, key, value):
                object.__getattribute__(self, '_get_target')()[key] = value