本文整理汇总了Python中pylons.Response类的典型用法代码示例。如果您正苦于以下问题:Python Response类的具体用法?Python Response怎么用?Python Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: no_lang
def no_lang(self):
resp = Response()
set_lang(None)
resp.write(_("No language"))
set_lang([])
resp.write(_("No languages"))
return resp
开发者ID:scbarber,项目名称:horriblepoems,代码行数:7,代码来源:controller_sample.py
示例2: __call__
def __call__(self, environ, start_response):
cl_key = "CONTENT_LENGTH"
if environ["REQUEST_METHOD"] == "POST":
if (cl_key not in environ) or int(environ[cl_key]) > self.max_size:
r = Response()
r.status_code = 500
r.content = '<html><head></head><body><script type="text/javascript">parent.too_big();</script>request too big</body></html>'
return r(environ, start_response)
return self.app(environ, start_response)
开发者ID:Julian,项目名称:reddit,代码行数:10,代码来源:middleware.py
示例3: __call__
def __call__(self, environ, start_response):
cl_key = 'CONTENT_LENGTH'
if environ['REQUEST_METHOD'] == 'POST':
if cl_key not in environ:
r = Response()
r.status_code = 411
r.content = '<html><head></head><body>length required</body></html>'
return r(environ, start_response)
try:
cl_int = int(environ[cl_key])
except ValueError:
r = Response()
r.status_code = 400
r.content = '<html><head></head><body>bad request</body></html>'
return r(environ, start_response)
if cl_int > self.max_size:
from r2.lib.strings import string_dict
error_msg = string_dict['css_validator_messages']['max_size'] % dict(max_size = self.max_size/1024)
r = Response()
r.status_code = 413
r.content = ("<html>"
"<head>"
"<script type='text/javascript'>"
"parent.completedUploadImage('failed',"
"'',"
"'',"
"[['BAD_CSS_NAME', ''], ['IMAGE_ERROR', '", error_msg,"']],"
"'image-upload');"
"</script></head><body>you shouldn\'t be here</body></html>")
return r(environ, start_response)
return self.app(environ, start_response)
开发者ID:barneyfoxuk,项目名称:reddit,代码行数:34,代码来源:middleware.py
示例4: __call__
def __call__(self, environ, start_response):
g = config["pylons.g"]
http_host = environ.get("HTTP_HOST", "localhost").lower()
domain, s, port = http_host.partition(":")
# remember the port
try:
environ["request_port"] = int(port)
except ValueError:
pass
# localhost is exempt so paster run/shell will work
# media_domain doesn't need special processing since it's just ads
if domain == "localhost" or is_subdomain(domain, g.media_domain):
return self.app(environ, start_response)
# tell reddit_base to redirect to the appropriate subreddit for
# a legacy CNAME
if not is_subdomain(domain, g.domain):
environ["legacy-cname"] = domain
return self.app(environ, start_response)
# figure out what subdomain we're on if any
subdomains = domain[: -len(g.domain) - 1].split(".")
extension_subdomains = dict(m="mobile", i="compact", api="api", rss="rss", xml="xml", json="json")
sr_redirect = None
for subdomain in subdomains[:]:
if subdomain in g.reserved_subdomains:
continue
extension = extension_subdomains.get(subdomain)
if extension:
environ["reddit-domain-extension"] = extension
elif self.lang_re.match(subdomain):
environ["reddit-prefer-lang"] = subdomain
environ["reddit-domain-prefix"] = subdomain
else:
sr_redirect = subdomain
subdomains.remove(subdomain)
# if there was a subreddit subdomain, redirect
if sr_redirect and environ.get("FULLPATH"):
r = Response()
if not subdomains and g.domain_prefix:
subdomains.append(g.domain_prefix)
subdomains.append(g.domain)
redir = "%s/r/%s/%s" % (".".join(subdomains), sr_redirect, environ["FULLPATH"])
redir = "http://" + redir.replace("//", "/")
r.status_code = 301
r.headers["location"] = redir
r.content = ""
return r(environ, start_response)
return self.app(environ, start_response)
开发者ID:jorik041,项目名称:reddit,代码行数:55,代码来源:middleware.py
示例5: filter
def filter(self, execution_func, prof_arg = None):
# put thie imports here so the app doesn't choke if profiling
# is not present (this is a debug-only feature anyway)
import cProfile as profile
from pstats import Stats
from r2.lib.contrib import gprof2dot
# profiling needs an actual file to dump to. Everything else
# can be mitigated with streams
tmpfile = tempfile.NamedTemporaryFile()
dotfile = StringIO()
# simple cutoff validation
try:
cutoff = .01 if prof_arg is None else float(prof_arg)/100
except ValueError:
cutoff = .01
try:
# profile the code in the current context
profile.runctx('execution_func()',
globals(), locals(), tmpfile.name)
# parse the data
parser = gprof2dot.PstatsParser(tmpfile.name)
prof = parser.parse()
# remove nodes and edges with less than cutoff work
prof.prune(cutoff, cutoff)
# make the dotfile
dot = gprof2dot.DotWriter(dotfile)
dot.graph(prof, gprof2dot.TEMPERATURE_COLORMAP)
# convert the dotfile to PNG in local stdout
proc = subprocess.Popen("dot -Tpng",
shell = True,
stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, error = proc.communicate(input = dotfile.getvalue())
# generate the response
r = Response()
r.status_code = 200
r.headers['content-type'] = "image/png"
r.content = out
return r
finally:
tmpfile.close()
开发者ID:JediWatchman,项目名称:reddit,代码行数:42,代码来源:middleware.py
示例6: __call__
def __call__(self, environ, start_response):
# get base domain as defined in INI file
base_domain = config['global_conf']['domain']
sub_domains = environ['HTTP_HOST']
if not sub_domains.endswith(base_domain):
#if the domain doesn't end with base_domain, don't do anything
return self.app(environ, start_response)
sub_domains = sub_domains[:-len(base_domain)].strip('.')
sub_domains = sub_domains.split('.')
sr_redirect = None
for sd in list(sub_domains):
# subdomains to disregard completely
if sd in ('www', 'origin', 'beta'):
continue
# subdomains which change the extension
elif sd == 'm':
environ['reddit-domain-extension'] = 'mobile'
elif sd in ('api', 'rss', 'xml', 'json'):
environ['reddit-domain-extension'] = sd
elif (len(sd) == 2 or (len(sd) == 5 and sd[2] == '-')) and self.lang_re.match(sd):
environ['reddit-prefer-lang'] = sd
else:
sr_redirect = sd
sub_domains.remove(sd)
if sr_redirect and environ.get("FULLPATH"):
r = Response()
sub_domains.append(base_domain)
redir = "%s/r/%s/%s" % ('.'.join(sub_domains),
sr_redirect, environ['FULLPATH'])
redir = "http://" + redir.replace('//', '/')
r.status_code = 301
r.headers['location'] = redir
r.content = ""
return r(environ, start_response)
return self.app(environ, start_response)
开发者ID:cmak,项目名称:reddit,代码行数:40,代码来源:middleware.py
示例7: __call__
def __call__(self, environ, start_response):
cl_key = 'CONTENT_LENGTH'
if environ['REQUEST_METHOD'] == 'POST':
if cl_key not in environ:
r = Response()
r.status_code = 411
r.content = '<html><head></head><body>length required</body></html>'
return r(environ, start_response)
try:
cl_int = int(environ[cl_key])
except ValueError:
r = Response()
r.status_code = 400
r.content = '<html><head></head><body>bad request</body></html>'
return r(environ, start_response)
if cl_int > self.max_size:
r = Response()
r.status_code = 413
r.content = '<html><head></head><body><script type="text/javascript">parent.too_big();</script>request entity too large</body></html>'
return r(environ, start_response)
return self.app(environ, start_response)
开发者ID:3river,项目名称:reddit,代码行数:24,代码来源:middleware.py
示例8: __call__
def __call__(self, environ, start_response):
# get base domain as defined in INI file
base_domain = config['global_conf']['domain']
try:
sub_domains, request_port = environ['HTTP_HOST'].split(':')
environ['request_port'] = int(request_port)
except ValueError:
sub_domains = environ['HTTP_HOST'].split(':')[0]
except KeyError:
sub_domains = "localhost"
#If the domain doesn't end with base_domain, assume
#this is a cname, and redirect to the frame controller.
#Ignore localhost so paster shell still works.
#If this is an error, don't redirect
if (not sub_domains.endswith(base_domain)
and (not sub_domains == 'localhost')):
environ['sub_domain'] = sub_domains
if not environ.get('extension'):
if environ['PATH_INFO'].startswith('/frame'):
return self.app(environ, start_response)
elif self.is_auth_cname(sub_domains):
environ['frameless_cname'] = True
environ['authorized_cname'] = True
elif ("redditSession=cname" in environ.get('HTTP_COOKIE', '')
and environ['REQUEST_METHOD'] != 'POST'
and not environ['PATH_INFO'].startswith('/error')):
environ['original_path'] = environ['PATH_INFO']
environ['FULLPATH'] = environ['PATH_INFO'] = '/frame'
else:
environ['frameless_cname'] = True
return self.app(environ, start_response)
sub_domains = sub_domains[:-len(base_domain)].strip('.')
sub_domains = sub_domains.split('.')
sr_redirect = None
for sd in list(sub_domains):
# subdomains to disregard completely
if sd in ('www', 'origin', 'beta', 'pay'):
continue
# subdomains which change the extension
elif sd == 'm':
environ['reddit-domain-extension'] = 'mobile'
elif sd == 'I':
environ['reddit-domain-extension'] = 'compact'
elif sd == 'i':
environ['reddit-domain-extension'] = 'compact'
elif sd in ('api', 'rss', 'xml', 'json'):
environ['reddit-domain-extension'] = sd
elif (len(sd) == 2 or (len(sd) == 5 and sd[2] == '-')) and self.lang_re.match(sd):
environ['reddit-prefer-lang'] = sd
environ['reddit-domain-prefix'] = sd
else:
sr_redirect = sd
sub_domains.remove(sd)
if sr_redirect and environ.get("FULLPATH"):
r = Response()
sub_domains.append(base_domain)
redir = "%s/r/%s/%s" % ('.'.join(sub_domains),
sr_redirect, environ['FULLPATH'])
redir = "http://" + redir.replace('//', '/')
r.status_code = 301
r.headers['location'] = redir
r.content = ""
return r(environ, start_response)
return self.app(environ, start_response)
开发者ID:JediWatchman,项目名称:reddit,代码行数:69,代码来源:middleware.py
注:本文中的pylons.Response类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论