Live data from Hacker News

Parsing URLs in Python

tkte.ch

81–90 of 99 posts

Re: Parsing URLs in Python

#81

Earlier quoted context omitted.

> Ada is a WHATWG-compliant and fast URL parser written in modern C++ Why would you do that, Daniel?

Ada developer here, Ada is the name of my daughter, and this project is my gift to her, to remember me.

Congrats on having a daughter! I hope and day she’ll need to parse a url, and be able to see your love for her in her code!

Re: Parsing URLs in Python

#82

Okay so some googling found me that the "xn--" means the rest of the hostname will be unicode, but why does é become -fsa in www.xn--googl-fsa.com. Google failed on the second part.

In case anyone else is confused as to why the domain in the example provided needs to be unicode (compared to the filename which is obvious): it's because the hyphen is the shorter '‑' char, which is extended ASCII 226 not the standard '-' (which would be ASCII 45).

The first character you pasted is U+2011 (8209 in decimal), does not appear in the document and cannot be ASCII as it goes beyond the codepoint 127/7F. Also, U+2011 is meant to be a non-breaking hyphen.

Re: Parsing URLs in Python

#83
post #3

This is intriguing to me for the performance and correctness reasons, but also if it makes the result more dev friendly than the urllib.parse tiple-ish-object result thing.

Yeah, that tuple API is bizarre. It really doesn’t play well with type annotations either.

Re: Parsing URLs in Python

#84
post #57
post #54

Earlier quoted context omitted.

httpx is great, and "needs to be in base"

No it doesn’t, absolutely not. It’s ironic that you say this after the post you’re commenting on spells out quite explicitly why things “in base” are hard to change and adapt.

where do you draw the line with this approach?

Re: Parsing URLs in Python

#85

Okay so some googling found me that the "xn--" means the rest of the hostname will be unicode, but why does é become -fsa in www.xn--googl-fsa.com. Google failed on the second part.

FWIW I find this is the perfect question for ChatGPT/Gemini. Whenever the knowedge is somewhere on the web but hard to Google, I use these LLMs.

In this case, Gemini correctly points to Punycode

Re: Parsing URLs in Python

#86

Nice. I'll also throw in that I've recently wrote bindings to Mozilla's servo URL library. Those live at https://github.com/crate-py/url They're not complete yet (meaning only the parsing bits are exposed, not URL modification) but I too was frustrated with the state of URL parsing.

IMO that URL crate is not especially high quality. I barely work with URLs and I quickly found an embarrassingly trivial bug:

https://github.com/servo/rust-url/issues/864#issuecomment-16...

Re: Parsing URLs in Python

#89

Earlier quoted context omitted.

It is mindboggling to me how often developers create project names without even trying to search for precedent names in their own domain/industry . Calling this Ada is just ridiculous.

Ada developer here. Ada URL parser is named after my daughter Ada. We chose this name in particular as a reference to Ada Lovelace.

> We chose this name in particular as a reference to Ada Lovelace.

Just like the ~20 other projects named Ada.

Re: Parsing URLs in Python

#90
stdlib behavior may be more preferable:

- resolving "../" may have security implications - unicode hostname seems more readable. To get punycode, one can call .encode("idna") if necessary.

How often parsing urls is a performance bottleneck?

Post reply on HN