Nick Coghlan <ncogh...@gmail.com> added the comment:

Could you provide some failing examples?

The suggestion also seems to run slightly at odds with itself - in one part, 
silently replacing an invalid port specification with a different value, in 
another adding additional validation checks.

Also, rather than hardcoding default port numbers for selected protocols, it 
would make more sense to just look them up via socket.getservbyname(scheme) 
(and still return None if the scheme isn't recognised). However, I'll need to 
think about that one for a while - urlparse is designed to be almost purely a 
string *parsing* library. Looking up default port numbers if one isn't 
specified really isn't its job. (For one thing, you'd break the ability to 
exactly recreate the original URL text from the parsed version).

There should definitely by a try/except around that conversion to int(), though 
- it's just that I'm not yet sure what an appropriate return value is at that 
point. The raw port string? None? Should there be a separate "raw_port" 
descriptor that always returns some kind of string, with the port descriptor 
promising to always return a valid 16-bit port number or None?

----------
nosy: +ncoghlan
versions:  -Python 3.1, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14036>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to