diff options
-rwxr-xr-x | util/bin/urlparse | 23 | ||||
-rwxr-xr-x | util/t/urlparse/parse-url | 12 |
2 files changed, 35 insertions, 0 deletions
diff --git a/util/bin/urlparse b/util/bin/urlparse new file mode 100755 index 00000000..3767b929 --- /dev/null +++ b/util/bin/urlparse @@ -0,0 +1,23 @@ +#!/usr/bin/python +import os +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('USERNAME="%s"' % u.username) + print('PASSWORD="%s"' % u.password) + print('HOSTNAME="%s"' % u.hostname) + print('URIPATH="%s"' % u.path) diff --git a/util/t/urlparse/parse-url b/util/t/urlparse/parse-url new file mode 100755 index 00000000..b9f0aa31 --- /dev/null +++ b/util/t/urlparse/parse-url @@ -0,0 +1,12 @@ +#!/bin/sh +set -xeuf +tempfile="`mktemp /tmp/test.XXXXXXXX`" +trap "/bin/rm -f $tempfile" EXIT INT + +urlparse "http://user:pass@domain.tld/path" > $tempfile +. $tempfile +[ $HOSTNAME == "domain.tld" ] && \ + [ $USERNAME == "user" ] && \ + [ $PASSWORD == "pass" ] && \ + [ $URIPATH == "/path" ] + |