Generate URI from parameters.

    :param str scheme:
    :param str host:
    :param int port:
    :param str path:
    :param dict query:
    :return:
351868
def generate_url(scheme=None, host=None, port=None, path=None, query=None):
    
    url = ""
    if scheme is not None:
        url += "%s://" % scheme
    if host is not None:
        url += host
    if port is not None:
        url += ":%s" % str(port)
    if path is not None:
        url += ensure_url_path_starts_with_slash(path)
    if query is not None:
        url += "?%s" % (urlencode(query))
    return url
1347828
def host_from_uri(uri):
    
    default_ports = {
        'HTTP': '80',
        'HTTPS': '443',
    }

    sch, netloc, path, par, query, fra = urlparse(uri)
    if ':' in netloc:
        netloc, port = netloc.split(':', 1)
    else:
        port = default_ports.get(sch.upper())

    return netloc, port
894625
def url(self):
		
		return urlparse.urlunparse((self.scheme, self.host, self.path, None, None, None))
520509
def _get(self, scheme, host, port, path, assert_key=None):
        
        url = '%s://%s:%i/%s' % (scheme, host, port, path)
        try:
            request = urllib2.Request(url)
            if self.config['user'] and self.config['password']:
                base64string = base64.standard_b64encode(
                    '%s:%s' % (self.config['user'], self.config['password']))
                request.add_header("Authorization", "Basic %s" % base64string)
            response = urllib2.urlopen(request)
        except Exception as err:
            self.log.error("%s: %s" % (url, err))
            return False

        try:
            doc = json.load(response)
        except (TypeError, ValueError):
            self.log.error("Unable to parse response from elasticsearch as a" +
                           " json object")
            return False

        if assert_key and assert_key not in doc:
            self.log.error("Bad response from elasticsearch, expected key "
                           "'%s' was missing for %s" % (assert_key, url))
            return False
        return doc
797198
def build(
        cls,
        *,
        scheme="",
        user="",
        password=None,
        host="",
        port=None,
        path="",
        query=None,
        query_string="",
        fragment="",
        encoded=False
    ):
        """"""

        if not host and scheme:
            raise ValueError('Can\'t build URL with "scheme" but without "host".')
        if port and not host:
            raise ValueError('Can\'t build URL with "port" but without "host".')
        if query and query_string:
            raise ValueError('Only one of "query" or "query_string" should be passed')
        if path is None or query_string is None or fragment is None:
            raise TypeError('NoneType is illegal for "path", "query_string" and '
                            '"fragment" args, use string values instead.')

        if not user and not password and not host and not port:
            netloc = ""
        else:
            netloc = cls._make_netloc(user, password, host, port, encode=not encoded)
        if not encoded:
            path = cls._PATH_QUOTER(path)
            if netloc:
                path = cls._normalize_path(path)

            cls._validate_authority_uri_abs_path(host=host, path=path)
            query_string = cls._QUERY_QUOTER(query_string)
            fragment = cls._FRAGMENT_QUOTER(fragment)

        url = cls(
            SplitResult(scheme, netloc, path, query_string, fragment), encoded=True
        )

        if query:
            return url.with_query(query)
        else:
            return url
652718
def from_uri(cls, uri, socket_timeout=None, auto_decode=False):
        
        parts = six.moves.urllib.parse.urlparse(uri)
        if parts.scheme.lower() not in ('beanstalk', 'beanstalkd'):
            raise ValueError('Invalid scheme %s' % parts.scheme)
        ipv6_md = re.match(r'^\[([0-9a-fA-F:]+)\](:[0-9]+)?$', parts.netloc)
        if ipv6_md:
            host = ipv6_md.group(1)
            port = ipv6_md.group(2) or '11300'
            port = port.lstrip(':')
        elif ':' in parts.netloc:
            host, port = parts.netloc.rsplit(':', 1)
        else:
            host = parts.netloc
            port = 11300
        port = int(port)
        return cls(host, port, socket_timeout=socket_timeout, auto_decode=auto_decode)
128885
def path_from_uri(self, uri):
        
        (scheme, netloc, path, params, query, frag) = urlparse(uri)
        if (netloc == ''):
            return(uri)
        path = '/'.join([netloc, path])
        path = re.sub('[^\w\-\.]', '_', path)
        path = re.sub('__+', '_', path)
        path = re.sub('[_\.]+$', '', path)
        path = re.sub('^[_\.]+', '', path)
        return(path)
959304
public static function makeUri($host, $path, $query = '', $port = 80, $scheme = 'http', $fragment = '', $userInfo = '')
    {
        return new static(static::makeUriString($host, $path, $query, $port, $scheme, $fragment, $userInfo));
    }
51098
def safe_parse_http_uri(path)
      raise ArgumentError.new("URI path cannot be empty") if path.to_s.empty?
      begin
        uri = URI.parse(path)
      rescue URI::InvalidURIError => e
        # URI raises an exception for paths like "<IP>:<port>"
        # (e.g. "127.0.0.1:123") unless they also have scheme (e.g. http)
        # prefix.
        raise e if path.start_with?("http://") || path.start_with?("https://")
        uri = URI.parse("http://" + path)
        uri = URI.parse("https://" + path) if uri.port == 443
        path = uri.to_s
      end

      # supply any missing default values to make URI as complete as possible.
      if uri.scheme.nil? || uri.host.nil?
        scheme = (uri.port == 443) ? 'https' : 'http'
        uri = URI.parse("#{scheme}://#{path}")
        path = uri.to_s
      end
      if uri.path.to_s.empty?
        uri = URI.parse("#{path}/")
        path = uri.to_s
      end

      return uri
    end
