[CalendarServer-changes] [7521] CalendarServer/branches/users/cdaboo/timezones/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Tue May 24 14:34:57 PDT 2011
Revision: 7521
http://trac.macosforge.org/projects/calendarserver/changeset/7521
Author: cdaboo at apple.com
Date: 2011-05-24 14:34:57 -0700 (Tue, 24 May 2011)
Log Message:
-----------
Support optional timezones-by-reference mode whereby the server strips out any VTIMEZONEs sent, and returns
data without VTIMEZONEs.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/caldavxml.py
CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/ical.py
CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/get.py
CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/put_common.py
CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/stdconfig.py
CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/timezones.py
Modified: CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/caldavxml.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/caldavxml.py 2011-05-24 21:10:35 UTC (rev 7520)
+++ CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/caldavxml.py 2011-05-24 21:34:57 UTC (rev 7521)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2005-2009 Apple Inc. All rights reserved.
+# Copyright (c) 2005-2011 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
from twext.python.log import Logger
+from twistedcaldav.config import config
from twistedcaldav.ical import Component as iComponent
log = Logger()
@@ -330,7 +331,7 @@
return clazz(davxml.PCDATAElement(calendar))
elif isinstance(calendar, iComponent):
assert calendar.name() == "VCALENDAR", "Not a calendar: %r" % (calendar,)
- return clazz(davxml.PCDATAElement(str(calendar)))
+ return clazz(davxml.PCDATAElement(calendar.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference)))
else:
raise ValueError("Not a calendar: %s" % (calendar,))
Modified: CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/ical.py 2011-05-24 21:10:35 UTC (rev 7520)
+++ CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/ical.py 2011-05-24 21:34:57 UTC (rev 7521)
@@ -37,9 +37,11 @@
from twext.web2.stream import IStream
from twext.web2.dav.util import allDataFromStream
+from twistedcaldav.config import config
from twistedcaldav.dateops import timeRangesOverlap, normalizeForIndex, differenceDateTime
from twistedcaldav.instance import InstanceList
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
+from twistedcaldav.timezones import hasTZ, TimezoneException
from pycalendar import definitions
from pycalendar.attribute import PyCalendarAttribute
@@ -416,6 +418,12 @@
return False
return self._pycalendar == other._pycalendar
+ def getTextWithTimezones(self, includeTimezones):
+ """
+ Return text representation and include timezones if the option is on
+ """
+ return self._pycalendar.getText(includeTimezones=includeTimezones)
+
# FIXME: Should this not be in __eq__?
def same(self, other):
return self._pycalendar == other._pycalendar
@@ -1198,6 +1206,27 @@
return self._resource_type
+ def stripKnownTimezones(self):
+ """
+ Remove timezones that this server knows about
+ """
+
+ changed = False
+ for subcomponent in tuple(self.subcomponents()):
+ if subcomponent.name() == "VTIMEZONE":
+ tzid = subcomponent.propertyValue("TZID")
+ try:
+ hasTZ(tzid)
+ except TimezoneException:
+ # tzid not available - do not strip
+ pass
+ else:
+ # tzid known - strip component out
+ self.removeComponent(subcomponent)
+ changed = True
+
+ return changed
+
def validCalendarForCalDAV(self):
"""
@raise InvalidICalendarDataError: if the given calendar data is not valid.
@@ -1353,11 +1382,12 @@
#
# Make sure required timezone components are present
#
- for timezone_ref in timezone_refs:
- if timezone_ref not in timezones:
- msg = "Timezone ID %s is referenced but not defined: %s" % (timezone_ref, self,)
- log.debug(msg)
- raise InvalidICalendarDataError(msg)
+ if not config.EnableTimezonesByReference:
+ for timezone_ref in timezone_refs:
+ if timezone_ref not in timezones:
+ msg = "Timezone ID %s is referenced but not defined: %s" % (timezone_ref, self,)
+ log.debug(msg)
+ raise InvalidICalendarDataError(msg)
#
# FIXME:
Modified: CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/get.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/get.py 2011-05-24 21:10:35 UTC (rev 7520)
+++ CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/get.py 2011-05-24 21:34:57 UTC (rev 7521)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2005-2008 Apple Inc. All rights reserved.
+# Copyright (c) 2005-2011 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
from twext.web2.http_headers import MimeType
from twext.web2.stream import MemoryStream
+from twistedcaldav.config import config
from twistedcaldav.customxml import calendarserver_namespace
from twistedcaldav.datafilters.privateevents import PrivateEventFilter
from twistedcaldav.resource import isPseudoCalendarCollectionResource,\
@@ -87,7 +88,7 @@
caldata = PrivateEventFilter(self.accessMode, isowner).filter(caldata)
response = Response()
- response.stream = MemoryStream(str(caldata))
+ response.stream = MemoryStream(caldata.getTextWithTimezones(includeTimezones=not config.EnableTimezonesByReference))
response.headers.setHeader("content-type", MimeType.fromString("text/calendar; charset=utf-8"))
# Add Schedule-Tag header if property is present
Modified: CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/put_common.py 2011-05-24 21:10:35 UTC (rev 7520)
+++ CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/method/put_common.py 2011-05-24 21:34:57 UTC (rev 7521)
@@ -275,7 +275,12 @@
(caldav_namespace, "valid-calendar-data"),
description="Can't parse calendar data"
))
-
+
+ # Possible timezone stripping
+ if config.EnableTimezonesByReference:
+ if self.calendar.stripKnownTimezones():
+ self.calendardata = None
+
# Valid calendar data check
result, message = self.validCalendarDataCheck()
if not result:
Modified: CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/stdconfig.py 2011-05-24 21:10:35 UTC (rev 7520)
+++ CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/stdconfig.py 2011-05-24 21:34:57 UTC (rev 7521)
@@ -463,6 +463,8 @@
"UpdateIntervalMinutes" : 24 * 60,
}
},
+
+ "EnableTimezonesByReference" : False, # Strip out VTIMEZONES that are known
"EnableBatchUpload" : True, # POST batch uploads
"MaxResourcesBatchUpload" : 100, # Maximum number of resources in a batch POST
Modified: CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/timezones.py
===================================================================
--- CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/timezones.py 2011-05-24 21:10:35 UTC (rev 7520)
+++ CalendarServer/branches/users/cdaboo/timezones/twistedcaldav/timezones.py 2011-05-24 21:34:57 UTC (rev 7521)
@@ -84,7 +84,20 @@
cachedVTZs = {}
cachedTZIDs = []
+def hasTZ(tzid):
+ """
+ Check if the specified TZID is available. Try to load it if not and raise if it
+ cannot be found.
+ """
+
+ if tzid not in cachedVTZs:
+ readVTZ(tzid)
+ return True
+
def readVTZ(tzid):
+ """
+ Try to load the specified TZID as a calendar object from the database. Raise if not found.
+ """
if tzid not in cachedVTZs:
@@ -97,6 +110,9 @@
return cachedVTZs[tzid]
def readTZ(tzid):
+ """
+ Try to load the specified TZID as text from the database. Raise if not found.
+ """
if tzid not in cachedTZs:
@@ -109,6 +125,10 @@
return cachedTZs[tzid]
def listTZs(path=""):
+ """
+ List all timezones in the database.
+ """
+
if not path and cachedTZIDs:
return cachedTZIDs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110524/0486d28b/attachment-0001.html>
More information about the calendarserver-changes
mailing list