From 61fce3877cd11508f43b4d4e71276b03c3ef2823 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 1 Apr 2009 15:23:43 +0000 Subject: [PATCH] Fix test_xmlrpc and make the CGI handler work with no CONTENT_LENGTH. --- Lib/SimpleXMLRPCServer.py | 2 +- Lib/test/test_xmlrpc.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/SimpleXMLRPCServer.py b/Lib/SimpleXMLRPCServer.py index 4c286884a3f..b304e45c112 100644 --- a/Lib/SimpleXMLRPCServer.py +++ b/Lib/SimpleXMLRPCServer.py @@ -600,7 +600,7 @@ class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher): # POST data is normally available through stdin try: length = int(os.environ.get('CONTENT_LENGTH', None)) - except ValueError: + except (TypeError, ValueError): length = -1 if request_text is None: request_text = sys.stdin.read(length) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index 05154cc5b59..4f057c78a32 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -629,7 +629,11 @@ class CGIHandlerTestCase(unittest.TestCase): sys.stdin = open("xmldata.txt", "r") sys.stdout = open(test_support.TESTFN, "w") - self.cgi.handle_request() + os.environ['CONTENT_LENGTH'] = str(len(data)) + try: + self.cgi.handle_request() + finally: + del os.environ['CONTENT_LENGTH'] sys.stdin.close() sys.stdout.close()