コード例 #1
0
ファイル: transports.py プロジェクト: xcnix/pyxcli
    def send(self, data, timeout=None):

        while data:
            chunk = data[:self.MAX_IO_CHUNK]
            byte_chunk = chunk.encode()
            sent = self.sock.send(byte_chunk)
            data = data[sent:]

        parser = TerminationDetectingXMLParser()
        raw = ""
        try:
            while not parser.root_element_closed:
                chunk = self.sock.recv(self.MAX_IO_CHUNK)
                if not chunk:
                    break
                raw += chunk.decode()
                parser.feed(chunk)
            return parser.close()
        except XMLException as ex:
            xlog.exception("Termination-detecting parser failed, %s", ex)
            if not self.is_connected():
                ex = chained(DisconnectedWhileReceivingData())
            else:
                ex = chained(CorruptResponse(str(ex), raw))
            self.close()
            raise ex
コード例 #2
0
ファイル: transports.py プロジェクト: beckmani/pyxcli
    def send(self, data, timeout=None):

        while data:
            chunk = data[:self.MAX_IO_CHUNK]
            sent = self.sock.send(chunk)
            data = data[sent:]

        parser = TerminationDetectingXMLParser()
        raw = ""
        try:
            while not parser.root_element_closed:
                chunk = self.sock.recv(self.MAX_IO_CHUNK)
                if not chunk:
                    break
                raw += chunk
                parser.feed(chunk)
            return parser.close()
        except XMLException as ex:
            xlog.exception("Termination-detecting parser failed, %s", ex)
            if not self.is_connected():
                ex = chained(DisconnectedWhileReceivingData())
            else:
                ex = chained(CorruptResponse(str(ex), raw))
            self.close()
            raise ex
コード例 #3
0
ファイル: client.py プロジェクト: xcnix/pyxcli
 def execute_remote(self, remote_target, cmd, **kwargs):
     """
     Executes the given command (with the given arguments)
     on the given remote target of the connected machine
     """
     data = self._build_command(cmd, kwargs, self._contexts[-1],
                                remote_target)
     with self._lock:
         rootelem = self.transport.send(data)
     try:
         return self._build_response(rootelem)
     except ElementNotFoundException:
         xlog.exception("XCLIClient.execute")
         raise chained(CorruptResponse(rootelem))
     except Exception as e:
         xlog.exception("XCLIClient.execute")
         raise e
コード例 #4
0
ファイル: client.py プロジェクト: beckmani/pyxcli
 def execute_remote(self, remote_target, cmd, **kwargs):
     """
     Executes the given command (with the given arguments)
     on the given remote target of the connected machine
     """
     data = self._build_command(cmd, kwargs, self._contexts[-1],
                                remote_target)
     with self._lock:
         rootelem = self.transport.send(data)
     try:
         return self._build_response(rootelem)
     except ElementNotFoundException:
         xlog.exception("XCLIClient.execute")
         raise chained(CorruptResponse(rootelem))
     except Exception as e:
         xlog.exception("XCLIClient.execute")
         raise e