def url_fix(s, charset='utf-8'): if PY2 and isinstance(s, text_type): s = s.encode(charset, 'ignore') elif PY3 and not isinstance(s, text_type): s = s.decode(charset) scheme, netloc, path, qs, anchor = urlsplit(s) path = quote(path, '/%') qs = quote_plus(qs, ':&=') return urlunsplit((scheme, netloc, path, qs, anchor))
def url_fix(s, charset='utf-8'): if PY2 and isinstance(s, text_type): s = s.encode(charset, 'ignore') elif not PY2 and not isinstance(s, text_type): s = s.decode(charset) scheme, netloc, path, qs, anchor = urlsplit(s) path = quote(path, '/%') qs = quote_plus(qs, ':&=') return urlunsplit((scheme, netloc, path, qs, anchor))