[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Replace remaining bytes() calls



commit 03494c59e13e08b0f153e46a8831ea664cabcbcc
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Jan 15 16:55:59 2020 -0800

    Replace remaining bytes() calls
    
    Python 3 converts unicode to bytes with its encode() method. This fixes...
    
      Traceback (most recent call last):
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_https_server.py", line 442, in test_render_GET_missingTemplate
          page = self.captchaResource.render_GET(self.request)
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/distributors/https/server.py", line 678, in render_GET
          return CaptchaProtectedResource.render_GET(self, request)
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/distributors/https/server.py", line 525, in render_GET
          rendered = replaceErrorPage(request, err, 'captcha.html')
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/distributors/https/server.py", line 147, in replaceErrorPage
          rendered = bytes(errorMessage)
      builtins.TypeError: string argument without an encoding
    
    Test results changed as follows...
    
      before: FAILED (skips=109, failures=23, errors=225, successes=624)
      after:  FAILED (skips=109, failures=24, errors=220, successes=628)
---
 bridgedb/distributors/https/server.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/bridgedb/distributors/https/server.py b/bridgedb/distributors/https/server.py
index d1c058c..aea19da 100644
--- a/bridgedb/distributors/https/server.py
+++ b/bridgedb/distributors/https/server.py
@@ -135,13 +135,13 @@ def replaceErrorPage(request, error, template_name=None, html=True):
     errorMessage = _("Sorry! Something went wrong with your request.")
 
     if not html:
-        return bytes(errorMessage)
+        return errorMessage.encode('utf-8')
 
     try:
         rendered = resource500.render(request)
     except Exception as err:
         logging.exception(err)
-        rendered = bytes(errorMessage)
+        rendered = errorMessage.encode('utf-8')
 
     return rendered
 
@@ -1024,7 +1024,7 @@ class BridgesResource(CustomErrorHandlingResource, CSPResource):
         if format == 'plain':
             request.setHeader("Content-Type", "text/plain")
             try:
-                rendered = bytes('\n'.join(bridgeLines))
+                rendered = '\n'.join(bridgeLines).encode('utf-8')
             except Exception as err:
                 rendered = replaceErrorPage(request, err, html=False)
         else:
@@ -1100,7 +1100,7 @@ def addWebServer(config, distributor):
     howto   = HowtoResource()
     robots  = static.File(os.path.join(TEMPLATE_DIR, 'robots.txt'))
     assets  = static.File(os.path.join(TEMPLATE_DIR, 'assets/'))
-    keys    = static.Data(bytes(strings.BRIDGEDB_OPENPGP_KEY), 'text/plain')
+    keys    = static.Data(strings.BRIDGEDB_OPENPGP_KEY.encode('utf-8'), 'text/plain')
     csp     = CSPResource(enabled=config.CSP_ENABLED,
                           includeSelf=config.CSP_INCLUDE_SELF,
                           reportViolations=config.CSP_REPORT_ONLY,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits