1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-15 01:24:29 +02:00

add username, password, hostname, and port

This commit is contained in:
Kelly Brazil
2022-07-19 08:23:27 -07:00
parent 450d0d5ddf
commit da631c8b22

View File

@ -14,11 +14,15 @@ Schema:
{ {
"scheme": string, "scheme": string,
"netloc": string, "netloc": string,
"path": string, "path": string or null,
"query": { object or null, "query": { object or null,
<query-key>: string <query-key>: string
}, },
"fragment": string or null "fragment": string or null,
"username": string or null,
"password": string or null,
"hostname": string or null,
"port": integer or null
} }
Examples: Examples:
@ -32,7 +36,11 @@ Examples:
"q1": "foo", "q1": "foo",
"q2": "bar" "q2": "bar"
}, },
"fragment": "frag" "fragment": "frag",
"username": null,
"password": null,
"hostname": "example.com",
"port": null
} }
$ echo "ftp://localhost/filepath" | jc --url -p $ echo "ftp://localhost/filepath" | jc --url -p
@ -41,7 +49,11 @@ Examples:
"netloc": "localhost", "netloc": "localhost",
"path": "/filepath", "path": "/filepath",
"query": null, "query": null,
"fragment": null "fragment": null,
"username": null,
"password": null,
"hostname": "localhost",
"port": null
} }
""" """
from urllib.parse import urlparse from urllib.parse import urlparse
@ -117,7 +129,11 @@ def parse(
'netloc': parts.netloc or None, 'netloc': parts.netloc or None,
'path': parts.path or None, 'path': parts.path or None,
'query': query or None, 'query': query or None,
'fragment': parts.fragment or None 'fragment': parts.fragment or None,
'username': parts.username,
'password': parts.password,
'hostname': parts.hostname,
'port': parts.port
} }
return raw_output if raw else _process(raw_output) return raw_output if raw else _process(raw_output)