Python cPickle.Pickler() Examples

The following are 30 code examples of cPickle.Pickler(). 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 cPickle , or try the search function .
Example #1
Source File: memcacheclient.py    From ccs-calendarserver with Apache License 2.0 6 votes vote down vote up
def getClient(
        cls, servers, debug=0, pickleProtocol=0,
        pickler=pickle.Pickler, unpickler=pickle.Unpickler,
        pload=None, pid=None
    ):

        if cls.allowTestCache:
            return TestClient(
                servers, debug=debug,
                pickleProtocol=pickleProtocol, pickler=pickler,
                unpickler=unpickler, pload=pload, pid=pid)
        elif config.Memcached.Pools.Default.ClientEnabled:
            return Client(
                servers, debug=debug, pickleProtocol=pickleProtocol,
                pickler=pickler, unpickler=unpickler, pload=pload, pid=pid)
        else:
            return None 
Example #2
Source File: __init__.py    From termite-visualizations with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, request, servers, debug=0, pickleProtocol=0,
                 pickler=pickle.Pickler, unpickler=pickle.Unpickler,
                 pload=None, pid=None,
                 default_time_expire = DEFAULT_TIME_EXPIRE):
        self.request=request
        self.default_time_expire = default_time_expire
        if request:
            app = request.application
        else:
            app = ''
        Client.__init__(self, servers, debug, pickleProtocol,
                        pickler, unpickler, pload, pid)
        if not app in self.meta_storage:
            self.storage = self.meta_storage[app] = {
                CacheAbstract.cache_stats_name: {
                    'hit_total': 0,
                    'misses': 0,
                    }}
        else:
            self.storage = self.meta_storage[app] 
Example #3
Source File: test_cpickle.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = StringIO()
        p = cPickle.Pickler(f, proto)
        p.dump(arg)
        f.seek(0)
        return f.read() 
Example #4
Source File: __init__.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def __init__(self,
               servers=None,
               debug=0,
               pickleProtocol=cPickle.HIGHEST_PROTOCOL,
               pickler=cPickle.Pickler,
               unpickler=cPickle.Unpickler,
               pload=None,
               pid=None,
               make_sync_call=None,
               _app_id=None):
    """Create a new Client object.

    No parameters are required.

    Arguments:
      servers: Ignored; only for compatibility.
      debug: Ignored; only for compatibility.
      pickleProtocol: Pickle protocol to use for pickling the object.
      pickler: pickle.Pickler sub-class to use for pickling.
      unpickler: pickle.Unpickler sub-class to use for unpickling.
      pload: Callable to use for retrieving objects by persistent id.
      pid: Callable to use for determine the persistent id for objects, if any.
      make_sync_call: Ignored; only for compatibility with an earlier version.
    """





    self._pickler_factory = pickler
    self._unpickler_factory = unpickler
    self._pickle_protocol = pickleProtocol
    self._persistent_id = pid
    self._persistent_load = pload
    self._app_id = _app_id
    self._cas_ids = {} 
Example #5
Source File: compiler.py    From quark with Apache License 2.0 5 votes vote down vote up
def compile(self):
        self.log.info("Compiling quark code")
        for root in self.roots.sorted():
            if getattr(root, "_compiled", False):
                continue
            for use in root.uses:
                dep = self.roots[use]
                assert getattr(dep, "_compiled", False)
                self.merge(root.env, dep.env)
            self.icompile(root)
            root._compiled = True

        modified = []
        for url, file in self.entries.items():
            if not os.path.exists(url): continue
            urlc = compiled_quark(url)
            trans_roots = tuple(self.trans_roots(file.root))
            deps = tuple(self.deps(trans_roots))
            if not is_newer(urlc, __file__, *deps):
                self.log.info("Writing %s" % urlc)
                with open(urlc, "w") as fd:
                    pickler = pickle.Pickler(fd, -1)
                    pickler.dump(deps)
                    pickler.dump(trans_roots)
                    # Write out an object to mark the archive end so
                    # we can detect partial writes.
                    pickler.dump(ARCHIVE_END)
                modified.append(file.root)
        # We compute the modified flag here so it never gets saved to disk.
        for r in modified:
            r._modified = True 
Example #6
Source File: shelve.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #7
Source File: test_cpickle.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = StringIO()
        p = cPickle.Pickler(f, proto)
        p.dump(arg)
        f.seek(0)
        return f.read() 
