# HG changeset patch # User Jeff Laughlin # Date 1322060257 18000 # Node ID 351d2799f145d19bb642e795f20786399fd02326 # Parent 3bbf6a3266f44ce822b19b0a857dd3a3cea1d515 client: added context manager protocol methods This allows client objects to be used with the 'with' statement and be closed automatically when the 'with' context exits. diff -r 3bbf6a3266f4 -r 351d2799f145 hglib/client.py --- a/hglib/client.py Fri Nov 18 00:49:47 2011 +0200 +++ b/hglib/client.py Wed Nov 23 09:57:37 2011 -0500 @@ -27,6 +27,12 @@ self._readhello() self._version = None + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.close() + def _readhello(self): """ read the hello message the server sends when started """ ch, msg = self._readchannel()