summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-09-02 19:28:00 +0200
committermakefu <github@syntax-fehler.de>2013-09-02 19:28:00 +0200
commit34d684f27da3500db837d56628fe82e03359278c (patch)
treef3e933aa835f547b5ef31930d907111d98a2b73a /util
parent655ff5e0ec72e4ad021964e6c5d3e8087fe01e6f (diff)
add urlparse
Diffstat (limited to 'util')
-rw-r--r--util/Makefile11
-rwxr-xr-xutil/bin/urlparse15
-rwxr-xr-xutil/t/urlparse/parse-url12
3 files changed, 26 insertions, 12 deletions
diff --git a/util/Makefile b/util/Makefile
index 90f8bfb2..ab22947f 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -7,8 +7,11 @@ test:
n=`echo "$$tests" | wc -l`; \
echo $$i..$$n; \
for exe in $$tests; do \
- ./$$exe; \
- case $$? in 0) result=ok;; *) result='not ok';; esac; \
- echo $$result $$i - $$exe; \
+ { \
+ ./$$exe; \
+ case $$? in 0) result=ok;; *) result='not ok';; esac; \
+ echo $$result $$i - $$exe; \
+ } & \
(( i++ )); \
- done
+ done; \
+ wait
diff --git a/util/bin/urlparse b/util/bin/urlparse
index f536bafa..3767b929 100755
--- a/util/bin/urlparse
+++ b/util/bin/urlparse
@@ -1,24 +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
- from sys import argv,exit
return urlparse(uri)
if __name__ == "__main__":
-
try:
- uri=argv[1]
+ uri = argv[1]
except:
print('usage: %s URI')
exit(1)
- for k,v in uri_parser(uri):
- print('USERNAME='% u.username)
- print('PASSWORD='% u.password)
- print('HOST="%s"'% u.password)
- print('PATH="%s"'% u.path)
+ 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" ]
+