Commits

Ginés Martínez Sánchez committed cab7fc0 Draft

clarifying when use derived Webob Response

Comments (0)

Files changed (5)

ginsfsm/protocols/sockjs/server/basehandler.py

         self.request = request
         super(BaseHandler, self).__init__()
         self.ginsfsm_channel = None
-
-    def set_response(self, response):
-        """ response can be request.response for static urls
-            or self for sessioned urls.
-        """
-        self.response = response
-        return response
+        self.response = self
 
     # Various helpers
     def set_header(self, name, value):
     def set_body(self, body):
         self.response.body = body
 
-    def add_body(self, chunk):
-        self.response.body_file.write(chunk)
-
     def enable_cache(self):
         """Enable client-side caching for the current request"""
         d = datetime.now() + timedelta(seconds=CACHE_TIME)
 
     def options(self, *args, **kwargs):
         """XHR cross-domain OPTIONS handler"""
-        response = self.set_response(self.request.response)
+        #response = self.set_response(self.request.response)
+        response = self.response = self.request.response
+        # we override __call__ of self in XhrStreamingTransport!!
+
         self.enable_cache()
         self.handle_session_cookie()
         self.preflight()

ginsfsm/protocols/sockjs/server/c_sockjs_server.py

 class GreetingsHandler(BaseHandler):
     """SockJS greetings page handler"""
     def get(self):
-        response = self.set_response(self.request.response)
+        #response = self.set_response(self.request.response)
+        response = self
         self.enable_cache()
         response.content_type = 'text/plain'
         response.charset = 'UTF-8'

ginsfsm/protocols/sockjs/server/static.py

         self.access_methods = 'OPTIONS, GET'
 
     def get(self):
-        response = self.set_response(self.request.response)
+        #response = self.set_response(self.request.response)
+        response = self
         response.content_type = 'application/json'
         response.charset = 'UTF-8'
         self.preflight()
 class IFrameHandler(BaseHandler):
     """SockJS IFrame page handler"""
     def get(self):
-        response = self.set_response(self.request.response)
+        #response = self.set_response(self.request.response)
+        response = self
         data = IFRAME_TEXT % self.context.sockjs_server.sockjs_url
         hsh = hashlib.md5(data).hexdigest()
 

ginsfsm/protocols/sockjs/server/transports/xhr.py

     name = 'xhr'
 
     def post(self):
-        response = self.set_response(self.request.response)
+        #response = self.set_response(self.request.response)
+        #response = self.set_response(self)  # Response is self.
+        response = self
         # Start response
         self.preflight()
         self.handle_session_cookie()
             self.response.charset = 'UTF-8'
 
             print "zzzzz", message
-            self.add_body(message + '\n')
+            self.set_body(message + '\n')
             self.context.gaplic.add_callback(self.send_complete)
             #self.flush(callback=self.send_complete)
         except:
 )
 class XhrSendHandler(pollingbase.PollingTransportBase):
     def post(self):
-        response = self.set_response(self.request.response)
+        #response = self.set_response(self.request.response)
+        #response = self.set_response(self)  # Response is self.
+        response = self
 
         self.sid = self.context.parent.re_matched_name  # session_id
         if self.context.sockjs_server.per_user:

ginsfsm/protocols/sockjs/server/transports/xhrstreaming.py

 
     def post(self):
         #response = self.set_response(self.request.response)
-        response = self.set_response(self)  # Response is self.
+        #response = self.set_response(self)  # Response is self.
+        response = self
         response.headers = ()  # important trick: clean default webob headers.
 
         self.sid = self.context.parent.re_matched_name  # session_id