# Pastebin YkdwKnwF --- website/build_plugins.py (original) +++ website/build_plugins.py (refactored) @@ -11,7 +11,7 @@ from tempfile import mkdtemp # for Py2/3 compatibility try: - from urllib import urlretrieve + from urllib.request import urlretrieve except ImportError: from urllib.request import urlretrieve @@ -85,7 +85,7 @@ try: root = ast.parse(source, filepath) except Exception: - print("Cannot parse " + filepath) + print(("Cannot parse " + filepath)) raise for node in ast.iter_child_nodes(root): if isinstance(node, ast.Assign) and len(node.targets) == 1: @@ -98,9 +98,9 @@ try: data[name] = ast.literal_eval(node.value) except ValueError: - print('Cannot evaluate value in ' + print(('Cannot evaluate value in ' + filepath + ':' + - ast.dump(node)) + ast.dump(node))) return data @@ -136,7 +136,7 @@ if ((supported_versions and set(map(version_from_string, data['api_versions'])) & set(supported_versions)) or not supported_versions): - print("Added: " + dirname) + print(("Added: " + dirname)) data['files'] = files plugins[dirname] = data out_path = os.path.join(dest_dir, PLUGIN_FILE_NAME) @@ -185,7 +185,7 @@ name_in_zip, compress_type=zipfile.ZIP_DEFLATED) - print("Created: " + dirname + ".zip") + print(("Created: " + dirname + ".zip")) def download_plugins(version=None): --- website/build_plugins_test.py (original) +++ website/build_plugins_test.py (refactored) @@ -8,9 +8,9 @@ # python 2 & 3 compatibility try: - basestring + str except NameError: - basestring = str + str = str class GenerateTestCase(unittest.TestCase): @@ -97,9 +97,9 @@ plugin_json = json.load(in_file)["plugins"] # All plugins should contain all required fields - for module_name, data in plugin_json.items(): - self.assertIsInstance(data['name'], basestring) + for module_name, data in list(plugin_json.items()): + self.assertIsInstance(data['name'], str) self.assertIsInstance(data['api_versions'], list) - self.assertIsInstance(data['author'], basestring) - self.assertIsInstance(data['description'], basestring) - self.assertIsInstance(data['version'], basestring) + self.assertIsInstance(data['author'], str) + self.assertIsInstance(data['description'], str) + self.assertIsInstance(data['version'], str) --- website/expand.py (original) +++ website/expand.py (refactored) @@ -12,7 +12,7 @@ def make_link(match): var = match.group(1) text = match.group(2) - if text in args.keys(): + if text in list(args.keys()): final_text = args[text] else: final_text = text @@ -32,11 +32,11 @@ def simple_expr(match): var = match.group(1) - if var in args.keys(): + if var in list(args.keys()): return args[var] return '{' + var + '}' - r = '|'.join([re.escape(k) for k in args.keys()]) + r = '|'.join([re.escape(k) for k in list(args.keys())]) r1 = re.compile('\{(' + r + ')\|(.*?)\}', re.UNICODE) r2 = re.compile('\{(' + r + ')\}', re.UNICODE) --- website/expand_test.py (original) +++ website/expand_test.py (refactored) @@ -8,15 +8,15 @@ def test_expand_1(self): "Empty dict + empty strings" d = {} - s = u'' - expected = u'' + s = '' + expected = '' self.assertEqual(expected, expand(s, d)) def test_expand_2(self): "Empty dict" d = {} - s = u'xx{}xx' - expected = u'xx{}xx' + s = 'xx{}xx' + expected = 'xx{}xx' self.assertEqual(expected, expand(s, d)) def test_expand_3(self): @@ -59,15 +59,15 @@ def test_expand_8(self): "Replacement of empty string by a single word" d = {"": "YES"} - s = u'xx{}xx' - expected = u'xxYESxx' + s = 'xx{}xx' + expected = 'xxYESxx' self.assertEqual(expected, expand(s, d)) def test_expand_9(self): "Replacement of { and }" d = {"{": "YES", '}': "NO"} - s = u'xx{{}{}}xx' - expected = u'xxYESNOxx' + s = 'xx{{}{}}xx' + expected = 'xxYESNOxx' self.assertEqual(expected, expand(s, d)) def test_expand_10(self): @@ -79,7 +79,7 @@ --- website/frontend/__init__.py (original) +++ website/frontend/__init__.py (refactored) @@ -23,11 +23,11 @@ ), silent=True) # Error handling - import errors + from . import errors errors.init_error_handlers(app) # I18n - import babel + from . import babel babel.init_app(app) # Caching @@ -41,12 +41,12 @@ app.jinja_env.filters['expand'] = expand # Blueprints - from views import frontend_bp - from views.changelog import changelog_bp - from views.humans import humans_bp - from views.plugins import plugins_bp - from views.docs import docs_bp - from views.api import api_bp + from .views import frontend_bp + from .views.changelog import changelog_bp + from .views.humans import humans_bp + from .views.plugins import plugins_bp + from .views.docs import docs_bp + from .views.api import api_bp app.register_blueprint(frontend_bp) app.register_blueprint(changelog_bp, url_prefix='/changelog') --- website/frontend/views/api_test.py (original) +++ website/frontend/views/api_test.py (refactored) @@ -24,7 +24,7 @@ for path in ['/api', '/api/']: response = self.client.get(path) self.assert404(response) - self.assertEquals(response.json, dict( + self.assertEqual(response.json, dict( message=_MESSAGES['missing_api_version'])) def test_api_noroute_path(self): @@ -44,7 +44,7 @@ "Test /api/v1/" response = self.client.get("/api/v1/") self.assert200(response) - self.assertEquals(response.json, dict( + self.assertEqual(response.json, dict( message=_MESSAGES['invalid_endpoint'])) # /v1/plugins/ @@ -58,20 +58,20 @@ "Test plugins list" response = self.client.get("/api/v1/plugins/") self.assert200(response) - self.assertIn('plugins', response.json.keys()) + self.assertIn('plugins', list(response.json.keys())) def test_api_v1_plugins_with_id_not_found(self): "Test bad plugin id" response = self.client.get("/api/v1/plugins/?id=0") self.assert404(response) - self.assertEquals( + self.assertEqual( response.json, dict(error=_MESSAGES['plugin_not_found'])) def test_api_v1_plugins_with_id(self): "Test valid plugin id" response = self.client.get("/api/v1/plugins/?id=addrelease") self.assert200(response) - self.assertIn('plugin', response.json.keys()) + self.assertIn('plugin', list(response.json.keys())) # /v1/download @@ -84,18 +84,18 @@ "Test download with invalid plugin id" response = self.client.get("/api/v1/download/?id=0") self.assert404(response) - self.assertEquals( + self.assertEqual( response.json, dict(error=_MESSAGES['plugin_not_found'])) def test_api_v1_download_with_no_id(self): "Test download with no plugin id" response = self.client.get("/api/v1/download/") self.assert400(response) - self.assertEquals(response.json, dict(error=_MESSAGES['missing_id'], + self.assertEqual(response.json, dict(error=_MESSAGES['missing_id'], message=_MESSAGES['download_usage'])) def test_api_v1_download_with_id(self): "Test download with a valid plugin id" response = self.client.get("/api/v1/download/?id=addrelease") self.assert200(response) - self.assertEquals(response.content_type, 'application/zip') + self.assertEqual(response.content_type, 'application/zip') --- website/frontend/views/changelog.py (original) +++ website/frontend/views/changelog.py (refactored) @@ -1,4 +1,4 @@ -from urllib import urlopen +from urllib.request import urlopen from flask import current_app, Blueprint, render_template import re --- website/frontend/views/plugins.py (original) +++ website/frontend/views/plugins.py (refactored) @@ -1,7 +1,7 @@ from collections import OrderedDict import os import json -from urllib import urlopen +from urllib.request import urlopen from flask import current_app, Blueprint, render_template from website.frontend.views.api import plugins_json_file plugins_bp = Blueprint('plugins', __name__)