summaryrefslogtreecommitdiffstats
path: root/deluge/ui/web
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2017-02-22 13:40:17 +0000
committerCalum Lind <calumlind+deluge@gmail.com>2017-02-23 00:35:43 +0000
commitb2db96e4df86ef38d79b9c304d527e793597260c (patch)
treea123a1fdcb73eb66f6aca87bf3ccf6048e80a69c /deluge/ui/web
parent52a85cb91cc3f536941133bfff1ef26f6855e151 (diff)
downloaddeluge-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')
-rw-r--r--deluge/ui/web/auth.py10
-rw-r--r--deluge/ui/web/json_api.py2
2 files changed, 4 insertions, 8 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
diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py
index 96cf80aaf..0e66408c8 100644
--- a/deluge/ui/web/json_api.py
+++ b/deluge/ui/web/json_api.py
@@ -897,8 +897,6 @@ class WebApi(JSONComponent):
if key in ['sessions', 'pwd_salt', 'pwd_sha1']:
log.warn('Ignored attempt to overwrite web config key: %s', key)
continue
- if isinstance(config[key], basestring):
- config[key] = config[key].encode('utf8')
web_config[key] = config[key]
@export