collective/icalendar — pull request #113 by geier (2013-10-27 14:41:55+00:00)
Title: Python3 Support

Hi,
this pull request should make icalendar compatible with python 3.3 (and hopefully
upwards of that) while retaining python 2.6 & 2.7 support. I do not expect you
to accept this pull request as is, but would rather see it as a base for
discussion.

I've started this work as part of a 'port to python 3' sprint at PyCon DE this
month with Stefan Schwarzer.

Some notes on the changes:

#### replaced dict.iteritems() with .items()
I have done some timeits and couldn't find any significant performance
differences between those two for some real world icalendar files (randomly
taken from one of my calendars). If still don't like this, I'll look for another
solution.

#### included compat.py
which defines unicode_type and bytes_type depending on which python version we
are on. Than we replaced any occurance of either str/unicode with
bytes_type/unicode_type and basestring with (unicode_type/bytes_type)

#### made sure that to_ical() always returns bytes

#### made some functions work with bytes as well as unicode
FOLD -> FOLD + uFOLD, unescape_char

### Tests

We put a *lot* of *b* s around strings (for all those to_ical() asserts), or
decoded the return value of to_ical().

#### removed tests that compare CaselessDict.__repr__() with a string
as I couldn't get those to run under py2 & 3, instead compare the CaselessDict
with a dict but made sure it really is a CaselessDict (isinstance).

A general question: would you like me to rebase this into a smaller set of
commits, each doing one thing (instead of having ~10 commits all just slapping
*b* s onto strings?) or even only one commit?

Best Regards,
Christian