From b2db96e4df86ef38d79b9c304d527e793597260c Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 22 Feb 2017 13:40:17 +0000 Subject: [Py2to3] Refactor out usage of unicode and basestring - Python 3 renames `unicode` type to `str` and introduces `bytes` type. - Python 2.7 has `bytes` but is only an alias for `str` so restricted to comparisons but helps keep compatibility. - To test for unicode string on Py2 and Py3 uses the "''.__class__" type. - Remove usage of utf8encode and just encode, problems with bytes being passed in code will be picked up faster. - Where possible refactor out isinstance for try..except duck-typing. --- deluge/ui/web/auth.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'deluge/ui/web/auth.py') diff --git a/deluge/ui/web/auth.py b/deluge/ui/web/auth.py index be862a11d..d5a439d42 100644 --- a/deluge/ui/web/auth.py +++ b/deluge/ui/web/auth.py @@ -18,8 +18,6 @@ from email.utils import formatdate from twisted.internet.task import LoopingCall -from deluge.common import utf8_encoded - log = logging.getLogger(__name__) @@ -143,7 +141,7 @@ class Auth(JSONComponent): log.debug('Received a password via the 1.2-dev auth method') m = hashlib.md5() m.update(config['pwd_salt']) - m.update(utf8_encoded(password)) + m.update(password.encode('utf8')) if m.hexdigest() == config['pwd_md5']: # We want to move the password over to sha1 and remove # the old passwords from the config file. @@ -163,7 +161,7 @@ class Auth(JSONComponent): from base64 import decodestring m = hashlib.md5() m.update(decodestring(config['old_pwd_salt'])) - m.update(utf8_encoded(password)) + m.update(password.encode('utf8')) if m.digest() == decodestring(config['old_pwd_md5']): # We want to move the password over to sha1 and remove @@ -179,7 +177,7 @@ class Auth(JSONComponent): log.debug('Received a password via the 1.2 auth method') s = hashlib.sha1() s.update(config['pwd_salt']) - s.update(utf8_encoded(password)) + s.update(password.encode('utf8')) if s.hexdigest() == config['pwd_sha1']: return True @@ -249,7 +247,7 @@ class Auth(JSONComponent): log.debug('Changing password') salt = hashlib.sha1(os.urandom(32)).hexdigest() s = hashlib.sha1(salt) - s.update(utf8_encoded(new_password)) + s.update(new_password.encode('utf8')) self.config['pwd_salt'] = salt self.config['pwd_sha1'] = s.hexdigest() return True -- cgit