Просмотр исходного кода

Rename calendar into ical to avoid name collisions.

Guillaume Ayoub 16 лет назад
Родитель
Сommit
e1a161edc9
3 измененных файлов с 21 добавлено и 17 удалено
  1. 3 3
      radicale/__init__.py
  2. 11 8
      radicale/ical.py
  3. 7 6
      radicale/xmlutils.py

+ 3 - 3
radicale/__init__.py

@@ -45,7 +45,7 @@ except ImportError:
     import BaseHTTPServer as server
     import BaseHTTPServer as server
 # pylint: enable-msg=F0401
 # pylint: enable-msg=F0401
 
 
-from radicale import acl, calendar, config, xmlutils
+from radicale import acl, config, ical, xmlutils
 
 
 
 
 def _check(request, function):
 def _check(request, function):
@@ -105,12 +105,12 @@ class CalendarHTTPHandler(server.BaseHTTPRequestHandler):
 
 
     @property
     @property
     def _calendar(self):
     def _calendar(self):
-        """The ``calendar.Calendar`` object corresponding to the given path."""
+        """The ``ical.Calendar`` object corresponding to the given path."""
         # ``normpath`` should clean malformed and malicious request paths
         # ``normpath`` should clean malformed and malicious request paths
         attributes = os.path.normpath(self.path.strip("/")).split("/")
         attributes = os.path.normpath(self.path.strip("/")).split("/")
         if len(attributes) >= 2:
         if len(attributes) >= 2:
             path = "%s/%s" % (attributes[0], attributes[1])
             path = "%s/%s" % (attributes[0], attributes[1])
-            return calendar.Calendar(path)
+            return ical.Calendar(path)
 
 
     def _decode(self, text):
     def _decode(self, text):
         """Try to decode text according to various parameters."""
         """Try to decode text according to various parameters."""

+ 11 - 8
radicale/calendar.py → radicale/ical.py

@@ -42,6 +42,15 @@ def open(path, mode="r"):
 # pylint: enable-msg=W0622
 # pylint: enable-msg=W0622
 
 
 
 
+def serialize(headers=(), timezones=(), events=(), todos=()):
+    items = ["BEGIN:VCALENDAR"]
+    for part in (headers, timezones, todos, events):
+        if part:
+            items.append("\n".join(item.text for item in part))
+    items.append("END:VCALENDAR")
+    return "\n".join(items)
+
+
 class Header(object):
 class Header(object):
     """Internal header class."""
     """Internal header class."""
     def __init__(self, text):
     def __init__(self, text):
@@ -179,14 +188,8 @@ class Calendar(object):
         # Create folder if absent
         # Create folder if absent
         if not os.path.exists(os.path.dirname(self.path)):
         if not os.path.exists(os.path.dirname(self.path)):
             os.makedirs(os.path.dirname(self.path))
             os.makedirs(os.path.dirname(self.path))
-            
-        text = "\n".join((
-                "BEGIN:VCALENDAR",
-                "\n".join([header.text for header in headers]),
-                "\n".join([timezone.text for timezone in timezones]),
-                "\n".join([todo.text for todo in todos]),
-                "\n".join([event.text for event in events]),
-                "END:VCALENDAR"))
+        
+        text = serialize(headers, timezones, events, todos)
         return open(self.path, "w").write(text)
         return open(self.path, "w").write(text)
 
 
     @property
     @property

+ 7 - 6
radicale/xmlutils.py

@@ -175,10 +175,7 @@ def report(xml_request, calendar, url):
     #       is that really what is needed?
     #       is that really what is needed?
     #       Read rfc4791-9.[6|10] for info
     #       Read rfc4791-9.[6|10] for info
     for hreference in hreferences:
     for hreference in hreferences:
-        headers = ical.headers(calendar.text)
-        timezones = ical.timezones(calendar.text)
-
-        objects = ical.events(calendar.text) + ical.todos(calendar.text)
+        objects = calendar.events + calendar.todos
 
 
         if not objects:
         if not objects:
             # TODO: Read rfc4791-9.[6|10] to find a right answer
             # TODO: Read rfc4791-9.[6|10] to find a right answer
@@ -216,8 +213,12 @@ def report(xml_request, calendar, url):
 
 
             if _tag("C", "calendar-data") in props:
             if _tag("C", "calendar-data") in props:
                 element = ET.Element(_tag("C", "calendar-data"))
                 element = ET.Element(_tag("C", "calendar-data"))
-                # TODO: Maybe assume that events and todos are not the same
-                element.text = ical.write_calendar(headers, timezones, [obj])
+                if isinstance(obj, ical.Event):
+                    element.text = ical.serialize(
+                        calendar.headers, calendar.timezones, events=[obj])
+                elif isinstance(obj, ical.Todo):
+                    element.text = ical.serialize(
+                        calendar.headers, calendar.timezones, todos=[obj])
                 prop.append(element)
                 prop.append(element)
 
 
             status = ET.Element(_tag("D", "status"))
             status = ET.Element(_tag("D", "status"))