summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/tests/test_llcorehttp_peer.py
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcorehttp/tests/test_llcorehttp_peer.py')
-rwxr-xr-xindra/llcorehttp/tests/test_llcorehttp_peer.py46
1 files changed, 22 insertions, 24 deletions
diff --git a/indra/llcorehttp/tests/test_llcorehttp_peer.py b/indra/llcorehttp/tests/test_llcorehttp_peer.py
index 493143641b..778de90962 100755
--- a/indra/llcorehttp/tests/test_llcorehttp_peer.py
+++ b/indra/llcorehttp/tests/test_llcorehttp_peer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""\
@file test_llsdmessage_peer.py
@author Nat Goodspeed
@@ -34,11 +34,9 @@ import sys
import time
import select
import getopt
-try:
- from cStringIO import StringIO
-except ImportError:
- from StringIO import StringIO
-from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from io import StringIO
+from http.server import HTTPServer, BaseHTTPRequestHandler
+
from llbase.fastest_elementtree import parse as xml_parse
from llbase import llsd
@@ -97,13 +95,13 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
except (KeyError, ValueError):
return ""
max_chunk_size = 10*1024*1024
- L = []
+ L = bytes()
while size_remaining:
chunk_size = min(size_remaining, max_chunk_size)
chunk = self.rfile.read(chunk_size)
- L.append(chunk)
+ L += chunk
size_remaining -= len(chunk)
- return ''.join(L)
+ return L.decode("utf-8")
# end of swiped read() logic
def read_xml(self):
@@ -127,8 +125,8 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
try:
self.answer(dict(reply="success", status=200,
reason="Your GET operation worked"))
- except self.ignore_exceptions, e:
- print >> sys.stderr, "Exception during GET (ignoring): %s" % str(e)
+ except self.ignore_exceptions as e:
+ print("Exception during GET (ignoring): %s" % str(e), file=sys.stderr)
def do_POST(self):
# Read the provided POST data.
@@ -136,8 +134,8 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
try:
self.answer(dict(reply="success", status=200,
reason=self.read()))
- except self.ignore_exceptions, e:
- print >> sys.stderr, "Exception during POST (ignoring): %s" % str(e)
+ except self.ignore_exceptions as e:
+ print("Exception during POST (ignoring): %s" % str(e), file=sys.stderr)
def do_PUT(self):
# Read the provided PUT data.
@@ -145,8 +143,8 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
try:
self.answer(dict(reply="success", status=200,
reason=self.read()))
- except self.ignore_exceptions, e:
- print >> sys.stderr, "Exception during PUT (ignoring): %s" % str(e)
+ except self.ignore_exceptions as e:
+ print("Exception during PUT (ignoring): %s" % str(e), file=sys.stderr)
def answer(self, data, withdata=True):
debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data, self.path)
@@ -221,7 +219,7 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
self.send_header("Content-type", "text/plain")
self.end_headers()
if body:
- self.wfile.write(body)
+ self.wfile.write(body.encode("utf-8"))
elif "fail" not in self.path:
data = data.copy() # we're going to modify
# Ensure there's a "reply" key in data, even if there wasn't before
@@ -255,9 +253,9 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):
self.end_headers()
def reflect_headers(self):
- for name in self.headers.keys():
- # print "Header: %s: %s" % (name, self.headers[name])
- self.send_header("X-Reflect-" + name, self.headers[name])
+ for (name, val) in self.headers.items():
+ # print("Header: %s %s" % (name, val), file=sys.stderr)
+ self.send_header("X-Reflect-" + name, val)
if not VERBOSE:
# When VERBOSE is set, skip both these overrides because they exist to
@@ -283,10 +281,10 @@ class Server(HTTPServer):
# default behavior which *shouldn't* cause the program to return
# a failure status.
def handle_error(self, request, client_address):
- print '-'*40
- print 'Ignoring exception during processing of request from',
- print client_address
- print '-'*40
+ print('-'*40)
+ print('Ignoring exception during processing of request from %' % (client_address))
+ print('-'*40)
+
if __name__ == "__main__":
do_valgrind = False
@@ -307,7 +305,7 @@ if __name__ == "__main__":
# "Then there's Windows"
# Instantiate a Server(TestHTTPRequestHandler) on the first free port
# in the specified port range.
- httpd, port = freeport(xrange(8000, 8020), make_server)
+ httpd, port = freeport(range(8000, 8020), make_server)
# Pass the selected port number to the subject test program via the
# environment. We don't want to impose requirements on the test program's