summaryrefslogtreecommitdiff
path: root/src/vobject/icalendar.py
diff options
context:
space:
mode:
authorGuido Guenther <agx@sigxcpu.org>2006-09-23 23:25:37 +0200
committerGuido Guenther <agx@bogon.sigxcpu.org>2006-09-23 23:25:37 +0200
commit83cca3541c1171102bcda16aa5aab732f5a9097f (patch)
tree8482a7de9a4c9daa636796d9e9f2638aa13e88d9 /src/vobject/icalendar.py
parent0f963fa4c3d05e0f8b297aeb20aa5d719f7ab31d (diff)
Imported python-vobject-0.0.svn155
into Git repository
Diffstat (limited to 'src/vobject/icalendar.py')
-rw-r--r--src/vobject/icalendar.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/vobject/icalendar.py b/src/vobject/icalendar.py
index 9350131..728afb0 100644
--- a/src/vobject/icalendar.py
+++ b/src/vobject/icalendar.py
@@ -84,6 +84,9 @@ class TimezoneComponent(Component):
good_lines = ('rdate', 'rrule', 'dtstart', 'tzname', 'tzoffsetfrom',
'tzoffsetto', 'tzid')
buffer = StringIO.StringIO()
+ # allow empty VTIMEZONEs
+ if len(self.contents) == 0:
+ return None
def customSerialize(obj):
if isinstance(obj, Component):
foldOneLine(buffer, u"BEGIN:" + obj.name)
@@ -380,7 +383,9 @@ class RecurringComponent(Component):
rule = dateutil.rrule.rrulestr(str(line.value),
dtstart=dtstart)
until = rule._until
- if until is not None and until.tzinfo != dtstart.tzinfo:
+ if until is not None and \
+ isinstance(dtstart, datetime.datetime) and \
+ (until.tzinfo != dtstart.tzinfo):
# dateutil converts the UNTIL date to a datetime,
# check to see if the UNTIL parameter value was a date
vals = dict(pair.split('=') for pair in
@@ -482,9 +487,11 @@ class RecurringComponent(Component):
values['BYMONTHDAY'] = [str(n) for n in rule._bymonthday]
if rule._bymonth is not None and len(rule._bymonth) > 0:
- if not (rule._freq == dateutil.rrule.YEARLY and
- len(rule._bymonth) == 1 and
- rule._bymonth[0] == rule._dtstart.month):
+ if (rule._byweekday is not None or
+ len(rrule._bynweekday or ()) > 0 or
+ not (rule._freq == dateutil.rrule.YEARLY and
+ len(rule._bymonth) == 1 and
+ rule._bymonth[0] == rule._dtstart.month)):
# ignore bymonth if it's generated by dateutil
values['BYMONTH'] = [str(n) for n in rule._bymonth]
@@ -657,8 +664,7 @@ class MultiDateBehavior(behavior.Behavior):
appropriate strings.
"""
- # Fixme: obj.value should be a list, so this test should never succeed
- if type(obj.value) == datetime.date:
+ if obj.value and type(obj.value[0]) == datetime.date:
obj.isNative = False
obj.value_param = 'DATE'
obj.value = ','.join([dateToString(val) for val in obj.value])
@@ -791,8 +797,8 @@ class VCalendar2_0(behavior.Behavior):
findTzids(obj, tzidsUsed)
oldtzids = [x.tzid.value for x in getattr(obj, 'vtimezone_list', [])]
for tzid in tzidsUsed.keys():
- if tzid == 'UTC' or tzid in oldtzids: continue
- obj.add(TimezoneComponent(tzinfo=getTzid(tzid)))
+ if tzid != 'UTC' and tzid not in oldtzids:
+ obj.add(TimezoneComponent(tzinfo=getTzid(tzid)))
registerBehavior(VCalendar2_0)
class VTimezone(behavior.Behavior):
@@ -811,7 +817,11 @@ class VTimezone(behavior.Behavior):
@classmethod
def validate(cls, obj, raiseException, *args):
- return True #TODO: FIXME
+ if not hasattr(obj, 'tzid') or obj.tzid.value is None:
+ if raiseException:
+ m = "VTIMEZONE components must contain a valid TZID"
+ raise ValidateError(m)
+ return False
if obj.contents.has_key('standard') or obj.contents.has_key('daylight'):
return super(VTimezone, cls).validate(obj, raiseException, *args)
else: