mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1232257 - Update to latest wptserve, a=testonly
This commit is contained in:
parent
aa928a99a3
commit
01e6581160
@ -138,8 +138,8 @@ class FileHandler(object):
|
||||
pipeline = Pipeline(query["pipe"][-1])
|
||||
elif os.path.splitext(path)[0].endswith(".sub"):
|
||||
ml_extensions = {".html", ".htm", ".xht", ".xhtml", ".xml", ".svg"}
|
||||
escape_quote = os.path.splitext(path)[1] in ml_extensions
|
||||
pipeline = Pipeline("sub(%r)" % escape_quote)
|
||||
escape_type = "html" if os.path.splitext(path)[1] in ml_extensions else "none"
|
||||
pipeline = Pipeline("sub(%s)" % escape_type)
|
||||
if pipeline is not None:
|
||||
response = pipeline(request, response)
|
||||
|
||||
@ -169,7 +169,7 @@ class FileHandler(object):
|
||||
return []
|
||||
else:
|
||||
if use_sub:
|
||||
data = template(request, data, escape_quote=False)
|
||||
data = template(request, data, escape_type="none")
|
||||
return [tuple(item.strip() for item in line.split(":", 1))
|
||||
for line in data.splitlines() if line]
|
||||
|
||||
|
@ -313,10 +313,13 @@ class FirstWrapper(object):
|
||||
return ""
|
||||
|
||||
|
||||
@pipe(opt(nullable(boolean)))
|
||||
def sub(request, response, escape_quote=False):
|
||||
@pipe(opt(nullable(str)))
|
||||
def sub(request, response, escape_type="html"):
|
||||
"""Substitute environment information about the server and request into the script.
|
||||
|
||||
:param escape_type: String detailing the type of escaping to use. Known values are
|
||||
"html" and "none", with "html" the default for historic reasons.
|
||||
|
||||
The format is a very limited template language. Substitutions are
|
||||
enclosed by {{ and }}. There are several avaliable substitutions:
|
||||
|
||||
@ -359,12 +362,12 @@ def sub(request, response, escape_quote=False):
|
||||
"""
|
||||
content = resolve_content(response)
|
||||
|
||||
new_content = template(request, content, escape_quote=escape_quote)
|
||||
new_content = template(request, content, escape_type=escape_type)
|
||||
|
||||
response.content = new_content
|
||||
return response
|
||||
|
||||
def template(request, content, escape_quote=False):
|
||||
def template(request, content, escape_type="html"):
|
||||
#TODO: There basically isn't any error handling here
|
||||
tokenizer = ReplacementTokenizer()
|
||||
|
||||
@ -419,9 +422,12 @@ def template(request, content, escape_quote=False):
|
||||
if variable is not None:
|
||||
variables[variable] = value
|
||||
|
||||
escape_func = {"html": lambda x:escape(x, quote=True),
|
||||
"none": lambda x:x}[escape_type]
|
||||
|
||||
#Should possibly support escaping for other contexts e.g. script
|
||||
#TODO: read the encoding of the response
|
||||
return escape(unicode(value), quote=escape_quote).encode("utf-8")
|
||||
return escape_func(unicode(value)).encode("utf-8")
|
||||
|
||||
template_regexp = re.compile(r"{{([^}]*)}}")
|
||||
new_content, count = template_regexp.subn(config_replacement, content)
|
||||
|
@ -119,7 +119,7 @@ class Stash(object):
|
||||
if internal_key in self.data:
|
||||
raise StashError("Tried to overwrite existing shared stash value "
|
||||
"for key %s (old value was %s, new value is %s)" %
|
||||
(internal_key, self[str(internal_key)], value))
|
||||
(internal_key, self.data[str(internal_key)], value))
|
||||
else:
|
||||
self.data[internal_key] = value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user