Strips the bewit parameter out of a url.

    Returns (encoded_bewit, stripped_url)

    Raises InvalidBewit if no bewit found.

    :param url:
        The url containing a bewit parameter
    :type url: str
181354
def strip_bewit(url):
    
    m = re.search('[?&]bewit=([^&]+)', url)
    if not m:
        raise InvalidBewit('no bewit data found')
    bewit = m.group(1)
    stripped_url = url[:m.start()] + url[m.end():]
    return bewit, stripped_url
841687
def clean_url(url):
        """"""
        if not url.startswith(('http://', 'https://')):
            url = f'http://{url}'

        if not URL_RE.match(url):
            raise BadURLException(f'{url} is not valid')

        return url
392368
def urlsplit(url):
    
    p = '((?P<scheme>.*)?.*://)?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*'
    m = re.search(p, url)
    scheme = m.group('scheme')
    host = m.group('host')
    port = m.group('port')

    _scheme, _netloc, path, query, _fragment = tuple(py_urlsplit(url))

    return scheme, host, port, path, query
504479
def parse_url(url):
    
    try:
        url = unicode(url)
    except UnicodeDecodeError:
        pass

    if py3k:
        make_utf8 = lambda x: x
    else:
        make_utf8 = lambda x: isinstance(x, unicode) and x.encode('utf-8') or x

    if '://' in url:
        scheme, url = url.split('://', 1)
    else:
        scheme = 'http'
    url = 'http://' + url
    parsed = urlparse.urlsplit(url)
    r = ObjectDict()
    r['scheme'] = make_utf8(scheme)
    r['netloc'] = make_utf8(parsed.netloc)
    r['path'] = make_utf8(parsed.path)
    r['query'] = make_utf8(parsed.query)
    r['fragment'] = make_utf8(parsed.fragment)
    r['uri'] = make_utf8(parsed.path)
    if parsed.query:
        r['uri'] += '?' + make_utf8(parsed.query)
    r['username'] = make_utf8(parsed.username)
    r['password'] = make_utf8(parsed.password)
    host = make_utf8(parsed.hostname.encode('idna').decode('utf-8'))
    r['host'] = r['hostname'] = host
    try:
        r['port'] = parsed.port
    except ValueError:
        r['port'] = None
    if r['port']:
        r['http_host'] = '%s:%d' % (r['host'], r['port'])
    else:
        r['http_host'] = r['host']

    return r
119232
def _remove_api_url_from_link(link):
    ''''''
    if link.startswith(_api_url()):
        link = link[len(_api_url()):]
    if link.startswith(_api_url(mirror=True)):
        link = link[len(_api_url(mirror=True)):]
    return link
172327
def raw_urlsafe_b64encode(b):
    '''
    '''
    b = to_bytes(b)
    b = base64.urlsafe_b64encode(b)
    b = b.rstrip(b'=')  # strip padding
    return b
1177432
def try_parse_url(url):
    
    if len(url.strip()) < 4:
        logger.info('URL too short: {}'.format(url))
        return None
    try:
        parsed_url = urlparse(url)
    except ValueError:
        logger.info('Parse URL ValueError: {}'.format(url))
        return None
    if parsed_url.scheme:
        return parsed_url
    try:
        parsed_url = urlparse('http://' + parsed_url.geturl())
    except ValueError:
        logger.info('Invalid URL for assumed http scheme: urlparse("{}") from "{}" '.format('http://' + parsed_url.geturl(), url))
        return None
    if not parsed_url.scheme:
        logger.info('Unable to guess a scheme for URL: {}'.format(url))
        return None
    return parsed_url
34395
def get(url)
      stdin, stdout, stderr, t = Open3.popen3(curl_get_cmd(url))
      output = encode_utf8(stdout.read).strip
      error = encode_utf8(stderr.read).strip
      if !error.nil? && !error.empty?
        if error.include? "SSL"
          raise FaviconParty::Curl::SSLError.new(error)
        elsif error.include? "Couldn't resolve host"
          raise FaviconParty::Curl::DNSError.new(error)
        else
          raise FaviconParty::CurlError.new(error)
        end
      end
      output
    end
873930
def normalize_url!(url)
      raise ArgumentError, "Invalid URL: #{url}" unless url.to_s =~ /^http|socks/
      url.kind_of?(URI) ? url : URI(url)
    end
1005416
def split(self, url):
        
        parts = url.split('://', 1)
        if len(parts) == 2:
            return parts
        else:
            return (None, url)
64671
def _hash_url(self, url):
        

        if isinstance(url, six.text_type):
            url = url.encode('utf-8')

        return hashlib.md5(url).hexdigest()
965217
def correct_uri(url)
      return unless url.is_a?(String) && !url.empty?

      uri = URI(url)
      uri.scheme == 'http' ? known_https(uri) : uri
    end
816177
def _url(self, url):
        

        protocol = 'https' if self.https else 'http'
        return '{0}://{1}/spaces/{2}{3}'.format(
            protocol,
            self.api_url,
            self.space_id,
            url
        )
1118133
def parse_url(url):
        
        parsed = url

        if not url.startswith("http://") and not url.startswith(
                "https://"):  # if url is like www.yahoo.com
            parsed = "http://" + parsed
        elif url.startswith("https://"):
            parsed = parsed[8:]
            parsed = "http://" + parsed

        index_hash = parsed.rfind("#")  # remove trailing #
        index_slash = parsed.rfind("/")
        if index_hash > index_slash:
            parsed = parsed[0: index_hash]

        return parsed
1199741
def fromurl(url):
  
  ps = PatchSet( urllib_request.urlopen(url) )
  if ps.errors == 0:
    return ps
  return False
1162249
def parse_s3_url(url):
    
    parsed_url = urlparse(url)
    if parsed_url.scheme != "s3":
        raise ValueError("Expecting 's3' scheme, got: {} in {}".format(parsed_url.scheme, url))
    return parsed_url.netloc, parsed_url.path.lstrip('/')
619369
def split_url(url)
      str = split_get_last(split_get_last(url, '/'), '?')
      str = split_get_last(str, '&', -1)
      str
    end