Python pickle.loads() Examples
The following are 30
code examples of pickle.loads().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pickle
, or try the search function
.
Example #1
Source File: cache.py From vergeml with MIT License | 10 votes |
def _deserialize(self, data, type_): if self.compress: # decompress the data if needed data = lz4.frame.decompress(data) if type_ == _NUMPY: # deserialize numpy arrays buf = io.BytesIO(data) data = np.load(buf) elif type_ == _PICKLE: # deserialize other python objects data = pickle.loads(data) else: # Otherwise we just return data as it is (bytes) pass return data
Example #2
Source File: vachat.py From The-chat-room with MIT License | 10 votes |
def run(self): print("VEDIO server starts...") self.sock.bind(self.ADDR) self.sock.listen(1) conn, addr = self.sock.accept() print("remote VEDIO client success connected...") data = "".encode("utf-8") payload_size = struct.calcsize("L") cv2.namedWindow('Remote', cv2.WINDOW_AUTOSIZE) while True: while len(data) < payload_size: data += conn.recv(81920) packed_size = data[:payload_size] data = data[payload_size:] msg_size = struct.unpack("L", packed_size)[0] while len(data) < msg_size: data += conn.recv(81920) zframe_data = data[:msg_size] data = data[msg_size:] frame_data = zlib.decompress(zframe_data) frame = pickle.loads(frame_data) cv2.imshow('Remote', frame) if cv2.waitKey(1) & 0xFF == 27: break
Example #3
Source File: SockPuppet.py From ALF with Apache License 2.0 | 6 votes |
def recv_data(self): data_remaining = struct.unpack("I", self.conn.recv(4))[0] if not data_remaining: log.debug("no data?!") return None log.debug("<- recving %d bytes", data_remaining) data = [] while data_remaining: recv_bytes = data_remaining if data_remaining < self.SOCK_BUF else self.SOCK_BUF data.append(self.conn.recv(recv_bytes)) data_len = len(data[-1]) if data_len == 0: break data_remaining -= data_len data = pickle.loads("".join(data)) if data["cmd"] != self.ACK: self.send_ack() return data
Example #4
Source File: kvstore_server.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
def _controller(self): """Return the server controller.""" def server_controller(cmd_id, cmd_body, _): """Server controler.""" if not self.init_logginig: # the reason put the codes here is because we cannot get # kvstore.rank earlier head = '%(asctime)-15s Server[' + str( self.kvstore.rank) + '] %(message)s' logging.basicConfig(level=logging.DEBUG, format=head) self.init_logginig = True if cmd_id == 0: try: optimizer = pickle.loads(cmd_body) except: raise self.kvstore.set_optimizer(optimizer) else: print("server %d, unknown command (%d, %s)" % ( self.kvstore.rank, cmd_id, cmd_body)) return server_controller
Example #5
Source File: test_attr.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
def test_attr_basic(): with mx.AttrScope(group='4', data='great'): data = mx.symbol.Variable('data', attr={'dtype':'data', 'group': '1', 'force_mirroring': 'True'}, lr_mult=1) gdata = mx.symbol.Variable('data2') assert gdata.attr('group') == '4' assert data.attr('group') == '1' assert data.attr('lr_mult') == '1' assert data.attr('__lr_mult__') == '1' assert data.attr('force_mirroring') == 'True' assert data.attr('__force_mirroring__') == 'True' data2 = pkl.loads(pkl.dumps(data)) assert data.attr('dtype') == data2.attr('dtype')
Example #6
Source File: test_sparse_ndarray.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
def test_sparse_nd_pickle(): dim0 = 40 dim1 = 40 stypes = ['row_sparse', 'csr'] densities = [0, 0.5] stype_dict = {'row_sparse': RowSparseNDArray, 'csr': CSRNDArray} shape = rand_shape_2d(dim0, dim1) for stype in stypes: for density in densities: a, _ = rand_sparse_ndarray(shape, stype, density) assert isinstance(a, stype_dict[stype]) data = pkl.dumps(a) b = pkl.loads(data) assert isinstance(b, stype_dict[stype]) assert same(a.asnumpy(), b.asnumpy()) # @kalyc: Getting rid of fixed seed as flakiness could not be reproduced # tracked at https://github.com/apache/incubator-mxnet/issues/11741
Example #7
Source File: adventure.py From Dumb-Cogs with MIT License | 6 votes |
def load(self, ctx, save=None): """loads current team's save. defaults to most recent""" server = ctx.message.server author = ctx.message.author channel = ctx.message.channel try: team = self.splayers[server.id][channel.id][author.id] except: team = None await self.embark.callback(self, ctx, team, save) # @adventure.command(pass_context=True) # async def save(self, ctx, file): # pass # if no team and no save, if user doesn't have a save, new game. otherwise new game must specify team and save
Example #8
Source File: jobrunner.py From pywren-ibm-cloud with Apache License 2.0 | 6 votes |
def _load_data(self): extra_get_args = {} if self.data_byte_range is not None: range_str = 'bytes={}-{}'.format(*self.data_byte_range) extra_get_args['Range'] = range_str logger.debug("Getting function data") data_download_start_tstamp = time.time() data_obj = self.internal_storage.get_data(self.data_key, extra_get_args=extra_get_args) logger.debug("Finished getting Function data") logger.debug("Unpickle Function data") loaded_data = pickle.loads(data_obj) logger.debug("Finished unpickle Function data") data_download_end_tstamp = time.time() self.stats.write('data_download_time', round(data_download_end_tstamp-data_download_start_tstamp, 8)) return loaded_data
Example #9
Source File: test_case.py From jawfish with MIT License | 6 votes |
def testPickle(self): # Issue 10326 # Can't use TestCase classes defined in Test class as # pickle does not work with inner classes test = unittest.TestCase('run') for protocol in range(pickle.HIGHEST_PROTOCOL + 1): # blew up prior to fix pickled_test = pickle.dumps(test, protocol=protocol) unpickled_test = pickle.loads(pickled_test) self.assertEqual(test, unpickled_test) # exercise the TestCase instance in a way that will invoke # the type equality lookup mechanism unpickled_test.assertEqual(set(), set())
Example #10
Source File: test_analyze.py From me-ica with GNU Lesser General Public License v2.1 | 6 votes |
def test_pickle(self): # Test that images pickle # Image that is not proxied can pickle img_klass = self.image_class img = img_klass(np.zeros((2,3,4)), None) img_str = pickle.dumps(img) img2 = pickle.loads(img_str) assert_array_equal(img.get_data(), img2.get_data()) assert_equal(img.get_header(), img2.get_header()) # Save / reload using bytes IO objects for key, value in img.file_map.items(): value.fileobj = BytesIO() img.to_file_map() img_prox = img.from_file_map(img.file_map) img_str = pickle.dumps(img_prox) img2_prox = pickle.loads(img_str) assert_array_equal(img.get_data(), img2_prox.get_data())
Example #11
Source File: test_operation.py From pyGSTi with Apache License 2.0 | 5 votes |
def test_pickle(self): pklstr = pickle.dumps(self.gate) gate_pickle = pickle.loads(pklstr) self.assertArraysEqual(gate_pickle, self.gate) self.assertEqual(type(gate_pickle), type(self.gate))
Example #12
Source File: test_spamvec.py From pyGSTi with Apache License 2.0 | 5 votes |
def test_pickle(self): pklstr = pickle.dumps(self.vec) vec_pickle = pickle.loads(pklstr) self.assertArraysAlmostEqual(vec_pickle, self.vec) self.assertEqual(type(vec_pickle), type(self.vec))
Example #13
Source File: test_dataset.py From pyGSTi with Apache License 2.0 | 5 votes |
def test_pickle(self): s = pickle.dumps(self.ds) ds_pickled = pickle.loads(s) for expected_row, actual_row in zip(self.ds, ds_pickled): for expected, actual in zip(expected_row, actual_row): self.assertEqual(expected, actual) # Row instance tests
Example #14
Source File: test_labeldicts.py From pyGSTi with Apache License 2.0 | 5 votes |
def test_outcome_label_dict_pickles(self): d = ld.OutcomeLabelDict([(('0',), 90), (('1',), 10)]) s = pickle.dumps(d) d_pickle = pickle.loads(s) self.assertEqual(d, d_pickle)
Example #15
Source File: test_pickle.py From Telethon with MIT License | 5 votes |
def test_base_rpcerror_pickle(): error = RPCError("request", "message", 123) unpickled_error = pickle.loads(pickle.dumps(error)) _assert_equality(error, unpickled_error)
Example #16
Source File: wordlist.py From brutemap with GNU General Public License v3.0 | 5 votes |
def __iter__(self): # membuat klon objek, untuk proses bruteforce. # supaya, tidak mengurangi isi dari wordlist tersebut. return pickle.loads(pickle.dumps(self))
Example #17
Source File: dist.py From evolution-strategies-starter with MIT License | 5 votes |
def deserialize(x): return pickle.loads(x)
Example #18
Source File: policies.py From evolution-strategies-starter with MIT License | 5 votes |
def Load(cls, filename, extra_kwargs=None): with h5py.File(filename, 'r') as f: args, kwargs = pickle.loads(f.attrs['args_and_kwargs'].tostring()) if extra_kwargs: kwargs.update(extra_kwargs) policy = cls(*args, **kwargs) policy.set_all_vars(*[f[v.name][...] for v in policy.all_variables]) return policy # === Rollouts/training ===
Example #19
Source File: parallel.py From dataflow with Apache License 2.0 | 5 votes |
def _recv(self): ret = loads(self.socket.recv(copy=False)) exc = _ExceptionWrapper.unpack(ret) if exc is not None: logger.error("Exception '{}' in worker:".format(str(exc.exc_type))) raise exc.exc_type(exc.exc_msg) return ret
Example #20
Source File: parallel.py From dataflow with Apache License 2.0 | 5 votes |
def unpack(dp): if isinstance(dp, bytes) and dp.startswith(_ExceptionWrapper.MAGIC): return pickle.loads(dp[len(_ExceptionWrapper.MAGIC):])
Example #21
Source File: serialize.py From dataflow with Apache License 2.0 | 5 votes |
def loads(buf): """ Args: bytes """ return pickle.loads(buf) # Define the default serializer to be used that dumps data to bytes
Example #22
Source File: serialize.py From dataflow with Apache License 2.0 | 5 votes |
def loads(buf): """ Args: buf: the output of `dumps` or `dumps_bytes`. """ import pyarrow as pa return pa.deserialize(buf)
Example #23
Source File: serialize.py From dataflow with Apache License 2.0 | 5 votes |
def loads(buf): """ Args: buf: the output of `dumps`. """ # Since 0.6, the default max size was set to 1MB. # We change it to approximately 1G. return msgpack.loads(buf, raw=False, max_bin_len=MAX_MSGPACK_LEN, max_array_len=MAX_MSGPACK_LEN, max_map_len=MAX_MSGPACK_LEN, max_str_len=MAX_MSGPACK_LEN)
Example #24
Source File: wordnet_app.py From razzy-spinner with GNU General Public License v3.0 | 5 votes |
def decode(string): """ Decode a reference encoded with Reference.encode """ string = base64.urlsafe_b64decode(string.encode()) word, synset_relations = pickle.loads(string) return Reference(word, synset_relations)
Example #25
Source File: url_checker.py From YaYaGen with BSD 2-Clause "Simplified" License | 5 votes |
def __fetch(self, domain): """ Get VT detection results from DB """ query_read = 'SELECT `detections` FROM `detections` WHERE `domain` = ?' cursor = self.db.cursor() cursor.execute(query_read, (domain,)) data = cursor.fetchone() if data: return pickle.loads(data[0]) return None
Example #26
Source File: report.py From YaYaGen with BSD 2-Clause "Simplified" License | 5 votes |
def __fetch(self, sha256): """ Retrieves a report stored in a local db, given the SHA256 """ query_read = 'SELECT `yara_rule` FROM `reports` WHERE `sha256` = ?' cursor = self.__db.cursor() cursor.execute(query_read, (sha256,)) data = cursor.fetchone() if data: return pickle.loads(data[0]) else: return None
Example #27
Source File: Utility.py From fuku-ml with MIT License | 5 votes |
def deserialize(pickle_serialized=''): """ddserialize""" return pickle.loads(pickle_serialized)
Example #28
Source File: object_storage.py From jawfish with MIT License | 5 votes |
def pop(self, key, default=__UnProvided()): if type(default) is __UnProvided or pickle.dumps(key) in self.storage: return pickle.loads(self.storage.pop(pickle.dumps(key))) return default
Example #29
Source File: object_storage.py From jawfish with MIT License | 5 votes |
def __getitem__(self, key): return pickle.loads(self.storage[pickle.dumps(key)])
Example #30
Source File: test_pickle.py From Telethon with MIT License | 5 votes |
def test_rpcerror_pickle(): error = BadRequestError("request", "BAD_REQUEST", 400) unpickled_error = pickle.loads(pickle.dumps(error)) _assert_equality(error, unpickled_error)