summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/utils/url_parse.py
blob: 08f7a634d43ddcfdb9ee3671d95bba052ee4fe2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os

from six.moves.urllib import parse


def path_join(base, *urls):
    def _path_join(base, url):
        if not base.endswith('/'):
            base += '/'
        return parse.urljoin(base, url)

    urls = (base,) + urls
    return reduce(_path_join, urls)


def query_join(base, **queries):
    return base + '?' + parse.urlencode(queries)


def resource_join(url):
    testapi_url = os.environ.get('testapi_url')
    return path_join(testapi_url, url)