| Index: third_party/WebKit/Tools/Scripts/webkitpy/thirdparty/wpt/wpt/tools/wptserve/wptserve/pipes.py
|
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/thirdparty/wpt/wpt/tools/wptserve/wptserve/pipes.py b/third_party/WebKit/Tools/Scripts/webkitpy/thirdparty/wpt/wpt/tools/wptserve/wptserve/pipes.py
|
| index 3f1f1e4554c86542effb1d9e16949407881d252c..41f7dd33e26637c2c83591bfcfd94708134e87e3 100644
|
| --- a/third_party/WebKit/Tools/Scripts/webkitpy/thirdparty/wpt/wpt/tools/wptserve/wptserve/pipes.py
|
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/thirdparty/wpt/wpt/tools/wptserve/wptserve/pipes.py
|
| @@ -8,7 +8,7 @@ from cStringIO import StringIO
|
|
|
|
|
| def resolve_content(response):
|
| - rv = "".join(item for item in response.iter_content())
|
| + rv = "".join(item for item in response.iter_content(read_file=True))
|
| if type(rv) == unicode:
|
| rv = rv.encode(response.encoding)
|
| return rv
|
| @@ -232,33 +232,26 @@ def trickle(request, response, delays):
|
| if not delays:
|
| return response
|
| content = resolve_content(response)
|
| - modified_content = []
|
| offset = [0]
|
|
|
| - def sleep(seconds):
|
| - def inner():
|
| - time.sleep(seconds)
|
| - return ""
|
| - return inner
|
| -
|
| def add_content(delays, repeat=False):
|
| for i, (item_type, value) in enumerate(delays):
|
| if item_type == "bytes":
|
| - modified_content.append(content[offset[0]:offset[0] + value])
|
| + yield content[offset[0]:offset[0] + value]
|
| offset[0] += value
|
| elif item_type == "delay":
|
| - modified_content.append(sleep(value))
|
| + time.sleep(value)
|
| elif item_type == "repeat":
|
| - assert i == len(delays) - 1
|
| + if i != len(delays) - 1:
|
| + continue
|
| while offset[0] < len(content):
|
| - add_content(delays[-(value + 1):-1], True)
|
| + for item in add_content(delays[-(value + 1):-1], True):
|
| + yield item
|
|
|
| if not repeat and offset[0] < len(content):
|
| - modified_content.append(content[offset[0]:])
|
| -
|
| - add_content(delays)
|
| + yield content[offset[0]:]
|
|
|
| - response.content = modified_content
|
| + response.content = add_content(delays)
|
| return response
|
|
|
|
|
| @@ -313,10 +306,13 @@ class FirstWrapper(object):
|
| return ""
|
|
|
|
|
| -@pipe()
|
| -def sub(request, response):
|
| +@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 +355,12 @@ def sub(request, response):
|
| """
|
| content = resolve_content(response)
|
|
|
| - new_content = template(request, content)
|
| + new_content = template(request, content, escape_type=escape_type)
|
|
|
| response.content = new_content
|
| return response
|
|
|
| -def template(request, content):
|
| +def template(request, content, escape_type="html"):
|
| #TODO: There basically isn't any error handling here
|
| tokenizer = ReplacementTokenizer()
|
|
|
| @@ -403,9 +399,12 @@ def template(request, content):
|
| "hostname": request.url_parts.hostname,
|
| "port": request.url_parts.port,
|
| "path": request.url_parts.path,
|
| + "pathname": request.url_parts.path,
|
| "query": "?%s" % request.url_parts.query}
|
| elif field == "uuid()":
|
| value = str(uuid.uuid4())
|
| + elif field == "url_base":
|
| + value = request.url_base
|
| else:
|
| raise Exception("Undefined template variable %s" % field)
|
|
|
| @@ -417,12 +416,15 @@ def template(request, content):
|
| 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)).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)
|
| + new_content = template_regexp.sub(config_replacement, content)
|
|
|
| return new_content
|
|
|
|
|