Skip to content

Commit

Permalink
tests/http_pipe.py: Python 3 support
Browse files Browse the repository at this point in the history
The 2to3 tool converted socketserver (which I manually fixed up with an
import fallback) and the print(e) line. The xrange option was converted
to range, but it seems better to use the '*' operator here for
simplicity.

Signed-off-by: Peter Wu <peter@lekensteyn.nl>
  • Loading branch information
Lekensteyn authored and bagder committed Oct 10, 2014
1 parent c6c22ae commit 87a3a92
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions tests/http_pipe.py
Expand Up @@ -17,7 +17,10 @@
# Modified by Linus Nielsen Feltzing for inclusion in the libcurl test
# framework
#
import SocketServer
try:
import socketserver
except:
import SocketServer as socketserver
import argparse
import re
import select
Expand Down Expand Up @@ -251,24 +254,21 @@ def BuildResponses(self):
self._processed_end = True

elif path == '/1k.txt':
str = '0123456789abcdef'
body = ''.join([str for num in xrange(64)])
body = '0123456789abcdef' * 64
result += self._BuildResponse(
'200 OK', ['Server: Apache',
'Content-Length: 1024',
'Cache-Control: max-age=60'], body)

elif path == '/10k.txt':
str = '0123456789abcdef'
body = ''.join([str for num in xrange(640)])
body = '0123456789abcdef' * 640
result += self._BuildResponse(
'200 OK', ['Server: Apache',
'Content-Length: 10240',
'Cache-Control: max-age=60'], body)

elif path == '/100k.txt':
str = '0123456789abcdef'
body = ''.join([str for num in xrange(6400)])
body = '0123456789abcdef' * 6400
result += self._BuildResponse(
'200 OK',
['Server: Apache',
Expand All @@ -277,9 +277,7 @@ def BuildResponses(self):
body)

elif path == '/100k_chunked.txt':
str = '0123456789abcdef'
moo = ''.join([str for num in xrange(6400)])
body = self.Chunkify(moo, 20480)
body = self.Chunkify('0123456789abcdef' * 6400, 20480)
body.append('0\r\n\r\n')
body = ''.join(body)

Expand Down Expand Up @@ -337,7 +335,7 @@ def _BuildResponse(self, status, headers, body):
'%s' % (status, '\r\n'.join(headers), body))


class PipelineRequestHandler(SocketServer.BaseRequestHandler):
class PipelineRequestHandler(socketserver.BaseRequestHandler):
"""Called on an incoming TCP connection."""

def _GetTimeUntilTimeout(self):
Expand Down Expand Up @@ -407,11 +405,11 @@ def handle(self):
self.request.send(self._response_builder.WriteError(
'200 OK', INFO_MESSAGE))
except Exception as e:
print e
print(e)
self.request.close()


class PipelineServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
class PipelineServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass


Expand Down

0 comments on commit 87a3a92

Please sign in to comment.