Implemented SheerkaOntology
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
|
||||
import core.utils
|
||||
from core.global_symbols import NotInit, NotFound, Removed
|
||||
from sheerkapickle import tags, utils, handlers
|
||||
|
||||
|
||||
@@ -20,6 +21,9 @@ class SheerkaUnpickler:
|
||||
if has_tag(obj, tags.TUPLE):
|
||||
return self._restore_tuple(obj)
|
||||
|
||||
if has_tag(obj, tags.CUSTOM):
|
||||
return self._restore_custom(obj)
|
||||
|
||||
if has_tag(obj, tags.SET):
|
||||
return self._restore_set(obj)
|
||||
|
||||
@@ -43,6 +47,19 @@ class SheerkaUnpickler:
|
||||
def _restore_tuple(self, obj):
|
||||
return tuple([self.restore(v) for v in obj[tags.TUPLE]])
|
||||
|
||||
def _restore_custom(self, obj):
|
||||
if obj[tags.CUSTOM] == NotInit.value:
|
||||
instance = NotInit
|
||||
elif obj[tags.CUSTOM] == NotFound.value:
|
||||
instance = NotFound
|
||||
elif obj[tags.CUSTOM] == Removed.value:
|
||||
instance = Removed
|
||||
else:
|
||||
raise KeyError(f"unknown {obj[tags.CUSTOM]}")
|
||||
|
||||
self.objs.append(instance)
|
||||
return instance
|
||||
|
||||
def _restore_set(self, obj):
|
||||
return set([self.restore(v) for v in obj[tags.SET]])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user