Exemplo n.º 1
0
 def execute(self, cmd, wait=True):
     # need better way to return the result, how to use the socket well???
     # https://github.com/jprjr/sockexec
     args = cmd.split(" ")
     if not os.path.exists(self.socketpath):
         raise j.exceptions.Base("cannot find exec socket path:%s" %
                                 self.socketpath)
     self.client = socket.socket(socket.AF_UNIX)
     self.client.connect(self.socketpath)
     s = netstr.encode(str(len(args)).encode())
     for cmd in args:
         s += netstr.encode(cmd.encode())
     s += netstr.encode(b"")
     self.client.sendall(s)
     res = []
     r = b""
     while wait:
         r += self.client.recv(1024)
         while b"," in r:
             splitted = r.split(b",")
             if len(splitted) > 0:
                 r2 = netstr.decode(splitted[0] + b",")
                 res.append(r2)
                 r = b",".join(splitted[1:])
         if len(res) > 2 and b"exitcode" == res[-2]:
             return res
         time.sleep(0.01)
Exemplo n.º 2
0
  def test_bad_input(self):
    clbk1 = lambda: netstr.decode(b'-' + self.binary_data)
    clbk2 = lambda: netstr.decode(self.binary_data.replace(b',', b'.'))

    self.assertRaises(ValueError, clbk1)
    self.assertRaises(ValueError, clbk2)
Exemplo n.º 3
0
 def test_decode(self):
   self.assertEqual(netstr.decode(self.binary_data), self.ascii_data)
Exemplo n.º 4
0
    def test_bad_input(self):
        clbk1 = lambda: netstr.decode(b'-' + self.binary_data)
        clbk2 = lambda: netstr.decode(self.binary_data.replace(b',', b'.'))

        self.assertRaises(ValueError, clbk1)
        self.assertRaises(ValueError, clbk2)
Exemplo n.º 5
0
 def test_decode(self):
     self.assertEqual(netstr.decode(self.binary_data), self.ascii_data)