Use range instead of xrange, and list(range()).

Only do this for tests, as there a potential performance hit.
Use key functions rather than cmp functions.
Use collections.MutableMapping instead of UserDict.DictMixin
Use io.BytesIO rather than cStringIO.
Use email.parser rather than rfc822.
Use next(iter) instead of iter.next()