Add support for pickle

This commit is contained in:
ZyX 2014-07-12 23:22:28 +04:00
parent 2296290037
commit b043749daa
1 changed files with 13 additions and 0 deletions

View File

@ -22,8 +22,15 @@ def gen_init(cls):
return __init__
def gen_getnewargs(cls):
def __getnewargs__(self):
return (self.value, self.mark)
return __getnewargs__
class MarkedUnicode(unicode):
__new__ = gen_new(unicode)
__getnewargs__ = gen_getnewargs(unicode)
def _proc_partition(self, part_result):
pointdiff = 1
@ -47,15 +54,18 @@ class MarkedUnicode(unicode):
class MarkedInt(int):
__new__ = gen_new(int)
__getnewargs__ = gen_getnewargs(int)
class MarkedFloat(float):
__new__ = gen_new(float)
__getnewargs__ = gen_getnewargs(float)
class MarkedDict(dict):
__new__ = gen_new(dict)
__init__ = gen_init(dict)
__getnewargs__ = gen_getnewargs(dict)
def copy(self):
return MarkedDict(super(MarkedDict, self).copy(), self.mark)
@ -64,6 +74,7 @@ class MarkedDict(dict):
class MarkedList(list):
__new__ = gen_new(list)
__init__ = gen_init(list)
__getnewargs__ = gen_getnewargs(list)
class MarkedValue:
@ -71,6 +82,8 @@ class MarkedValue:
self.mark = mark
self.value = value
__getinitargs__ = gen_getnewargs(None)
specialclasses = {
unicode: MarkedUnicode,