comparison mercurial/commandserver.py @ 28156:75f586a1bf55

commandserver: add _readstr and _readlist Reading a string or a list are common operations for commandserver and chgserver. This patch adds _readstr and _readlist to avoid duplication.
author Jun Wu <quark@fb.com>
date Tue, 16 Feb 2016 19:11:45 +0000
parents 14033c5dd261
children e7c9b59dbbcf
comparison
equal deleted inserted replaced
28155:7f430b2ac7fd 28156:75f586a1bf55
187 # is the other end closed? 187 # is the other end closed?
188 if not data: 188 if not data:
189 raise EOFError 189 raise EOFError
190 190
191 return data 191 return data
192
193 def _readstr(self):
194 """read a string from the channel
195
196 format:
197 data length (uint32), data
198 """
199 length = struct.unpack('>I', self._read(4))[0]
200 if not length:
201 return ''
202 return self._read(length)
203
204 def _readlist(self):
205 """read a list of NULL separated strings from the channel"""
206 s = self._readstr()
207 if s:
208 return s.split('\0')
209 else:
210 return []
192 211
193 def runcommand(self): 212 def runcommand(self):
194 """ reads a list of \0 terminated arguments, executes 213 """ reads a list of \0 terminated arguments, executes
195 and writes the return code to the result channel """ 214 and writes the return code to the result channel """
196 from . import dispatch # avoid cycle 215 from . import dispatch # avoid cycle