[icalendar-checkins] r19537 - iCalendar/branch/sidnei-schooltool-compat/src/icalendar

dreamcatcher at codespeak.net dreamcatcher at codespeak.net
Sat Nov 5 02:35:11 CET 2005


Author: dreamcatcher
Date: Sat Nov  5 02:35:01 2005
New Revision: 19537

Modified:
   iCalendar/branch/sidnei-schooltool-compat/src/icalendar/cal.py
   iCalendar/branch/sidnei-schooltool-compat/src/icalendar/parser.py
Log:

- Some problems with newlines


Modified: iCalendar/branch/sidnei-schooltool-compat/src/icalendar/cal.py
==============================================================================
--- iCalendar/branch/sidnei-schooltool-compat/src/icalendar/cal.py	(original)
+++ iCalendar/branch/sidnei-schooltool-compat/src/icalendar/cal.py	Sat Nov  5 02:35:01 2005
@@ -2,7 +2,7 @@
 
 """
 
-Calendar is a dictionary like Python object that can render itself as VCAL 
+Calendar is a dictionary like Python object that can render itself as VCAL
 files according to rfc2445.
 
 These are the defined components.
@@ -25,21 +25,21 @@
 # The component factory
 
 class ComponentFactory(CaselessDict):
-    
+
     """
-    All components defined in rfc 2445 are registered in this factory class. To 
+    All components defined in rfc 2445 are registered in this factory class. To
     get a component you can use it like this.
-    
+
     >>> factory = ComponentFactory()
     >>> component = factory['VEVENT']
     >>> event = component(dtstart='19700101')
     >>> event.as_string()
     'BEGIN:VEVENT\\r\\nDTSTART:19700101\\r\\nEND:VEVENT\\r\\n'
-    
+
     >>> factory.get('VCALENDAR', Component)
     <class 'icalendar.cal.Calendar'>
     """
-    
+
     def __init__(self, *args, **kwargs):
         "Set keys to upper for initial dict"
         CaselessDict.__init__(self, *args, **kwargs)
@@ -52,7 +52,7 @@
         self['VCALENDAR'] = Calendar
 
 
-# These Properties have multiple property values inlined in one propertyline 
+# These Properties have multiple property values inlined in one propertyline
 # seperated by comma. Use CaselessDict as simple caseless set.
 INLINE = CaselessDict(
     [(cat, 1) for cat in ('CATEGORIES', 'RESOURCES', 'FREEBUSY')]
@@ -63,25 +63,25 @@
 class Component(CaselessDict):
 
     """
-    
-    Component is the base object for calendar, Event and the other components 
-    defined in RFC 2445. normally you will not use this class directy, but 
+
+    Component is the base object for calendar, Event and the other components
+    defined in RFC 2445. normally you will not use this class directy, but
     rather one of the subclasses.
-    
-    A component is like a dictionary with extra methods and attributes. 
+
+    A component is like a dictionary with extra methods and attributes.
     >>> c = Component()
     >>> c.name = 'VCALENDAR'
-    
-    Every key defines a property. A property can consist of either a single 
+
+    Every key defines a property. A property can consist of either a single
     item. This can be set with a single value
     >>> c['prodid'] = '-//max m//icalendar.mxm.dk/'
     >>> c
     VCALENDAR({'PRODID': '-//max m//icalendar.mxm.dk/'})
-    
+
     or with a list
     >>> c['ATTENDEE'] = ['Max M', 'Rasmussen']
-    
-    if you use the add method you don't have to considder if a value is a list 
+
+    if you use the add method you don't have to considder if a value is a list
     or not.
     >>> c = Component()
     >>> c.name = 'VEVENT'
@@ -89,27 +89,27 @@
     >>> c.add('attendee', 'test at example.dk')
     >>> c
     VEVENT({'ATTENDEE': [vCalAddress('maxm at mxm.dk'), vCalAddress('test at example.dk')]})
