Refs #6506: Import sorted from trac.util.compat, for compatibility with Python 2.3. Thanks to ryan@igglybob.com for the patch.