diff hglib/client.py @ 89:351d2799f145

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.
author Jeff Laughlin <jmlaughlin@integrated-informatics.com>
date Wed, 23 Nov 2011 09:57:37 -0500
parents 5661d5f7e39b
children b894c2222dff
line wrap: on
line diff
--- 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()