def transform_technology_targeting_to_dfp(targeting):
    """
    Convert TargetingCriterion to DFP technology targeting data
    in dictionary form.

    @param targeting: TargetingCriterion
    @return: dict
    """
    includes, excludes = targeting.get_includes_and_excludes()
    targeting_data = {
        'include': includes,
        'exclude': excludes,
    }

    dict_info = defaultdict(lambda: defaultdict(list))
    for criterion_type, criterion in targeting_data.iteritems():
        for item in criterion:
            tech_type = item.type

            _map = TECHNOLOGY_KEY_MAP[tech_type]
            _map_type = _map['type']
            _target_name = _map['target_name']

            # Only output the id of the technology target
            dfp_doc = {'id': item.id}
            if _map_type == 'list':
                _list_name = _map['list_name']
                dict_info[_target_name][_list_name].append(dfp_doc)
                dict_info[_target_name]['isTargeted'] = (criterion_type == 'include')
            elif _map_type == 'categorical':
                _category_name = _map[criterion_type]
                dict_info[_target_name][_category_name].append(dfp_doc)

    # Convert defaultdict to dictionary
    dfp_dict = {}
    for _key, _val in dict_info.items():
        dfp_dict[_key] = dict(_val)

    return dfp_dict
dataset/ETHPy150Open chartbeat-labs/parselmouth/parselmouth/adapters/dfp/targeting_utils.py/transform_technology_targeting_to_dfp/original