Example #1
0
def check_script_metadata(repo_root, path, f, css_mode):
    if not path.endswith((".worker.js", ".any.js")):
        return []

    done = False
    errors = []
    for idx, line in enumerate(f):
        assert isinstance(line, binary_type), line

        m = meta_re.match(line)
        if m:
            key, value = m.groups()
            if key == b"timeout":
                if value != b"long":
                    errors.append(("UNKNOWN-TIMEOUT-METADATA",
                                   "Unexpected value for timeout metadata",
                                   path, idx + 1))
            elif key == b"script":
                pass
            else:
                errors.append(("UNKNOWN-METADATA",
                               "Unexpected kind of metadata", path, idx + 1))
        else:
            done = True

        if done:
            if meta_re.match(line):
                errors.append(
                    ("STRAY-METADATA",
                     "Metadata comments should start the file", path, idx + 1))
            elif meta_re.search(line):
                errors.append(
                    ("INDENTED-METADATA",
                     "Metadata comments should start the line", path, idx + 1))
            elif broken_metadata.search(line):
                errors.append(("BROKEN-METADATA",
                               "Metadata comment is not formatted correctly",
                               path, idx + 1))

    return errors
Example #2
0
 def _get_meta(self, request):
     path = filesystem_path(self.base_path, request, self.url_base)
     path = path.replace(".worker.html", ".worker.js")
     meta_values = []
     with open(path) as f:
         for line in f:
             m = meta_re.match(line)
             if m:
                 name, content = m.groups()
                 name = name.replace('"', '\\"').replace(">", ">")
                 content = content.replace('"', '\\"').replace(">", ">")
                 meta_values.append((name, content))
     return "\n".join('<meta name="%s" content="%s">' % item for item in meta_values)
Example #3
0
 def _get_meta(self, request):
     path = filesystem_path(self.base_path, request, self.url_base)
     path = path.replace(".worker", ".worker.js")
     meta_values = []
     with open(path) as f:
         for line in f:
             m = meta_re.match(line)
             if m:
                 name, content = m.groups()
                 name = name.replace('"', '\\"').replace(">", "&gt;")
                 content = content.replace('"', '\\"').replace(">", "&gt;")
                 meta_values.append((name, content))
     return "\n".join('<meta name="%s" content="%s">' % item for item in meta_values)