#!/usr/bin/python
import logging
+import os
+import random
import tornado.web
from handlers_base import *
def stasy(self):
return backend.Stasy()
+ def get_error_html(self, status_code, **kwargs):
+ """
+ Select a random image from the errors directory
+ and return the content.
+ """
+ self.set_header("Content-Type", "image/png")
+
+ template_path = self.application.settings.get("template_path", "")
+ template_path = os.path.join(template_path, "i-use", "errors")
+
+ images = os.listdir(template_path)
+ if images:
+ image = random.choice(images)
+ image = os.path.join(template_path, image)
+
+ with open(image, "rb") as f:
+ return f.read()
+
def get(self, profile_id, image_id):
image = None
# Try to get the image from memcache. If we have a cache miss we