'Parse the given URI into a L{URI}.
@type uri: C{bytes}
@param uri: URI to parse.
@type defaultPort: C{int} or L{None}
@param defaultPort: An alternate value to use as the port if the URI
does not include one.
@rtype: L{URI}
@return: Parsed URI instance.'

@classmethod
def fromBytes(cls, uri, defaultPort=None):

    uri = uri.strip()
    (scheme, netloc, path, params, query, fragment) = http.urlparse(uri)
    if (defaultPort is None):
        if (scheme == 'https'):
            defaultPort = 443
        else:
            defaultPort = 80
    if (':' in netloc):
        (host, port) = netloc.rsplit(':', 1)
        try:
            port = int(port)
        except ValueError:
            (host, port) = (netloc, defaultPort)
    else:
        (host, port) = (netloc, defaultPort)
    return cls(scheme, netloc, host, port, path, params, query, fragment)
