2010-01-15 00:15:41 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-12-30 16:25:42 +00:00
|
|
|
#
|
|
|
|
# This file is part of Radicale Server - Calendar Server
|
2010-01-15 00:15:41 +01:00
|
|
|
# Copyright © 2008-2010 Guillaume Ayoub
|
2009-07-27 15:04:54 +00:00
|
|
|
# Copyright © 2008 Nicolas Kandel
|
|
|
|
# Copyright © 2008 Pascal Halter
|
2008-12-30 16:25:42 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-07-27 15:04:54 +00:00
|
|
|
"""
|
|
|
|
Radicale calendar classes.
|
2008-12-30 16:25:42 +00:00
|
|
|
|
2009-07-27 15:04:54 +00:00
|
|
|
Define the main classes of a calendar as seen from the server.
|
|
|
|
"""
|
2008-12-30 16:25:42 +00:00
|
|
|
|
2010-01-15 16:04:03 +01:00
|
|
|
from radicale import support
|
2008-12-30 16:25:42 +00:00
|
|
|
|
2009-07-27 15:04:54 +00:00
|
|
|
hash_tag = lambda vcalendar: str(hash(vcalendar))
|
|
|
|
|
2008-12-30 16:25:42 +00:00
|
|
|
class Calendar(object):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Internal calendar class."""
|
2008-12-30 16:25:42 +00:00
|
|
|
def __init__(self, user, cal):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Initialize the calendar with ``cal`` and ``user`` parameters."""
|
|
|
|
# TODO: Use properties from the calendar configuration
|
2010-01-15 16:04:03 +01:00
|
|
|
self.support = support.load()
|
2008-12-30 16:25:42 +00:00
|
|
|
self.encoding = "utf-8"
|
2010-01-15 16:04:03 +01:00
|
|
|
self.owner = "radicale"
|
2008-12-30 16:25:42 +00:00
|
|
|
self.user = user
|
|
|
|
self.cal = cal
|
|
|
|
self.version = "2.0"
|
2009-07-27 15:04:54 +00:00
|
|
|
self.ctag = hash_tag(self.vcalendar())
|
2008-12-30 16:25:42 +00:00
|
|
|
|
|
|
|
def append(self, vcalendar):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Append vcalendar to the calendar."""
|
|
|
|
self.ctag = hash_tag(self.vcalendar())
|
2010-01-15 16:04:03 +01:00
|
|
|
self.support.append(self.cal, vcalendar)
|
2008-12-30 16:25:42 +00:00
|
|
|
|
|
|
|
def remove(self, uid):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Remove object named ``uid`` from the calendar."""
|
|
|
|
self.ctag = hash_tag(self.vcalendar())
|
2010-01-15 16:04:03 +01:00
|
|
|
self.support.remove(self.cal, uid)
|
2008-12-30 16:25:42 +00:00
|
|
|
|
|
|
|
def replace(self, uid, vcalendar):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Replace objet named ``uid`` by ``vcalendar`` in the calendar."""
|
|
|
|
self.ctag = hash_tag(self.vcalendar())
|
2010-01-15 16:04:03 +01:00
|
|
|
self.support.remove(self.cal, uid)
|
|
|
|
self.support.append(self.cal, vcalendar)
|
2008-12-30 16:25:42 +00:00
|
|
|
|
|
|
|
def vcalendar(self):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Return unicode calendar from the calendar."""
|
2010-01-15 16:04:03 +01:00
|
|
|
return self.support.read(self.cal)
|
2008-12-30 16:25:42 +00:00
|
|
|
|
2009-12-09 12:56:03 +01:00
|
|
|
def etag(self):
|
|
|
|
"""Return etag from calendar."""
|
2009-12-29 20:05:38 +01:00
|
|
|
return '"%s"' % hash_tag(self.vcalendar())
|
2009-12-09 12:56:03 +01:00
|
|
|
|
2008-12-30 16:25:42 +00:00
|
|
|
class Event(object):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Internal event class."""
|
2008-12-30 16:25:42 +00:00
|
|
|
def __init__(self, vcalendar):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Initialize event from ``vcalendar``."""
|
2008-12-30 16:25:42 +00:00
|
|
|
self.text = vcalendar
|
|
|
|
|
|
|
|
def etag(self):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Return etag from event."""
|
2009-12-29 20:05:38 +01:00
|
|
|
return '"%s"' % hash_tag(self.text)
|
2008-12-30 16:25:42 +00:00
|
|
|
|
|
|
|
class Header(object):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Internal header class."""
|
2008-12-30 16:25:42 +00:00
|
|
|
def __init__(self, vcalendar):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Initialize header from ``vcalendar``."""
|
2008-12-30 16:25:42 +00:00
|
|
|
self.text = vcalendar
|
|
|
|
|
|
|
|
class Timezone(object):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Internal timezone class."""
|
2008-12-30 16:25:42 +00:00
|
|
|
def __init__(self, vcalendar):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Initialize timezone from ``vcalendar``."""
|
2008-12-30 16:25:42 +00:00
|
|
|
lines = vcalendar.splitlines()
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith("TZID:"):
|
|
|
|
self.tzid = line.lstrip("TZID:")
|
|
|
|
break
|
|
|
|
|
|
|
|
self.text = vcalendar
|
|
|
|
|
|
|
|
class Todo(object):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Internal todo class."""
|
2008-12-30 16:25:42 +00:00
|
|
|
def __init__(self, vcalendar):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Initialize todo from ``vcalendar``."""
|
2008-12-30 16:25:42 +00:00
|
|
|
self.text = vcalendar
|
|
|
|
|
|
|
|
def etag(self):
|
2009-07-27 15:04:54 +00:00
|
|
|
"""Return etag from todo."""
|
|
|
|
return hash_tag(self.text)
|