-    
+
     You can get the values back directly
     >>> c.add('prodid', '-//my product//')
     >>> c['prodid']
     vText(u'-//my product//')
-    
+
     or decoded to a python type
     >>> c.decoded('prodid')
     u'-//my product//'
-    
+
     With default values for non existing properties
     >>> c.decoded('version', 'No Version')
     'No Version'
-    
+
     The component can render itself in the RFC 2445 format.
     >>> c = Component()
     >>> c.name = 'VCALENDAR'
     >>> c.add('attendee', 'Max M')
     >>> c.as_string()
     'BEGIN:VCALENDAR\\r\\nATTENDEE:Max M\\r\\nEND:VCALENDAR\\r\\n'
-    
+
     >>> from icalendar.prop import vDatetime
 
     Components can be nested, so You can add a subcompont. Eg a calendar holds events.
@@ -123,48 +123,48 @@
     >>> c.add_component(e)
     >>> c.subcomponents
     [VEVENT({'DTEND': '20000102T000000', 'DTSTART': '20000101T000000', 'SUMMARY': 'A brief history of time'})]
-    
+
     We can walk over nested componentes with the walk method.
     >>> [i.name for i in c.walk()]
     ['VCALENDAR', 'VEVENT']
-    
-    We can also just walk over specific component types, by filtering them on 
+
+    We can also just walk over specific component types, by filtering them on
     their name.
     >>> [i.name for i in c.walk('VEVENT')]
     ['VEVENT']
-    
+
     >>> [i['dtstart'] for i in c.walk('VEVENT')]
     ['20000101T000000']
-    
-    INLINE properties have their values on one property line. Note the double 
+
+    INLINE properties have their values on one property line. Note the double
     quoting of the value with a colon in it.
     >>> c = Calendar()
     >>> c['resources'] = 'Chair, Table, "Room: 42"'
     >>> c
     VCALENDAR({'RESOURCES': 'Chair, Table, "Room: 42"'})
-    
+
     >>> c.as_string()
     'BEGIN:VCALENDAR\\r\\nRESOURCES:Chair, Table, "Room: 42"\\r\\nEND:VCALENDAR\\r\\n'
 
-    The inline values must be handled by the get_inline() and set_inline() 
+    The inline values must be handled by the get_inline() and set_inline()
     methods.
 
     >>> c.get_inline('resources', decode=0)
     ['Chair', 'Table', 'Room: 42']
-    
-    These can also be decoded 
+
+    These can also be decoded
     >>> c.get_inline('resources', decode=1)
     [u'Chair', u'Table', u'Room: 42']
-    
+
     You can set them directly
     >>> c.set_inline('resources', ['A', 'List', 'of', 'some, recources'], encode=1)
     >>> c['resources']
     'A,List,of,"some, recources"'
-    
+
     and back again
     >>> c.get_inline('resources', decode=0)
     ['A', 'List', 'of', 'some, recources']
-    
+
     >>> c['freebusy'] = '19970308T160000Z/PT3H,19970308T200000Z/PT1H,19970308T230000Z/19970309T000000Z'
     >>> c.get_inline('freebusy', decode=0)
     ['19970308T160000Z/PT3H', '19970308T200000Z/PT1H', '19970308T230000Z/19970309T000000Z']
@@ -193,9 +193,9 @@
 #        not implemented yet!
 #        Returns a dict describing non compliant properties, if any.
 #        If warnings is true it also returns warnings.
-#        
-#        If the parser is too strict it might prevent parsing erroneous but 
-#        otherwise compliant properties. So the parser is pretty lax, but it is 
+#
+#        If the parser is too strict it might prevent parsing erroneous but
+#        otherwise compliant properties. So the parser is pretty lax, but it is
 #        possible to test for non-complience by calling this method.
 #        """
 #        nc = {}
@@ -256,9 +256,9 @@
 
 
     ########################################################################
