Permalink
Browse files

Work around python2.6 requirement of fileno() method by crippling som…

…e new functionality. Gross, but closes #7.
  • Loading branch information...
1 parent 89edbd4 commit 37a485a4730f34fb816ebedff3fa6104aad892b1 @tonyg committed Sep 15, 2010
Showing with 34 additions and 0 deletions.
  1. +34 −0 priv/python/reversehttp.py
View
@@ -29,6 +29,40 @@ def __init__(self, label, server_address, RequestHandlerClass):
self.reportPollExceptions = False
self.locationChangeCallback = None
+ def handle_request(self):
+ """This code was originally written for python 2.5. In python
+ 2.6, BaseServer has been refactored to support timeout,
+ implemented using select, for socket servers. Since here we're
+ abusing the structure of BaseServer to get requests via HTTP,
+ we don't have a file handle we can give to select---or at
+ least, we don't have one *readily available*. Consequently, we
+ override handle_request here to return to the python 2.5
+ behaviour. While this makes the server work again,
+ unfortunately the new timeout and shutdown behaviours
+ available in 2.6 may not work well with this class."""
+ if hasattr(self, '_handle_request_noblock'):
+ ## We're in python 2.6.
+ ## Don't worry, in python 2.6, _handle_request_noblock
+ ## with the definition of get_request below *will* block!
+ return self._handle_request_noblock()
+ else:
+ ## We're in some other python so rely on base behaviour.
+ return SocketServer.BaseServer.handle_request(self)
+
+ def serve_forever(self):
+ """See the comment for handle_request. We override here to
+ return to the python 2.5 behaviour, so that we can shoehorn
+ our weird request-fetching mechanism into the standard httpd
+ classes."""
+ if hasattr(self, '_handle_request_noblock'):
+ ## We're in python 2.6.
+ ## Copy the code from 2.5 verbatim. Ick.
+ while 1:
+ self.handle_request()
+ else:
+ ## We're in some other python so rely on base behaviour.
+ return SocketServer.BaseServer.serve_forever(self)
+
def get_request(self):
while 1:
try:

0 comments on commit 37a485a

Please sign in to comment.