Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cleaning up the controllers. #939

Closed
wants to merge 1 commit into from

2 participants

@mssola
  • Removed unneeded imports.
  • Removed variables that were set and never used.
@mssola mssola Cleaning up the controllers.
  - Removed unneeded imports.
  - Removed variables that were set and never used.
1f0032d
@Deimos
Owner

Thanks for submitting, but this type of clean-up is risky since we unfortunately don't have the ability to easily test and make sure that there aren't any unexpected effects due to strange cases like import-chains.

We usually try to do this sort of clean-up in a more targeted manner, when a person is working on changes in the same area and has a good understanding of any possible connotations. Since some of the code left behind here after your changes doesn't have any function, it appears that this was just done by clearing warnings in some sort of tool without that level of deeper understanding.

@Deimos Deimos closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 30, 2013
  1. @mssola

    Cleaning up the controllers.

    mssola authored
      - Removed unneeded imports.
      - Removed variables that were set and never used.
This page is out of date. Refresh to see the latest.
View
38 r2/r2/controllers/api.py
@@ -31,7 +31,7 @@
)
from pylons.i18n import _
-from pylons import c, request, response
+from pylons import c, request
from r2.lib.validator import *
@@ -41,12 +41,12 @@
from r2.lib import recommender
from r2.lib import hooks
-from r2.lib.utils import get_title, sanitize_url, timeuntil, set_last_modified
-from r2.lib.utils import query_string, timefromnow, randstr
+from r2.lib.utils import get_title, timeuntil, set_last_modified
+from r2.lib.utils import query_string
from r2.lib.utils import timeago, tup, filter_links
-from r2.lib.pages import (EnemyList, FriendList, ContributorList, ModList,
+from r2.lib.pages import (FriendList, ContributorList, ModList,
BannedList, WikiBannedList, WikiMayContributeList,
- BoringPage, FormPage, CssError, UploadedImage,
+ BoringPage, CssError, UploadedImage,
ClickGadget, UrlParser, WrappedUser)
from r2.lib.pages import FlairList, FlairCsv, FlairTemplateEditor, \
FlairSelector
@@ -57,14 +57,14 @@
from r2.lib.menus import CommentSortMenu
from r2.lib.captcha import get_iden
from r2.lib.strings import strings
-from r2.lib.filters import _force_unicode, websafe_json, websafe, spaceCompress
+from r2.lib.filters import websafe, spaceCompress
from r2.lib.db import queries
from r2.lib.db.queries import changed
from r2.lib import media
from r2.lib.db import tdb_cassandra
from r2.lib import promote
from r2.lib.comment_tree import delete_comment
-from r2.lib import tracking, cssfilter, emailer
+from r2.lib import cssfilter, emailer
from r2.lib.subreddit_search import search_reddits
from r2.lib.log import log_text
from r2.lib.filters import safemarkdown
@@ -86,8 +86,6 @@
from datetime import datetime, timedelta
import hashlib
import re
-import urllib
-import urllib2
def reject_vote(thing):
voteword = request.params.get('dir')
@@ -446,7 +444,7 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
queries.queue_vote(c.user, l, True, ip, cheater=c.cheater)
if save:
- r = l._save(c.user)
+ l._save(c.user)
#set the ratelimiter
if should_ratelimit:
@@ -573,7 +571,7 @@ def _handle_register(self, form, responder, name, email,
langs.sort()
user.pref_content_langs = tuple(langs)
- d = c.user._dirties.copy()
+ c.user._dirties.copy()
user._commit()
amqp.add_item('new_account', user._fullname)
@@ -825,8 +823,6 @@ def POST_friend(self, form, jquery, ip, friend,
return
if form.has_errors('permissions', errors.INVALID_PERMISSIONS):
return
- else:
- permissions = None
if type == "moderator_invite" and container.is_moderator(friend):
c.errors.add(errors.ALREADY_MODERATOR, field="name")
@@ -926,7 +922,6 @@ def POST_accept_moderator_invite(self, form, jquery, ip):
form.set_error(errors.NO_INVITE_FOUND, None)
return
- permissions = rel.get_permissions()
ModAction.create(c.site, c.user, "acceptmoderatorinvite")
c.site.add_moderator(c.user, permissions=rel.get_permissions())
notify_user_added("accept_moderator_invite", c.user, c.user, c.site)
@@ -1241,7 +1236,7 @@ def POST_report(self, thing):
admintools.spam(thing, False, True, c.user.name)
# auto-hide links that are reported
elif isinstance(thing, Link):
- r = thing._hide(c.user)
+ thing._hide(c.user)
# TODO: be nice to be able to remove comments that are reported
# from a user's inbox so they don't have to look at them.
elif isinstance(thing, Comment):
@@ -1361,7 +1356,6 @@ def POST_comment(self, commentform, jquery, parent, comment, ip):
should_ratelimit = False
else:
is_message = False
- is_comment = True
if isinstance(parent, Link):
link = parent
parent_comment = None
@@ -2346,7 +2340,7 @@ def POST_save(self, thing):
"""
if not thing: return
if isinstance(thing, Comment) and not c.user.gold: return
- r = thing._save(c.user)
+ thing._save(c.user)
@require_oauth2_scope("save")
@noresponse(VUser(),
@@ -2362,7 +2356,7 @@ def POST_unsave(self, thing):
"""
if not thing: return
- r = thing._unsave(c.user)
+ thing._unsave(c.user)
def collapse_handler(self, things, collapse):
if not things:
@@ -2462,7 +2456,7 @@ def POST_hide(self, thing):
"""
if not thing: return
- r = thing._hide(c.user)
+ thing._hide(c.user)
@noresponse(VUser(),
VModhash(),
@@ -2475,7 +2469,7 @@ def POST_unhide(self, thing):
"""
if not thing: return
- r = thing._unhide(c.user)
+ thing._unhide(c.user)
@validatedForm(VUser(),
@@ -2608,7 +2602,7 @@ def GET_bookmarklet(self, action, uh, links):
# unlike most cases, if not already submitted, error.
elif errors.ALREADY_SUB in c.errors:
# preserve the subreddit if not Default
- sr = c.site if not isinstance(c.site, FakeSubreddit) else None
+ c.site if not isinstance(c.site, FakeSubreddit) else None
# check permissions on those links to make sure votes will count
Subreddit.load_subreddits(links, return_dict = False)
@@ -2624,7 +2618,7 @@ def GET_bookmarklet(self, action, uh, links):
cheater=c.cheater)
elif action == 'save':
link = max(links, key = lambda x: x._score)
- r = link._save(c.user)
+ link._save(c.user)
return self.redirect("/static/css_%sd.png" % action)
return self.redirect("/static/css_submit.png")
View
1  r2/r2/controllers/api_docs.py
@@ -20,7 +20,6 @@
# Inc. All Rights Reserved.
###############################################################################
-import re
from collections import defaultdict
from itertools import chain
import inspect
View
1  r2/r2/controllers/awards.py
@@ -20,7 +20,6 @@
# Inc. All Rights Reserved.
###############################################################################
-from pylons import request, g
from reddit_base import RedditController
from r2.lib.pages import AdminPage, AdminAwards
from r2.lib.pages import AdminAwardGive, AdminAwardWinners
View
1  r2/r2/controllers/buttons.py
@@ -44,7 +44,6 @@ def get_wrapped_link(self, url, link = None, wrapper = None):
pass
if links:
- kw = {}
if wrapper:
links = wrap_links(links, wrapper = wrapper)
else:
View
2  r2/r2/controllers/captcha.py
@@ -23,7 +23,7 @@
from reddit_base import RedditController
import StringIO
import r2.lib.captcha as captcha
-from pylons import c, response
+from pylons import response
from r2.controllers.api_docs import api_doc, api_section
View
6 r2/r2/controllers/embed.py
@@ -23,13 +23,13 @@
from r2.controllers.reddit_base import RedditController
from r2.lib.base import proxyurl
from r2.lib.template_helpers import get_domain
-from r2.lib.pages import Embed, BoringPage, HelpPage
-from r2.lib.filters import websafe, SC_OFF, SC_ON
+from r2.lib.pages import Embed, HelpPage
+from r2.lib.filters import SC_OFF, SC_ON
from r2.lib.memoize import memoize
from pylons.i18n import _
from pylons import c, g, request
-from BeautifulSoup import BeautifulSoup, Tag
+from BeautifulSoup import BeautifulSoup
from urllib2 import HTTPError
View
2  r2/r2/controllers/error.py
@@ -24,8 +24,6 @@
import os
import random
-import pylons
-
from webob.exc import HTTPFound, HTTPMovedPermanently
from pylons.i18n import _
from pylons import c, g, request, response
View
1  r2/r2/controllers/errorlog.py
@@ -20,7 +20,6 @@
# Inc. All Rights Reserved.
###############################################################################
-from pylons import request, g
from reddit_base import RedditController
from r2.lib.pages import AdminPage, AdminErrorLog
from r2.lib.validator import validate, VAdmin
View
13 r2/r2/controllers/front.py
@@ -20,7 +20,7 @@
# Inc. All Rights Reserved.
###############################################################################
-from pylons.i18n import _, ungettext
+from pylons.i18n import _
from pylons.controllers.util import redirect_to
from r2.controllers.reddit_base import (
base_listing,
@@ -30,7 +30,6 @@
disable_subreddit_css,
RedditController,
)
-from r2 import config
from r2.models import *
from r2.config.extensions import is_api
from r2.lib import recommender
@@ -40,17 +39,12 @@
from r2.lib.menus import *
from r2.lib.utils import to36, sanitize_url, check_cheating, title_to_url
from r2.lib.utils import query_string, UrlParser, link_from_url, url_links_builder
-from r2.lib.template_helpers import get_domain
-from r2.lib.filters import unsafe, _force_unicode, _force_utf8
+from r2.lib.filters import _force_unicode, _force_utf8
from r2.lib.emailer import Email
-from r2.lib.db.operators import desc
-from r2.lib.db import queries
-from r2.lib.db.tdb_cassandra import MultiColumnQuery
from r2.lib.strings import strings
from r2.lib.search import (SearchQuery, SubredditSearchQuery, SearchException,
InvalidQuery)
from r2.lib.validator import *
-from r2.lib import jsontemplates
from r2.lib import sup
import r2.lib.db.thing as thing
from r2.lib.errors import errors
@@ -61,8 +55,6 @@
from r2.models.token import EmailVerificationToken
from r2.controllers.ipn import generate_blob, validate_blob, GoldException
-from operator import attrgetter
-import string
import random as rand
import re, socket
import time as time_module
@@ -411,7 +403,6 @@ def _add_show_comments_link(self, array, article, num, max_comm, gold=False):
name=nop('name'))
def GET_newreddit(self, name):
"""Create a subreddit form"""
- title = _('create a subreddit')
content=CreateSubreddit(name=name or '')
res = FormPage(_("create a subreddit"),
content=content,
View
3  r2/r2/controllers/ipn.py
@@ -43,7 +43,6 @@
VByName,
VFloat,
VInt,
- VLength,
VModhash,
VOneOf,
VPrintable,
@@ -920,7 +919,7 @@ def POST_goldcharge(self, form, jquery, token, passthrough, pennies, months,
"""
try:
- payment_blob = validate_blob(passthrough)
+ validate_blob(passthrough)
except GoldException as e:
# This should never happen. All fields in the payment_blob
# are validated on creation
View
7 r2/r2/controllers/listingcontroller.py
@@ -28,14 +28,13 @@
from r2.config.extensions import is_api
from r2.lib.pages import *
from r2.lib.pages.things import wrap_links
-from r2.lib.menus import TimeMenu, SortMenu, RecSortMenu, ProfileSortMenu
+from r2.lib.menus import TimeMenu, ProfileSortMenu
from r2.lib.menus import ControversyTimeMenu
from r2.lib.rising import get_rising
from r2.lib.wrapped import Wrapped
from r2.lib.normalized_hot import normalized_hot
-from r2.lib.db.thing import Query, Merge, Relations
+from r2.lib.db.thing import Query
from r2.lib.db import queries
-from r2.lib.strings import Score
from r2.lib import organic
import r2.lib.search as search
from r2.lib.template_helpers import add_sr
@@ -43,7 +42,6 @@
from r2.lib import sup
from r2.lib.validator import *
from r2.lib.butler import extract_user_mentions
-import socket
from api_docs import api_doc, api_section
@@ -275,7 +273,6 @@ def make_spotlight(self):
"""
organic_fullnames = organic.organic_links(c.user)
- promoted_links = []
show_promo = False
srnames = []
View
7 r2/r2/controllers/multi.py
@@ -37,8 +37,7 @@
LabeledMulti,
TooManySubredditsError,
)
-from r2.lib.db import tdb_cassandra, thing
-from r2.lib.wrapped import Wrapped
+from r2.lib.db import tdb_cassandra
from r2.lib.validator import (
validate,
VUser,
@@ -56,7 +55,7 @@
LabeledMultiJsonTemplate,
LabeledMultiDescriptionJsonTemplate,
)
-from r2.lib.errors import errors, RedditError
+from r2.lib.errors import RedditError
multi_sr_data_json_spec = VValidatedJSON.Object({
@@ -135,7 +134,7 @@ def _add_multi_srs(self, multi, sr_datas):
try:
multi.add_srs(sr_props)
- except TooManySubredditsError as e:
+ except TooManySubredditsError:
raise RedditError('MULTI_TOO_MANY_SUBREDDITS', code=409)
return sr_props
View
6 r2/r2/controllers/oauth2.py
@@ -21,15 +21,11 @@
###############################################################################
from urllib import urlencode
-import base64
-import simplejson
-from pylons import c, g, request
-from pylons.i18n import _
+from pylons import c, request
from r2.config.extensions import set_extension
from r2.lib.base import abort
from reddit_base import RedditController, MinimalController, require_https
-from r2.lib.db.thing import NotFound
from r2.models import Account
from r2.models.token import (
OAuth2Client, OAuth2AuthorizationCode, OAuth2AccessToken,
View
4 r2/r2/controllers/post.py
@@ -21,15 +21,13 @@
###############################################################################
from r2.lib.pages import *
-from reddit_base import cross_domain
from api import ApiController
-from r2.lib.utils import Storage, query_string, UrlParser
+from r2.lib.utils import query_string, UrlParser
from r2.lib.emailer import opt_in, opt_out
from r2.lib.validator import *
from pylons import request, c, g
from pylons.i18n import _
from r2.models import *
-import hashlib
class PostController(ApiController):
def set_options(self, all_langs, pref_lang, **kw):
View
2  r2/r2/controllers/promotecontroller.py
@@ -22,7 +22,6 @@
from datetime import datetime, timedelta
from babel.numbers import format_number
-import json
import urllib
from pylons import c, g, request
@@ -70,7 +69,6 @@
VDate,
VDateRange,
VExistingUname,
- VFloat,
VImageType,
VInt,
VLength,
View
4 r2/r2/controllers/reddit_base.py
@@ -31,7 +31,6 @@
from copy import copy
from datetime import datetime, timedelta
from functools import wraps
-from hashlib import sha1
from urllib import quote, unquote
from urlparse import urlparse
@@ -58,7 +57,7 @@
from r2.lib.filters import _force_utf8, _force_unicode
from r2.lib.strings import strings
from r2.lib.template_helpers import add_sr, JSPreload
-from r2.lib.tracking import encrypt, decrypt
+from r2.lib.tracking import decrypt
from r2.lib.translation import set_lang
from r2.lib.utils import (
Enum,
@@ -545,7 +544,6 @@ def set_cnameframe():
c.authorized_cname = request.environ.get('authorized_cname', False)
def set_colors():
- theme_rx = re.compile(r'')
color_rx = re.compile(r'\A([a-fA-F0-9]){3}(([a-fA-F0-9]){3})?\Z')
c.theme = None
if color_rx.match(request.GET.get('bgcolor') or ''):
View
1  r2/r2/controllers/toolbar.py
@@ -26,7 +26,6 @@
from r2.lib.pages.things import wrap_links
from r2.lib.menus import CommentSortMenu
from r2.lib.filters import spaceCompress, safemarkdown
-from r2.lib.memoize import memoize
from r2.lib.template_helpers import add_sr
from r2.lib import utils
from r2.lib.validator import *
View
1  r2/r2/controllers/web.py
@@ -21,7 +21,6 @@
###############################################################################
from pylons import g, c, request
-from pylons.i18n import _
from r2.controllers.reddit_base import RedditController, abort_with_error
from r2.lib.base import abort
View
6 r2/r2/controllers/wiki.py
@@ -27,7 +27,6 @@
from reddit_base import paginated_listing
from r2.models.wiki import (WikiPage, WikiRevision, ContentLengthError,
modactions)
-from r2.models.subreddit import Subreddit
from r2.models.modaction import ModAction
from r2.models.builder import WikiRevisionBuilder, WikiRecentRevisionBuilder
@@ -44,7 +43,6 @@
VModhash,
VOneOf,
VPrintable,
- VRatelimit,
)
from r2.lib.validator.wiki import (
@@ -64,15 +62,13 @@
from r2.config.extensions import set_extension
from r2.lib.template_helpers import add_sr
-from r2.lib.db import tdb_cassandra
from r2.models.listing import WikiRevisionListing
from r2.lib.pages.things import default_thing_wrapper
from r2.lib.pages import BoringPage
from reddit_base import base_listing
-from r2.models import IDBuilder, LinkListing, DefaultSR
+from r2.models import LinkListing, DefaultSR
from r2.lib.merge import ConflictException, make_htmldiff
from pylons.i18n import _
-from r2.lib.pages import PaneStack
from r2.lib.utils import timesince
from r2.config import extensions
from r2.lib.base import abort
Something went wrong with that request. Please try again.