From: Shaun Duncan Date: Tue, 10 Sep 2013 18:31:45 +0000 (-0400) Subject: Connection as a context manager X-Git-Tag: 0.0.2~6^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fc4ef9829cc31ea7abab17874c52bff8f3413bf1;p=remoto.git Connection as a context manager --- diff --git a/remoto/connection.py b/remoto/connection.py index 93e1866..9d9370e 100644 --- a/remoto/connection.py +++ b/remoto/connection.py @@ -13,6 +13,13 @@ class Connection(object): self.logger = logger or FakeRemoteLogger() self.sudo = sudo + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.exit() + return False + def execute(self, function, **kw): return self.gateway.remote_exec(function, **kw)