Revision e3ff6830 snf-common/synnefo/lib/__init__.py

b/snf-common/synnefo/lib/__init__.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.
33 33

  
34
from urlparse import urlparse
35

  
34 36

  
35 37
def join_urls(a, b):
36 38
    """
......
56 58
    """
57 59
    return a.rstrip("/") + "/" + b.lstrip("/")
58 60

  
61

  
62
def parse_base_url(base_url):
63
    """
64
    >>> parse_base_url("https://one.two.three/four/five")
65
    ('https://one.two.three', '/four/five')
66
    >>> parse_base_url("https://one.two.three/four/five/")
67
    ('https://one.two.three', '/four/five/')
68
    >>> parse_base_url("https://one.two.three/")
69
    ('https://one.two.three', '/')
70
    >>> parse_base_url("https://one.two.three")
71
    ('https://one.two.three', '/')
72

  
73
    """
74
    parsed = urlparse(base_url)
75
    base_path = parsed.path.strip('/')
76
    base_host = parsed.scheme + '://' + parsed.netloc
77
    return base_host, base_path
78

  
79

  
59 80
if __name__ == "__main__":
60 81
    import doctest
61 82
    doctest.testmod()

Also available in: Unified diff