Index: Lib/test/test_xmlrpc.py =================================================================== --- Lib/test/test_xmlrpc.py (revision 70643) +++ Lib/test/test_xmlrpc.py (working copy) @@ -9,6 +9,7 @@ import http.client import socket import os +import re from test import support alist = [{'astring': 'foo@bar.baz.spam', @@ -352,6 +353,19 @@ # protocol error; provide additional information in test output self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) + def test_nonascii(self): + start_string = 'P\N{LATIN SMALL LETTER Y WITH CIRCUMFLEX}t' + end_string = 'h\N{LATIN SMALL LETTER O WITH HORN}n' + try: + p = xmlrpclib.ServerProxy(URL) + self.assertEqual(p.add(start_string, end_string), + start_string + end_string) + except (xmlrpclib.ProtocolError, socket.error) as e: + # ignore failures due to non-blocking socket 'unavailable' errors + if not is_unavailable_exception(e): + # protocol error; provide additional information in test output + self.fail("%s\n%s" % (e, getattr(e, "headers", ""))) + # [ch] The test 404 is causing lots of false alarms. def XXXtest_404(self): # send POST with http.client, it should return 404 header and @@ -577,6 +591,53 @@ os.remove(support.TESTFN) os.environ['REQUEST_METHOD'] = '' + def test_correct_content_length(self): + """Ensure that the correct HTTP content-length is returned. + + Tests that the correct content-length header is generated when + sys.stdout does Windows line-ending translation. See: + the http://bugs.python.org/issue5040 + """ + self.cgi.register_function(lambda x,y: x+y, 'add') + data = b""" + + add + + + Cheers,\n + + + Brian + + + +""" + + open("xmldata.txt", "wb").write(data) + tmp1 = sys.stdin + tmp2 = sys.stdout + + sys.stdin = open("xmldata.txt", "r") + sys.stdout = open(support.TESTFN, "w", newline="\r\n") + + try: + self.cgi.handle_request() + finally: + sys.stdin.close() + sys.stdout.close() + sys.stdin = tmp1 + sys.stdout = tmp2 + + response = open(support.TESTFN, "rb").read().decode('utf-8') + content = response[response.find("