def transform_technology_targeting_from_dfp(targeting):
    """
    Convert DFP technology targeting data to TargetingCriterion

    @param targeting: dict
    @return: TargetingCriterion
    """
    if not targeting:
        return None

    target_data = {
        'include': [],
        'exclude': [],
    }

    for tech_type, _map in TECHNOLOGY_KEY_MAP.items():
        target = targeting.get(_map['target_name'])
        if not target:
            continue

        _map_type = _map['type']
        if _map_type == 'list':
            _list_name = _map['list_name']
            browser_list = []
            for item in target[_list_name]:
                tech_target = Technology(
                    id=item['id'],
                    name=item.get('name'),
                    type=tech_type,
                )
                browser_list.append(tech_target)
            # The isTargeted key determines whether
            # to target this entire list or not
            if target['isTargeted']:
                target_data['include'] += browser_list
            else:
                target_data['exclude'] += browser_list

        elif _map_type == 'categorical':
            # Get lists of items to be included and excluded
            for _cat_key in ['include', 'exclude']:
                dfp_key = _map[_cat_key]
                raw_data = target.get(dfp_key, [])
                for item in raw_data:
                    tech_target = Technology(
                        id=item['id'],
                        name=item.get('name'),
                        type=tech_type,
                    )
                    target_data[_cat_key].append(tech_target)

    # Build TargetingCriterion from list of includes and excludes
    includes = target_data['include']
    inc = TargetingCriterion(includes, TargetingCriterion.OPERATOR.OR)
    excludes = target_data['exclude']
    exl = TargetingCriterion(excludes, TargetingCriterion.OPERATOR.OR)
    if includes and excludes:
        return inc & (~exl)
    elif includes:
        return inc
    elif excludes:
        return ~exl
    else:
        return None
dataset/ETHPy150Open chartbeat-labs/parselmouth/parselmouth/adapters/dfp/targeting_utils.py/transform_technology_targeting_from_dfp/original