-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (27 loc) · 759 Bytes
/
utils.py
File metadata and controls
30 lines (27 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from urlparse import urlparse
from cgi import parse_qs
import urllib
try:
import json
except ImportError:
import simplejson as json
def addToQueryString(orig, extra_data):
scheme, netloc, path, params, query, fragment = urlparse(orig)
query_data = parse_qs(query)
for k, v in extra_data.items():
if not v:
del(extra_data[k])
query_data.update(extra_data)
query = urllib.urlencode(query_data, True)
base_url = ""
if scheme and netloc:
base_url += "%s://%s" % (scheme, netloc)
if path:
base_url += "%s" % path
if params:
base_url += ";%s" % params
if query:
base_url += "?%s" % query
if fragment:
base_url += "#%s" % fragment
return base_url