Jason R. Coombs avatar Jason R. Coombs committed beffdf8

Fix login_screen so it works on Python 3 (and test passes)

Comments (0)

Files changed (2)

cherrypy/lib/cptools.py

 import re
 
 import cherrypy
-from cherrypy._cpcompat import basestring, md5, set
+from cherrypy._cpcompat import basestring, md5, set, unicodestr
 from cherrypy.lib import httputil as _httputil
 
 
         pass
 
     def login_screen(self, from_page='..', username='', error_msg='', **kwargs):
-        return (u"""<html><body>
+        return (unicodestr("""<html><body>
 Message: %(error_msg)s
 <form method="post" action="do_login">
     Login: <input type="text" name="username" value="%(username)s" size="10" /><br />
     <input type="hidden" name="from_page" value="%(from_page)s" /><br />
     <input type="submit" />
 </form>
-</body></html>""" % vars()).encode("utf-8")
+</body></html>""") % vars()).encode("utf-8")
 
     def do_login(self, username, password, from_page='..', **kwargs):
         """Login. May raise redirect, or return True if request handled."""

cherrypy/test/test_tools.py

 import unittest
 from cherrypy._cpcompat import BytesIO, copyitems, itervalues
 from cherrypy._cpcompat import IncompleteRead, ntob, ntou, py3k, xrange
-from cherrypy._cpcompat import bytestr
+from cherrypy._cpcompat import bytestr, unicodestr
 import time
 timeout = 0.2
 import types
         username and password were unicode.
         """
         sa = cherrypy.lib.cptools.SessionAuth()
-        res = sa.login_screen(None, username=u'nobody', password=u'anypass')
+        res = sa.login_screen(None, username=unicodestr('nobody'),
+            password=unicodestr('anypass'))
         self.assertIsInstance(res, bytestr)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.