From a34e34a854a6f366350d1dabb14e518619a45177 Mon Sep 17 00:00:00 2001 From: sidya82 Date: Fri, 28 Feb 2014 04:01:27 +0100 Subject: [PATCH] =?UTF-8?q?=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20supe?= =?UTF-8?q?rTornado.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- superTornado.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/superTornado.py b/superTornado.py index e6afae5..99cdc12 100644 --- a/superTornado.py +++ b/superTornado.py @@ -4,7 +4,8 @@ import tornado.httpserver import tornado.websocket import tornado.options import base64 -from urllib import urlretrieve +import urllib2 +#from urllib import urlretrieve from tornado.ioloop import PeriodicCallback @@ -75,14 +76,17 @@ class UnauthorizedHandler(BaseHandler): class AJAXHandler(BaseHandler): def post(self): - urlretrieve('http://test:a@192.168.1.15/image.jpg?cidx=791836195', 'image/temp.jpg') - with open("image/temp.jpg", 'rb') as f: - data = f.read() - #self.set_header('Content-type', 'image/jpeg') - encoded = base64.b64encode(data) - print encoded - self.write(encoded) - self.finish() + if not self.current_user : + self.redirect("/") + return + data = urllib2.urlopen('http://test:a@192.168.1.15/image.jpg?cidx=791836195').read() + #urlretrieve('http://test:a@192.168.1.15/image.jpg?cidx=791836195', 'image/temp.jpg') + #with open("image/temp.jpg", 'rb') as f: + #data = f.read() + encoded = base64.b64encode(data) + print encoded + self.write(encoded) + elf.finish()