[Py2to3] Replace deprecated base64.(de|en)codestring
* In Py3 base64.encodestring is deprecated so rather than use the Py3 only encodebytes instead use b64encode. The other advantage is that with issue a consistent TypeError is raised that we can catch.
This commit is contained in:
parent
74aa0db956
commit
277576268c
|
@ -390,7 +390,7 @@ class Core(component.Component):
|
|||
"""
|
||||
try:
|
||||
filedump = b64decode(filedump)
|
||||
except Exception as ex:
|
||||
except TypeError as ex:
|
||||
log.error('There was an error decoding the filedump string: %s', ex)
|
||||
|
||||
try:
|
||||
|
@ -958,7 +958,7 @@ class Core(component.Component):
|
|||
|
||||
try:
|
||||
filedump = b64decode(filedump)
|
||||
except Exception as ex:
|
||||
except TypeError as ex:
|
||||
log.error('There was an error decoding the filedump string!')
|
||||
log.exception(ex)
|
||||
return
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from base64 import b64encode
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.task import LoopingCall, deferLater
|
||||
|
@ -333,7 +333,7 @@ class Core(CorePluginBase):
|
|||
d = component.get('Core').add_torrent_magnet(filedump.strip(), options)
|
||||
else:
|
||||
d = component.get('Core').add_torrent_file_async(
|
||||
filename, base64.encodestring(filedump), options,
|
||||
filename, b64encode(filedump), options,
|
||||
)
|
||||
d.addCallback(on_torrent_added, filename, filepath)
|
||||
d.addErrback(fail_torrent_add, filepath, magnet)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
from base64 import b64encode
|
||||
from hashlib import sha1 as sha
|
||||
|
||||
import pytest
|
||||
|
@ -123,7 +123,7 @@ class CoreTestCase(BaseTestCase):
|
|||
for f in filenames:
|
||||
filename = common.get_test_data_file(f)
|
||||
with open(filename, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
files_to_add.append((filename, filedump, options))
|
||||
errors = yield self.core.add_torrent_files(files_to_add)
|
||||
self.assertEqual(len(errors), 0)
|
||||
|
@ -136,7 +136,7 @@ class CoreTestCase(BaseTestCase):
|
|||
for f in filenames:
|
||||
filename = common.get_test_data_file(f)
|
||||
with open(filename, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
files_to_add.append((filename, filedump, options))
|
||||
errors = yield self.core.add_torrent_files(files_to_add)
|
||||
self.assertEqual(len(errors), 1)
|
||||
|
@ -147,7 +147,7 @@ class CoreTestCase(BaseTestCase):
|
|||
options = {}
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
with open(filename, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = yield self.core.add_torrent_file_async(filename, filedump, options)
|
||||
|
||||
# Get the info hash from the test.torrent
|
||||
|
@ -215,7 +215,7 @@ class CoreTestCase(BaseTestCase):
|
|||
options = {}
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
with open(filename, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = yield self.core.add_torrent_file_async(filename, filedump, options)
|
||||
removed = self.core.remove_torrent(torrent_id, True)
|
||||
self.assertTrue(removed)
|
||||
|
@ -229,12 +229,12 @@ class CoreTestCase(BaseTestCase):
|
|||
options = {}
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
with open(filename, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = yield self.core.add_torrent_file_async(filename, filedump, options)
|
||||
|
||||
filename2 = common.get_test_data_file('unicode_filenames.torrent')
|
||||
with open(filename2, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id2 = yield self.core.add_torrent_file_async(filename2, filedump, options)
|
||||
d = self.core.remove_torrents([torrent_id, torrent_id2], True)
|
||||
|
||||
|
@ -252,7 +252,7 @@ class CoreTestCase(BaseTestCase):
|
|||
options = {}
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
with open(filename, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = yield self.core.add_torrent_file_async(filename, filedump, options)
|
||||
val = yield self.core.remove_torrents(['invalidid1', 'invalidid2', torrent_id], False)
|
||||
self.assertEqual(len(val), 2)
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import base64
|
||||
import os
|
||||
import time
|
||||
from base64 import b64encode
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.task import deferLater
|
||||
|
@ -129,7 +129,7 @@ class TorrentTestCase(BaseTestCase):
|
|||
options = {'seed_mode': True}
|
||||
filename = common.get_test_data_file('test_torrent.file.torrent')
|
||||
with open(filename) as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = self.core.add_torrent_file(filename, filedump, options)
|
||||
torrent = self.core.torrentmanager.torrents[torrent_id]
|
||||
|
||||
|
@ -147,7 +147,7 @@ class TorrentTestCase(BaseTestCase):
|
|||
options = {'seed_mode': True, 'add_paused': True}
|
||||
filename = common.get_test_data_file('test_torrent.file.torrent')
|
||||
with open(filename) as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = self.core.add_torrent_file(filename, filedump, options)
|
||||
torrent = self.core.torrentmanager.torrents[torrent_id]
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import warnings
|
||||
from base64 import b64encode
|
||||
|
||||
import pytest
|
||||
from twisted.internet import defer
|
||||
|
@ -46,7 +46,7 @@ class TorrentmanagerTestCase(BaseTestCase):
|
|||
def test_remove_torrent(self):
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
with open(filename) as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
torrent_id = yield self.core.add_torrent_file_async(filename, filedump, {})
|
||||
self.assertTrue(self.core.torrentmanager.remove(torrent_id, False))
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import os
|
||||
from base64 import b64encode
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
|
@ -85,7 +85,7 @@ class Command(BaseCommand):
|
|||
self.console.write('{!info!}Attempting to add torrent: %s' % path)
|
||||
filename = os.path.split(path)[-1]
|
||||
with open(path, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
deferreds.append(
|
||||
client.core.add_torrent_file_async(
|
||||
filename, filedump, t_options,
|
||||
|
|
|
@ -84,7 +84,7 @@ class Command(BaseCommand):
|
|||
|
||||
elif options.install:
|
||||
import os.path
|
||||
import base64
|
||||
from base64 import b64encode
|
||||
import shutil
|
||||
|
||||
filepath = options.install
|
||||
|
@ -102,7 +102,7 @@ class Command(BaseCommand):
|
|||
if not client.is_localhost():
|
||||
# We need to send this plugin to the daemon
|
||||
with open(filepath, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
try:
|
||||
client.core.upload_plugin(filename, filedump)
|
||||
client.core.rescan_plugins()
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
from base64 import b64encode
|
||||
|
||||
import deluge.common
|
||||
from deluge.ui.client import client
|
||||
|
@ -78,7 +78,7 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress):
|
|||
|
||||
filename = os.path.split(f)[-1]
|
||||
with open(f, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
|
||||
client.core.add_torrent_file_async(
|
||||
filename, filedump, t_options,
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
from base64 import b64encode
|
||||
|
||||
import deluge.common
|
||||
import deluge.component as component
|
||||
|
@ -393,7 +393,7 @@ class AddTorrents(BaseMode):
|
|||
directory = os.path.join(*self.path_stack[:self.path_stack_pos])
|
||||
path = os.path.join(directory, filename)
|
||||
with open(path, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
t_options = {}
|
||||
if result['location']['value']:
|
||||
t_options['download_location'] = result['location']['value']
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
from base64 import b64encode
|
||||
from xml.sax.saxutils import escape as xml_escape
|
||||
from xml.sax.saxutils import unescape as xml_unescape
|
||||
|
||||
|
@ -753,7 +753,7 @@ class AddTorrentDialog(component.Component):
|
|||
else:
|
||||
torrents_to_add.append((
|
||||
os.path.split(filename)[-1],
|
||||
base64.encodestring(self.infos[torrent_id]),
|
||||
b64encode(self.infos[torrent_id]),
|
||||
options,
|
||||
))
|
||||
row = self.torrent_liststore.iter_next(row)
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import os.path
|
||||
from base64 import b64encode
|
||||
|
||||
import gtk
|
||||
from gobject import TYPE_UINT64, idle_add
|
||||
|
@ -385,7 +385,7 @@ class CreateTorrentDialog(object):
|
|||
|
||||
if add_to_session:
|
||||
with open(target, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
client.core.add_torrent_file_async(
|
||||
os.path.split(target)[-1],
|
||||
filedump,
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from base64 import b64encode
|
||||
from glob import glob
|
||||
from tempfile import mkstemp
|
||||
|
||||
|
@ -223,5 +223,5 @@ def process_args(args):
|
|||
component.get('AddTorrentDialog').show(config['focus_add_dialog'])
|
||||
else:
|
||||
with open(path, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
client.core.add_torrent_file(os.path.split(path)[-1], filedump, None)
|
||||
|
|
|
@ -954,7 +954,7 @@ class Preferences(component.Component):
|
|||
chooser.destroy()
|
||||
return
|
||||
|
||||
import base64
|
||||
from base64 import b64encode
|
||||
import shutil
|
||||
filename = os.path.split(filepath)[1]
|
||||
shutil.copyfile(
|
||||
|
@ -967,7 +967,7 @@ class Preferences(component.Component):
|
|||
if not client.is_localhost():
|
||||
# We need to send this plugin to the daemon
|
||||
with open(filepath, 'rb') as _file:
|
||||
filedump = base64.encodestring(_file.read())
|
||||
filedump = b64encode(_file.read())
|
||||
client.core.upload_plugin(filename, filedump)
|
||||
|
||||
client.core.rescan_plugins()
|
||||
|
|
|
@ -143,11 +143,11 @@ class Auth(JSONComponent):
|
|||
elif 'old_pwd_md5' in config.config:
|
||||
# We are using the 1.1 webui auth method
|
||||
log.debug('Received a password via the 1.1 auth method')
|
||||
from base64 import decodestring
|
||||
from base64 import b64decode
|
||||
m = hashlib.md5()
|
||||
m.update(decodestring(config['old_pwd_salt']))
|
||||
m.update(b64decode(config['old_pwd_salt']))
|
||||
m.update(password.encode('utf8'))
|
||||
if m.digest() == decodestring(config['old_pwd_md5']):
|
||||
if m.digest() == b64decode(config['old_pwd_md5']):
|
||||
|
||||
# We want to move the password over to sha1 and remove
|
||||
# the old passwords from the config file.
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import base64
|
||||
import cgi
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from base64 import b64encode
|
||||
from types import FunctionType
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
|
@ -703,7 +703,7 @@ class WebApi(JSONComponent):
|
|||
else:
|
||||
filename = os.path.basename(torrent['path'])
|
||||
with open(torrent['path'], 'rb') as _file:
|
||||
fdump = base64.encodestring(_file.read())
|
||||
fdump = b64encode(_file.read())
|
||||
log.info(
|
||||
'Adding torrent from file `%s` with options `%r`',
|
||||
filename, torrent['options'],
|
||||
|
@ -903,7 +903,7 @@ class WebApi(JSONComponent):
|
|||
client.core.rescan_plugins()
|
||||
return True
|
||||
with open(path, 'rb') as _file:
|
||||
plugin_data = base64.encodestring(_file.read())
|
||||
plugin_data = b64encode(_file.read())
|
||||
|
||||
def on_upload_complete(*args):
|
||||
client.core.rescan_plugins()
|
||||
|
|
Loading…
Reference in New Issue