Like :attr:`url` but without the querystring
        See also: :attr:`trusted_hosts`.
8723
def base_url(self):
        
        return get_current_url(
            self.environ, strip_querystring=True, trusted_hosts=self.trusted_hosts
        )
585648
def host_url(self):
        
        return get_current_url(
            self.environ, host_only=True, trusted_hosts=self.trusted_hosts
        )
229978
def site_url(url):
    
    base_url = 'http://%s' % socket.gethostname()

    if server.port is not 80:
        base_url += ':%d' % server.port

    return urlparse.urljoin(base_url, url)
558834
def query_string(context, **kwargs):
    """"""
    params = context["request"].GET.copy()

    for key, value in list(kwargs.items()):
        params[key] = value

    return "?" + params.urlencode()
597585
def __valid_url(cls, url):
        """"""
        bits = urlparse(url)
        return ((bits.scheme == "http" or bits.scheme == "https") and
                _PATTERN_URL_PART.match(bits.netloc) and
                _PATTERN_URL_PART.match(bits.path))
292349
def clean_url(url, force_scheme=None):
    """"""
    # URL should be ASCII according to RFC 3986
    url = str(url)
    # Collapse ../../ and related
    url_parts = urlparse.urlparse(url)
    path_parts = []
    for part in url_parts.path.split('/'):
        if part == '.':
            continue
        elif part == '..':
            if path_parts:
                path_parts.pop()
        else:
            path_parts.append(part)

    url_parts = list(url_parts)
    if force_scheme:
        url_parts[0] = force_scheme
    url_parts[2] = '/'.join(path_parts)

    if FLAGS.keep_query_string == False:
        url_parts[4] = ''    # No query string

    url_parts[5] = ''    # No path

    # Always have a trailing slash
    if not url_parts[2]:
        url_parts[2] = '/'

    return urlparse.urlunparse(url_parts)
325037
def url_for(context, __route_name, **parts):
    
    app = context['app']

    query = None
    if 'query_' in parts:
        query = parts.pop('query_')

    for key in parts:
        val = parts[key]
        if isinstance(val, str):
            # if type is inherited from str expilict cast to str makes sense
            # if type is exactly str the operation is very fast
            val = str(val)
        elif type(val) is int:
            # int inherited classes like bool are forbidden
            val = str(val)
        else:
            raise TypeError("argument value should be str or int, "
                            "got {} -> [{}] {!r}".format(key, type(val), val))
        parts[key] = val

    url = app.router[__route_name].url_for(**parts)
    if query:
        url = url.with_query(query)
    return url
502559
def is_safe_url(url, host=None):
    
    if url is not None:
        url = url.strip()
    if not url:
        return False
    # Chrome treats \ completely as /
    url = url.replace("\\", "/")
    # Chrome considers any URL with more than two slashes to be absolute, but
    # urlparse is not so flexible. Treat any url with three slashes as unsafe.
    if url.startswith("///"):
        return False
    url_info = urlparse(url)
    # Forbid URLs like http:///example.com - with a scheme, but without a
    # hostname.
    # In that URL, example.com is not the hostname but, a path component.
    # However, Chrome will still consider example.com to be the hostname,
    # so we must not allow this syntax.
    if not url_info.netloc and url_info.scheme:
        return False
    # Forbid URLs that start with control characters. Some browsers (like
    # Chrome) ignore quite a few control characters at the start of a
    # URL and might consider the URL as scheme relative.
    if unicodedata.category(url[0])[0] == "C":
        return False
    return (not url_info.netloc or url_info.netloc == host) and (
        not url_info.scheme or url_info.scheme in {"http", "https"}
    )
1198605
function (urlStr) {
        var protocol = Url.isUrl(urlStr) ? urlStr.protocol : _.trimEnd(nodeUrl.parse(urlStr || E).protocol || E, COLON);

        // to allow target URLs without any protocol. e.g.: 'foo.com/bar'
        if (_.isEmpty(protocol)) {
            protocol = DEFAULT_PROTOCOL;
            urlStr = protocol + PROTOCOL_HOST_SEPARATOR + urlStr;
        }

        // this ensures we don't proceed any further for any non-supported protocol
        if (!_.includes(ALLOWED_PROTOCOLS, protocol)) {
            return false;
        }

        return this.match.test(urlStr);
    }
