

def parse_port_bindings(bindings):
    "\n    Parse array of string port bindings into a dict. For example:\n        ['4567:1111', '2222']\n    becomes\n        port_bindings={\n            1111: 4567,\n            2222: None\n        }\n    and\n        ['127.0.0.1:4567:1111']\n    becomes\n        port_bindings={\n            1111: ('127.0.0.1', 4567)\n        }\n    :param bindings: array of string\n    :return: dict\n    "

    def parse_port_mapping(s):
        '\n        Parse single port mapping.\n        '
        if (':' in s):
            parts = s.split(':')
            if (len(parts) > 2):
                (ip, hp, cp) = (parts[0], parts[1], parts[2])
                return (cp, (ip, (None if (hp == '') else hp)))
            else:
                (hp, cp) = (parts[0], parts[1])
                return (cp, (None if (hp == '') else hp))
        else:
            return (s, None)
    result = {
        
    }
    if bindings:
        for binding in bindings:
            (container_port, mapping) = parse_port_mapping(binding)
            result[container_port] = mapping
    return result

dataset/ETHPy150Open j-bennet/wharfee/wharfee/helpers.py parse_port_bindings/original