Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
TkTech committed Mar 10, 2024
2 parents 33c7890 + f0f855b commit b492273
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ pip install can_ada
Binary wheels are available for most platforms. If not available, a
C++17-or-greater compiler will be required to build the underlying Ada library.

## WHATWG URL compliance

Unlike the standard library's `urllib.parse` module, this library is compliant with the WHATWG URL specification.

```python
urlstring = "https://www.GOoglé.com/./path/../path2/"
import can_ada
# prints www.xn--googl-fsa.com,
# the correctly parsed domain name according to WHATWG
print(can_ada.parse(urlstring).hostname)
# prints /path2/
# the correctly parsed pathname according to WHATWG
print(can_ada.parse(urlstring).pathname)
import urllib
# prints www.googlé.com
print(urllib.parse.urlparse(urlstring).hostname)
# prints /./path/../path2/
print(urllib.parse.urlparse(urlstring).path)
```

## Usage

Parsing is simple:
Expand All @@ -37,4 +57,17 @@ url.search = "?q=canada&safe=off"
print(url) # https://google.com/search?q=canada&safe=off
```

## Performance

We find that `can_ada` may be faster than `urllib`:

```
$ python3 -m timeit -s 'import can_ada' 'can_ada.parse("https://tkte.ch/search?q=canada")'
1000000 loops, best of 5: 378 nsec per loop
$ python3 -m timeit -s 'import urllib' 'urllib.parse.urlparse("https://tkte.ch/search?q=canada")'
500000 loops, best of 5: 491 nsec per loop
```


[Ada]: https://ada-url.com/

0 comments on commit b492273

Please sign in to comment.