def build(
        cls,
        *,
        scheme="",
        user="",
        password=None,
        host="",
        port=None,
        path="",
        query=None,
        query_string="",
        fragment="",
        encoded=False
    ):
        """Creates and returns a new URL"""

        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
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
Creates and returns a new URL