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 receive(self): response = None try: buf = [self.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(self.sock.recv(elen - rlen)) rlen += len(buf[-1]) response = ''.join(buf) except socket.timeout: raise Unavailable('timed out waiting for response') result = None 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(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 receive(self): buf = [self.transport.readBytes(sniff_len)] if not buf[0]: raise WatchmanError('empty watchman response') elen = bser.pdu_len(buf[0]) rlen = len(buf[0]) while elen > rlen: buf.append(self.transport.readBytes(elen - rlen)) rlen += len(buf[-1]) if PY2: response = ''.join(buf) if PY3: response = b''.join(buf) try: res = self._loads(response) # normalize res keys to strings if PY3: for key, value in res.items(): if isinstance(key, bytes): res[key.decode()] = value res.pop(key) return res except ValueError as e: raise WatchmanError('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 receive(self): buf = [self.transport.readBytes(sniff_len)] if not buf[0]: raise WatchmanError('empty watchman response') elen = bser.pdu_len(buf[0]) rlen = len(buf[0]) while elen > rlen: buf.append(self.transport.readBytes(elen - rlen)) rlen += len(buf[-1]) response = ''.join(buf) try: res = bser.loads(response) return res except ValueError as e: raise WatchmanError('watchman response decode error: %s' % e)
def receive(self): buf = [self.transport.readBytes(sniff_len)] if not buf[0]: raise WatchmanError('empty watchman response') elen = bser.pdu_len(buf[0]) rlen = len(buf[0]) while elen > rlen: buf.append(self.transport.readBytes(elen - rlen)) rlen += len(buf[-1]) response = ''.join(buf) try: res = self._loads(response) return res except ValueError as e: raise WatchmanError('watchman response decode error: %s' % e)