-    # Inline values. A few properties have multiple values inlined in in one 
+    # Inline values. A few properties have multiple values inlined in in one
     # property line. These methods are used for splitting and joining these.
-    
+
     def get_inline(self, name, decode=1):
         """
         Returns a list of values (split on comma).
@@ -267,11 +267,11 @@
         if decode:
             return [self._decode(name, val) for val in vals]
         return vals
-        
-        
+
+
     def set_inline(self, name, values, encode=1):
         """
-        Converts a list of values into comma seperated string and sets value to 
+        Converts a list of values into comma seperated string and sets value to
         that.
         """
         if encode:
@@ -299,7 +299,7 @@
 
     def walk(self, name=None):
         """
-        Recursively traverses component and subcomponents. Returns sequence of 
+        Recursively traverses component and subcomponents. Returns sequence of
         same. If name is passed, only components with name will be returned.
         """
         if not name is None:
@@ -344,7 +344,7 @@
                 uname = name.upper()
                 # check for start of component
                 if uname == 'BEGIN':
-                    # try and create one of the components defined in the spec, 
+                    # try and create one of the components defined in the spec,
                     # otherwise get a general Components for robustness.
                     component_name = vals.upper()
                     component_class = component_factory.get(component_name, Component)
@@ -399,57 +399,57 @@
 
 
 #######################################
-# components defined in RFC 2445 
+# components defined in RFC 2445
 
 
 class Event(Component):
-    
+
     name = 'VEVENT'
-    
+
     required = ('UID',)
     singletons = (
         'CLASS', 'CREATED', 'DESCRIPTION', 'DTSTART', 'GEO',
-        'LAST-MOD', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'DTSTAMP', 'SEQUENCE', 
-        'STATUS', 'SUMMARY', 'TRANSP', 'URL', 'RECURID', 'DTEND', 'DURATION', 
+        'LAST-MOD', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'DTSTAMP', 'SEQUENCE',
+        'STATUS', 'SUMMARY', 'TRANSP', 'URL', 'RECURID', 'DTEND', 'DURATION',
         'DTSTART',
     )
     exclusive = ('DTEND', 'DURATION', )
     multiple = (
-        'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT','CONTACT', 'EXDATE', 
+        'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT','CONTACT', 'EXDATE',
         'EXRULE', 'RSTATUS', 'RELATED', 'RESOURCES', 'RDATE', 'RRULE'
     )
 
 
 
 class Todo(Component):
-    
+
     name = 'VTODO'
 
     required = ('UID',)
     singletons = (
-        'CLASS', 'COMPLETED', 'CREATED', 'DESCRIPTION', 'DTSTAMP', 'DTSTART', 
-        'GEO', 'LAST-MOD', 'LOCATION', 'ORGANIZER', 'PERCENT', 'PRIORITY', 
+        'CLASS', 'COMPLETED', 'CREATED', 'DESCRIPTION', 'DTSTAMP', 'DTSTART',
+        'GEO', 'LAST-MOD', 'LOCATION', 'ORGANIZER', 'PERCENT', 'PRIORITY',
         'RECURID', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL', 'DUE', 'DURATION',
     )
     exclusive = ('DUE', 'DURATION',)
     multiple = (
-        'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE', 
+        'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE',
         'EXRULE', 'RSTATUS', 'RELATED', 'RESOURCES', 'RDATE', 'RRULE'
     )
 
 
 
 class Journal(Component):
-    
+
     name = 'VJOURNAL'
 
     required = ('UID',)
     singletons = (
-        'CLASS', 'CREATED', 'DESCRIPTION', 'DTSTART', 'DTSTAMP', 'LAST-MOD', 
-        'ORGANIZER', 'RECURID', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL', 
+        'CLASS', 'CREATED', 'DESCRIPTION', 'DTSTART', 'DTSTAMP', 'LAST-MOD',
+        'ORGANIZER', 'RECURID', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL',
     )
     multiple = (
-        'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE', 
+        'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE',
         'EXRULE', 'RELATED', 'RDATE', 'RRULE', 'RSTATUS',
     )
 
@@ -460,7 +460,7 @@
 
     required = ('UID',)
     singletons = (
-        'CONTACT', 'DTSTART', 'DTEND', 'DURATION', 'DTSTAMP', 'ORGANIZER', 
+        'CONTACT', 'DTSTART', 'DTEND', 'DURATION', 'DTSTAMP', 'ORGANIZER',
         'UID', 'URL',
     )
     multiple = ('ATTENDEE', 'COMMENT', 'FREEBUSY', 'RSTATUS',)
@@ -471,13 +471,13 @@
     name = 'VTIMEZONE'
 
     required = (
-        'TZID', 'STANDARDC', 'DAYLIGHTC', 'DTSTART', 'TZOFFSETTO', 
+        'TZID', 'STANDARDC', 'DAYLIGHTC', 'DTSTART', 'TZOFFSETTO',
         'TZOFFSETFROM'
         )
     singletons = ('LAST-MOD', 'TZURL', 'TZID',)
     multiple = ('COMMENT', 'RDATE', 'RRULE', 'TZNAME',)
-    
-    
+
+
 class Alarm(Component):
 
     name = 'VALARM'
@@ -486,20 +486,20 @@
     singletons = ('ATTACH', 'ACTION', 'TRIGGER', 'DURATION', 'REPEAT',)
     inclusive = (('DURATION', 'REPEAT',),)
     multiple = ('STANDARDC', 'DAYLIGHTC')
-    
-    
+
+
 class Calendar(Component):
 
     """
     This is the base object for an iCalendar file.
