-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.py
262 lines (189 loc) · 6.55 KB
/
interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
try:
from zope.interface import Interface, Attribute
except ImportError:
class Interface:
"""A dummy interface base class"""
class Attribute:
"""A dummy attribute implementation"""
def __init__(self, doc):
self.doc = doc
_marker = object()
class IComponent(Interface):
"""
Component is the base object for calendar, Event and the other
components defined in RFC 2445.
A component is like a dictionary with extra methods and attributes.
"""
# MANIPULATORS
def __setitem__(name, value):
"""Set a property.
name - case insensitive name
value - value of the property to set. This can be either a single
item or a list.
Some iCalendar properties are set INLINE; these properties
have multiple values on one property line in the iCalendar
representation. The list can be supplied as a comma separated
string to __setitem__. If special iCalendar characters exist in
an entry, such as the colon (:) and (,), that comma-separated
entry needs to be quoted with double quotes. For example:
'foo, bar, "baz:hoi"'
See also set_inline() for an easier way to deal with this case.
"""
def set_inline(name, values, encode=1):
"""Set list of INLINE values for property.
Converts a list of values into valid iCalendar comma seperated
string and sets value to that.
name - case insensitive name of property
values - list of values to set
encode - if True, encode Python values as iCalendar types first.
"""
def add(name, value):
"""Add a property. Can be called multiple times to set a list.
name - case insensitive name
value - value of property to set or add to list for this property.
"""
def add_component(component):
"""Add a nested subcomponent to this component.
"""
# static method, can be called on class directly
def from_string(st, multiple=False):
"""Populates the component recursively from a iCalendar string.
Reads the iCalendar string and constructs components and
subcomponents out of it.
"""
# ACCESSORS
def __getitem__(name):
"""Get a property
name - case insensitive name
Returns an iCalendar property object such as vText.
"""
def decoded(name, default=_marker):
"""Get a property as a python object.
name - case insensitive name
default - optional argument. If supplied, will use this if
name cannot be found. If not supplied, decoded will raise a
KeyError if name cannot be found.
Returns python object (such as unicode string, datetime, etc).
"""
def get_inline(name, decode=1):
"""Get list of INLINE values from property.
name - case insensitive name
decode - decode to Python objects.
Returns list of python objects.
"""
def as_string():
"""Render the component in the RFC 2445 (iCalendar) format.
Returns a string in RFC 2445 format.
"""
subcomponents = Attribute("""
A list of all subcomponents of this component,
added using add_component()""")
name = Attribute("""
Name of this component (VEVENT, etc)
""")
def walk(name=None):
"""Recursively traverses component and subcomponents.
name - optional, if given, only return components with that name
Returns sequence of components.
"""
def property_items():
"""Return properties as (name, value) tuples.
Returns all properties in this comopnent and subcomponents as
name, value tuples.
"""
class IEvent(IComponent):
"""A component which conforms to an iCalendar VEVENT.
"""
class ITodo(IComponent):
"""A component which conforms to an iCalendar VTODO.
"""
class IJournal(IComponent):
"""A component which conforms to an iCalendar VJOURNAL.
"""
class IFreeBusy(IComponent):
"""A component which conforms to an iCalendar VFREEBUSY.
"""
class ITimezone(IComponent):
"""A component which conforms to an iCalendar VTIMEZONE.
"""
class IAlarm(IComponent):
"""A component which conforms to an iCalendar VALARM.
"""
class ICalendar(IComponent):
"""A component which conforms to an iCalendar VCALENDAR.
"""
class IPropertyValue(Interface):
"""An iCalendar property value.
iCalendar properties have strongly typed values.
This invariance should always be true:
assert x == vDataType.from_ical(vDataType(x).ical())
"""
def ical():
"""Render property as string, as defined in iCalendar RFC 2445.
"""
# this is a static method
def from_ical(ical):
"""Parse property from iCalendar RFC 2445 text.
Inverse of ical().
"""
class IBinary(IPropertyValue):
"""Binary property values are base 64 encoded
"""
class IBoolean(IPropertyValue):
"""Boolean property.
Also behaves like a python int.
"""
class ICalAddress(IPropertyValue):
"""Email address.
Also behaves like a python str.
"""
class IDateTime(IPropertyValue):
"""Render and generates iCalendar datetime format.
Important: if tzinfo is defined it renders itself as 'date with utc time'
Meaning that it has a 'Z' appended, and is in absolute time.
"""
class IDate(IPropertyValue):
"""Render and generates iCalendar date format.
"""
class IDuration(IPropertyValue):
"""Render and generates timedelta in iCalendar DURATION format.
"""
class IFloat(IPropertyValue):
"""Render and generate floats in iCalendar format.
Also behaves like a python float.
"""
class IInt(IPropertyValue):
"""Render and generate ints in iCalendar format.
Also behaves like a python int.
"""
class IPeriod(IPropertyValue):
"""A precise period of time (datetime, datetime).
"""
class IWeekDay(IPropertyValue):
"""Render and generate weekday abbreviation.
"""
class IFrequency(IPropertyValue):
"""Frequency.
"""
class IRecur(IPropertyValue):
"""Render and generate data based on recurrent event representation.
This acts like a caseless dictionary.
"""
class IText(IPropertyValue):
"""Unicode text.
"""
class ITime(IPropertyValue):
"""Time.
"""
class IUri(IPropertyValue):
"""URI
"""
class IGeo(IPropertyValue):
"""Geographical location.
"""
class IUTCOffset(IPropertyValue):
"""Offset from UTC.
"""
class IInline(IPropertyValue):
"""Inline list.
"""