def serve_once(self): rawLength = self.rfile.read(LENGTH_STRUCT_LENGTH) length = unpack(LENGTH_STRUCT_FMT, rawLength)[0] pickledCall = self.rfile.read(length) if len(pickledCall) < length: raise Exception("Pipe broke") name, args, kwargs = pickle.loads(pickledCall) err = res = None try: res = self.callRegisteredFunction(name, args, kwargs) except Exception as ex: err = ex resp = pickle.dumps((res, err)) self.wfile.write(pack(LENGTH_STRUCT_FMT, len(resp))) self.wfile.write(resp) self.wfile.flush()
def callCrabRPCFunction(self, timeout, name, *args, **kwargs): request = pickle.dumps((name, args, kwargs)) self._sendAll(pack(LENGTH_STRUCT_FMT, len(request)), timeout) self._sendAll(request, timeout) try: rawLength = self._recvAll(LENGTH_STRUCT_LENGTH, timeout) length = unpack(LENGTH_STRUCT_FMT, rawLength)[0] rawResponse = self._recvAll(length, timeout) except Timeout: raise except: # If for some reason the connection drops\gets out of sync we treat # it as a timeout so we only have one error path self.log.error("Problem with handler, treating as timeout", exc_info=True) raise Timeout() res, err = pickle.loads(rawResponse) if err is not None: raise err return res
def test_pickle_copy(self): p1 = ProtectedPassword("12345678") p2 = pickle.loads(pickle.dumps(p1)) self.assertEqual(p1, p2)