コード例 #1
0
ファイル: webapps.py プロジェクト: MaxMillion/app-validator
    def __init__(self, data, err, **kwargs):
        self.SPEC = copy.deepcopy(self.SPEC)

        # Get all of the locale-able nodes and allow them to be included within
        # locale elements.
        locale_nodes = ("name", "description", "launch_path", "icons",
                        "developer", "version", "screen_size", "orientation",
                        "fullscreen", "appcache_path", )
        child_nodes = self.SPEC["child_nodes"]
        sparse_nodes = dict((k, v) for k, v in child_nodes.items() if
                            k in locale_nodes)
        # Create a copy so we can modify it without modifying the *actual*
        # version.
        sparse_nodes = copy.deepcopy(sparse_nodes)

        if err.get_resource("packaged"):
            self.SPEC["required_nodes"].append("launch_path")

        # Allow the developer to avoid localizing their name.
        del sparse_nodes["developer"]["required_nodes"]
        sparse_nodes["developer"]["allowed_once_nodes"].append("name")

        # Put the locale bits in their appropriate place.
        locale_all_nodes = child_nodes["locales"]["child_nodes"]["*"]
        locale_all_nodes["child_nodes"] = sparse_nodes
        locale_all_nodes["allowed_once_nodes"] = locale_nodes

        # If we're listed, we require icons.
        if err.get_resource("listed"):
            self.SPEC["required_nodes"].append("icons")
            self.SPEC["allowed_once_nodes"].remove("icons")

        super(WebappSpec, self).__init__(data, err, **kwargs)
コード例 #2
0
    def __init__(self, data, err, **kwargs):
        self.SPEC = copy.deepcopy(self.SPEC)

        # Get all of the locale-able nodes and allow them to be included within
        # locale elements.
        locale_nodes = ("name", "description", "launch_path", "icons",
                        "developer", "version", "screen_size", "orientation",
                        "fullscreen", "appcache_path", )
        child_nodes = self.SPEC["child_nodes"]
        sparse_nodes = dict((k, v) for k, v in child_nodes.items() if
                            k in locale_nodes)
        # Create a copy so we can modify it without modifying the *actual*
        # version.
        sparse_nodes = copy.deepcopy(sparse_nodes)

        if err.get_resource("packaged"):
            self.SPEC["required_nodes"].append("launch_path")

        # Allow the developer to avoid localizing their name.
        del sparse_nodes["developer"]["required_nodes"]
        sparse_nodes["developer"]["allowed_once_nodes"].append("name")

        # Put the locale bits in their appropriate place.
        locale_all_nodes = child_nodes["locales"]["child_nodes"]["*"]
        locale_all_nodes["child_nodes"] = sparse_nodes
        locale_all_nodes["allowed_once_nodes"] = locale_nodes

        # If we're listed, we require icons.
        if err.get_resource("listed"):
            self.SPEC["required_nodes"].append("icons")
            self.SPEC["allowed_once_nodes"].remove("icons")

        super(WebappSpec, self).__init__(data, err, **kwargs)
コード例 #3
0
def NewExpression(traverser, node):
    args = [traverser.traverse_node(arg) for arg in node["arguments"]]
    elem = traverser.traverse_node(node["callee"])
    if not isinstance(elem, JSGlobal):
        return elem

    traverser._debug("Making overwritable")
    global_data = dict(elem.global_data)
    global_data.update(overwritable=True, readonly=False)
    temp = JSGlobal(global_data, traverser=traverser)
    temp.data = deepcopy(elem.data) if elem.data else {}
    if "new" in temp.global_data:
        new_temp = temp.global_data["new"](node, args, traverser)
        if new_temp is not None:
            # typeof new Boolean() === "object"
            traverser._debug("Stripping global typeof")
            new_temp.TYPEOF = "object"
            return new_temp
    elif "return" in temp.global_data:
        new_temp = temp.global_data["return"](wrapper=node,
                                              arguments=args,
                                              traverser=traverser)
        if new_temp is not None:
            return new_temp
    return temp
コード例 #4
0
def NewExpression(traverser, node):
    args = [traverser.traverse_node(arg) for arg in node["arguments"]]
    elem = traverser.traverse_node(node["callee"])
    if not isinstance(elem, JSGlobal):
        return elem

    traverser._debug("Making overwritable")
    global_data = dict(elem.global_data)
    global_data.update(overwritable=True, readonly=False)
    temp = JSGlobal(global_data, traverser=traverser)
    temp.data = deepcopy(elem.data) if elem.data else {}
    if "new" in temp.global_data:
        new_temp = temp.global_data["new"](node, args, traverser)
        if new_temp is not None:
            # typeof new Boolean() === "object"
            traverser._debug("Stripping global typeof")
            new_temp.TYPEOF = "object"
            return new_temp
    elif "return" in temp.global_data:
        new_temp = temp.global_data["return"](wrapper=node, arguments=args, traverser=traverser)
        if new_temp is not None:
            return new_temp
    return temp
コード例 #5
0
def _new(traverser, node):
    "Returns a new copy of a node."

    # We don't actually process the arguments as part of the flow because of
    # the Angry T-Rex effect. For now, we just traverse them to ensure they
    # don't contain anything dangerous.
    args = node["arguments"]
    if isinstance(args, list):
        for arg in args:
            traverser.traverse_node(arg)
    else:
        traverser.traverse_node(args)

    elem = traverser.traverse_node(node["callee"])
    if not isinstance(elem, JSWrapper):
        elem = JSWrapper(elem, traverser=traverser)
    if elem.is_global:
        traverser._debug("Making overwritable")
        elem.value = deepcopy(elem.value)
        elem.value["overwritable"] = True
        elem.value["readonly"] = False
        if "new" in elem.value:
            elem = elem.value["new"](traverser, node, elem)
    return elem