Skip to content
Snippets Groups Projects
Commit 893c29d2 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Python-dependent string serialization added

parent a5c08f17
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,23 @@ class LogEntry(object):
return self
def to_compact(self):
"""Serializes this as Python-specific string"""
return pickle.dumps(
(self.when, self.who, self.tags, self.main_attachment, self.attachments),
pickle.HIGHEST_PROTOCOL
)
@staticmethod
def from_compact(p):
"""@param p: str"""
when, who, tags, main_attachment, attachments = pickle.loads(p)
le = LogEntry(who, tags, when).attach(main_attachment)
for k, v in attachments.iteritems():
le.attach(k, v)
return le
def to_JSON(self):
"""Serializes this object to JSON."""
return json.dumps({
......
......@@ -5,7 +5,15 @@ import unittest
class LogsetTest(unittest.TestCase):
def test_serialization(self):
def test_compact_serialization(self):
k = LogEntry('a.b', 'a b').attach('stefan', 'nope')
k = LogEntry.from_compact(k.to_compact())
self.assertEquals(k.attachments['stefan'], 'nope')
def test_JSON_serialization(self):
k = LogEntry('a.b', 'a b').attach('stefan', 'nope')
k = LogEntry.from_JSON(k.to_JSON())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment