Rewrite port from host
The naïve implementation of get_port_by_host
with a single split works for host names and IPv4 literal addresses, but doesn’t work with IPv6 literals. Instead of trying to work that around, it’s better to write a regex instead and add a doctest.
By the way, this function belongs in utils.py
.