forked from livid/v2ex-gae
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathavatar.py
34 lines (27 loc) · 1.07 KB
/
avatar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
# coding=utf-8
from google.appengine.ext import webapp
from google.appengine.api import memcache
from google.appengine.ext import db
from google.appengine.ext.webapp import util
from v2ex.babel import Avatar
from v2ex.babel.security import *
from v2ex.babel.da import *
class AvatarHandler(webapp.RequestHandler):
def get(self, member_num, size):
avatar = GetKindByName('Avatar', 'avatar_' + str(member_num) + '_' + str(size))
if avatar is not None:
self.response.headers['Content-Type'] = "image/png"
self.response.headers['Cache-Control'] = "max-age=172800, public, must-revalidate"
self.response.headers['Expires'] = "Sun, 25 Apr 2011 20:00:00 GMT"
self.response.out.write(avatar.content)
else:
self.error(404)
def main():
application = webapp.WSGIApplication([
('/avatar/([0-9]+)/(large|normal|mini)', AvatarHandler)
],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()