Пример #1
0
 def post(self,action):
     request = self.get_django_request()
     if action == "weblink":
         self.action = action
         self.links = json.loads( self.request.body )
         self.data = {}
         if len(self.links)>=1:
             http = tornado.httpclient.AsyncHTTPClient()
             http.fetch(self.links[0],callback=self.on_response)
         else:
             self.finish({"status":"failed","reason":"invalid request syntax"})
     elif action == "upload":
         self.finish(api_class.image(request,action))
     elif action == "delete":
         self.finish(api_class.image(request,action))
Пример #2
0
 def post(self, action):
     request = self.get_django_request()
     if action == "weblink":
         self.action = action
         self.links = json.loads(self.request.body)
         self.data = {}
         if len(self.links) >= 1:
             http = tornado.httpclient.AsyncHTTPClient()
             http.fetch(self.links[0], callback=self.on_response)
         else:
             self.finish({
                 "status": "failed",
                 "reason": "invalid request syntax"
             })
     elif action == "upload":
         self.finish(api_class.image(request, action))
     elif action == "delete":
         self.finish(api_class.image(request, action))
Пример #3
0
 def on_response(self, response):
     '''recursively fetch the links, finally finish'''
     if response.error:
         self.data[self.links[0]] = None
     else:
         self.data[self.links[0]] = response.body
     self.links = self.links[1:]
     if len(self.links) >= 1:
         http = tornado.httpclient.AsyncHTTPClient()
         http.fetch(self.links[0], callback=self.on_response)
     else:
         request = self.get_django_request()
         response = api_class.image(request, self.action, self.data)
         self.finish(response)
Пример #4
0
 def on_response(self,response):
     '''recursively fetch the links, finally finish'''
     if response.error:
         self.data[self.links[0]] = None
     else:
         self.data[self.links[0]] = response.body
     self.links = self.links[1:]
     if len(self.links)>=1:
         http = tornado.httpclient.AsyncHTTPClient()
         http.fetch(self.links[0],callback=self.on_response)
     else:
         request = self.get_django_request()
         response = api_class.image(request,self.action,self.data)
         self.finish(response)