Esempio n. 1
0
def make_redirect_url(url, use_fragment=False, **params):
    urlparts = list(urlparse.urlsplit(url))
    # URL parts:
    # 0: scheme
    # 1: netloc
    # 2: path
    # 3: query -- appended to
    # 4: fragment
    queryparts = urlparse.parse_qsl(urlparts[4] if use_fragment else urlparts[3], keep_blank_values=True)
    queryparts.extend([(k, v) for k, v in params.items() if v is not None])
    queryparts = [(key.encode('utf-8') if isinstance(key, unicode) else key,
                   value.encode('utf-8') if isinstance(value, unicode) else value) for key, value in queryparts]
    if use_fragment:
        urlparts[4] = make_query_string(queryparts)
    else:
        urlparts[3] = make_query_string(queryparts)
    return urlparse.urlunsplit(urlparts)
Esempio n. 2
0
def make_redirect_url(url, **params):
    urlparts = list(urlparse.urlsplit(url))
    # URL parts:
    # 0: scheme
    # 1: netloc
    # 2: path
    # 3: query -- appended to
    # 4: fragment
    queryparts = urlparse.parse_qsl(urlparts[3], keep_blank_values=True)
    queryparts.extend(params.items())
    urlparts[3] = make_query_string(queryparts)
    return urlparse.urlunsplit(urlparts)
Esempio n. 3
0
def make_redirect_url(url, **params):
    urlparts = list(urlparse.urlsplit(url))
    # URL parts:
    # 0: scheme
    # 1: netloc
    # 2: path
    # 3: query -- appended to
    # 4: fragment
    queryparts = urlparse.parse_qsl(urlparts[3], keep_blank_values=True)
    queryparts.extend(params.items())
    urlparts[3] = make_query_string(queryparts)
    return urlparse.urlunsplit(urlparts)
Esempio n. 4
0
def make_redirect_url(url, use_fragment=False, **params):
    urlparts = list(urlparse.urlsplit(url))
    # URL parts:
    # 0: scheme
    # 1: netloc
    # 2: path
    # 3: query -- appended to
    # 4: fragment
    queryparts = urlparse.parse_qsl(
        urlparts[4] if use_fragment else urlparts[3], keep_blank_values=True)
    queryparts.extend([(k, v) for k, v in params.items() if v is not None])
    queryparts = [
        (key.encode('utf-8') if isinstance(key, unicode) else key,
         value.encode('utf-8') if isinstance(value, unicode) else value)
        for key, value in queryparts
    ]
    if use_fragment:
        urlparts[4] = make_query_string(queryparts)
    else:
        urlparts[3] = make_query_string(queryparts)
    return urlparse.urlunsplit(urlparts)