From 5c0a3965cdb9cac87d0b0ea773a6276c73a27ba6 Mon Sep 17 00:00:00 2001
From: Helmut Grohne <helmut@subdivi.de>
Date: Sun, 29 Mar 2009 17:42:48 +0200
Subject: quite some changes for py3

These changes introduce some compatibility code. They don't make
wsgitools usable with Python 3.0, but they also don't break
compatibility with Python 2.5.
---
 wsgitools/scgi/asynchronous.py | 13 ++++++++++---
 wsgitools/scgi/forkpool.py     | 14 ++++++++++----
 2 files changed, 20 insertions(+), 7 deletions(-)

(limited to 'wsgitools/scgi')

diff --git a/wsgitools/scgi/asynchronous.py b/wsgitools/scgi/asynchronous.py
index 9fedb87..33d5130 100644
--- a/wsgitools/scgi/asynchronous.py
+++ b/wsgitools/scgi/asynchronous.py
@@ -4,9 +4,16 @@ import asyncore
 import socket
 import sys
 try:
-    import cStringIO as StringIO
+    import io
 except ImportError:
-    import StringIO
+    try:
+        import cStringIO as io
+    except ImportError:
+        import StringIO as io
+try:
+    long
+except NameError:
+    long = int
 
 class SCGIConnection(asyncore.dispatcher):
     """SCGI connection class used by L{SCGIServer}."""
@@ -32,7 +39,7 @@ class SCGIConnection(asyncore.dispatcher):
         self.wsgihandler = None # wsgi application iterator
         self.outheaders = () # headers to be sent
                              # () -> unset, (..,..) -> set, True -> sent
-        self.body = StringIO.StringIO() # request body
+        self.body = io.StringIO() # request body
 
     def _wsgi_headers(self):
         return {"wsgi.version": (1, 0),
diff --git a/wsgitools/scgi/forkpool.py b/wsgitools/scgi/forkpool.py
index 26de9ef..b913190 100644
--- a/wsgitools/scgi/forkpool.py
+++ b/wsgitools/scgi/forkpool.py
@@ -11,6 +11,11 @@ import select
 import sys
 import errno
 
+try:
+    long
+except NameError:
+    long = int
+
 class SocketFileWrapper:
     """Wraps a socket to a wsgi-compliant file-like object."""
     def __init__(self, sock, toread):
@@ -153,7 +158,8 @@ class SocketFileWrapper:
             return
     def writelines(self, lines):
         """see pep333"""
-        map(self.write, lines)
+        for line in lines:
+            self.write(line)
 
 class SCGIServer:
     """Usage: create an L{SCGIServer} object and invoke the run method which
@@ -228,7 +234,7 @@ class SCGIServer:
                 elif data in ('0', '1'):
                     self.workers[s].state = int(data)
                 else:
-                    raise RuntimeError, "unexpected data from worker"
+                    raise RuntimeError("unexpected data from worker")
             try:
                 pid = 1
                 while pid > 0:
@@ -263,7 +269,7 @@ class SCGIServer:
             self.workers[srvsock.fileno()] = SCGIServer.\
                                              WorkerState(pid, srvsock, 0)
         else:
-            raise RuntimeError, "fork failed"
+            raise RuntimeError("fork failed")
 
     def work(self, worksock):
         """
@@ -299,7 +305,7 @@ class SCGIServer:
         if not length.isdigit(): # clear protocol violation
             con.close()
             return
-        length = long(length)
+        length = int(length)
 
         while len(data) != length + 1: # read one byte beyond
             try:
-- 
cgit v1.2.3