1205206
def base_url(self):
        """"""
        if self.location in self.known_locations:
            return self.known_locations[self.location]
        elif '.' in self.location or self.location == 'localhost':
            return 'https://' + self.location
        else:
            return 'https://' + self.location + API_HOST_SUFFIX
1112648
def build_url_base(host, port, is_https):
    
    base = "http"
    if is_https:
        base += 's'

    base += "://"
    base += host

    if port:
        base += ":"
        base += str(port)

    return base
1230720
def _url(self, uri):
        """"""
        prefix = "{}://{}{}".format(
            self._protocol,
            self.real_connection.host,
            self._port_postfix(),
        )
        return uri.replace(prefix, '', 1)
1273141
def subdomains(self, value=None):
        
        if value is not None:
            return URL._mutate(self, host='.'.join(value))
        return self.host().split('.')
518108
def any_match(self, urls):
        
        return any(urlparse(u).hostname in self for u in urls)
1192677
def is_meta_url (attr, attrs):
    """"""
    res = False
    if attr == "content":
        equiv = attrs.get_true('http-equiv', u'').lower()
        scheme = attrs.get_true('scheme', u'').lower()
        res = equiv in (u'refresh',) or scheme in (u'dcterms.uri',)
    if attr == "href":
        rel = attrs.get_true('rel', u'').lower()
        res = rel in (u'shortcut icon', u'icon')
    return res
137556
def get_tld(url):
        

        if url not in URLHelper.__cache:
            URLHelper.__cache[url] = urlparse(url)

        parts = URLHelper.__cache[url].netloc.split(".")

        if len(parts) == 1:
            return ""
        else:
            return parts[-1]
357337
def urlopen(url, timeout=20, redirects=None):
    """"""
    scheme, host, path, params, query, frag = urlparse(url)

    if not scheme in ('http', 'https'):
        return urllib.urlopen(url)
    if params: path = '%s;%s' % (path, params)
    if query:  path = '%s?%s' % (path, query)
    if frag:   path = '%s#%s' % (path, frag)

    if scheme == 'https':
        # If ssl is not compiled into Python, you will not get an exception
        # until a conn.endheaders() call.   We need to know sooner, so use
        # getattr.
        try:
            import M2Crypto
        except ImportError:
            if not hasattr(socket, 'ssl'):
                raise RuntimeError, 'no built-in SSL Support'

            conn = TimeoutHTTPS(host, None, timeout)
        else:
            ctx = M2Crypto.SSL.Context()
            ctx.set_session_timeout(timeout)
            conn = M2Crypto.httpslib.HTTPSConnection(host, ssl_context=ctx)
            conn.set_debuglevel(1)

    else:
        conn = TimeoutHTTP(host, None, timeout)

    conn.putrequest('GET', path)
    conn.putheader('Connection', 'close')
    conn.endheaders()
    response = None
    while 1:
        response = conn.getresponse()
        if response.status != 100:
            break
        conn._HTTPConnection__state = httplib._CS_REQ_SENT
        conn._HTTPConnection__response = None

    status = response.status

    # If we get an HTTP redirect, we will follow it automatically.
    if status >= 300 and status < 400:
        location = response.msg.getheader('location')
        if location is not None:
            response.close()
            if redirects is not None and redirects.has_key(location):
                raise RecursionError(
                    'Circular HTTP redirection detected.'
                    )
            if redirects is None:
                redirects = {}
            redirects[location] = 1
            return urlopen(location, timeout, redirects)
        raise HTTPResponse(response)

    if not (status >= 200 and status < 300):
        raise HTTPResponse(response)

    body = StringIO(response.read())
    response.close()
    return body