summaryrefslogtreecommitdiffstats
path: root/util/bin/uriparse
blob: b16bd9c8820363359748e7ddf33fa4a5b4898c5c (plain)
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
#!/usr/bin/python
from sys import argv, exit


def uri_parser(uri):
    try:
        from urlparse import urlparse
    except:
        from urllib.parse import urlparse

    return urlparse(uri)

if __name__ == "__main__":
    try:
        uri = argv[1]
    except:
        print('usage: %s URI')
        exit(1)
    u = uri_parser(uri)

    print("SCHEME='%s'" % u.scheme.replace("'", "'\\''"))
    if u.username:
        print("USERNAME='%s'" % u.username.replace("'", "'\\''"))
    if u.password:
        print("PASSWORD='%s'" % u.password.replace("'", "'\\''"))
    if u.path:
        print("URIPATH='%s'" % u.path.replace("'", "'\\''"))
    print("HOSTN='%s'" % u.hostname.replace("'", "'\\''"))