diff --git a/drama/classes/submission.py b/drama/classes/submission.py index 22ffc024f4..c918abf270 100644 --- a/drama/classes/submission.py +++ b/drama/classes/submission.py @@ -123,7 +123,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing): output = re.sub('&\w{2,3};', '', output) output = [re.sub('\W', '', word) for word in output.split()] - output = [x for x in output if x][0:6] + output = [x for x in output if x][:6] output = '-'.join(output) diff --git a/drama/routes/comments.py b/drama/routes/comments.py index e068f0c112..925dc2cec3 100644 --- a/drama/routes/comments.py +++ b/drama/routes/comments.py @@ -188,7 +188,7 @@ def api_comment(v): abort(400) #process and sanitize - body = request.form.get("body", "")[0:10000] + body = request.form.get("body", "")[:10000] body = body.strip() if not body and not request.files.get('file'): return jsonify({"error":"You need to actually write something!"}), 400 @@ -572,7 +572,7 @@ def edit_comment(cid, v): if c.is_banned or c.deleted_utc > 0: abort(403) - body = request.form.get("body", "")[0:10000] + body = request.form.get("body", "")[:10000] for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF))', body, re.MULTILINE): body = body.replace(i.group(1), f'![]({i.group(1)})') body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") with CustomRenderer(post_id=c.post.id) as renderer: body_md = renderer.render(mistletoe.Document(body)) diff --git a/drama/routes/front.py b/drama/routes/front.py index ea7cd8c01b..dff0e095ed 100644 --- a/drama/routes/front.py +++ b/drama/routes/front.py @@ -209,7 +209,7 @@ def front_all(v): # check existence of next page next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] # check if ids exist posts = get_posts(ids, v=v) @@ -309,7 +309,7 @@ def changelog(v): # check existence of next page next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] # check if ids exist posts = get_posts(ids, v=v) @@ -412,7 +412,7 @@ def all_comments(v): next_exists = len(idlist) == 26 - idlist = idlist[0:25] + idlist = idlist[:25] if request.headers.get("Authorization"): return {"data": [x.json for x in comments]} else: return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists) \ No newline at end of file diff --git a/drama/routes/oauth.py b/drama/routes/oauth.py index e988e7226e..891a649ab1 100644 --- a/drama/routes/oauth.py +++ b/drama/routes/oauth.py @@ -118,7 +118,7 @@ def oauth_authorize_post(v): new_auth = ClientAuth( oauth_client=application.id, - oauth_code=secrets.token_urlsafe(128)[0:128], + oauth_code=secrets.token_urlsafe(128)[:128], user_id=v.id, scope_identity="identity" in scopes, scope_create="create" in scopes, @@ -126,7 +126,7 @@ def oauth_authorize_post(v): scope_update="update" in scopes, scope_delete="delete" in scopes, scope_vote="vote" in scopes, - refresh_token=secrets.token_urlsafe(128)[0:128] if permanent else None + refresh_token=secrets.token_urlsafe(128)[:128] if permanent else None ) g.db.add(new_auth) @@ -167,7 +167,7 @@ def oauth_grant(): return {"oauth_error": "Invalid code"}, 401 auth.oauth_code = None - auth.access_token = secrets.token_urlsafe(128)[0:128] + auth.access_token = secrets.token_urlsafe(128)[:128] auth.access_token_expire_utc = int(time.time()) + 60 * 60 g.db.add(auth) @@ -201,7 +201,7 @@ def oauth_grant(): if not auth: return {"oauth_error": "Invalid refresh_token"}, 401 - auth.access_token = secrets.token_urlsafe(128)[0:128] + auth.access_token = secrets.token_urlsafe(128)[:128] auth.access_token_expire_utc = int(time.time()) + 60 * 60 g.db.add(auth) @@ -284,8 +284,8 @@ def admin_app_approve(v, aid): app = g.db.query(OauthApp).filter_by(id=aid).first() - app.client_id = secrets.token_urlsafe(64)[0:64] - app.client_secret = secrets.token_urlsafe(128)[0:128] + app.client_id = secrets.token_urlsafe(64)[:64] + app.client_secret = secrets.token_urlsafe(128)[:128] g.db.add(app) @@ -347,7 +347,7 @@ def admin_app_id(v, aid): ) next_exists=len(pids)==101 - pids=pids[0:100] + pids=pids[:100] posts=get_posts(pids, v=v) @@ -373,7 +373,7 @@ def admin_app_id_comments(v, aid): ) next_exists=len(cids)==101 - cids=cids[0:100] + cids=cids[:100] comments=get_comments(cids, v=v) @@ -411,8 +411,8 @@ def reroll_oauth_tokens(aid, v): if a.author_id != v.id: abort(403) - a.client_id = secrets.token_urlsafe(64)[0:64] - a.client_secret = secrets.token_urlsafe(128)[0:128] + a.client_id = secrets.token_urlsafe(64)[:64] + a.client_secret = secrets.token_urlsafe(128)[:128] g.db.add(a) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 607596ffd8..12956b4bd5 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -403,11 +403,11 @@ def thumbs(new_post): try: meta_title=soup.find('title') if meta_title: - post.submission_aux.meta_title=str(meta_title.string)[0:500] + post.submission_aux.meta_title=str(meta_title.string)[:500] meta_desc = soup.find('meta', attrs={"name":"description"}) if meta_desc: - post.submission_aux.meta_description=meta_desc['content'][0:1000] + post.submission_aux.meta_description=meta_desc['content'][:1000] if meta_title or meta_desc: g.db.add(post.submission_aux) @@ -542,7 +542,7 @@ def submit_post(v): elif len(title) > 500: if request.headers.get("Authorization"): return {"error": "500 character limit for titles"}, 400 - else: render_template("submit.html", v=v, error="500 character limit for titles.", title=title[0:500], url=url, body=request.form.get("body", "")), 400 + else: render_template("submit.html", v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.form.get("body", "")), 400 parsed_url = urlparse(url) diff --git a/drama/routes/search.py b/drama/routes/search.py index 00e90abe5f..c112561f8a 100644 --- a/drama/routes/search.py +++ b/drama/routes/search.py @@ -198,7 +198,7 @@ def searchcommentlisting(criteria, v=None, page=1, t="None", sort="top"): @app.get("/search/posts") @auth_desired -def searchposts(v, search_type="posts"): +def searchposts(v): if v and v.is_banned and not v.unban_utc: return render_template("seized.html") query = request.args.get("q", '').strip() @@ -265,7 +265,7 @@ def searchcomments(v): @app.get("/search/users") @auth_desired -def searchusers(v, search_type="posts"): +def searchusers(v): if v and v.is_banned and not v.unban_utc: return render_template("seized.html") query = request.args.get("q", '').strip() diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 71e33a4fd9..e03fe5b6fe 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -62,7 +62,7 @@ def settings_profile_post(v): v.is_nofollow = request.values.get("nofollow", None) == 'true' if request.values.get("bio"): - bio = request.values.get("bio")[0:1500] + bio = request.values.get("bio")[:1500] if bio == v.bio: return render_template("settings_profile.html", @@ -98,7 +98,7 @@ def settings_profile_post(v): if request.values.get("filters"): - filters=request.values.get("filters")[0:1000].strip() + filters=request.values.get("filters")[:1000].strip() if filters==v.custom_filter_list: return render_template("settings_profile.html", @@ -413,7 +413,7 @@ def settings_css_get(v): @app.post("/settings/css") @auth_required def settings_css(v): - css = request.form.get("css").replace('\\', '')[0:50000] + css = request.form.get("css").replace('\\', '')[:50000] if not v.agendaposter: v.css = css @@ -433,7 +433,7 @@ def settings_profilecss_get(v): @auth_required def settings_profilecss(v): if v.dramacoins < 1000: return "You must have +1000 dramacoins to set profile css." - profilecss = request.form.get("profilecss").replace('\\', '')[0:50000] + profilecss = request.form.get("profilecss").replace('\\', '')[:50000] v.profilecss = profilecss g.db.add(v) return render_template("settings_profilecss.html", v=v) diff --git a/drama/templates/settings_profile.html b/drama/templates/settings_profile.html index 25dbcc75e7..8f3fb43e73 100644 --- a/drama/templates/settings_profile.html +++ b/drama/templates/settings_profile.html @@ -25,7 +25,7 @@
Change the theme for the website.