- commit
- 715883b5de21a2c56a1b52915858fb67e96fc819
- parent
- a7fa218d50fd203bf7ba9b9db438442b91a55fdb
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-05-08 18:38
implement BSDCal.load
Diffstat
| M | cctool.py | 19 | +++++++++++++++++++ |
| M | tests.py | 14 | +++++++++----- |
2 files changed, 28 insertions, 5 deletions
diff --git a/cctool.py b/cctool.py
@@ -29,6 +29,7 @@ from __future__ import print_function 29 29 30 30 import os 31 31 import sys -1 32 import re 32 33 import argparse 33 34 import logging as log 34 35 from collections import OrderedDict @@ -74,6 +75,7 @@ def _str(x): 74 75 75 76 def formats(): 76 77 informats = { -1 78 'bsdcal': BSDCal, 77 79 'abook': ABook, 78 80 'json': JSON, 79 81 'pickle': Pickle, @@ -240,6 +242,23 @@ class BSDCal(Format): 240 242 elif dt.year == datetime.today().year: 241 243 _fh.write('%s\t%s\n' % (dt.strftime('%m/%d'), item.join('summary'))) 242 244 -1 245 @classmethod -1 246 def load(cls, fh): -1 247 # Reads only a subset of bsdcal syntax! -1 248 year = datetime.today().year -1 249 for line in fh: -1 250 m = re.match(b'(\d\d)\/(\d\d)(\*?)\t(.*)', line.rstrip()) -1 251 if m: -1 252 month, day, yearly, summary = m.groups() -1 253 -1 254 mdict = MultiDict() -1 255 mdict['dtstart'] = [datetime(year, int(month), int(day))] -1 256 mdict['summary'] = [summary.decode('utf8')] -1 257 if yearly == b'*': -1 258 mdict['freq'] = ['yearly'] -1 259 -1 260 yield mdict -1 261 243 262 244 263 class ICal(Format): 245 264 fields = {
diff --git a/tests.py b/tests.py
@@ -81,14 +81,18 @@ class TestBSDCal(_TestFormat): 81 81 def setUp(self): 82 82 self.format = cctool.BSDCal() 83 83 self.data = [84 -1 cctool.MultiDict({'dtstart': [dt], 'summary': ['foo']}),85 -1 cctool.MultiDict({'bday': [dt], 'name': ['bar']}),-1 84 cctool.MultiDict([ -1 85 ('dtstart', [dt]), -1 86 ('summary', [u'foo']), -1 87 ]), -1 88 cctool.MultiDict([ -1 89 ('dtstart', [dt]), -1 90 ('summary', [u'bar']), -1 91 ('freq', ['yearly']), -1 92 ]), 86 93 ] 87 94 self.text = b'01/01\tfoo\n01/01*\tbar\n' 88 9589 -1 def test_load(self):90 -1 pass91 -192 96 93 97 @unittest.skipIf(isinstance(cctool.icalendar, Exception), 'icalendar not available') 94 98 class TestICal(_TestFormat):