Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from urllib import quote
  4.  
  5. import tornado.gen
  6.  
  7. from pilbox.app import PilboxApplication, ImageHandler, main
  8.  
  9.  
  10. class CustomApplication(PilboxApplication):
  11. def get_handlers(self):
  12. return [(r"/(\d+)x(\d+)/(.+)", CustomImageHandler)]
  13.  
  14.  
  15. class CustomImageHandler(ImageHandler):
  16. def prepare(self):
  17. self.args = self.request.arguments.copy()
  18.  
  19. @tornado.gen.coroutine
  20. def get(self, w, h, url):
  21. self.args.update(dict(w=w, h=h, url=quote(url, ':/?=&')))
  22.  
  23. self.validate_request()
  24. resp = yield self.fetch_image()
  25. self.render_image(resp)
  26.  
  27. def get_argument(self, name, default=None):
  28. return self.args.get(name, default)
  29.  
  30.  
  31. if __name__ == "__main__":
  32. main(app=CustomApplication())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement