blob: 3fdf370c52c10cf76d088d1dd50785f9b8ca0197 [file] [log] [blame]
Daryl Walleck1465d612011-11-02 02:22:15 -05001import random
Rohit Karajgie1b050d2011-12-02 16:13:18 -08002import urllib
Daryl Walleck1465d612011-11-02 02:22:15 -05003
4
Rohit Karajgicb5d9542011-12-02 14:17:06 -08005def rand_name(name='test'):
Daryl Walleck1465d612011-11-02 02:22:15 -05006 return name + str(random.randint(1, 99999999999))
Rohit Karajgie1b050d2011-12-02 16:13:18 -08007
8
9def build_url(host, port, apiVer=None, path=None, params=None, https=False):
10 """Build the request URL from given host, port, path and parameters"""
11
12 if https:
13 url = "https://" + host
14 else:
15 url = "http://" + host
16
17 if port is not None:
18 url += ":" + port
19 url += "/"
20
21 if apiVer is not None:
22 url += apiVer + "/"
23
24 if path is not None:
25 url += path
26
27 if params is not None:
28 url += "?"
29 url += urllib.urlencode(params)
30
31 return url