from urllib.parse import urlparse, urlunparse




def frag2param(url):

    res = urlparse(url)

    return urlunparse(res[0:4] + ("&".join([val for val in res[4:] if val]),
None))




frag2param("http://test.foo/cosi/page;code?day=0&night=2#param=1";)

'http://test.foo/cosi/page;code?day=0&night=2&param=1'




frag2param("http://test.foo/cosi/page;code#param=1";)

'http://test.foo/cosi/page;code?param=1'




frag2param("http://test.foo/cosi/page;code?day=0&night=2";)

'http://test.foo/cosi/page;code?day=0&night=2'




frag2param("http://test.foo/cosi/page";)

'http://test.foo/cosi/page'



_______________________________________________
Python mailing list
python@py.cz
http://www.py.cz/mailman/listinfo/python

Visit: http://www.py.cz

Odpovedet emailem