Run update-copyright.py
[pycalendar.git] / pycalendar / property / __init__.py
1 # Copyright (C) 2013 W. Trevor King <wking@tremily.us>
2 #
3 # This file is part of pycalender.
4 #
5 # pycalender is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # pycalender is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # pycalender.  If not, see <http://www.gnu.org/licenses/>.
16
17 """Classes representing calendar properties
18
19 As defined in :RFC:`5545`, sections 3.7 (Calendar Properties) and 3.8
20 (Component Properties).
21 """
22
23 from . import base as _base
24
25 from . import alarm as _alarm
26 from . import calendar as _calendar
27 from . import change as _change
28 from . import component as _component
29 from . import datetime as _datetime
30 from . import descriptive as _descriptive
31 from . import misc as _misc
32 from . import recurrence as _recurrence
33 from . import relationship as _relationship
34 from . import timezone as _timezone
35
36
37 PROPERTY = {}
38
39
40 def register(property):
41     """Register a property class
42     """
43     PROPERTY[property.name] = property
44
45
46 def parse(line):
47     name_param,value = [x.strip() for x in line.split(':', 1)]
48     parameters = name_param.split(';')
49     name = parameters.pop(0).upper()  # names are case insensitive
50     parameters = dict(tuple(x.split('=', 1)) for x in parameters)
51     for k,v in parameters.items():
52         if ',' in v:
53             parameters[k] = v.split(',')
54     prop_class = PROPERTY[name]
55     prop = prop_class(parameters=parameters)
56     prop.check_parameters()
57     prop.value = prop.decode(value=value)
58     prop.check_value()
59     return prop
60
61
62 for module in [
63         _alarm,
64         _calendar,
65         _change,
66         _component,
67         _datetime,
68         _descriptive,
69         _misc,
70         _recurrence,
71         _relationship,
72         _timezone,
73         ]:
74     for name in dir(module):
75         if name.startswith('_'):
76             continue
77         obj = getattr(module, name)
78         if isinstance(obj, type) and issubclass(obj, _base.Property):
79             register(property=obj)
80 del module, name, obj