本文整理汇总了Python中pyramid.response.Response.body_file方法的典型用法代码示例。如果您正苦于以下问题:Python Response.body_file方法的具体用法?Python Response.body_file怎么用?Python Response.body_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.body_file方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: thumbnail
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def thumbnail(request):
matchdict = request.matchdict
photo_album_id = matchdict['photo_album_id']
photo_id = matchdict['photo_id']
photo_album = models.PhotoAlbum.objects.with_id(photo_album_id)
photo = photo_album.get_photo(photo_id)
extension = photo.image.filename[photo.image.filename.rfind('.')+1:]
if photo.image.thumbnail:
image = photo.image.thumbnail
response = Response()
if extension.lower() in ['jpg', 'jpeg']:
response.content_type='image/jpeg'
elif extension.lower() in ['png']:
response.content_type='image/png'
img = Image.open(image)
img_format = img.format
if photo.orientation == 'vertical':
img = img.transpose(Image.ROTATE_90)
tmp_img = tempfile.TemporaryFile()
img.save(tmp_img, format=img_format)
tmp_img.seek(0)
response.body_file = tmp_img
return response
示例2: __call__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def __call__(self):
response = Response()
response.content_disposition = 'attachment; filename="{}"'.format(self.context.filename)
response.charset = 'utf-8'
response.content_type = self.context.content_type
response.body_file = self.context.content.open()
response.content_length = self.context.size
return response
示例3: retrieve_list
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def retrieve_list(req):
params = _parse_retrieve_params(req)
headers = {
'Content-Type': 'application/json',
}
resp = requests.get(_get_db_uri(req.db, params),
stream=True, params=params)
r = Response(headers=headers)
r.body_file = resp.raw
return r
示例4: account_photo_get
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def account_photo_get(self):
if self.user is None or self.user.photo.get() is None:
response = Response(content_type='image/png')
response.app_iter = open('myproject/static/images/unknown.png', 'rb')
else:
content_type = self.user.photo.content_type.encode('ascii')
response = Response(content_type=content_type)
response.body_file = self.user.photo
return response
示例5: zip
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def zip(context, request):
temp = tempfile.mkdtemp()
filename = '%s/%s' % (temp,'buildout.zip')
with zipfile.ZipFile(filename, 'w') as buildout:
for bfile in context.keys():
buildout.writestr(bfile.encode('utf-8'), context[bfile].data.encode('utf-8'))
response = Response()
zipped_file = open(filename, 'r')
response.body_file = zipped_file
response.content_type = 'application/zip'
response.content_disposition = "attachment; filename=buildout.zip"
return response
示例6: __call__
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def __call__(self):
check_update = True if self.request.GET.get('check_update', 'true') == 'true' else False
package = self.context.__parent__.__parent__
last_remote_version = Package.get_last_remote_version(self.proxy, package.name)
if check_update:
if not package.repository_is_up_to_date(last_remote_version):
return not_found(self.request)
response = Response()
response.content_disposition = 'attachment; filename="{}"'.format(self.context.filename)
response.charset = 'utf-8'
response.content_type = self.context.content_type
response.body_file = self.context.content.open()
return response
示例7: file_storage
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def file_storage(request):
id = request.matchdict['id']
try:
f = fs_files.get(id)
content_type = f.content_type.encode('ascii')
response = Response(content_type=content_type)
response.body_file = f
response.headers["Content-disposition"] = "filename=" + f.name.encode('euc-kr')
except:
response = Response(content_type='image/png')
response.app_iter = open('myproject/static/images/not_found.png', 'rb')
return response
示例8: image_fullsize
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def image_fullsize(request):
id = request.matchdict['id']
try:
image = fs_images.get(id)
content_type = image.content_type.encode('ascii')
response = Response(content_type=content_type)
response.body_file = image
response.headers["Content-disposition"] = "filename=" + image.name.encode('euc-kr')
except:
response = Response(content_type='image/png')
response.app_iter = open('myproject/static/images/no_image.png', 'rb')
return response
示例9: export
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def export(request):
from pyramid.response import Response
from pyramid.httpexceptions import HTTPServerError
from subprocess import Popen, PIPE
import os.path
import datetime
response = Response(
content_type='application/zip',
)
if not os.path.isdir('.git'):
raise HTTPServerError('not a git directory')
try:
proc = Popen(
[
'git',
'describe',
'--always',
],
stdout=PIPE)
rev = proc.stdout.read().strip()
proc = Popen(
[
'git',
'archive',
'--format=zip',
'--prefix=oscad/',
'-9',
'HEAD',
],
stdout=PIPE)
except OSError as e:
raise HTTPServerError(e)
time = datetime.datetime.now().replace(microsecond=0)
filename = 'oscad-{}-git-{}.zip'.format(
time.isoformat(),
rev
)
response.content_disposition = 'attachment; filename="{}"'.format(filename)
response.body_file = proc.stdout
return response
示例10: view
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def view(request):
matchdict = request.matchdict
photo_album_id = matchdict['photo_album_id']
photo_id = matchdict['photo_id']
photo_album = models.PhotoAlbum.objects.with_id(photo_album_id)
image = photo_album.get_photo(photo_id).image
response = Response()
extension = image.filename[image.filename.rfind('.')+1:]
if extension.lower() in ['jpg', 'jpeg']:
response.content_type='image/jpeg'
elif extension.lower() in ['png']:
response.content_type='image/png'
response.body_file = image
return response
示例11: image_thumbnail
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import body_file [as 别名]
def image_thumbnail(request):
id = request.matchdict['id']
image = fs_images.get(id)
#generate thumbnail in memory
img = Image.open(image)
if img.size[0] > THUMBNAIL_WIDTH:
w, h = THUMBNAIL_WIDTH, (THUMBNAIL_WIDTH * img.size[1]) / img.size[0]
else:
w, h = img.size
thumbnail = img.copy()
thumbnail.thumbnail((w, h), Image.ANTIALIAS)
io = StringIO()
thumbnail.save(io, img.format)
io.seek(0)
content_type = image.content_type.encode('ascii')
response = Response(content_type=content_type)
response.body_file = io
response.headers["Content-disposition"] = "filename=" + image.name.encode('euc-kr')
return response