Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[g_sorcery/serialization] fix serialization for collections
- Loading branch information
Showing
6 changed files
with
94 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
serializable.py | ||
~~~~~~~~~~~~~~~ | ||
test classes for serialization | ||
:copyright: (c) 2013-2015 by Jauhien Piatlicki | ||
:license: GPL-2, see LICENSE for more details. | ||
""" | ||
|
||
class NonSerializableClass(object): | ||
pass | ||
|
||
|
||
class SerializableClass(object): | ||
|
||
__slots__ = ("field1", "field2") | ||
|
||
def __init__(self, field1, field2): | ||
self.field1 = field1 | ||
self.field2 = field2 | ||
|
||
def __eq__(self, other): | ||
return self.field1 == other.field1 \ | ||
and self.field2 == other.field2 | ||
|
||
def serialize(self): | ||
return {"field1": self.field1, "field2": self.field2} | ||
|
||
|
||
class DeserializableClass(SerializableClass): | ||
|
||
@classmethod | ||
def deserialize(cls, value): | ||
return DeserializableClass(value["field1"], value["field2"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters