diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2017-02-22 13:40:17 +0000 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2017-02-23 00:35:43 +0000 |
commit | b2db96e4df86ef38d79b9c304d527e793597260c (patch) | |
tree | a123a1fdcb73eb66f6aca87bf3ccf6048e80a69c /deluge/ui/web/auth.py | |
parent | 52a85cb91cc3f536941133bfff1ef26f6855e151 (diff) | |
download | deluge-b2db96e4df86ef38d79b9c304d527e793597260c.tar.gz deluge-b2db96e4df86ef38d79b9c304d527e793597260c.tar.bz2 deluge-b2db96e4df86ef38d79b9c304d527e793597260c.zip |
[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.
Diffstat (limited to 'deluge/ui/web/auth.py')
-rw-r--r-- | deluge/ui/web/auth.py | 10 |
1 files changed, 4 insertions, 6 deletions
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 |