Beispiel #1
0
    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]))
Beispiel #2
0
    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]))
Beispiel #3
0
    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)
Beispiel #4
0
    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)
Beispiel #5
0
 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()
Beispiel #6
0
 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()
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 def send(self, *args):
     cmd = bser.dumps(*args)
     self.transport.write(cmd)
Beispiel #10
0
 def send(self, *args):
     cmd = bser.dumps(*args)
     self.transport.write(cmd)
Beispiel #11
0
 def roundtrip(self, val):
     enc = bser.dumps(val)
     print "# %s  -->  %s" % (val, enc.encode('hex'))
     dec = bser.loads(enc)
     self.assertEquals(val, dec)
Beispiel #12
0
 def roundtrip(self, val):
     enc = bser.dumps(val)
     print "# %s  -->  %s" % (val, enc.encode('hex'))
     dec = bser.loads(enc)
     self.assertEquals(val, dec)