This is an automated email from the ASF dual-hosted git repository. dill0wn pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/allura.git
commit 38a9e5d189a93f035df3d6eea0ab82fb172f2371 Author: Kenton Taylor <[email protected]> AuthorDate: Thu Feb 24 17:06:06 2022 +0000 [#8415] py2 removal - removal of six.PY2 checks --- Allura/allura/controllers/basetest_project_root.py | 2 +- Allura/allura/lib/custom_middleware.py | 4 ++-- Allura/allura/lib/utils.py | 5 ++--- Allura/allura/model/auth.py | 3 +-- Allura/allura/model/project.py | 5 ----- Allura/allura/scripts/trac_export.py | 3 +-- Allura/allura/tasks/export_tasks.py | 3 +-- Allura/allura/tests/functional/test_admin.py | 2 +- Allura/allura/tests/functional/test_root.py | 3 --- Allura/allura/tests/test_tasks.py | 2 +- Allura/allura/tests/test_webhooks.py | 2 +- AlluraTest/alluratest/validation.py | 8 -------- .../forgediscussion/tests/functional/test_forum.py | 4 ++-- ForgeImporters/forgeimporters/base.py | 3 +-- ForgeImporters/forgeimporters/tests/test_base.py | 12 ++++++------ ForgeTracker/forgetracker/tests/functional/test_root.py | 2 +- run_tests | 3 --- scripts/teamforge-import.py | 7 +++---- scripts/trac_export_wiki.py | 3 +-- tox.ini | 2 +- 20 files changed, 26 insertions(+), 52 deletions(-) diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py index dc63048..7d382de 100644 --- a/Allura/allura/controllers/basetest_project_root.py +++ b/Allura/allura/controllers/basetest_project_root.py @@ -109,7 +109,7 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController): def _perform_call(self, context): """ Called from a WebTest 'app' instance, going through TurboGears dispatcher code - Example: self.app.get('/auth/', extra_environ={'disable_auth_magic': str("True")}) + Example: self.app.get('/auth/', extra_environ={'disable_auth_magic': "True"}) """ environ = context.request.environ c.app = None diff --git a/Allura/allura/lib/custom_middleware.py b/Allura/allura/lib/custom_middleware.py index 503881d..3a5ca4c 100644 --- a/Allura/allura/lib/custom_middleware.py +++ b/Allura/allura/lib/custom_middleware.py @@ -342,9 +342,9 @@ class AlluraTimerMiddleware(TimerMiddleware): Timer('repo.LastCommit.{method_name}', allura.model.repository.LastCommit, '*'), Timer('repo.Tree.{method_name}', allura.model.repository.Tree, '*'), - Timer('socket_read', socket._fileobject if six.PY2 else socket.SocketIO, 'read', 'readline', + Timer('socket_read', socket.SocketIO, 'read', 'readline', 'readlines', debug_each_call=False), - Timer('socket_write', socket._fileobject if six.PY2 else socket.SocketIO, 'write', 'writelines', + Timer('socket_write', socket.SocketIO, 'write', 'writelines', 'flush', debug_each_call=False), Timer('solr', pysolr.Solr, 'add', 'delete', 'search', 'commit'), Timer('urlopen', urlopen_pkg, 'urlopen'), diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py index e6ddc51..6639734 100644 --- a/Allura/allura/lib/utils.py +++ b/Allura/allura/lib/utils.py @@ -23,7 +23,6 @@ import string import hashlib import binascii import logging.handlers -import codecs import os.path import datetime import random @@ -223,7 +222,7 @@ class AntiSpam: self.spinner_text = request.params['spinner'] self.timestamp = int(self.timestamp_text) self.spinner = self._unwrap(self.spinner_text) - trans_fn = ord if six.PY2 else int + trans_fn = int self.spinner_ord = list(map(trans_fn, self.spinner)) self.random_padding = [random.randint(0, 255) for x in self.spinner] self.honey_class = self.enc(self.spinner_text, css_safe=True) @@ -525,7 +524,7 @@ def serve_file(fp, filename, content_type, last_modified=None, from allura.lib import helpers as h tg.response.headers.add( 'Content-Disposition', - str('attachment;filename="%s"' % h.urlquote(filename))) + 'attachment;filename="%s"' % h.urlquote(filename)) # http://code.google.com/p/modwsgi/wiki/FileWrapperExtension block_size = 4096 if 'wsgi.file_wrapper' in tg.request.environ: diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py index f188962..3dda3ba 100644 --- a/Allura/allura/model/auth.py +++ b/Allura/allura/model/auth.py @@ -835,8 +835,7 @@ class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable): def email_address_header(self): h = header.Header() - h.append('"{}"{}'.format(self.get_pref('display_name'), - ' ' if six.PY2 else '')) # py2 needs explicit space for unicode/text_type cast of Header + h.append('"{}"{}'.format(self.get_pref('display_name'), '')) h.append('<%s>' % self.get_pref('email_address')) return h diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py index b994c60..0e35ae3 100644 --- a/Allura/allura/model/project.py +++ b/Allura/allura/model/project.py @@ -1163,11 +1163,6 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject): shortname = self.shortname.split('/')[1] filename_format = config['bulk_export_filename'] - if six.PY2: - # in py3 ConfigParser requires %% to escape literal "%" - # since % has interpolation meaning within ConfigParser - # but in py2 the "%%" stays as "%%" so we have to switch it back to a single one - filename_format = filename_format.replace('%%', '%') return filename_format.format(project=shortname, date=datetime.utcnow()) def bulk_export_status(self): diff --git a/Allura/allura/scripts/trac_export.py b/Allura/allura/scripts/trac_export.py index cb131a5..6b2949b 100644 --- a/Allura/allura/scripts/trac_export.py +++ b/Allura/allura/scripts/trac_export.py @@ -28,7 +28,6 @@ import time import re from optparse import OptionParser from itertools import islice -import codecs from io import TextIOWrapper from bs4 import BeautifulSoup, NavigableString @@ -329,7 +328,7 @@ def main(): out_file = sys.stdout if options.out_filename: - out_file = codecs.open(options.out_filename, 'w', encoding='utf-8') + out_file = open(options.out_filename, 'w', encoding='utf-8') out_file.write( json.dumps(doc, cls=DateJSONEncoder, indent=2, sort_keys=True)) # It's bad habit not to terminate lines diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py index 90b0369..13bb6f4 100644 --- a/Allura/allura/tasks/export_tasks.py +++ b/Allura/allura/tasks/export_tasks.py @@ -19,7 +19,6 @@ import os import os.path import logging import shutil -import codecs import tg from tg import app_globals as g, tmpl_context as c @@ -100,7 +99,7 @@ class BulkExport: tool = app.config.options.mount_point json_file = os.path.join(export_path, '%s.json' % tool) try: - with codecs.open(json_file, 'w', encoding='utf-8') as f: + with open(json_file, 'w', encoding='utf-8') as f: app.bulk_export(f, export_path, with_attachments) except Exception: log.error('Error exporting: %s on %s', tool, diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py index 287e121..8ab03d1 100644 --- a/Allura/allura/tests/functional/test_admin.py +++ b/Allura/allura/tests/functional/test_admin.py @@ -165,7 +165,7 @@ class TestProjectAdmin(TestController): def test_features(self): proj = M.Project.query.get(shortname='test') assert_equals(proj.features, []) - with audits(r"change project features to \[{u}'One', {u}'Two'\]".format(u='u' if six.PY2 else '')): + with audits(r"change project features to \[{u}'One', {u}'Two'\]".format(u='')): resp = self.app.post('/admin/update', params={ 'features-0.feature': 'One', 'features-1.feature': ' ', diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py index ddfaf98..97e9189 100644 --- a/Allura/allura/tests/functional/test_root.py +++ b/Allura/allura/tests/functional/test_root.py @@ -100,9 +100,6 @@ class TestRootController(TestController): self.app.get('/', headers=dict(Accept=str(hdr)), validate_skip=True) def test_encoded_urls(self): - if six.PY2: - # not valid unicode - self.app.get(b'/foo\xFF', status=400) self.app.get('/foo%FF', status=400) # encoded self.app.get('/foo%C3%A9', status=404) diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py index d35634e..b1b2215 100644 --- a/Allura/allura/tests/test_tasks.py +++ b/Allura/allura/tests/test_tasks.py @@ -591,7 +591,7 @@ def raise_exc(): errs = [] for x in range(10): try: - assert False, str('assert %d' % x) + assert False, 'assert %d' % x except Exception: errs.append(sys.exc_info()) raise CompoundError(*errs) diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py index d7b87d2..da3035f 100644 --- a/Allura/allura/tests/test_webhooks.py +++ b/Allura/allura/tests/test_webhooks.py @@ -678,7 +678,7 @@ class TestWebhookRestController(TestRestApiBase): self.setup_with_tools() self.project = M.Project.query.get(shortname=test_project_with_repo) self.git = self.project.app_instance('src') - self.url = str('/rest' + self.git.admin_url + 'webhooks') + self.url = '/rest' + self.git.admin_url + 'webhooks' self.webhooks = [] for i in range(3): webhook = M.Webhook( diff --git a/AlluraTest/alluratest/validation.py b/AlluraTest/alluratest/validation.py index 7761944..df838e9 100644 --- a/AlluraTest/alluratest/validation.py +++ b/AlluraTest/alluratest/validation.py @@ -273,14 +273,6 @@ class PostParamCheckingTestApp(AntiSpamTestApp): raise TypeError( '%s key %s has value %s of type %s, not str. ' % (method, k, v, type(v))) - elif six.PY2 and isinstance(v, str): - try: - v.encode('ascii') - #pass - except UnicodeEncodeError: - raise TypeError( - '%s key "%s" has value "%s" of type %s, should be utf-8 encoded. ' % - (method, k, v, type(v))) def get(self, *args, **kwargs): params = None diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py index 941d07a..3bfd8b8 100644 --- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py +++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py @@ -222,7 +222,7 @@ class TestForumMessageHandling(TestController): def test_threads(self): self._post('testforum', 'Test', 'test') thd = FM.ForumThread.query.find().first() - url = str('/discussion/testforum/thread/%s/' % thd._id) + url = '/discussion/testforum/thread/%s/' % thd._id self.app.get(url) # accessing a non-existent thread should return a 404 self.app.get('/discussion/testforum/thread/foobar/', status=404) @@ -232,7 +232,7 @@ class TestForumMessageHandling(TestController): c.user = M.User.by_username('test-admin') self._post('testforum', 'Test', 'test') thd = FM.ForumThread.query.find().first() - thd_url = str('/discussion/testforum/thread/%s/' % thd._id) + thd_url = '/discussion/testforum/thread/%s/' % thd._id r = self.app.get(thd_url) p = FM.ForumPost.query.find().first() url = str(f'/discussion/testforum/thread/{thd._id}/{p.slug}/') diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py index 5004f7e..0d9d359 100644 --- a/ForgeImporters/forgeimporters/base.py +++ b/ForgeImporters/forgeimporters/base.py @@ -28,7 +28,6 @@ import traceback from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import unquote from datetime import datetime -import codecs import six from bs4 import BeautifulSoup @@ -664,6 +663,6 @@ def save_importer_upload(project, filename, data): except OSError as e: if e.errno != errno.EEXIST: raise - with codecs.open(dest_file, 'w', encoding='utf-8') as fp: + with open(dest_file, 'w', encoding='utf-8') as fp: fp.write(data) return dest_file diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py index 8b9dc07..44595cb 100644 --- a/ForgeImporters/forgeimporters/tests/test_base.py +++ b/ForgeImporters/forgeimporters/tests/test_base.py @@ -363,13 +363,13 @@ def test_save_importer_upload(giup, os): os.path.join = lambda *a: '/'.join(a) giup.return_value = 'path' os.makedirs.side_effect = OSError(errno.EEXIST, 'foo') - _open = mock.MagicMock() - fp = _open.return_value.__enter__.return_value - with mock.patch.object(base.codecs, 'open', _open): + with mock.patch('forgeimporters.base.open') as m_open: + m_open = mock.mock_open(m_open) + fp = m_open.return_value.__enter__.return_value base.save_importer_upload('project', 'file', 'data') - os.makedirs.assert_called_once_with('path') - _open.assert_called_once_with('path/file', 'w', encoding='utf-8') - fp.write.assert_called_once_with('data') + os.makedirs.assert_called_once_with('path') + m_open.assert_called_once_with('path/file', 'w', encoding='utf-8') + fp.write.assert_called_once_with('data') os.makedirs.side_effect = OSError(errno.EACCES, 'foo') assert_raises(OSError, base.save_importer_upload, diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py index 1ca515c..a5c8b23 100644 --- a/ForgeTracker/forgetracker/tests/functional/test_root.py +++ b/ForgeTracker/forgetracker/tests/functional/test_root.py @@ -377,7 +377,7 @@ class TestFunctionalController(TrackerTestController): # Private tickets shouldn't be included in counts if user doesn't # have read access to private tickets. - r = self.app.get('/bugs/bin_counts', extra_environ=dict(username=str('*anonymous'))) + r = self.app.get('/bugs/bin_counts', extra_environ=dict(username='*anonymous')) assert_equal(r.json, {"bin_counts": [{"count": 1, "label": "Changes"}, {"count": 0, "label": "Closed Tickets"}, {"count": 1, "label": "Open Tickets"}]}) diff --git a/run_tests b/run_tests index c4ff7b4..23b8d3d 100755 --- a/run_tests +++ b/run_tests @@ -17,9 +17,6 @@ # specific language governing permissions and limitations # under the License. -from __future__ import unicode_literals -from __future__ import absolute_import -from __future__ import print_function import argparse from glob import glob import multiprocessing diff --git a/scripts/teamforge-import.py b/scripts/teamforge-import.py index 9fc2926..8b375ec 100644 --- a/scripts/teamforge-import.py +++ b/scripts/teamforge-import.py @@ -33,7 +33,6 @@ from datetime import datetime from six.moves.configparser import ConfigParser import random import string -import codecs import sqlalchemy from suds.client import Client @@ -158,7 +157,7 @@ def main(): get_news(project) if not options.skip_unsupported_check: check_unsupported_tools(project) - with codecs.open(os.path.join(options.output_dir, 'users.json'), 'w', encoding='utf-8') as user_file: + with open(os.path.join(options.output_dir, 'users.json'), 'w', encoding='utf-8') as user_file: json.dump(users, user_file, default=str) except Exception: log.exception('Error extracting %s' % pid) @@ -678,7 +677,7 @@ def save(content, project, *paths): out_file = os.path.join(options.output_dir, project.id, *paths) if not os.path.exists(os.path.dirname(out_file)): os.makedirs(os.path.dirname(out_file)) - with codecs.open(out_file, 'w', encoding='utf-8') as out: + with open(out_file, 'w', encoding='utf-8') as out: out.write(content.encode('utf-8')) @@ -714,7 +713,7 @@ def download_file(tool, url_path, *filepaths): 'returnToUrl': url, 'sfsubmit': 'submit' })) - with codecs.open(out_file, 'w', encoding='utf-8') as out: + with open(out_file, 'w', encoding='utf-8') as out: out.write(resp.fp.read()) return out_file diff --git a/scripts/trac_export_wiki.py b/scripts/trac_export_wiki.py index 650206b..3a18955 100755 --- a/scripts/trac_export_wiki.py +++ b/scripts/trac_export_wiki.py @@ -19,7 +19,6 @@ import sys from optparse import OptionParser -import codecs from tracwikiimporter.scripts.wiki_from_trac.extractors import WikiExporter @@ -52,6 +51,6 @@ if __name__ == '__main__': out = sys.stdout if options.out_filename: - out = codecs.open(options.out_filename, 'w', encoding='utf-8') + out = open(options.out_filename, 'w', encoding='utf-8') exporter.export(out) diff --git a/tox.ini b/tox.ini index 4239c0c..5eff60b 100644 --- a/tox.ini +++ b/tox.ini @@ -21,7 +21,7 @@ # for full test suite runs, use ./run_tests within the virtualenv [tox] -envlist = py{27,37} +envlist = py{37} # since we don't have one top-level setup.py: skipsdist = True
