'Make sure applications are sorted with longest URLs first'

def sort_apps(self):

    def key(app_desc):
        ((domain, url), app) = app_desc
        if (not domain):
            return ('\xff', (- len(url)))
        else:
            return (domain, (- len(url)))
    apps = [(key(desc), desc) for desc in self.applications]
    apps.sort()
    self.applications = [desc for (sortable, desc) in apps]
