[tor-commits] [bridgedb/master] Fix remaining str/bytes issues in moat server.

phw at torproject.org phw at torproject.org
Wed Feb 19 18:26:38 UTC 2020


commit 468dfa0fc5e13da9ba384f9bcb6e7e11bfc26482
Author: Philipp Winter <phw at nymity.ch>
Date:   Thu Feb 13 15:05:24 2020 -0800

    Fix remaining str/bytes issues in moat server.
    
    We ran into these issues while test-deploying the Python 3 branch on
    polyanthum.
---
 bridgedb/distributors/moat/server.py           | 16 ++++++++--------
 bridgedb/test/test_distributors_moat_server.py |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/bridgedb/distributors/moat/server.py b/bridgedb/distributors/moat/server.py
index e49a6bb..cdf2022 100644
--- a/bridgedb/distributors/moat/server.py
+++ b/bridgedb/distributors/moat/server.py
@@ -178,11 +178,11 @@ class JsonAPIResource(resource.Resource):
         :param request: A ``Request`` for a :api:`twisted.web.resource.Resource`.
         :returns: The encoded data.
         """
-        request.responseHeaders.addRawHeader(b"Content-Type", b"application/vnd.api+json")
-        request.responseHeaders.addRawHeader(b"Server", b"moat/%s" % MOAT_API_VERSION.encode('utf-8'))
+        request.responseHeaders.addRawHeader("Content-Type", "application/vnd.api+json")
+        request.responseHeaders.addRawHeader("Server", "moat/%s" % MOAT_API_VERSION)
 
         if data:
-            rendered = json.dumps(data)
+            rendered = json.dumps(data).encode("utf-8")
         else:
             rendered = b""
 
@@ -824,13 +824,13 @@ def addMoatServer(config, distributor):
                                  hmacKey, publicKey, secretKey,
                                  fwdHeaders, skipLoopback)
 
-    moat.putChild("fetch", fetch)
-    moat.putChild("check", check)
-    meek.putChild("moat", moat)
+    moat.putChild(b"fetch", fetch)
+    moat.putChild(b"check", check)
+    meek.putChild(b"moat", moat)
 
     root = CustomErrorHandlingResource()
-    root.putChild("meek", meek)
-    root.putChild("moat", moat)
+    root.putChild(b"meek", meek)
+    root.putChild(b"moat", moat)
 
     site = Site(root)
     site.displayTracebacks = False
diff --git a/bridgedb/test/test_distributors_moat_server.py b/bridgedb/test/test_distributors_moat_server.py
index 222518d..695116b 100644
--- a/bridgedb/test/test_distributors_moat_server.py
+++ b/bridgedb/test/test_distributors_moat_server.py
@@ -884,7 +884,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
 
         response = self.resource.failureResponse(6, request, bridgeRequest)
 
-        self.assertIn("No bridges available", response)
+        self.assertIn(b"No bridges available", response)
 
     def test_render_POST_no_bridges(self):
         self.mock_getBridgeLines()
@@ -892,7 +892,7 @@ class CaptchaCheckResourceTests(unittest.TestCase):
         request = self.create_valid_POST_make_new_challenge()
         response = self.resource.render(request)
 
-        self.assertIn("No bridges available", response)
+        self.assertIn(b"No bridges available", response)
 
     def test_render_POST_unexpired(self):
         request = self.create_valid_POST_make_new_challenge()





More information about the tor-commits mailing list