Bug 1496102 [wpt PR 13337] - Python 3: Encode text content in Response.iter_content()., a=testonly
authorMs2ger <Ms2ger@gmail.com>
Tue, 09 Oct 2018 04:13:49 +0000
changeset 498660 bd3bcc96361ce2cb1ed39a75c183f47fcee97376
parent 498659 15045982171d102c1d06208a2e4c0c98cc3dc947
child 498661 12ab4712761393918be4595367bc31bf0bd54ece
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1496102, 13337
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1496102 [wpt PR 13337] - Python 3: Encode text content in Response.iter_content()., a=testonly Automatic update from web-platform-testsPython 3: Encode text content in Response.iter_content(). -- wpt-commits: a49e7638c45072077a92916ae41a26873e15d59a wpt-pr: 13337
testing/web-platform/tests/tools/wptserve/tests/functional/test_pipes.py
testing/web-platform/tests/tools/wptserve/wptserve/response.py
--- a/testing/web-platform/tests/tools/wptserve/tests/functional/test_pipes.py
+++ b/testing/web-platform/tests/tools/wptserve/tests/functional/test_pipes.py
@@ -139,30 +139,28 @@ class TestTrickle(TestUsingServer):
 
     def test_headers(self):
         resp = self.request("/document.txt", query="pipe=trickle(d0.01)")
         self.assertEqual(resp.info()["Cache-Control"], "no-cache, no-store, must-revalidate")
         self.assertEqual(resp.info()["Pragma"], "no-cache")
         self.assertEqual(resp.info()["Expires"], "0")
 
 class TestPipesWithVariousHandlers(TestUsingServer):
-    @pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
     def test_with_python_file_handler(self):
         resp = self.request("/test_string.py", query="pipe=slice(null,2)")
-        self.assertEqual(resp.read(), "PA")
+        self.assertEqual(resp.read(), b"PA")
 
-    @pytest.mark.xfail(sys.version_info >= (3,), reason="wptserve only works on Py2")
     def test_with_python_func_handler(self):
         @wptserve.handlers.handler
         def handler(request, response):
             return "PASS"
         route = ("GET", "/test/test_pipes_1/", handler)
         self.server.router.register(*route)
         resp = self.request(route[1], query="pipe=slice(null,2)")
-        self.assertEqual(resp.read(), "PA")
+        self.assertEqual(resp.read(), b"PA")
 
     def test_with_python_func_handler_using_response_writer(self):
         @wptserve.handlers.handler
         def handler(request, response):
             response.writer.write_content("PASS")
         route = ("GET", "/test/test_pipes_1/", handler)
         self.server.router.register(*route)
         resp = self.request(route[1], query="pipe=slice(null,2)")
--- a/testing/web-platform/tests/tools/wptserve/wptserve/response.py
+++ b/testing/web-platform/tests/tools/wptserve/wptserve/response.py
@@ -178,18 +178,20 @@ class Response(object):
         and the resulting value (if any) returned.
 
         :param read_file: - boolean controlling the behaviour when content
         is a file handle. When set to False the handle will be returned directly
         allowing the file to be passed to the output in small chunks. When set to
         True, the entire content of the file will be returned as a string facilitating
         non-streaming operations like template substitution.
         """
-        if isinstance(self.content, (binary_type, text_type)):
+        if isinstance(self.content, binary_type):
             yield self.content
+        elif isinstance(self.content, text_type):
+            yield self.content.encode(self.encoding)
         elif hasattr(self.content, "read"):
             if read_file:
                 yield self.content.read()
             else:
                 yield self.content
         else:
             for item in self.content:
                 if hasattr(item, "__call__"):