home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / rdflib / store / NodePickler.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.9 KB  |  50 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from cPickle import Pickler, Unpickler, UnpicklingError
  5. from cStringIO import StringIO
  6.  
  7. class NodePickler(object):
  8.     
  9.     def __init__(self):
  10.         self._objects = { }
  11.         self._ids = { }
  12.         self._get_object = self._objects.__getitem__
  13.  
  14.     
  15.     def _get_ids(self, key):
  16.         
  17.         try:
  18.             return self._ids.get(key)
  19.         except TypeError:
  20.             e = None
  21.             return None
  22.  
  23.  
  24.     
  25.     def register(self, object, id):
  26.         self._objects[id] = object
  27.         self._ids[object] = id
  28.  
  29.     
  30.     def loads(self, s):
  31.         up = Unpickler(StringIO(s))
  32.         up.persistent_load = self._get_object
  33.         
  34.         try:
  35.             return up.load()
  36.         except KeyError:
  37.             e = None
  38.             raise UnpicklingError, 'Could not find Node class for %s' % e
  39.  
  40.  
  41.     
  42.     def dumps(self, obj, protocol = None, bin = None):
  43.         src = StringIO()
  44.         p = Pickler(src)
  45.         p.persistent_id = self._get_ids
  46.         p.dump(obj)
  47.         return src.getvalue()
  48.  
  49.  
  50.