Convert or-ed startswith()s to tuples elsewhere

This commit is contained in:
Chad Birch
2013-03-12 22:25:21 -06:00
parent 9354da77cd
commit a182078fcd
4 changed files with 4 additions and 7 deletions

View File

@@ -96,7 +96,7 @@ def fetch_url(url, referer = None, retries = 1, dimension = False):
nothing = None if dimension else (None, None)
url = clean_url(url)
#just basic urls
if not (url.startswith('http://') or url.startswith('https://')):
if not url.startswith(('http://', 'https://')):
return nothing
while True:
try:

View File

@@ -378,7 +378,7 @@ def add_sr(path, sr_path = True, nocname=False, force_hostname = False, retain_e
c.cname, c.render_style, c.site.name
"""
# don't do anything if it is just an anchor
if path.startswith('#') or path.startswith('javascript:'):
if path.startswith(('#', 'javascript:')):
return path
u = UrlParser(path)

View File

@@ -251,7 +251,7 @@ def path_component(s):
def get_title(url):
"""Fetches the contents of url and extracts (and utf-8 encodes)
the contents of <title>"""
if not url or not (url.startswith('http://') or url.startswith('https://')):
if not url or not url.startswith(('http://', 'https://')):
return None
try:

View File

@@ -1808,10 +1808,7 @@ class VDestination(Validator):
dest = request.referer or self.default or "/"
ld = dest.lower()
if (ld.startswith("/") or
ld.startswith("http://") or
ld.startswith("https://")):
if ld.startswith(('/', 'http://', 'http://')):
u = UrlParser(dest)
if u.is_reddit_url(c.site):