本文整理汇总了Python中pyramid.response.Response.cache_expires方法的典型用法代码示例。如果您正苦于以下问题:Python Response.cache_expires方法的具体用法?Python Response.cache_expires怎么用?Python Response.cache_expires使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.cache_expires方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SendFile
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def SendFile(self, file):
"""
Creates the response and sends the file back. Uses the FileIterator.
#!date format
"""
if not file:
return HTTPNotFound()
last_mod = file.mtime()
if not last_mod:
last_mod = self.context.meta.pool_change
r = Response(content_type=str(GetMimeTypeExtension(file.extension)), conditional_response=True)
iterator = file.iterator()
if iterator:
r.app_iter = iterator
else:
try:
r.body = file.read()
except FileNotFound:
raise NotFound
r.content_length = file.size
r.last_modified = last_mod
r.etag = '%s-%s' % (last_mod, hash(file.path))
r.cache_expires(self.fileExpires)
return r
示例2: MergeFile
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def MergeFile(req):
def DecreaseLarger(arr, n):
for i in xrange(len(arr)):
if arr[i] > n:
arr[i] -= 1
fname = GetQueryFileName(req.GET)
links = Reference.FileLinks(fname)
try:
n = int(req.GET["n"])
except:
return HTTPBadRequest_Param("n")
try:
o = int(req.GET["o"])
except:
return HTTPBadRequest_Param("o")
for j in links:
if n in j.Depends:
j.Depends.remove(n)
if not o in j.Depends:
j.Depends = sorted(j.Depends + [o])
DecreaseLarger(j.Depends, n)
for i in xrange(n, len(links) - 1):
f = fname + "_" + str(i + 1)
if os.path.exists(f):
os.rename(f, fname + "_" + str(i))
if o > n:
o -= 1
del links.Links[n]
links.Write(fname)
resp = Response('{"removed":[' + str(n) + '],"select":' + str(o) + ',"files":[' + ",".join(['{"name":"' + os.path.split(l.Name)[1] + '","type":' + str(l.Type) + ',"deps":[' + ",".join([test(d < 65535, str(d), "-1") for d in l.Depends]) + ']}' for l in links]) + ']}\r\n', request=req)
resp.cache_expires(0)
return resp
示例3: __call__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def __call__(self):
# # find the filename, css files, and format they wanted
# filename = params['filename'] || 'RegionReport'
# format = params['format'] || 'html'
# css_to_include = (params['css'] && params['css'].split(',')) || []
# grab some params
filename = self.request.params.get('filename', 'RegionReport')
css_inclusions = self.request.params.get('css', '')
css_inclusions = css_inclusions.split(',')
# start our response
response = Response()
# use this to write body content to (better than a giant memory-hogging string)
body = response.body_file
# tell the client this is a downloadable html file
response.content_type='application/octet-stream'
response.content_disposition='attachment; filename="' + filename + '.html"'
response.headers['Content-Desciption'] = 'File Transfer' # unnecessary?
# don't cache this file
response.cache_expires(0) # sets various cache headers
# now start filling out the body
body.write("<html><head>\n")
# add in the css they wanted
for css in css_inclusions:
# skip a blank css file (from splitting a blank string, for example)
if len(css) == 0:
continue
# throw away path in case we're being hacked
css_file = os.path.join(
os.path.dirname(__file__),
'..', 'static', 'css',
# also replace extension with .css coz SECURITAY
os.path.splitext(os.path.basename(css))[0] + '.css'
)
css_content = ''
try:
with file(css_file) as f:
css_content = f.read()
except IOError:
css_content = '/* could not load "' + cgi.escape(css, True) + '" */'
body.write("<style>" + css_content + "</style>\n")
content = self.request.params.get('content', '(no content was supplied)')
content = content.replace(
'<img src="/',
'<img src="' + self.request.route_url('home')
)
body.write("</head><body><div id='report'>\n")
body.write(content)
body.write("\n</div></body></html>\n")
return response
示例4: stream
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def stream(request):
response = Response()
response.headers.update({'Access-Control-Allow-Origin': '*'})
response.content_type = 'text/event-stream'
response.cache_expires(0)
response.app_iter = produce()
return response
示例5: QueryInitStatus
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def QueryInitStatus(req):
try:
f = req.GET["file"]
except:
return HTTPBadRequest_Param("file")
try:
i = int(req.GET["id"])
except:
return HTTPBadRequest_Param("id")
try:
alive = Jobs.QueryStatus(f, i)
resp = Response(str(alive) + "\r\n", request=req)
except HTTPException:
raise
except:
resp = Response("-\r\n", request=req)
resp.cache_expires(0)
return resp
示例6: download_xml
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def download_xml(self):
value = self.context.__data__['form']
response = Response(body=value['data'],
content_type="text/xml")
# set response caching headers..
response.cache_expires = (3600 * 24 * 7)
return response
示例7: _return_file_response
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def _return_file_response(self, value):
blob = value['data']
filename = value['name']
mimeType = "application/octet-stream"
try:
guessed = mimetypes.guess_type(filename, strict=False)[0]
if guessed:
mimeType = guessed
except:
pass
if isinstance(blob, str):
# hmm. no blob image.. (should probably never happen)
response = Response(blob, content_type=mimeType)
etag = len(blob)
elif isinstance(blob, TheBlob):
# Can't use FileResponse like this because file might be zipped
# get file path.. don't know the proper way to do this..
# but open() sort of works..
#opened_file = blob.open_blob('r')
etag = blob._blob._p_mtime
#response = FileResponse(opened_file.name, self.request,
# content_type=mimeType)
response = Response(blob.get(), content_type=mimeType)
elif isinstance(blob, Blob):
# get file path.. don't know the proper way to do this..
# but open() sort of works..
opened_file = blob.open('r')
etag = blob._p_mtime
response = FileResponse(opened_file.name, self.request,
content_type=mimeType)
else:
raise "Not a valid file type"
# set response caching headers..
response.etag = str(etag)
response.cache_expires = (3600 * 24 * 7)
cd = u'attachment; filename="{0}"'.format(value['name'])
response.content_disposition = cd.encode('utf-8')
return response
示例8: Upload
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def Upload(req):
#uploading from a remote server
fs = req.POST.getall("uploadedfiles[]")
if platform.system() == "Windows": # Windows has an extra .file in here for some reason
for f in fs:
if hasattr(f.file, "file"):
f.file = f.file.file
for f in fs:
f.file.seek(0)
#Build the index file
if not os.path.exists(converted):
os.makedirs(converted)
try:
cleanup = req.POST["delete"]
except:
cleanup = 7
(jobid, f) = Jobs.add_job("remote", fs, cleanup * 24 * 60 * 60)
json_response = '{"file":"' + f + '","jobid":' + str(jobid) + '}\r\n'
resp = Response(json_response)
resp.cache_expires(0)
return resp
示例9: _return_file_response
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def _return_file_response(self, value):
blob = value['data']
filename = value['name']
mimeType = "image/png"
try:
guessed = mimetypes.guess_type(filename, strict=False)[0]
if guessed:
mimeType = guessed
except:
pass
if isinstance(blob, str):
# hmm. no blob image.. (should probably never happen)
response = Response(blob, content_type=mimeType)
etag = len(blob)
elif isinstance(blob, TheBlob):
# get file path.. don't know the proper way to do this..
# but open() sort of works..
opened_file = blob.open_blob('r')
etag = blob._blob._p_mtime
response = FileResponse(opened_file.name, self.request,
content_type=mimeType)
elif isinstance(blob, Blob):
# get file path.. don't know the proper way to do this..
# but open() sort of works..
opened_file = blob.open('r')
etag = blob._p_mtime
response = FileResponse(opened_file.name, self.request,
content_type=mimeType)
else:
raise "Not a valid image type"
# set response caching headers..
response.etag = str(etag)
response.cache_expires = (3600 * 24 * 7)
return response
示例10: AddFile
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def AddFile(req):
def DecreaseLarger(arr, n):
for i in xrange(len(arr)):
if arr[i] > n:
arr[i] -= 1
fname = GetQueryFileName(req.GET)
links = Reference.FileLinks(fname)
try:
n = req.GET["n"]
ni = int(n)
except:
return HTTPBadRequest_Param("n")
l = links[ni]
try:
s = req.POST["datas[]"]
except:
try:
s = req.POST["data0"]
except:
try:
s = req.POST["data"]
except:
return HTTPBadRequest_Param("data")
sf = s.file
sf.seek(0)
t = l.Type & 0x7F
if t == Reference.FileType.UNKNOWN:
t = TryGet(req.POST, "type")
if t != None and int(t) != 0:
t = int(t)
else:
t = Reference.GuessType(sf)
if t == Reference.FileType.UNKNOWN:
return HTTPUnsupportedMediaType("File type could not be determined")
sf.seek(0)
sf.seek(0)
t2 = Reference.GetTypeParser(t).ToBinary(sf, fname + "_" + n, s.filename)
l.Name = s.filename
if t2 > t:
t = t2
l.Type = t
same = TryGet(req.POST, "similar")
removed = []
if same != None:
same = [int(m) for m in set(same.split(","))]
for idx in xrange(len(same)):
i = same[idx]
for j in links:
if i in j.Depends:
removed.append(str(i))
j.Depends.remove(i)
if not ni in j.Depends:
j.Depends = list(set(j.Depends + [ni]))
DecreaseLarger(j.Depends, i)
if ni > i:
ni -= 1
n = str(ni)
del links.Links[i]
DecreaseLarger(same, i)
for i in xrange(i, len(links) - 1):
f = fname + "_" + str(i + 1)
if os.path.exists(f):
os.rename(f, fname + "_" + str(i))
new = Reference.LoadChainGroup([[s.filename, sf]], t)
deps_start = len(links)
deps_exists = []
added = []
for f in new:
if f.Stream != sf:
found = False
i = 0
for link in links:
if link.Name == f.Name:
found = True
deps_exists.append(i)
break
i += 1
if not found:
if (f.Type & ~Reference.FileType.MISSING) == Reference.FileType.DATABASE:
links.AddDB(f.Name)
else:
added.append(str(len(links)))
links.Add(f.Name, f.Type, [])
l.Depends = deps_exists + range(deps_start, len(links))
links.Write(fname)
resp = Response('{"added":[' + ",".join(added) + '],"removed":[' + ",".join(removed) + '],"select":' + n + ',"files":[' + ",".join(['{"name":"' + os.path.split(l.Name)[1] + '","type":' + str(l.Type) + ',"deps":[' + ",".join([test(d < 65535, str(d), "-1") for d in l.Depends]) + ']}' for l in links]) + ']}\r\n', request=req)
resp.cache_expires(0)
return resp
示例11: cssview
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def cssview(self):
response = Response(body=css, content_type='text/css')
response.cache_expires = 360
return response
示例12: render
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import cache_expires [as 别名]
def render(self, request):
css= request.cache_region.get_or_create('css', self.get_css)
response = Response(css)
response.content_type = 'text/css'
response.cache_expires(3600 * 24)
return response