Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5d8764c8ec
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (38 sloc) 1.714 kb
#!/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:
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.redirect('/static/img/avatar_' + str(size) + '.png')
class NodeAvatarHandler(webapp.RequestHandler):
def get(self, node_num, size):
avatar = GetKindByName('Avatar', 'node_' + str(node_num) + '_' + str(size))
if avatar:
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),
('/navatar/([0-9]+)/(large|normal|mini)', NodeAvatarHandler)
],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
Jump to Line
Something went wrong with that request. Please try again.