- commit
- 82cf4c9b5edebcb4326466af97e3c6687ae1ede1
- parent
- d9814f9eda06537d07c47911d61659e7e705712f
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-05-08 11:51
add pickle
Diffstat
| M | cctool.py | 13 | +++++++++++++ |
| M | tests.py | 6 | ++++++ |
2 files changed, 19 insertions, 0 deletions
diff --git a/cctool.py b/cctool.py
@@ -34,6 +34,7 @@ import logging as log 34 34 from collections import OrderedDict 35 35 import json 36 36 from datetime import datetime -1 37 import pickle 37 38 38 39 try: 39 40 from StringIO import StringIO @@ -63,11 +64,13 @@ def formats(): 63 64 informats = { 64 65 'abook': ABook, 65 66 'json': JSON, -1 67 'pickle': Pickle, 66 68 } 67 69 outformats = { 68 70 'bsdcal': BSDCal, 69 71 'abook': ABook, 70 72 'json': JSON, -1 73 'pickle': Pickle, 71 74 } 72 75 if not isinstance(vobject, Exception): 73 76 informats['ics'] = ICal @@ -321,6 +324,16 @@ class JSON(Format): 321 324 json.dump(list(data), fh, indent=4, cls=DateTimeJSONEncoder) 322 325 323 326 -1 327 class Pickle(Format): -1 328 @classmethod -1 329 def load(cls, fh): -1 330 return pickle.load(fh) -1 331 -1 332 @classmethod -1 333 def dump(cls, data, fh): -1 334 pickle.dump(data, fh) -1 335 -1 336 324 337 def parse_args(argv=None): 325 338 informats, outformats = formats() 326 339
diff --git a/tests.py b/tests.py
@@ -125,6 +125,12 @@ class TestJSON(_TestFormat): 125 125 self.text = '[\n {\n "name": [\n "foo"\n ]\n }\n]' 126 126 127 127 -1 128 class TestPickle(_TestFormat): -1 129 def setUp(self): -1 130 self.format = cctool.Pickle() -1 131 self.text = '(lp0\nccctool\nMultiDict\np1\n((lp2\n(lp3\nS\'name\'\np4\na(lp5\nS\'foo\'\np6\naaatp7\nRp8\na.' -1 132 -1 133 128 134 class TestArgs(unittest.TestCase): 129 135 def test_args(self): 130 136 args = cctool.parse_args(['-f', 'abook', '-t', 'bsdcal'])