def decX(self, l): if len(self.bytes) < l : raise py9p.Error("buffer exhausted") x = "".join(self.bytes[:l]) #del self.bytes[:l] self.bytes[:l] = [] # significant speedup return x
def recv(self, fd): "Read and decode a message" self.setBuf(fd.read(4)) size = self.dec4() if size > self.MAXSIZE or size < 4: raise py9p.Error("Bad message size: %d" % size) self.setBuf(fd.read(size - 4)) type,tag = self.dec1(),self.dec2() self._checkType(type) fcall = py9p.Fcall(type, tag) self.dec(fcall) self._checkResid() if self.chatty: print "<-%d-" % fd.fileno(), py9p.cmdName[type], tag, fcall.tostr() return fcall
def _checkLen(self, x, l): if len(x) != l: raise py9p.Error("Wrong length %d, expected %d: %r" % (len(x), l, x))
def _checkSize(self, v, mask): if v != v & mask: raise py9p.Error("Invalid value %d" % v)
def _checkResid(self): if len(self.bytes): raise py9p.Error("Extra information in message: %r" % self.bytes)
def _checkType(self, t): if t not in py9p.cmdName: raise py9p.Error("Invalid message type %d" % t)