'extract host and port from an URL string'

def from_url(self, url):

    parts = urlparse.urlsplit(url)
    if (parts.scheme != 'spy'):
        raise serial.SerialException('expected    a    string    in    the    form    "spy://port[?option[=value][&option[=value]]]":    not    starting    with    spy://    ({!r})'.format(parts.scheme))
    formatter = FormatHexdump
    color = False
    output = sys.stderr
    try:
        for (option, values) in urlparse.parse_qs(parts.query, True).items():
            if (option == 'file'):
                output = open(values[0], 'w')
            elif (option == 'color'):
                color = True
            elif (option == 'raw'):
                formatter = FormatRaw
            elif (option == 'all'):
                self.show_all = True
            else:
                raise ValueError('unknown    option:    {!r}'.format(option))
    except ValueError as e:
        raise serial.SerialException('expected    a    string    in    the    form    "spy://port[?option[=value][&option[=value]]]":    {}'.format(e))
    self.formatter = formatter(output, color)
    return ''.join([parts.netloc, parts.path])
