text
stringlengths
0
828
if isinstance(var, list):
out = var
else:
out = [var]
elif new_type == 'str': # return str
if isinstance(var, list):
try:
out = ""%s"" % var[0]
except:
out = """"
elif isinstance(var, str):
out = var
else:
out = ""%s"" % var
elif new_type == 'int': # return int
if isinstance(var, list):
try:
out = int(var[0])
except:
out = 0
elif isinstance(var, (int, long)):
out = var
elif isinstance(var, str):
try:
out = int(var)
except:
out = 0
else:
out = 0
elif new_type == 'tuple': # return tuple
if isinstance(var, tuple):
out = var
else:
out = (var, )
elif new_type == 'dict': # return dictionary
if isinstance(var, dict):
out = var
else:
out = {0: var}
return out"
4731,"def is_local_url(target):
""""""Determine if URL is a local.""""""
ref_url = urlparse(cfg.get('CFG_SITE_SECURE_URL'))
test_url = urlparse(urljoin(cfg.get('CFG_SITE_SECURE_URL'), target))
return test_url.scheme in ('http', 'https') and \
ref_url.netloc == test_url.netloc"
4732,"def get_safe_redirect_target(arg='next'):
""""""Get URL to redirect to and ensure that it is local.""""""
for target in request.args.get(arg), request.referrer:
if not target:
continue
if is_local_url(target):
return target
return None"
4733,"def redirect_to_url(req, url, redirection_type=None, norobot=False):
""""""
Redirect current page to url.
@param req: request as received from apache
@param url: url to redirect to
@param redirection_type: what kind of redirection is required:
e.g.: apache.HTTP_MULTIPLE_CHOICES = 300
apache.HTTP_MOVED_PERMANENTLY = 301
apache.HTTP_MOVED_TEMPORARILY = 302
apache.HTTP_SEE_OTHER = 303
apache.HTTP_NOT_MODIFIED = 304
apache.HTTP_USE_PROXY = 305
apache.HTTP_TEMPORARY_REDIRECT = 307
The default is apache.HTTP_MOVED_TEMPORARILY
@param norobot: wether to instruct crawlers and robots such as GoogleBot
not to index past this point.
@see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
""""""
url = url.strip()
if redirection_type is None:
redirection_type = apache.HTTP_MOVED_TEMPORARILY
from flask import redirect
r = redirect(url, code=redirection_type)
raise apache.SERVER_RETURN(r)
# FIXME enable code bellow
del req.headers_out[""Cache-Control""]
req.headers_out[""Cache-Control""] = ""no-cache, private, no-store, "" \
""must-revalidate, post-check=0, pre-check=0, max-age=0""
req.headers_out[""Pragma""] = ""no-cache""
if norobot:
req.headers_out[
""X-Robots-Tag""] = ""noarchive, nosnippet, noindex, nocache""
user_agent = req.headers_in.get('User-Agent', '')
if 'Microsoft Office Existence Discovery' in user_agent or 'ms-office' in user_agent:
# HACK: this is to workaround Microsoft Office trying to be smart
# when users click on URLs in Office documents that require
# authentication. Office will check the validity of the URL
# but will pass the browser the redirected URL rather than
# the original one. This is incompatible with e.g. Shibboleth
# based SSO since the referer would be lost.
# See: http://support.microsoft.com/kb/899927
req.status = 200