From 7473785b5cd986baf5d6fd8aa1f47efa2a63eeaa Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Wed, 26 Jun 2024 01:10:53 +0000 Subject: [PATCH] Remove some Python 2 compatibility leftovers (#1415) --- libweasyl/files.py | 6 +- libweasyl/models/media.py | 2 +- libweasyl/models/tables.py | 8 +- libweasyl/ratings.py | 2 +- libweasyl/test/test_files.py | 2 +- libweasyl/test/test_text.py | 54 ++++++------- libweasyl/text.py | 78 +++++++++---------- weasyl-apidocs/source/conf.py | 16 ++-- weasyl/commishinfo.py | 2 +- weasyl/configuration_builder.py | 6 +- weasyl/controllers/moderation.py | 2 +- weasyl/controllers/profile.py | 14 ++-- weasyl/define.py | 4 +- weasyl/middleware.py | 14 ++-- weasyl/orm.py | 4 +- weasyl/pagination.py | 2 +- weasyl/profile.py | 8 +- weasyl/search.py | 2 +- weasyl/test/login/test_authenticate_bcrypt.py | 16 ++-- weasyl/test/login/test_create.py | 2 +- weasyl/test/login/test_password_secure.py | 8 +- weasyl/test/test_comment.py | 2 +- weasyl/test/test_define.py | 2 +- weasyl/test/test_search.py | 56 ++++++------- weasyl/test/test_submission.py | 2 +- weasyl/test/test_two_factor_auth.py | 2 +- weasyl/test/web/test_characters.py | 24 +++--- weasyl/test/web/test_journals.py | 28 +++---- weasyl/test/web/test_site_updates.py | 24 +++--- weasyl/test/web/test_submissions.py | 10 +-- 30 files changed, 201 insertions(+), 201 deletions(-) diff --git a/libweasyl/files.py b/libweasyl/files.py index 857b9beaa..f58436b8d 100644 --- a/libweasyl/files.py +++ b/libweasyl/files.py @@ -98,9 +98,9 @@ def file_type_for_category(data, category): except SanperaError: raise UnknownFileFormat('The image data provided could not be decoded.') fmt = im.original_format.decode() - if fmt == u'JPEG': - fmt = u'JPG' - if fmt not in {u'GIF', u'JPG', u'PNG'}: + if fmt == 'JPEG': + fmt = 'JPG' + if fmt not in {'GIF', 'JPG', 'PNG'}: raise InvalidFileFormat('Image files must be in the GIF, JPG, or PNG formats.') return im, str(fmt.lower()) elif category == Category.literary: diff --git a/libweasyl/models/media.py b/libweasyl/models/media.py index 777ad599d..221b1c9b4 100644 --- a/libweasyl/models/media.py +++ b/libweasyl/models/media.py @@ -94,7 +94,7 @@ def file_url(self): return '/' + '/'.join(self._file_path_components) -class _LinkMixin(object): +class _LinkMixin: cache_func = None @classmethod diff --git a/libweasyl/models/tables.py b/libweasyl/models/tables.py index b151ef2b0..40c14f80f 100644 --- a/libweasyl/models/tables.py +++ b/libweasyl/models/tables.py @@ -239,7 +239,7 @@ def default_fkey(*args, **kwargs): Column('height', String(length=100), nullable=False, server_default=''), Column('weight', String(length=100), nullable=False, server_default=''), Column('species', String(length=100), nullable=False, server_default=''), - Column('content', String(length=100000), nullable=False, server_default=u""), + Column('content', String(length=100000), nullable=False, server_default=""), Column('rating', RatingColumn, nullable=False), Column('settings', CharSettingsColumn({}, length=20), nullable=False, server_default=''), Column('hidden', Boolean(), nullable=False, server_default='f'), @@ -365,7 +365,7 @@ def default_fkey(*args, **kwargs): 'media', metadata, Column('mediaid', Integer(), primary_key=True, nullable=False), Column('file_type', String(length=8), nullable=False), - Column('attributes', JSONValuesColumn(), nullable=False, server_default=text(u"''::hstore")), + Column('attributes', JSONValuesColumn(), nullable=False, server_default=text("''::hstore")), Column('sha256', String(length=64)), ) @@ -655,7 +655,7 @@ def default_fkey(*args, **kwargs): Column('created_at', ArrowColumn(), nullable=False, server_default=text('now()')), Column('last_active', TIMESTAMP(timezone=True), nullable=True, server_default=func.now()), Column('userid', Integer()), - Column('additional_data', JSONValuesColumn(), nullable=False, server_default=text(u"''::hstore")), + Column('additional_data', JSONValuesColumn(), nullable=False, server_default=text("''::hstore")), Column('ip_address', String(length=39), nullable=True), Column('user_agent_id', Integer(), nullable=True), default_fkey(['userid'], ['login.userid'], name='sessions_userid_fkey'), @@ -825,7 +825,7 @@ def _tag_suggestion_feedback_table(content_table, id_column): Column('added', ARRAY(Text())), Column('removed', ARRAY(Text())), Column('updated_at', Integer(), nullable=False, - server_default=text(u"(date_part('epoch'::text, now()) - (18000)::double precision)")), + server_default=text("(date_part('epoch'::text, now()) - (18000)::double precision)")), default_fkey(['submitid'], ['submission.submitid'], name='tag_updates_submitid_fkey'), ForeignKeyConstraint(['userid'], ['login.userid'], name='tag_updates_userid_fkey'), ) diff --git a/libweasyl/ratings.py b/libweasyl/ratings.py index bc00b5251..5ecc67e0a 100644 --- a/libweasyl/ratings.py +++ b/libweasyl/ratings.py @@ -2,7 +2,7 @@ @functools.total_ordering -class Rating(object): +class Rating: def __init__(self, code, character, name, nice_name, minimum_age, block_text, additional_description=None): diff --git a/libweasyl/test/test_files.py b/libweasyl/test/test_files.py index 08315ea7e..a88680318 100644 --- a/libweasyl/test/test_files.py +++ b/libweasyl/test/test_files.py @@ -117,4 +117,4 @@ def test_file_type_for_category_literary_results(): """ Non-PDF UTF-8 documents are returned decoded. """ - assert files.file_type_for_category(b'hello\xc3\xbfworld', Category.literary) == (u'hello\xffworld', 'txt') + assert files.file_type_for_category(b'hello\xc3\xbfworld', Category.literary) == ('hello\xffworld', 'txt') diff --git a/libweasyl/test/test_text.py b/libweasyl/test/test_text.py index 959811ecb..17e87473e 100644 --- a/libweasyl/test/test_text.py +++ b/libweasyl/test/test_text.py @@ -125,17 +125,17 @@ def test_markdown_respect_ordered_list_start(): def test_markdown_strikethrough(): - assert markdown(u"~~test~~") == u"

test

\n" + assert markdown("~~test~~") == "

test

\n" @pytest.mark.parametrize(('target', 'expected'), [ - (u"[external](http://example.com/)", u'external'), - (u'external', u'external'), - (u'external', u'external'), - (u"[external](//example.com/)", u'external'), + ("[external](http://example.com/)", 'external'), + ('external', 'external'), + ('external', 'external'), + ("[external](//example.com/)", 'external'), ]) def test_markdown_external_link_noreferrer(target, expected): - assert markdown(target) == u"

%s

\n" % (expected,) + assert markdown(target) == "

%s

\n" % (expected,) markdown_link_tests = [ @@ -151,28 +151,28 @@ def test_markdown_link(target, expected): def test_tag_stripping(): - assert markdown(u"") == u"

text

\n" - assert markdown(u"") == u"

text

\n" - assert markdown(u"") == u"\n" + assert markdown("") == "

text

\n" + assert markdown("") == "

text

\n" + assert markdown("") == "\n" markdown_excerpt_tests = [ - (u'', u''), - (u'short', u'short'), - (u'just short enoughAAAAAAAAAAAAA', u'just short enoughAAAAAAAAAAAAA'), - (u'not short enoughAAAAAAAAAAAAAAA', u'not short enoughAAAAAAAAAAAAA…'), - (u'*leading* inline formatting', u'leading inline formatting'), - (u'middle *inline* formatting', u'middle inline formatting'), - (u'trailing inline *formatting*', u'trailing inline formatting'), - (u'*nested **inline** formatting*', u'nested inline formatting'), - (u' unnecessary whitespace\t', u'unnecessary whitespace'), - (u'multiple\nlines', u'multiple lines'), - (u'multiple \nlines', u'multiple lines'), - (u'multiple\n\nparagraphs', u'multiple paragraphs'), - (u'Üñíçôđe\N{COMBINING ACUTE ACCENT}', u'Üñíçôđe\N{COMBINING ACUTE ACCENT}'), - (u'single-codepoint graphemes😊😊😊😊', u'single-codepoint graphemes😊😊😊😊'), - (u'single-codepoint graphemes😊😊😊😊😊', u'single-codepoint graphemes😊😊😊…'), - (u'test\n - lists\n - of\n - items\n\ntest', u'test lists of items test'), + ('', ''), + ('short', 'short'), + ('just short enoughAAAAAAAAAAAAA', 'just short enoughAAAAAAAAAAAAA'), + ('not short enoughAAAAAAAAAAAAAAA', 'not short enoughAAAAAAAAAAAAA…'), + ('*leading* inline formatting', 'leading inline formatting'), + ('middle *inline* formatting', 'middle inline formatting'), + ('trailing inline *formatting*', 'trailing inline formatting'), + ('*nested **inline** formatting*', 'nested inline formatting'), + (' unnecessary whitespace\t', 'unnecessary whitespace'), + ('multiple\nlines', 'multiple lines'), + ('multiple \nlines', 'multiple lines'), + ('multiple\n\nparagraphs', 'multiple paragraphs'), + ('Üñíçôđe\N{COMBINING ACUTE ACCENT}', 'Üñíçôđe\N{COMBINING ACUTE ACCENT}'), + ('single-codepoint graphemes😊😊😊😊', 'single-codepoint graphemes😊😊😊😊'), + ('single-codepoint graphemes😊😊😊😊😊', 'single-codepoint graphemes😊😊😊…'), + ('test\n - lists\n - of\n - items\n\ntest', 'test lists of items test'), ('
**foo**
\n', "foo"), ('1 < 3 > 2 "foo"', '1 < 3 > 2 "foo"'), ("©", "©"), @@ -189,5 +189,5 @@ def test_excerpt(target, expected): def test_excerpt_default_length(): - assert markdown_excerpt(u'a' * 300) == u'a' * 300 - assert markdown_excerpt(u'a' * 301) == u'a' * 299 + u'…' + assert markdown_excerpt('a' * 300) == 'a' * 300 + assert markdown_excerpt('a' * 301) == 'a' * 299 + '…' diff --git a/libweasyl/text.py b/libweasyl/text.py index e32465c7b..2be571c4a 100644 --- a/libweasyl/text.py +++ b/libweasyl/text.py @@ -72,7 +72,7 @@ def _sofurry(target): def strip_outer_tag(html): match = locatestarttagend.match(html) start_tag_end = match.end() - end_tag_start = html.rindex(u'<') + end_tag_start = html.rindex('<') return html[:start_tag_end + 1], html[start_tag_end + 1:end_tag_start], html[end_tag_start:] @@ -82,7 +82,7 @@ def block_html(self, raw_html): if raw_html.startswith('