[Checkins] SVN: zc.parse_addr/trunk/ Tiny utility that I'm tired of writing over and over.

Wichert Akkerman wichert at wiggy.net
Wed Dec 21 11:43:28 UTC 2011


On 12/21/2011 12:35 PM, Jim Fulton wrote:
> +def parse_addr(s):
> +    """Parse network addresses of the form: HOST:PORT
> +
> +>>>  import zc.parse_addr
> +>>>  zc.parse_addr.parse_addr('1.2.3.4:56')
> +    ('1.2.3.4', 56)
> +
> +    It would be great if this little utility function was part
> +    of the socket module.
> +    """
> +    host, port = s.rsplit(':', 1)
> +    return host, int(port)

FWIW this will not work correctly for IPv6 addresses. The syntax there 
is [ipv6-address]:port .

Wichert.



More information about the checkins mailing list