-    
+
     Setting up a minimal calendar component looks like this
     >>> cal = Calendar()
-    
+
     Som properties are required to be compliant
     >>> cal['prodid'] = '-//My calendar product//mxm.dk//'
     >>> cal['version'] = '2.0'
-    
+
     We also need at least one subcomponent for a calendar to be compliant
     >>> from datetime import datetime
     >>> event = Event()
@@ -509,7 +509,7 @@
     >>> cal.add_component(event)
     >>> cal.subcomponents[0].as_string()
     'BEGIN:VEVENT\\r\\nDTSTART:20050404T080000\\r\\nSUMMARY:Python meeting about calendaring\\r\\nUID:42\\r\\nEND:VEVENT\\r\\n'
-    
+
     Write to disc
     >>> import tempfile, os
     >>> directory = tempfile.mkdtemp()

Modified: iCalendar/branch/sidnei-schooltool-compat/src/icalendar/parser.py
==============================================================================
--- iCalendar/branch/sidnei-schooltool-compat/src/icalendar/parser.py	(original)
+++ iCalendar/branch/sidnei-schooltool-compat/src/icalendar/parser.py	Sat Nov  5 02:35:01 2005
@@ -393,7 +393,7 @@
         "Unfolds the content lines in an iCalendar into long content lines"
         try:
             # a fold is carriage return followed by either a space or a tab
-            a_fold = re.compile('\r\n[ \t]{1}')
+            a_fold = re.compile('[\r]?\n[ \t]{1}')
             return Contentline(a_fold.sub('', st), strict=strict)
         except:
             raise ValueError, 'Expected StringType with content line'
@@ -445,7 +445,7 @@
             # a fold is carriage return followed by either a space or a tab
             a_fold = re.compile('\r\n[ \t]{1}')
             unfolded = a_fold.sub('', st)
-            lines = [Contentline(line) for line in unfolded.split('\r\n') if line]
+            lines = [Contentline(line) for line in unfolded.splitlines() if line]
             lines.append('') # we need a '\r\n' in the end of every content line
             return Contentlines(lines)
         except:


More information about the icalendar-checkins mailing list