コード例 #1
0
ファイル: unpickler.py プロジェクト: jakesyl/cing
 def _restore(self, obj):
     if has_tag(obj, tags.ID):
         restore = self._restore_id
     elif has_tag(obj, tags.REF): # Backwards compatibility
         restore = self._restore_ref
     elif has_tag(obj, tags.ITERATOR):
         restore = self._restore_iterator
     elif has_tag(obj, tags.TYPE):
         restore = self._restore_type
     elif has_tag(obj, tags.REPR): # Backwards compatibility
         restore = self._restore_repr
     elif has_tag(obj, tags.REDUCE):
         restore = self._restore_reduce
     elif has_tag(obj, tags.OBJECT):
         return self._restore_object(obj)
     elif has_tag(obj, tags.FUNCTION):
         restore = self._restore_function
     elif util.is_list(obj):
         restore = self._restore_list
     elif has_tag(obj, tags.TUPLE):
         restore = self._restore_tuple
     elif has_tag(obj, tags.SET):
         restore = self._restore_set
     elif util.is_dictionary(obj):
         restore = self._restore_dict
     else:
         restore = lambda x: x
     return restore(obj)
コード例 #2
0
ファイル: pickler.py プロジェクト: jakesyl/cing
    def _get_flattener(self, obj):

        if util.is_primitive(obj):
            return lambda obj: obj

        list_recurse = self._list_recurse

        if util.is_list(obj):
            if self._mkref(obj):
                return list_recurse
            else:
                self._push()
                return self._getref

        # We handle tuples and sets by encoding them in a "(tuple|set)dict"
        if util.is_tuple(obj):
            if not self.unpicklable:
                return list_recurse
            return lambda obj: {tags.TUPLE: [self._flatten(v) for v in obj]}

        if util.is_set(obj):
            if not self.unpicklable:
                return list_recurse
            return lambda obj: {tags.SET: [self._flatten(v) for v in obj]}

        if util.is_dictionary(obj):
            return self._flatten_dict_obj

        if util.is_type(obj):
            return _mktyperef

        if util.is_object(obj):
            return self._ref_obj_instance

        if util.is_module_function(obj):
            return self._flatten_function

        # instance methods, lambdas, old style classes...
        self._pickle_warning(obj)
        return None