Commit 8c63a5d1 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

better pickling support

parent fdb84c42
...@@ -149,6 +149,9 @@ class DomainTuple(object): ...@@ -149,6 +149,9 @@ class DomainTuple(object):
return ("DomainTuple, len: {}\n".format(len(self)) + return ("DomainTuple, len: {}\n".format(len(self)) +
"\n".join(str(i) for i in self)) "\n".join(str(i) for i in self))
def __reduce__(self):
return (_unpickleDomainTuple, (self._dom,))
@staticmethod @staticmethod
def scalar_domain(): def scalar_domain():
if DomainTuple._scalarDomain is None: if DomainTuple._scalarDomain is None:
...@@ -158,3 +161,7 @@ class DomainTuple(object): ...@@ -158,3 +161,7 @@ class DomainTuple(object):
def __repr__(self): def __repr__(self):
subs = "\n".join(sub.__repr__() for sub in self._dom) subs = "\n".join(sub.__repr__() for sub in self._dom)
return "DomainTuple:\n"+utilities.indent(subs) return "DomainTuple:\n"+utilities.indent(subs)
def _unpickleDomainTuple(*args):
return DomainTuple.make(*args)
...@@ -73,6 +73,9 @@ class MultiDomain(object): ...@@ -73,6 +73,9 @@ class MultiDomain(object):
def keys(self): def keys(self):
return self._keys return self._keys
def values(self):
return self._domains
def domains(self): def domains(self):
return self._domains return self._domains
...@@ -121,7 +124,14 @@ class MultiDomain(object): ...@@ -121,7 +124,14 @@ class MultiDomain(object):
res[key] = subdom res[key] = subdom
return MultiDomain.make(res) return MultiDomain.make(res)
def __reduce__(self):
return (_unpickleMultiDomain, (dict(self),))
def __repr__(self): def __repr__(self):
subs = "\n".join("{}:\n {}".format(key, dom.__repr__()) subs = "\n".join("{}:\n {}".format(key, dom.__repr__())
for key, dom in self.items()) for key, dom in self.items())
return "MultiDomain:\n"+indent(subs) return "MultiDomain:\n"+indent(subs)
def _unpickleMultiDomain(*args):
return MultiDomain.make(*args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment