示例#1
0
    def __copy__(self):
 
        copy = DefaultDict(self.default)
 
        copy.update(self)
 
        return copy
示例#2
0
def get_combination_internal(ranged_properties):
    if len(list(ranged_properties.keys())) == 1 and isinstance(
            list(ranged_properties.values())[0], list):
        for property_name, values in ranged_properties.items():
            for value in values:
                yield {property_name: value}
        return

    for property_name, values in ranged_properties.items():
        if isinstance(values, dict):
            for combination in get_combination_internal(
                    ranged_properties[property_name]):
                copy = {property_name: combination.copy()}
                if len(ranged_properties.keys()) == 1:
                    yield copy
                    continue
                dict_witout_key = ranged_properties.copy()
                del dict_witout_key[property_name]
                for combination in get_combination_internal(dict_witout_key):
                    copy.update(combination.copy())
                    yield copy
            break
        elif isinstance(values, list):
            dict_witout_key = ranged_properties.copy()
            del dict_witout_key[property_name]
            for value in values:
                for combination in get_combination_internal(dict_witout_key):
                    copy = combination.copy()
                    copy[property_name] = value
                    yield copy
            break
示例#3
0
 def __copy__(self):
     """
     >>> d = RecursiveDict(2, [])
     >>> d[1]['keyword'].append(5)
     >>> p = d.copy()
     >>> p
     {1: {'keyword': [5]}}
     """
     copy = RecursiveDict(self.ncount, self.default)
     copy.update(self)
     return copy
示例#4
0
 def __copy__(self):
     """
     >>> d = DefaultDict(0)
     >>> d[1] += 1
     >>> p = d.copy()
     >>> p
     {1: 1}
     """
     copy = DefaultDict(self.default)
     copy.update(self)
     return copy
示例#5
0
 def __copy__(self):
     """
     >>> d = RecursiveDict(2, [])
     >>> d[1]['keyword'].append(5)
     >>> p = d.copy()
     >>> p
     {1: {'keyword': [5]}}
     """
     copy = RecursiveDict(self.ncount, self.default)
     copy.update(self)
     return copy
示例#6
0
 def __copy__(self):
     """
     >>> d = DefaultDict(0)
     >>> d[1] += 1
     >>> p = d.copy()
     >>> p
     {1: 1}
     """
     copy = DefaultDict(self.default)
     copy.update(self)
     return copy
示例#7
0
def _create_tiles(tile, bucketer, legacy=False):
    """Create the new Directory/Suggested/Legacy tiles

    Params:
        tile: sqlalchemy record for tiles table
        bucketer: dict of buckets
        legacy: flag to create legacy tile
    Return:
        List of tile dicts. It returns multiple new tiles if the argument tile is a
        suggested tile with multiple categories. Otherwise, it returns a one item list.
    """
    new_tiles = []
    tile_dict = dict(directoryId=tile.id,
                     url=tile.target_url,
                     bgColor=tile.bg_color,
                     title=tile.title,
                     type=tile.type,
                     created_at=tile.created_at,
                     position_priority=tile.position_priority)
    if tile.image_uri:
        tile_dict['imageURI'] = switch_to_cdn_url(tile.image_uri)
    if tile.enhanced_image_uri:
        tile_dict['enhancedImageURI'] = switch_to_cdn_url(
            tile.enhanced_image_uri)
    if not legacy and tile.adgroup.type == "suggested" and tile.adgroup.categories:
        for category in tile.adgroup.categories:
            bucket = bucketer[category.category]
            frequency_caps = {
                "daily": tile.adgroup.frequency_cap_daily,
                "total": tile.adgroup.frequency_cap_total
            }
            copy = dict(tile_dict)
            copy.update(
                dict(titleBgColor=tile.title_bg_color,
                     frecent_sites=bucket["sites"],
                     frequency_caps=frequency_caps,
                     adgroup_name=bucket["adgroup_name"],
                     adgroup_categories=[category.category],
                     explanation=tile.adgroup.explanation
                     or bucket["explanation"],
                     check_inadjacency=tile.adgroup.check_inadjacency))
            new_tiles.append(copy)
    else:
        new_tiles.append(tile_dict)

    return new_tiles
示例#8
0
        def optimizeTree(tree):

            if "comments" in optimize:
                commentoptimizer.patch(tree)

            # "variants" prunes parts of the tree, so all subsequent optimizations benefit
            if "variants" in optimize:
                variantoptimizer.search(tree, variantSet, self.id)

            # 'statics' has to come before 'privates', as it needs the original key names in tree
            # if features should be removed recursively, this has to be controlled on the calling
            # level.
            if "statics" in optimize:
                if not featureMap:
                    console.warn(
                        "Empty feature map passed to static methods optimization; skipping"
                    )
                elif self.type == 'static' and self.id in featureMap:
                    optimzed_features = featureoptimizer.patch(
                        tree, self, featureMap)
                    if optimzed_features:
                        optimized_statics_overall = load_features()
                        copy = optimized_statics_overall.copy()
                        copy.update(optimzed_features)
                        write_features(copy)

            if "basecalls" in optimize:
                basecalloptimizer.patch(tree)

            if "privates" in optimize:
                privatesMap = load_privates()
                privateoptimizer.patch(tree, id, privatesMap)
                write_privates(privatesMap)

            if "globals" in optimize:
                tree = globalsoptimizer.process(
                    tree
                )  # need to re-assign as this optimizer might change the root node

            if "strings" in optimize:
                tree = stringoptimizer.process(tree, self.id)

            if "variables" in optimize:
                variableoptimizer.search(tree)

            return tree
示例#9
0
def _create_tiles(tile, bucketer, legacy=False):
    """Create the new Directory/Suggested/Legacy tiles

    Params:
        tile: sqlalchemy record for tiles table
        bucketer: dict of buckets
        legacy: flag to create legacy tile
    Return:
        List of tile dicts. It returns multiple new tiles if the argument tile is a
        suggested tile with multiple categories. Otherwise, it returns a one item list.
    """
    new_tiles = []
    tile_dict = dict(
        directoryId=tile.id,
        url=tile.target_url,
        bgColor=tile.bg_color,
        title=tile.title,
        type=tile.type,
        created_at=tile.created_at,
        position_priority=tile.position_priority)
    if tile.image_uri:
        tile_dict['imageURI'] = switch_to_cdn_url(tile.image_uri)
    if tile.enhanced_image_uri:
        tile_dict['enhancedImageURI'] = switch_to_cdn_url(tile.enhanced_image_uri)
    if not legacy and tile.adgroup.type == "suggested" and tile.adgroup.categories:
        for category in tile.adgroup.categories:
            bucket = bucketer[category.category]
            frequency_caps = {"daily": tile.adgroup.frequency_cap_daily,
                              "total": tile.adgroup.frequency_cap_total}
            copy = dict(tile_dict)
            copy.update(dict(
                titleBgColor=tile.title_bg_color,
                frecent_sites=bucket["sites"],
                frequency_caps=frequency_caps,
                adgroup_name=bucket["adgroup_name"],
                adgroup_categories=[category.category],
                explanation=tile.adgroup.explanation or bucket["explanation"],
                check_inadjacency=tile.adgroup.check_inadjacency))
            new_tiles.append(copy)
    else:
        new_tiles.append(tile_dict)

    return new_tiles
示例#10
0
        def optimizeTree(tree):

            if "comments" in optimize:
                commentoptimizer.patch(tree)

            # "variants" prunes parts of the tree, so all subsequent optimizations benefit
            if "variants" in optimize:
                variantoptimizer.search(tree, variantSet, self.id)

            # 'statics' has to come before 'privates', as it needs the original key names in tree
            # if features should be removed recursively, this has to be controlled on the calling
            # level.
            if "statics" in optimize:
                if not featureMap:
                    console.warn("Empty feature map passed to static methods optimization; skipping")
                elif self.type == 'static' and self.id in featureMap:
                    optimzed_features = featureoptimizer.patch(tree, self, featureMap)
                    if optimzed_features:
                        optimized_statics_overall = load_features()
                        copy = optimized_statics_overall.copy()
                        copy.update(optimzed_features)
                        write_features(copy)

            if "basecalls" in optimize:
                basecalloptimizer.patch(tree)

            if "privates" in optimize:
                privatesMap = load_privates()
                privateoptimizer.patch(tree, id, privatesMap)
                write_privates(privatesMap)

            if "globals" in optimize:
                tree = globalsoptimizer.process(tree) # need to re-assign as this optimizer might change the root node

            if "strings" in optimize:
                tree = stringoptimizer.process(tree, self.id)

            if "variables" in optimize:
                variableoptimizer.search(tree)

            return tree
示例#11
0
文件: utils.py 项目: Letram/Practica1
 def __copy__(self):
     copy = DefaultDict(self.default)
     copy.update(self)
     return copy
示例#12
0
 def updated(settings, update):
     copy = settings.copy()
     copy.update(update or {})
     return copy
示例#13
0
def get_val_types():
    copy = set(IPV4_TYPES)
    copy.update(IPV6_TYPES)
    copy.update(MAC_TYPES)
    return copy
示例#14
0
 def compose(self, style: "TextStyle") -> "TextStyle":
     """Create a new style that will be the combination of the current and the given style."""
     copy = self.copy()
     copy.update(style)
     return copy