def _environment_for_container(self, container):
        """
        Get the custom environment specified for the container and infer its
        links.

        It would be nice to do these two things separately but links are only
        represented in the container's environment so both steps involve
        inspecting the environment.

        :param flocker.node._docker.Unit container: The container to inspect.

        :return: A two-tuple of the container's links and environment.  Links
            are given as a ``list`` of ``Link`` instances.  Environment is
            given as a ``list`` of two-tuples giving the environment variable
            name and value (as ``bytes``).
        """
        # Improve the factoring of this later.  Separate it into two methods.
        links = []
        environment = []
        if container.environment:
            environment_dict = container.environment.to_dict()
            for label, value in environment_dict.items():
                # <ALIAS>_PORT_<PORTNUM>_TCP_PORT=<value>
                parts = label.rsplit(b"_", 4)
                try:
                    alias, pad_a, port, pad_b, pad_c = parts
                    local_port = int(port)
                except ValueError:
                    # <ALIAS>_PORT_<PORT>_TCP
                    parts = label.rsplit(b"_", 3)
                    try:
                        alias, pad_a, port, pad_b = parts
                    except __HOLE__:
                        environment.append((label, value))
                        continue
                    if not (pad_a, pad_b) == (b"PORT", b"TCP"):
                        environment.append((label, value))
                    continue
                if (pad_a, pad_b, pad_c) == (b"PORT", b"TCP", b"PORT"):
                    links.append(Link(
                        local_port=local_port,
                        remote_port=int(value),
                        alias=alias,
                    ))
        return links, environment
dataset/ETHPy150Open ClusterHQ/flocker/flocker/node/_container.py/ApplicationNodeDeployer._environment_for_container