def split_conn_port(connection):
    """Return port number of a string such as 'port0' as an
    integer, or raise ValueError if format is invalid"""
    try:
        return int(connection.split('port', 1)[1])
    except (ValueError, IndexError):
        msg = "port string %s does not match format 'port<N>' for integer N"
        raise ValueError(msg % str(connection))