Revision c1a0ab9b snf-common/synnefo/lib/__init__.py
b/snf-common/synnefo/lib/__init__.py | ||
---|---|---|
56 | 56 |
'http://www.test.org/a/b/c/d' |
57 | 57 |
>>> join_urls("http://www.test.org/a/b/", "/c/d") |
58 | 58 |
'http://www.test.org/a/b/c/d' |
59 |
>>> join_urls("http://www.test.org/a/b/", "/c/d/", "/e/f/") |
|
60 |
'http://www.test.org/a/b/c/d/e/f/' |
|
59 | 61 |
>>> join_urls("/path1", "/path") |
60 | 62 |
'/path1/path' |
61 | 63 |
>>> join_urls("path1", "/path") |
... | ... | |
78 | 80 |
return args[0] |
79 | 81 |
|
80 | 82 |
return "/".join([args[0].rstrip("/")] + |
81 |
[a.lstrip("/") for a in args[1:-1]] +
|
|
83 |
[a.strip("/") for a in args[1:-1]] + |
|
82 | 84 |
[args[-1].lstrip("/")]) |
83 | 85 |
|
84 | 86 |
|
85 | 87 |
def parse_base_url(base_url): |
86 | 88 |
""" |
87 | 89 |
>>> parse_base_url("https://one.two.three/four/five") |
88 |
('https://one.two.three', '/four/five')
|
|
90 |
('https://one.two.three', 'four/five') |
|
89 | 91 |
>>> parse_base_url("https://one.two.three/four/five/") |
90 |
('https://one.two.three', '/four/five/')
|
|
92 |
('https://one.two.three', 'four/five')
|
|
91 | 93 |
>>> parse_base_url("https://one.two.three/") |
92 |
('https://one.two.three', '/')
|
|
94 |
('https://one.two.three', '') |
|
93 | 95 |
>>> parse_base_url("https://one.two.three") |
94 |
('https://one.two.three', '/')
|
|
96 |
('https://one.two.three', '') |
|
95 | 97 |
|
96 | 98 |
""" |
97 | 99 |
parsed = urlparse(base_url) |
Also available in: Unified diff