mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 14:27:58 -05:00
Remove ip_and_slash16 which was causing issues for IPv6.
This commit is contained in:
@@ -39,7 +39,6 @@ from r2.lib.strings import Score
|
||||
from r2.lib import organic
|
||||
import r2.lib.search as search
|
||||
from r2.lib.utils import iters, check_cheating, timeago
|
||||
from r2.lib.utils.trial_utils import populate_spotlight
|
||||
from r2.lib import sup
|
||||
from r2.lib.promote import randomized_promotion_list, get_promote_srid
|
||||
import socket
|
||||
@@ -234,7 +233,6 @@ class HotController(FixListing, ListingController):
|
||||
|
||||
if c.user.pref_show_sponsors or not c.user.gold:
|
||||
spotlight_links, pos = promote.insert_promoted(spotlight_links, pos)
|
||||
trial = populate_spotlight()
|
||||
|
||||
# Need to do this again, because if there was a duplicate removed,
|
||||
# pos might be pointing outside the list.
|
||||
@@ -243,9 +241,6 @@ class HotController(FixListing, ListingController):
|
||||
elif pos != 0:
|
||||
pos = pos % len(spotlight_links)
|
||||
|
||||
if trial:
|
||||
spotlight_links.insert(pos, trial._fullname)
|
||||
|
||||
if not spotlight_links:
|
||||
return None
|
||||
|
||||
@@ -258,24 +253,11 @@ class HotController(FixListing, ListingController):
|
||||
disp_links = [spotlight_links[(i + pos) % num_tl]
|
||||
for i in xrange(-2, left_side)]
|
||||
|
||||
def trial_keep_fn(item):
|
||||
if trial and trial._fullname == item._fullname:
|
||||
return True
|
||||
return organic.keep_fresh_links(item)
|
||||
|
||||
def trial_wrap(item):
|
||||
if item is trial:
|
||||
w = Wrapped(item)
|
||||
w.trial_mode = True
|
||||
w.render_class = LinkOnTrial
|
||||
return w
|
||||
return self.builder_wrapper(item)
|
||||
|
||||
b = IDBuilder(disp_links,
|
||||
wrap = trial_wrap if trial else self.builder_wrapper,
|
||||
wrap = self.builder_wrapper,
|
||||
num = organic.organic_length,
|
||||
skip = True,
|
||||
keep_fn = trial_keep_fn if trial else organic.keep_fresh_links)
|
||||
keep_fn = organic.keep_fresh_links)
|
||||
|
||||
try:
|
||||
vislink = spotlight_links[pos]
|
||||
|
||||
@@ -27,7 +27,7 @@ from pylons.i18n import _
|
||||
from pylons.i18n.translation import LanguageError
|
||||
from r2.lib.base import BaseController, proxyurl
|
||||
from r2.lib import pages, utils, filters, amqp, stats
|
||||
from r2.lib.utils import http_utils, is_subdomain, UniqueIterator, ip_and_slash16
|
||||
from r2.lib.utils import http_utils, is_subdomain, UniqueIterator
|
||||
from r2.lib.cache import LocalCache, make_key, MemcachedError
|
||||
import random as rand
|
||||
from r2.models.account import valid_cookie, FakeAccount, valid_feed, valid_admin_cookie
|
||||
@@ -456,9 +456,8 @@ def throttled(key):
|
||||
return g.cache.get("throttle_" + key)
|
||||
|
||||
def ratelimit_throttled():
|
||||
ip, slash16 = ip_and_slash16(request)
|
||||
|
||||
if throttled(ip) or throttled(slash16):
|
||||
ip = request.ip.strip()
|
||||
if throttled(ip):
|
||||
abort(429)
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
###############################################################################
|
||||
|
||||
from pylons import c, g, request
|
||||
from r2.lib.utils import ip_and_slash16, jury_cache_dict, voir_dire_priv, tup
|
||||
from r2.lib.utils import jury_cache_dict, voir_dire_priv, tup
|
||||
from r2.lib.memoize import memoize
|
||||
from r2.lib.log import log_text
|
||||
import random as rand
|
||||
@@ -165,6 +165,8 @@ def assign_trial(account, juries_already_on, ip, slash16):
|
||||
return None
|
||||
|
||||
def populate_spotlight():
|
||||
raise Exception("this function is broken (re: ip_and_slash16) and pending demolition")
|
||||
|
||||
from r2.models import Jury
|
||||
from r2.lib.db.thing import NotFound
|
||||
|
||||
|
||||
@@ -1123,22 +1123,6 @@ def in_chunks(it, size=25):
|
||||
if chunk:
|
||||
yield chunk
|
||||
|
||||
r_subnet = re.compile("\A(\d+\.\d+)\.\d+\.\d+\Z")
|
||||
def ip_and_slash16(req):
|
||||
ip = req.ip
|
||||
|
||||
if ip is None:
|
||||
raise ValueError("request.ip is None")
|
||||
ip = ip.strip()
|
||||
|
||||
m = r_subnet.match(ip)
|
||||
if m is None:
|
||||
raise ValueError("Couldn't parse IP %s" % ip)
|
||||
|
||||
slash16 = m.group(1) + '.x.x'
|
||||
|
||||
return (ip, slash16)
|
||||
|
||||
def spaceout(items, targetseconds,
|
||||
minsleep = 0, die = False,
|
||||
estimate = None):
|
||||
|
||||
Reference in New Issue
Block a user