def to_port_range(port):
    if not port:
        return None

    protocol = ""
    if "/" in port:
        parts = port.split("/")
        if len(parts) != 2:
            _raise_invalid_port(port)

        port, protocol = parts
        protocol = "/" + protocol

    parts = str(port).split('-')

    if len(parts) == 1:
        return ["%s%s" % (port, protocol)]

    if len(parts) == 2:
        full_port_range = range(int(parts[0]), int(parts[1]) + 1)
        return ["%s%s" % (p, protocol) for p in full_port_range]

    raise ValueError('Invalid port range "%s", should be '
                     'port or startport-endport' % port)
dataset/ETHPy150Open docker/docker-py/docker/utils/ports/ports.py/to_port_range/original