From 514b9aa1bbe48a5bfcb919e739cc7e7b1cc0209e Mon Sep 17 00:00:00 2001 From: Salman Haq Date: Fri, 3 Sep 2010 15:47:41 -0400 Subject: [PATCH] Python 2.4 compatibility changes: - remove import from __future__. - replace two instances of `with eventlet.timeout.Timeout` with equivalent logic using `eventlet.timeout.with_timeout`. --- csp_eventlet/__init__.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/csp_eventlet/__init__.py b/csp_eventlet/__init__.py index f8cee5a..a9e3cb9 100644 --- a/csp_eventlet/__init__.py +++ b/csp_eventlet/__init__.py @@ -1,4 +1,3 @@ -from __future__ import with_statement import eventlet from eventlet import wsgi import cgi @@ -179,10 +178,17 @@ def _timeout(self, is_teardown): # SPEC TODO: No mention in csp spec (Draft 0.4 Nov 19, 2009) of # session timeout. Choosing twice the comet duration or # 60 seconds when du = 0 (polling mode) - with eventlet.timeout.Timeout(self.conn_vars['du'] * 2 or 60, False): - if self._activity_queue.get(): + try: + if eventlet.timeout.with_timeout(self.conn_vars['du'] * 2 or 60, self._activity_queue.get): break continue + except eventlet.timeout.Timeout, e: + pass + # XXX remove the following: + #with eventlet.timeout.Timeout(self.conn_vars['du'] * 2 or 60, False): + # if self._activity_queue.get(): + # break + # continue if is_teardown: self.teardown() else: @@ -310,8 +316,13 @@ def comet_request(self, environ, start_response): self._comet_request_lock.release() duration = self.conn_vars['du'] if duration: - with eventlet.timeout.Timeout(duration, False): - self._comet_request_channel.get() + try: + eventlet.timeout.with_timeout(duration, self._comet_request_channel.get) + except eventlet.timeout.Timeout, e: + pass + # XXX remove the following: + #with eventlet.timeout.Timeout(duration, False): + # self._comet_request_channel.get() headers = [ ('Content-type', self.conn_vars['ct']) , ('Access-Control-Allow-Origin','*') ]