def split_port(port):
    parts = str(port).split(':')

    if not 1 <= len(parts) <= 3:
        _raise_invalid_port(port)

    if len(parts) == 1:
        internal_port, = parts
        return to_port_range(internal_port), None
    if len(parts) == 2:
        external_port, internal_port = parts

        internal_range = to_port_range(internal_port)
        external_range = to_port_range(external_port)

        if internal_range is None or external_range is None:
            _raise_invalid_port(port)

        if len(internal_range) != len(external_range):
            raise ValueError('Port ranges don\'t match in length')

        return internal_range, external_range

    external_ip, external_port, internal_port = parts
    internal_range = to_port_range(internal_port)
    external_range = to_port_range(external_port)
    if not external_range:
        external_range = [None] * len(internal_range)

    if len(internal_range) != len(external_range):
        raise ValueError('Port ranges don\'t match in length')

    return internal_range, [(external_ip, ex_port or None)
                            for ex_port in external_range]
dataset/ETHPy150Open docker/docker-py/docker/utils/ports/ports.py/split_port/original