From a641acaf8fe5731079b5b838e2ea794bce7d53a3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 26 Nov 2022 06:52:47 +0200 Subject: [PATCH] use sets instead of lists in some statements --- files/classes/comment.py | 4 ++-- files/classes/user.py | 2 +- files/helpers/get.py | 2 +- files/helpers/sanitize.py | 12 ++++++------ files/routes/posts.py | 4 ++-- files/routes/users.py | 2 +- files/routes/votes.py | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 205ede4e1..f92b328cd 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -243,7 +243,7 @@ class Comment(Base): @lazy def realbody(self, v): - if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))): + if self.post and self.post.club and not (v and (v.paid_dues or v.id in {self.author_id, self.post.author_id} or (self.parent_comment and v.id == self.parent_comment.author_id))): return f"

{CC} ONLY

" if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]" if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return "" @@ -298,7 +298,7 @@ class Comment(Base): @lazy def plainbody(self, v): - if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))): + if self.post and self.post.club and not (v and (v.paid_dues or v.id in {self.author_id, self.post.author_id} or (self.parent_comment and v.id == self.parent_comment.author_id))): return f"{CC} ONLY" if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]" if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return "" diff --git a/files/classes/user.py b/files/classes/user.py index 4853538c5..06e4b8d26 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -875,7 +875,7 @@ class User(Base): def get_relationship_count(self, relationship_cls): # TODO: deduplicate (see routes/users.py) - if relationship_cls in [SaveRelationship, Subscription]: + if relationship_cls in {SaveRelationship, Subscription}: query = relationship_cls.submission_id join = relationship_cls.post cls = Submission diff --git a/files/helpers/get.py b/files/helpers/get.py index a2c1d8a9b..a84bd5be4 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -228,7 +228,7 @@ def add_block_props(target:Union[Submission, Comment, User], v:Optional[User]): if not v: return target id = None - if any(isinstance(target, cls) for cls in [Submission, Comment]): + if any(isinstance(target, cls) for cls in {Submission, Comment}): id = target.author_id elif isinstance(target, User): id = target.id diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 21b3315f5..6a156e486 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -52,7 +52,7 @@ def allowed_attributes(tag, name, value): if name == 'style': return True if tag == 'marquee': - if name in ['direction', 'behavior', 'scrollamount']: return True + if name in {'direction', 'behavior', 'scrollamount'}: return True if name in {'height', 'width'}: try: value = int(value.replace('px', '')) except: return False @@ -67,11 +67,11 @@ def allowed_attributes(tag, name, value): return False if tag == 'img': - if name in ['src','data-src']: return is_safe_url(value) + if name in {'src','data-src'}: return is_safe_url(value) if name == 'loading' and value == 'lazy': return True if name == 'data-bs-toggle' and value == 'tooltip': return True - if name in ['g','b','glow'] and not value: return True - if name in ['alt','title']: return True + if name in {'g','b','glow'} and not value: return True + if name in {'alt','title'}: return True return False if tag == 'lite-youtube': @@ -426,8 +426,8 @@ def allowed_attributes_emojis(tag, name, value): if name == 'src' and value.startswith('/') and '\\' not in value: return True if name == 'loading' and value == 'lazy': return True if name == 'data-bs-toggle' and value == 'tooltip': return True - if name in ['g','glow'] and not value: return True - if name in ['alt','title']: return True + if name in {'g','glow'} and not value: return True + if name in {'alt','title'}: return True if tag == 'span': if name == 'data-bs-toggle' and value == 'tooltip': return True diff --git a/files/routes/posts.py b/files/routes/posts.py index 52f331929..5b912bc04 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -392,7 +392,7 @@ def edit_post(pid, v): p.body = body - for text in [p.body, p.title, p.url]: + for text in {p.body, p.title, p.url}: if not execute_blackjack(v, p, text, 'submission'): break if len(body_html) > POST_BODY_HTML_LENGTH_LIMIT: @@ -810,7 +810,7 @@ def submit_post(v, sub=None): g.db.add(post) g.db.flush() - for text in [post.body, post.title, post.url]: + for text in {post.body, post.title, post.url}: if not execute_blackjack(v, post, text, 'submission'): break if v and v.admin_level >= PERMS['POST_BETS']: diff --git a/files/routes/users.py b/files/routes/users.py index 3565a5b01..15415ff91 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -933,7 +933,7 @@ def user_profile_name(username): return redirect(x.profile_url) def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone=False): - if relationship_cls in [SaveRelationship, Subscription]: + if relationship_cls in {SaveRelationship, Subscription}: query = relationship_cls.submission_id join = relationship_cls.post cls = Submission diff --git a/files/routes/votes.py b/files/routes/votes.py index 5d6d21e4e..ad6e5a282 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -42,7 +42,7 @@ def vote_info_get(v, link): def vote_post_comment(target_id, new, v, cls, vote_cls): if new == "-1" and DISABLE_DOWNVOTES: abort(403) - if new not in ["-1", "0", "1"]: abort(400) + if new not in {"-1", "0", "1"}: abort(400) if v.client and v.id not in PRIVILEGED_USER_BOTS: abort(403) new = int(new) target = None