本文整理汇总了Python中session.Session.access方法的典型用法代码示例。如果您正苦于以下问题:Python Session.access方法的具体用法?Python Session.access怎么用?Python Session.access使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.access方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import access [as 别名]
def post(self):
f = self.request.files[u'files[]'][0]
# limit upload file size
filesize = len(f['body'])
if filesize > (options.maxupload * 1024):
self.send_error()
return
# check file extension
iname, iext = os.path.splitext(f['filename'])
if iext == "" or iext.lower() not in ['.png', '.jpg', '.jpeg', '.tiff', '.tif', '.gif']:
self.send_error({ 'name' : filename, 'size' : size, 'success' : False })
return
# obtain a random file name
filename = rand_string() + iext
# save file to user session
sid = self.get_secure_cookie('session')
session = None
if sid:
session = Session(sessionStore, sessionid = sid)
else:
session = Session(sessionStore)
# store updated upload list to redis
session.access(self.request.remote_ip)
uploaded = session.uploaded()
uploaded.append(filename)
session.setUploaded(uploaded)
print session.fetch('uploaded')
# resize to a thumbnail then save to disk
upload_path = file_path("static/uploads/") + filename
save_thumbnail(f['body'], upload_path)
resp = {
'success' : True,
'name' : filename,
'size' : filesize,
'url' : '/static/uploads/' + filename,
'thunmnail_url' : '/static/uploads/' + filename,
'delete_url' : '',
'delete_type' : 'DELETE',
}
self.finish(resp)