mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-31 09:48:01 -05:00
Allow VByName from cassandra.
This commit is contained in:
@@ -433,12 +433,12 @@ def ratelimit_throttled():
|
||||
abort(503, 'service temporarily unavailable')
|
||||
|
||||
|
||||
def paginated_listing(default_page_size=25, max_page_size=100):
|
||||
def paginated_listing(default_page_size=25, max_page_size=100, backend='sql'):
|
||||
def decorator(fn):
|
||||
@validate(num=VLimit('limit', default=default_page_size,
|
||||
max_limit=max_page_size),
|
||||
after=VByName('after'),
|
||||
before=VByName('before'),
|
||||
after=VByName('after', backend=backend),
|
||||
before=VByName('before', backend=backend),
|
||||
count=VCount('count'),
|
||||
target=VTarget("target"),
|
||||
show=VLength('show', 3))
|
||||
@@ -468,6 +468,9 @@ def paginated_listing(default_page_size=25, max_page_size=100):
|
||||
def base_listing(fn):
|
||||
return paginated_listing()(fn)
|
||||
|
||||
def base_cassandra_listing(fn):
|
||||
return paginated_listing(backend='cassandra')(fn)
|
||||
|
||||
def is_trusted_origin(origin):
|
||||
try:
|
||||
origin = urlparse(origin)
|
||||
@@ -879,4 +882,3 @@ class RedditController(MinimalController):
|
||||
request.environ['retry_after'] = 60
|
||||
|
||||
abort(503)
|
||||
|
||||
|
||||
@@ -529,25 +529,38 @@ def fullname_regex(thing_cls = None, multiple = False):
|
||||
return re.compile(r"\A" + pattern + r"\Z")
|
||||
|
||||
class VByName(Validator):
|
||||
# Lookup tdb_sql.Thing or tdb_cassandra.Thing objects by fullname.
|
||||
splitter = re.compile('[ ,]+')
|
||||
def __init__(self, param, thing_cls = None, multiple = False,
|
||||
error = errors.NO_THING_ID, **kw):
|
||||
error = errors.NO_THING_ID, backend='sql', **kw):
|
||||
self.re = fullname_regex(thing_cls)
|
||||
self.multiple = multiple
|
||||
self._error = error
|
||||
|
||||
self.backend = backend
|
||||
|
||||
Validator.__init__(self, param, **kw)
|
||||
|
||||
def run(self, items):
|
||||
if items and self.multiple:
|
||||
items = [item for item in self.splitter.split(items)
|
||||
if item and self.re.match(item)]
|
||||
if items and (self.multiple or self.re.match(items)):
|
||||
try:
|
||||
return Thing._by_fullname(items, return_dict = False,
|
||||
data=True)
|
||||
except NotFound:
|
||||
pass
|
||||
if self.backend == 'cassandra':
|
||||
# tdb_cassandra.Thing objects can't use the regex
|
||||
if items and self.multiple:
|
||||
items = [item for item in self.splitter.split(items)]
|
||||
if items:
|
||||
try:
|
||||
return tdb_cassandra.Thing._by_fullname(items, return_dict=False)
|
||||
except NotFound:
|
||||
pass
|
||||
else:
|
||||
if items and self.multiple:
|
||||
items = [item for item in self.splitter.split(items)
|
||||
if item and self.re.match(item)]
|
||||
if items and (self.multiple or self.re.match(items)):
|
||||
try:
|
||||
return Thing._by_fullname(items, return_dict=False,
|
||||
data=True)
|
||||
except NotFound:
|
||||
pass
|
||||
|
||||
return self.set_error(self._error)
|
||||
|
||||
class VByNameIfAuthor(VByName):
|
||||
|
||||
Reference in New Issue
Block a user