1273387
def parse_url_to_dict(url):
    
    p = urlparse(url)

    return {
        'scheme': p.scheme,
        'netloc': p.netloc,
        'path': p.path,
        'params': p.params,
        'query': p.query,
        'fragment': p.fragment,
        'username': p.username,
        'password': p.password,
        'hostname': p.hostname,
        'port': p.port
    }
1098225
def geturi(self):
        
        scheme, authority, path, query, fragment = self

        # RFC 3986 5.3. Component Recomposition
        result = []
        if scheme is not None:
            result.extend([scheme, self.COLON])
        if authority is not None:
            result.extend([self.SLASH, self.SLASH, authority])
        result.append(path)
        if query is not None:
            result.extend([self.QUEST, query])
        if fragment is not None:
            result.extend([self.HASH, fragment])
        return self.EMPTY.join(result)
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
806905
def parse_url(self):
        
        self.scheme = None
        self.resource = None
        self.host = None
        self.port = None

        if self.url is None:
            return

        scheme, url = self.url.split(":", 1)
        parsed = urlsplit(url, scheme="http")
        if parsed.hostname:
            self.host = parsed.hostname
        elif '+unix' in scheme:
            self.host = 'localhost'
        else:
            raise ValueError("Invalid hostname from: %s", self.url)

        if parsed.port:
            self.port = parsed.port

        if scheme == "ws":
            if not self.port:
                self.port = 8080
        elif scheme == "wss":
            if not self.port:
                self.port = 443
        elif scheme in ('ws+unix', 'wss+unix'):
            pass
        else:
            raise ValueError("Invalid scheme: %s" % scheme)

        if parsed.path:
            resource = parsed.path
        else:
            resource = "/"

        if '+unix' in scheme:
            self.unix_socket_path = resource
            resource = '/'

        if parsed.query:
            resource += "?" + parsed.query

        self.scheme = scheme
        self.resource = resource
353536
def parse_uri(uri_string):
    
    parts = urlparse.urlparse(uri_string)
    uri = Uri()
    if parts[0]:
      uri.scheme = parts[0]
    if parts[1]:
      host_parts = parts[1].split(':')
      if host_parts[0]:
        uri.host = host_parts[0]
      if len(host_parts) > 1:
        uri.port = int(host_parts[1])
    if parts[2]:
      uri.path = parts[2]
    if parts[4]:
      param_pairs = parts[4].split('&')
      for pair in param_pairs:
        pair_parts = pair.split('=')
        if len(pair_parts) > 1:
          uri.query[urllib.unquote_plus(pair_parts[0])] = (
              urllib.unquote_plus(pair_parts[1]))
        elif len(pair_parts) == 1:
          uri.query[urllib.unquote_plus(pair_parts[0])] = None
    return uri
667498
def _build_url(cls, request, path=None, **changes):
        
        changes = {k: v for k, v in changes.items() if v is not None}
        queries = {**request.url.query, **changes}
        queries = {k: v for k, v in queries.items() if v is not False}
        query_strings = []

        def add_query(key):
            query_strings.append('{}={}'.format(key, queries[key])
                                 if queries[key] != '' else key)

        def del_query(key):
            queries.pop(key, None)

        if 'head' in queries:
            add_query('head')
            del_query('head')

        if 'start' in changes:
            add_query('start')
        elif 'start' in queries:
            add_query('start')

        del_query('start')

        if 'limit' in queries:
            add_query('limit')
            del_query('limit')

        for key in sorted(queries):
            add_query(key)

        scheme = cls._get_forwarded(request, 'proto') or request.url.scheme
        host = cls._get_forwarded(request, 'host') or request.host
        forwarded_path = cls._get_forwarded(request, 'path')
        path = path if path is not None else request.path
        query = '?' + '&'.join(query_strings) if query_strings else ''

        url = '{}://{}{}{}{}'.format(scheme, host, forwarded_path, path, query)
        return url
364650
def url
      url = scheme + "://"
      url << host

      if scheme == "https" && port != 443 ||
          scheme == "http" && port != 80
        url << ":#{port}"
      end

      url << fullpath

      url
    end
1069289
def _build_path(self):
        '''
        

        '''
        if not self.path:
            self.path = '/'

        if self.uri_parameters:
            self.path = self.path + ';' + requote_uri(self.uri_parameters)

        if self.query:
            self.path = (self.path + '?' + self.query)

        if self.params:
            try:
                if self.query:
                    self.path = self.path + self._dict_to_query(
                        self.params, base_query=True)
                else:
                    self.path = self.path + self._dict_to_query(self.params)
            except AttributeError:
                self.path = self.path + '?' + self.params

        self.path = requote_uri(self.path)

        self.req_url = urlunparse(
            (self.scheme, self.host, (self.path or ''), '', '', ''))