'Helper method used during redirect to ensure that the redirect
url (assisted by frame busting code or javasctipt) will point
to the correct domain and not have any extra dangling get
parameters.  The extensions are also made to match and the
resulting url is utf8 encoded.
Node: for development purposes, also checks that the port
matches the request port'

@classmethod
def format_output_url(cls, url, **kw):

    preserve_extension = kw.pop('preserve_extension', True)
    u = UrlParser(url)
    if u.is_reddit_url():
        if (not kw.has_key('port')):
            kw['port'] = request.port
        if (preserve_extension and c.extension):
            u.set_extension(c.extension)
    rv = _force_unicode(u.unparse()).encode('utf8')
    if (('\n' in rv) or ('\r' in rv)):
        abort(400)
    return rv
