urllibparse ~master
Translation of Python's urllib.parse for parsing and manipulating URLs
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
urllibparse
Direct D translation of Python's urllib.parse
(beauty spots, warts and all).
Features
- Supports parsing, manipulation, relative URL joining, quoting, etc
- Supports URLs containing non-UTF-8 character sets
- Reuses Python's test suite based on RFCs and bug reports
- Single-file library with no non-
std
dependencies @safe
Usage example
Either add to an existing DUB project with dub add urllibparse
, or just add the urllibparse.d
file to somewhere in your D compiler's import path (such as the main project's source directory).
import urllibparse;
// Parsing
auto parsed = urlParse("https://dlang.org/blog/");
assert (parsed.scheme == "https");
assert (parsed.path == "/blog/");
assert (parsed.password is null);
parsed.path = "documentation.html";
assert (parsed.getUrl() == "https://dlang.org/documentation.html");
// Relative URL handling
assert (urlJoin("https://dlang.org/blog/", "../articles.html") == "https://dlang.org/articles.html");
// Low-level quoting/unquoting
assert (quote("URLs in D!") == "URLs%20in%20D%21");
assert (quotePlus("URLs in D!") == "URLs+in+D%21");
assert (unquote("URLs%20in%20D%21") == "URLs in D!");
assert (unquotePlus("URLs+in+D%21") == "URLs in D!");
// Query encoding
const args = [
QueryArg("query", "d tools"),
QueryArg("page", "1"),
QueryArg("orderBy", "date"),
];
assert (urlEncode(args) == "query=d+tools&page=1&orderBy=date");
// can also use associative arrays, but can't guarantee order or handle repeated keys
assert (urlEncode([
"query": "d tools",
"page": "1",
"orderBy": "date",
]));
// Query parsing
assert (parseQSL("query=d+tools&page=1&orderBy=date") == args);
// likewise, parseQS returns an associative array
Documentation
See the original Python documentation and the auto-generated D documentation.
Differences from Python:
- Function names have been changed to match D's camelCase functionNamingConvention
ValueException
is thrown where the Python throwsValueError
, andEncodingException
is thrown instead ofUnicodeEncodeError
- The
ParseResult
class has been changed to aURLParseResult
struct (and similarly for other*Result
classes) - Character encodings (and names) are those supported by
std.encoding
- D isn't duck-typey like Python (but pull requests are welcome if you think an overload should be added)
- Some deprecated (trivial) functions are missing. (They're not in the Python docs now, anyway.)
- ~master released 4 years ago
- sarneaud/urllibparse
- gitlab.com/sarneaud/urllibparse
- PSFv2
- Copyright © 2020, PSF
- Authors:
- Dependencies:
- none
- Versions:
-
0.1.0 2020-Jan-21 ~master 2020-Jul-11 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
0 downloads total
-
- Score:
- 0.0
- Short URL:
- urllibparse.dub.pm