Python cPickle.Unpickler() Examples

The following are 30 code examples of cPickle.Unpickler(). 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: record.py    From oldnyc with Apache License 2.0 6 votes vote down vote up
def AllRecords(path=None):
  """Reads all records from the pickled file and returns a list."""
  if not path:
    path = os.path.join(os.path.dirname(__file__), 'records.pickle')
  unpickler = cPickle.Unpickler(open(path, 'r'))

  count = 0
  rs = []
  try:
    while True:
      r = unpickler.load()
      rs.append(r)
      count += 1
  except EOFError:
    pass

  sys.stderr.write("Loaded %d records\n" % count)
  return rs 
Example #2
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 #3
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #4
Source File: shelve.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #5
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example #6
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #7
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #8
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #9
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #10
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #11
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #12
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #13
Source File: shelve.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example #14
Source File: shelve.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #15
Source File: shelve.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example #16
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 #17
Source File: shelve.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def first(self):
        (key, value) = self.dict.first()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #18
Source File: shelve.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def previous(self):
        (key, value) = self.dict.previous()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #19
Source File: shelve.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def next(self):
        (key, value) = self.dict.next()
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #20
Source File: shelve.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_location(self, key):
        (key, value) = self.dict.set_location(key)
        f = StringIO(value)
        return (key, Unpickler(f).load()) 
Example #21
Source File: shelve.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __getitem__(self, key):
        try:
            value = self.cache[key]
        except KeyError:
            f = StringIO(self.dict[key])
            value = Unpickler(f).load()
            if self.writeback:
                self.cache[key] = value
        return value 
Example #22
Source File: test_cpickle.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def loads(self, *args):
        f = self.input(args[0])
        try:
            p = cPickle.Unpickler(f)
            return p.load()
        finally:
            self.close(f) 
Example #23
Source File: test_cpickle.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def loads(self, *args):
        f = self.input(args[0])
        try:
            p = cPickle.Unpickler(f)
            return p.load()
        finally:
            self.close(f) 
Example #24
Source File: test_cpickle.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def loads(self, buf):
        f = self.input(buf)
        try:
            p = cPickle.Unpickler(f)
            return p.load()
        finally:
            self.close(f) 
Example #25
Source File: old-cpDetect.py    From cpdetect with GNU General Public License v3.0 5 votes vote down vote up
def load_testdata( filename = "trajectory.dat" ):
	FILE = open( filename )
	u = cPickle.Unpickler( FILE )
	data = u.load()
	FILE.close()
	return data

# for Gaussian noise only. For this reason, the first three points and the last two points
# cannot correspond to a change point. Thus, we return an array of length (npts-5). 
Example #26
Source File: cpDetect.py    From cpdetect with GNU General Public License v3.0 5 votes vote down vote up
def load_testdata( filename = "trajectory.dat" ):
	FILE = open( filename )
	u = cPickle.Unpickler( FILE )
	data = u.load()
	FILE.close()
	return data 
Example #27
Source File: old2cpDetect.py    From cpdetect with GNU General Public License v3.0 5 votes vote down vote up
def load_testdata( filename = "trajectory.dat" ):
	FILE = open( filename )
	u = cPickle.Unpickler( FILE )
	data = u.load()
	FILE.close()
	return data

# for Gaussian noise only. For this reason, the first three points and the last two points
# cannot correspond to a change point. Thus, we return an array of length (npts-5). 
Example #28
Source File: memcacheclient.py    From ccs-calendarserver with Apache License 2.0 5 votes vote down vote up
def __init__(self, servers, debug=0, pickleProtocol=0,
                 pickler=pickle.Pickler, unpickler=pickle.Unpickler,
                 pload=None, pid=None):

        local.__init__(self)

        super(TestClient, self).__init__(
            servers, debug=debug,
            pickleProtocol=pickleProtocol, pickler=pickler, unpickler=unpickler,
            pload=pload, pid=pid)

        self.data = {}
        self.token = 0 
Example #29
Source File: memcacheclient.py    From ccs-calendarserver with Apache License 2.0 5 votes vote down vote up
def __init__(self, servers, debug=0, pickleProtocol=0,
                 pickler=pickle.Pickler, unpickler=pickle.Unpickler,
                 pload=None, pid=None):
        """
        Create a new Client object with the given list of servers.

        @param servers: C{servers} is passed to L{set_servers}.
        @param debug: whether to display error messages when a server can't be
        contacted.
        @param pickleProtocol: number to mandate protocol used by (c)Pickle.
        @param pickler: optional override of default Pickler to allow subclassing.
        @param unpickler: optional override of default Unpickler to allow subclassing.
        @param pload: optional persistent_load function to call on pickle loading.
        Useful for cPickle since subclassing isn't allowed.
        @param pid: optional persistent_id function to call on pickle storing.
        Useful for cPickle since subclassing isn't allowed.
        """
        local.__init__(self)
        self.set_servers(servers)
        self.debug = debug
        self.stats = {}

        # Allow users to modify pickling/unpickling behavior
        self.pickleProtocol = pickleProtocol
        self.pickler = pickler
        self.unpickler = unpickler
        self.persistent_load = pload
        self.persistent_id = pid

        #  figure out the pickler style
        file = StringIO()
        try:
            pickler = self.pickler(file, protocol=self.pickleProtocol)
            self.picklerIsKeyword = True
        except TypeError:
            self.picklerIsKeyword = False 
Example #30
Source File: page_construct.py    From namsel with MIT License 5 votes vote down vote up
def load_pkl_page(pkl_path):
    if os.path.exists(pkl_path):
        fl = gzip.open(pkl_path)
        return pickle.Unpickler(fl).load()