From: James French Date: Sun, 1 Aug 2010 15:57:32 +0000 (+0800) Subject: Much simplified unfolding function X-Git-Tag: 0.7~15 X-Git-Url: https://git.ucc.asn.au/?p=frenchie%2Ficalparse.git;a=commitdiff_plain;h=f1871b1e6866c901ffdfc6e086f25ce786bf0c9b Much simplified unfolding function --- 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'''