Example #8
Source File: test_cpickle.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        p = cPickle.Pickler(proto)
        p.dump(arg)
        return p.getvalue() 
Example #9
Source File: test_cpickle.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = StringIO()
        p = cPickle.Pickler(f, proto)
        p.fast = 1
        p.dump(arg)
        f.seek(0)
        return f.read() 
Example #10
Source File: data_manager.py    From automl_gpu with MIT License 5 votes vote down vote up
def loadData (self, filename, verbose=True, replace_missing=True):
		''' Get the data from a text file in one of 3 formats: matrix, sparse, binary_sparse'''
		if verbose:  print("========= Reading " + filename)
		start = time.time()
		if self.use_pickle and os.path.exists (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle")):
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "r") as pickle_file:
				vprint (verbose, "Loading pickle file : " + os.path.join(self.tmp_dir, os.path.basename(filename) + ".pickle"))
				return pickle.load(pickle_file)
		if 'format' not in self.info.keys():
			self.getFormatData(filename)
		if 'feat_num' not in self.info.keys():
			self.getNbrFeatures(filename)
			
		data_func = {'dense':data_io.data, 'sparse':data_io.data_sparse, 'sparse_binary':data_io.data_binary_sparse}
		
		data = data_func[self.info['format']](filename, self.info['feat_num'])
  
		# INPORTANT: when we replace missing values we double the number of variables
  
		if self.info['format']=='dense' and replace_missing and np.any(map(np.isnan,data)):
			vprint (verbose, "Replace missing values by 0 (slow, sorry)")
			data = data_converter.replace_missing(data)
		if self.use_pickle:
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "wb") as pickle_file:
				vprint (verbose, "Saving pickle file : " + os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"))
				p = pickle.Pickler(pickle_file) 
				p.fast = True 
				p.dump(data)
		end = time.time()
		if verbose:  print( "[+] Success in %5.2f sec" % (end - start))
		return data 
Example #11
Source File: data_manager.py    From automl_gpu with MIT License 5 votes vote down vote up
def loadLabel (self, filename, verbose=True):
		''' Get the solution/truth values'''
		if verbose:  print("========= Reading " + filename)
		start = time.time()
		if self.use_pickle and os.path.exists (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle")):
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "r") as pickle_file:
				vprint (verbose, "Loading pickle file : " + os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"))
				return pickle.load(pickle_file)
		if 'task' not in self.info.keys():
			self.getTypeProblem(filename)
	
           # IG: Here change to accommodate the new multiclass label format
		if self.info['task'] == 'multilabel.classification':
			label = data_io.data(filename)
		elif self.info['task'] == 'multiclass.classification':
			label = data_converter.convert_to_num(data_io.data(filename))              
		else:
			label = np.ravel(data_io.data(filename)) # get a column vector
			#label = np.array([np.ravel(data_io.data(filename))]).transpose() # get a column vector
   
		if self.use_pickle:
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "wb") as pickle_file:
				vprint (verbose, "Saving pickle file : " + os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"))
				p = pickle.Pickler(pickle_file) 
				p.fast = True 
				p.dump(label)
		end = time.time()
		if verbose:  print( "[+] Success in %5.2f sec" % (end - start))
		return label 
Example #12
Source File: data_manager.py    From AutoML with MIT License 5 votes vote down vote up
def loadData (self, filename, verbose=True, replace_missing=True):
		''' Get the data from a text file in one of 3 formats: matrix, sparse, binary_sparse'''
		if verbose:  print("========= Reading " + filename)
		start = time.time()
		if self.use_pickle and os.path.exists (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle")):
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "r") as pickle_file:
				vprint (verbose, "Loading pickle file : " + os.path.join(self.tmp_dir, os.path.basename(filename) + ".pickle"))
				return pickle.load(pickle_file)
		if 'format' not in self.info.keys():
			self.getFormatData(filename)
		if 'feat_num' not in self.info.keys():
			self.getNbrFeatures(filename)
			
		data_func = {'dense':data_io.data, 'sparse':data_io.data_sparse, 'sparse_binary':data_io.data_binary_sparse}
		
		data = data_func[self.info['format']](filename, self.info['feat_num'])
  
		# INPORTANT: when we replace missing values we double the number of variables
  
		if self.info['format']=='dense' and replace_missing and np.any(map(np.isnan,data)):
			vprint (verbose, "Replace missing values by 0 (slow, sorry)")
			data = data_converter.replace_missing(data)
		if self.use_pickle:
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "wb") as pickle_file:
				vprint (verbose, "Saving pickle file : " + os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"))
				p = pickle.Pickler(pickle_file) 
				p.fast = True 
				p.dump(data)
		end = time.time()
		if verbose:  print( "[+] Success in %5.2f sec" % (end - start))
		return data 
Example #13
Source File: data_manager.py    From AutoML with MIT License 5 votes vote down vote up
def loadLabel (self, filename, verbose=True):
		''' Get the solution/truth values'''
		if verbose:  print("========= Reading " + filename)
		start = time.time()
		if self.use_pickle and os.path.exists (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle")):
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "r") as pickle_file:
				vprint (verbose, "Loading pickle file : " + os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"))
				return pickle.load(pickle_file)
		if 'task' not in self.info.keys():
			self.getTypeProblem(filename)
	
           # IG: Here change to accommodate the new multiclass label format
		if self.info['task'] == 'multilabel.classification':
			label = data_io.data(filename)
		elif self.info['task'] == 'multiclass.classification':
			label = data_converter.convert_to_num(data_io.data(filename))              
		else:
			label = np.ravel(data_io.data(filename)) # get a column vector
			#label = np.array([np.ravel(data_io.data(filename))]).transpose() # get a column vector
   
		if self.use_pickle:
			with open (os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"), "wb") as pickle_file:
				vprint (verbose, "Saving pickle file : " + os.path.join (self.tmp_dir, os.path.basename(filename) + ".pickle"))
				p = pickle.Pickler(pickle_file) 
				p.fast = True 
				p.dump(label)
		end = time.time()
		if verbose:  print( "[+] Success in %5.2f sec" % (end - start))
		return label 
Example #14
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #15
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #16
Source File: simple_search_stub.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def Write(self):
    """Write search indexes to the index file.

    This method is a no-op if index_file is set to None.
    """
    if not self.__index_file:
      return





    descriptor, tmp_filename = tempfile.mkstemp(
        dir=os.path.dirname(self.__index_file))
    tmpfile = os.fdopen(descriptor, 'wb')

    pickler = pickle.Pickler(tmpfile, protocol=1)
    pickler.fast = True
    pickler.dump((self._VERSION, self.__indexes))

    tmpfile.close()

    self.__index_file_lock.acquire()
    try:
      try:

        os.rename(tmp_filename, self.__index_file)
      except OSError:


        os.remove(self.__index_file)
        os.rename(tmp_filename, self.__index_file)
    finally:
      self.__index_file_lock.release() 
Example #17
Source File: test_cpickle.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        p = cPickle.Pickler(proto)
        p.dump(arg)
        return p.getvalue() 
Example #18
Source File: test_cpickle.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = StringIO()
        p = cPickle.Pickler(f, proto)
        p.fast = 1
        p.dump(arg)
        f.seek(0)
        return f.read() 
Example #19
Source File: shelve.py    From RevitBatchProcessor with GNU General Public License v3.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #20
Source File: shelve.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #21
Source File: shelve.py    From unity-python with MIT License 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #22
Source File: shelve.py    From canape with GNU General Public License v3.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #23
Source File: shelve.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #24
Source File: shelve.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue() 
Example #25
Source File: test_cpickle.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = StringIO()
        p = cPickle.Pickler(f, proto)
        p.dump(arg)
        f.seek(0)
        return f.read() 
Example #26
Source File: test_cpickle.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        p = cPickle.Pickler(proto)
        p.dump(arg)
        return p.getvalue() 
Example #27
Source File: test_cpickle.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = StringIO()
        p = cPickle.Pickler(f, proto)
        p.fast = 1
        p.dump(arg)
        f.seek(0)
        return f.read() 
Example #28
Source File: test_cpickle.py    From oss-ftp with MIT License 5 votes vote down vote up
def dumps(self, arg, proto=0):
        f = self.output()
        try:
            p = cPickle.Pickler(f, proto)
            p.dump(arg)
            f.seek(0)
            return f.read()
        finally:
            self.close(f) 
Example #29
Source File: gencache.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def _SaveDicts():
	if is_readonly:
		raise RuntimeError("Trying to write to a readonly gencache ('%s')!" \
		                    % win32com.__gen_path__)
	f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
	try:
		p = pickle.Pickler(f)
		p.dump(pickleVersion)
		p.dump(clsidToTypelib)
	finally:
		f.close() 
Example #30
Source File: shelve.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue()