From f1871b1e6866c901ffdfc6e086f25ce786bf0c9b Mon Sep 17 00:00:00 2001 From: James French Date: Sun, 1 Aug 2010 23:57:32 +0800 Subject: [PATCH] Much simplified unfolding function --- icalparse.py | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/icalparse.py b/icalparse.py index d7349fd..3b9091a 100755 --- a/icalparse.py +++ b/icalparse.py @@ -33,32 +33,16 @@ class notJoined(Exception): pass icalEntry = re.compile('^[A-Z\-]+:.*') def lineJoiner(oldcal): - '''Unfolds a calendar so that items can be parsed''' + '''Takes a string containing a calendar and returns an array of its lines''' - cal = [] - - # Strip newlines ( - for line in oldcal: - line = line.rstrip('\r\n') - - # Reassemble broken Lines - if not line: - if not cal: continue - else: cal[-1] += '\\n' - elif line[0] == ' ': - if not cal: raise InvalidICS, 'First line of ICS must be element' - line = line[1:len(line)] - cal[-1] += line - elif not icalEntry.match(line): - if not cal: raise InvalidICS, 'First line of ICS must be element' - cal[-1] += '\\n' + line - else: - if cal: cal[-1] += '\r\n' - cal.append(line) + if list(oldcal) == oldcal: + oldcal = '\r\n'.join(oldcal) - cal[-1] += '\r\n' + # RFC2445 This sequence defines a content 'fold' and needs to be stripped + # from the output before writing the file + oldcal.replace('\r\n ', '') + return oldcal.split('\r\n') - return cal def lineFolder(oldcal, length=75): '''Folds content lines to a specified length, returns a list''' -- 2.20.1