def test_pdu_len(self): enc = bser.dumps(1) self.assertEquals(len(enc), bser.pdu_len(enc)) # try a bigger one; prove that we get the correct length # even though we receive just a portion of the complete # data enc = bser.dumps([1, 2, 3, "hello there, much larger"]) self.assertEquals(len(enc), bser.pdu_len(enc[0:7]))
def query(self, *args): cmd = bser.dumps(args) response = None result = None sock = self._connect() try: sock.sendall(cmd) buf = [sock.recv(sniff_len)] if not buf[0]: raise Unavailable('empty watchman response') elen = bser.pdu_len(buf[0]) rlen = len(buf[0]) while elen > rlen: buf.append(sock.recv(elen - rlen)) rlen += len(buf[-1]) response = ''.join(buf) except socket.timeout: raise Unavailable('timed out waiting for response') try: result = bser.loads(response) except ValueError, e: raise Unavailable('watchman response decode error: %s' % e)
def query(self, *args): cmd = bser.dumps(args) response = None result = None sock = self._connect() try: sock.sendall(cmd) buf = [sock.recv(8192)] if not buf[0]: raise Unavailable('empty watchman response') elen = bser.pdu_len(buf[0]) rlen = len(buf[0]) while elen > rlen: buf.append(sock.recv(elen - rlen)) rlen += len(buf[-1]) response = ''.join(buf) except socket.timeout: raise Unavailable('timed out waiting for response') try: result = bser.loads(response) except ValueError, e: raise Unavailable('watchman response decode error: %s' % e)
def query(self, *args): cmd = bser.dumps(args) sock = self._connect() try: sock.sendall(cmd) except socket.timeout: raise Unavailable('timed out sending query command') return self.receive()
def munged(self, val, munged): enc = bser.dumps(val) if isinstance(val, unicode): print "# %s --> %s" % (val.encode('utf-8'), enc.encode('hex')) else: print "# %s --> %s" % (val, enc.encode('hex')) dec = bser.loads(enc) self.assertEquals(munged, dec)
def send(self, *args): cmd = bser.dumps(*args) self.transport.write(cmd)
def roundtrip(self, val): enc = bser.dumps(val) print "# %s --> %s" % (val, enc.encode('hex')) dec = bser.loads(enc) self.assertEquals(val, dec)