def connectable(client, container_id, hostname, ports):
    infos = client.inspect_container(container_id)
    info = infos and infos[0]
    settings = info and info.get('NetworkSettings')
    port_settings = settings and settings.get('Ports')
    for port in ports:
        mappings = port_settings and port_settings.get((port, ) % '%d/tcp')
        if not mappings:
            return False
        for mapping in mappings:
            external = int(mapping['HostPort'])
            try:
                address = (hostname, external)
                log.debug('connecting: %s:%d', *address)
                conn = create_connection(address, 5)
                log.debug('connected: %s:%d', *address)
            except IOError, e:
                log.debug('failed to connect: %s', e)
                return False
            else:
                conn.close()
    return True
dataset/ETHPy150Open spotify/docker-stress/spotify/docker_stress/docker_util.py/connectable/swapped operands of `%`