comparison 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
comparison
equal deleted inserted replaced
88:3bbf6a3266f4 89:351d2799f145
24 env['HGENCODING'] = encoding 24 env['HGENCODING'] = encoding
25 25
26 self.server = util.popen(args, env) 26 self.server = util.popen(args, env)
27 self._readhello() 27 self._readhello()
28 self._version = None 28 self._version = None
29
30 def __enter__(self):
31 return self
32
33 def __exit__(self, exc_type, exc_val, exc_tb):
34 self.close()
29 35
30 def _readhello(self): 36 def _readhello(self):
31 """ read the hello message the server sends when started """ 37 """ read the hello message the server sends when started """
32 ch, msg = self._readchannel() 38 ch, msg = self._readchannel()
33 assert ch == 'o' 39 assert ch == 'o'