Permalink
Browse files

Files added

git-svn-id: http://svn.32rwr.info/radicale/trunk@2 74e4794c-479d-4a33-9dda-c6c359d70f12
  • Loading branch information...
(no author)
(no author) committed Dec 30, 2008
1 parent 1308ca0 commit b1591aea6f4de6ceb9ea96e636c36843ffe450c8
Showing with 872 additions and 0 deletions.
  1. +52 −0 main.py
  2. +146 −0 radicale/__init__.py
  3. +23 −0 radicale/acl/__init__.py
  4. +25 −0 radicale/acl/htpasswd.py
  5. +103 −0 radicale/calendar.py
  6. +68 −0 radicale/config.py
  7. +119 −0 radicale/ical.py
  8. +26 −0 radicale/support/__init__.py
  9. +104 −0 radicale/support/plain.py
  10. +206 −0 radicale/xmlutils.py
View
52 main.py
@@ -0,0 +1,52 @@
#!/usr/bin/python
# -*- coding: utf-8; indent-tabs-mode: nil; -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2008 The Radicale Team
#
# 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/>.
# TODO: Manage depth and calendars/collections (see xmlutils)
# TODO: Manage smart and configurable logs
# TODO: Manage authentication
# TODO: remove this hack
import sys
sys.path.append("/usr/local/lib/python2.5/site-packages")
from OpenSSL import SSL
from twisted.web import server
from twisted.internet import reactor
from twisted.python import log
import radicale
class ServerContextFactory(object):
"""
SSL context factory
"""
def getContext(self):
"""
Get SSL context for the HTTP server
"""
ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.use_certificate_file(radicale.config.get("server", "certificate"))
ctx.use_privatekey_file(radicale.config.get("server", "privatekey"))
return ctx
log.startLogging(sys.stdout)
log.startLogging(open(radicale.config.get("server", "log"), "w"))
factory = server.Site(radicale.HttpResource())
reactor.listenSSL(radicale.config.getint("server", "port"), factory, ServerContextFactory())
reactor.run()
View
@@ -0,0 +1,146 @@
# -*- coding: utf-8; indent-tabs-mode: nil; -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2008 The Radicale Team
#
# 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/>.
# TODO: Manage errors (see xmlutils)
from twisted.web.resource import Resource
from twisted.web import http
import posixpath
import config
import support
import acl
import xmlutils
import calendar
_users = acl.users()
_calendars = support.calendars()
class CalendarResource(Resource):
"""
Twisted resource for requests at calendar depth (/user/calendar)
"""
isLeaf = True
def __init__(self, user, cal):
"""
Initialize resource creating a calendar object corresponding
to the stocked calendar named user/cal
"""
Resource.__init__(self)
self.calendar = calendar.Calendar(user, cal)
def render_DELETE(self, request):
"""
Manage DELETE requests
"""
obj = request.getHeader("if-match")
answer = xmlutils.delete(obj, self.calendar, str(request.URLPath()))
request.setResponseCode(http.NO_CONTENT)
return answer
def render_OPTIONS(self, request):
"""
Manage OPTIONS requests
"""
request.setHeader("Allow", "DELETE, OPTIONS, PROPFIND, PUT, REPORT")
request.setHeader("DAV", "1, calendar-access")
request.setResponseCode(http.OK)
return ""
def render_PROPFIND(self, request):
"""
Manage PROPFIND requests
"""
xmlRequest = request.content.read()
answer = xmlutils.propfind(xmlRequest, self.calendar, str(request.URLPath()))
request.setResponseCode(http.MULTI_STATUS)
return answer
def render_PUT(self, request):
"""
Manage PUT requests
"""
# TODO: Improve charset detection
contentType = request.getHeader("content-type")
if contentType and "charset=" in contentType:
charset = contentType.split("charset=")[1].strip()
else:
charset = config.get("encoding", "request")
icalRequest = unicode(request.content.read(), charset)
obj = request.getHeader("if-match")
xmlutils.put(icalRequest, self.calendar, str(request.URLPath()), obj)
request.setResponseCode(http.CREATED)
return ""
def render_REPORT(self, request):
"""
Manage REPORT requests
"""
xmlRequest = request.content.read()
answer = xmlutils.report(xmlRequest, self.calendar, str(request.URLPath()))
request.setResponseCode(http.MULTI_STATUS)
return answer
class UserResource(Resource):
"""
Twisted resource for requests at user depth (/user)
"""
def __init__(self, user):
"""
Initialize resource by connecting children requests to
the user calendars resources
"""
Resource.__init__(self)
for cal in _calendars:
if cal.startswith("%s%s"%(user, posixpath.sep)):
calName = cal.split(posixpath.sep)[1]
self.putChild(calName, CalendarResource(user, cal))
def getChild(self, cal, request):
"""
Get calendar resource if user exists
"""
if cal in _calendars:
return Resource.getChild(self, cal, request)
else:
return self
class HttpResource(Resource):
"""
Twisted resource for requests at root depth (/)
"""
def __init__(self):
"""
Initialize resource by connecting children requests to
the users resources
"""
Resource.__init__(self)
for user in _users:
self.putChild(user, UserResource(user))
def getChild(self, user, request):
"""
Get user resource if user exists
"""
if user in _users:
return Resource.getChild(self, user, request)
else:
return self
View
@@ -0,0 +1,23 @@
# -*- coding: utf-8; indent-tabs-mode: nil; -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2008 The Radicale Team
#
# 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/>.
from .. import config
_acl = __import__(config.get("acl", "type"), locals(), globals())
users = _acl.users
View
@@ -0,0 +1,25 @@
# -*- coding: utf-8; indent-tabs-mode: nil; -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2008 The Radicale Team
#
# 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/>.
from .. import config
def users():
"""
Get the List of all Users
"""
return [line.split(":")[0] for line in open(config.get("acl", "filename")).readlines()]
View
@@ -0,0 +1,103 @@
# -*- coding: utf-8; indent-tabs-mode: nil; -*-
#
# This file is part of Radicale Server - Calendar Server
# Copyright © 2008 The Radicale Team
#
# 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/>.
# TODO: Manage inheritance for classes
from time import time
import support
class Calendar(object):
"""
Internal Calendar Class
"""
def __init__(self, user, cal):
# TODO: Use properties from the calendar
self.encoding = "utf-8"
self.owner = "lize"
self.user = user
self.cal = cal
self.version = "2.0"
self.ctag = str(hash(self.vcalendar()))
def append(self, vcalendar):
"""
Append vcalendar
"""
self.ctag = str(hash(self.vcalendar()))
support.append(self.cal, vcalendar)
def remove(self, uid):
"""
Remove Object Named uid
"""
self.ctag = str(hash(self.vcalendar()))
support.remove(self.cal, uid)
def replace(self, uid, vcalendar):
"""
Replace Objet Named uid by vcalendar
"""
self.ctag = str(hash(self.vcalendar()))
support.remove(self.cal, uid)
support.append(self.cal, vcalendar)
def vcalendar(self):
return unicode(support.read(self.cal), self.encoding)
class Event(object):
"""
Internal Event Class
"""
# TODO: Fix the behaviour if no UID is given
def __init__(self, vcalendar):
self.text = vcalendar
def etag(self):
return str(hash(self.text))
class Header(object):
"""
Internal Headers Class
"""
def __init__(self, vcalendar):
self.text = vcalendar
class Timezone(object):
"""
Internal Timezone Class
"""
def __init__(self, vcalendar):
lines = vcalendar.splitlines()
for line in lines:
if line.startswith("TZID:"):
self.tzid = line.lstrip("TZID:")
break
self.text = vcalendar
class Todo(object):
"""
Internal Todo Class
"""
# TODO: Fix the behaviour if no UID is given
def __init__(self, vcalendar):
self.text = vcalendar
def etag(self):
return str(hash(self.text))
Oops, something went wrong.

0 comments on commit b1591ae

Please sign in to comment.