Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(127307)

Side by Side Diff: Lib/test/test_httpservers.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_gdb.py ('k') | Lib/test/test_import/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Unittests for the various HTTPServer modules. 1 """Unittests for the various HTTPServer modules.
2 2
3 Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>, 3 Written by Cody A.W. Somerville <cody-somerville@ubuntu.com>,
4 Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest. 4 Josip Dzolonga, and Michael Otteneder for the 2007/08 GHOP contest.
5 """ 5 """
6 6
7 from http.server import BaseHTTPRequestHandler, HTTPServer, \ 7 from http.server import BaseHTTPRequestHandler, HTTPServer, \
8 SimpleHTTPRequestHandler, CGIHTTPRequestHandler 8 SimpleHTTPRequestHandler, CGIHTTPRequestHandler
9 from http import server, HTTPStatus 9 from http import server, HTTPStatus
10 10
11 import os 11 import os
12 import sys 12 import sys
13 import re 13 import re
14 import base64 14 import base64
15 import shutil 15 import shutil
16 import urllib.parse 16 import urllib.parse
17 import html 17 import html
18 import http.client 18 import http.client
19 import subprocess
19 import tempfile 20 import tempfile
20 from io import BytesIO 21 from io import BytesIO
21 22
22 import unittest 23 import unittest
23 from test import support 24 from test import support
24 threading = support.import_module('threading') 25 threading = support.import_module('threading')
25 26
26 class NoLogRequestHandler: 27 class NoLogRequestHandler:
27 def log_message(self, *args): 28 def log_message(self, *args):
28 # don't write log messages to stderr 29 # don't write log messages to stderr
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 325
325 @support.requires_mac_ver(10, 5) 326 @support.requires_mac_ver(10, 5)
326 @unittest.skipUnless(support.TESTFN_UNDECODABLE, 327 @unittest.skipUnless(support.TESTFN_UNDECODABLE,
327 'need support.TESTFN_UNDECODABLE') 328 'need support.TESTFN_UNDECODABLE')
328 def test_undecodable_filename(self): 329 def test_undecodable_filename(self):
329 enc = sys.getfilesystemencoding() 330 enc = sys.getfilesystemencoding()
330 filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt' 331 filename = os.fsdecode(support.TESTFN_UNDECODABLE) + '.txt'
331 with open(os.path.join(self.tempdir, filename), 'wb') as f: 332 with open(os.path.join(self.tempdir, filename), 'wb') as f:
332 f.write(support.TESTFN_UNDECODABLE) 333 f.write(support.TESTFN_UNDECODABLE)
333 response = self.request(self.tempdir_name + '/') 334 response = self.request(self.tempdir_name + '/')
334 if sys.platform == 'darwin': 335 if sys.platform in ('darwin', 'ios'):
335 # On Mac OS the HFS+ filesystem replaces bytes that aren't valid 336 # On Mac OS the HFS+ filesystem replaces bytes that aren't valid
336 # UTF-8 into a percent-encoded value. 337 # UTF-8 into a percent-encoded value.
337 for name in os.listdir(self.tempdir): 338 for name in os.listdir(self.tempdir):
338 if name != 'test': # Ignore a filename created in setUp(). 339 if name != 'test': # Ignore a filename created in setUp().
339 filename = name 340 filename = name
340 break 341 break
341 body = self.check_status_and_reason(response, HTTPStatus.OK) 342 body = self.check_status_and_reason(response, HTTPStatus.OK)
342 quotedname = urllib.parse.quote(filename, errors='surrogatepass') 343 quotedname = urllib.parse.quote(filename, errors='surrogatepass')
343 self.assertIn(('href="%s"' % quotedname) 344 self.assertIn(('href="%s"' % quotedname)
344 .encode(enc, 'surrogateescape'), body) 345 .encode(enc, 'surrogateescape'), body)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 432
432 print("Content-type: text/html") 433 print("Content-type: text/html")
433 print() 434 print()
434 435
435 print(os.environ["%s"]) 436 print(os.environ["%s"])
436 """ 437 """
437 438
438 439
439 @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0, 440 @unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
440 "This test can't be run reliably as root (issue #13308).") 441 "This test can't be run reliably as root (issue #13308).")
442 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess.Pop en()")
441 class CGIHTTPServerTestCase(BaseTestCase): 443 class CGIHTTPServerTestCase(BaseTestCase):
442 class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler): 444 class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
443 pass 445 pass
444 446
445 linesep = os.linesep.encode('ascii') 447 linesep = os.linesep.encode('ascii')
446 448
447 def setUp(self): 449 def setUp(self):
448 BaseTestCase.setUp(self) 450 BaseTestCase.setUp(self)
449 self.cwd = os.getcwd() 451 self.cwd = os.getcwd()
450 self.parent_dir = tempfile.mkdtemp() 452 self.parent_dir = tempfile.mkdtemp()
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 SimpleHTTPServerTestCase, 920 SimpleHTTPServerTestCase,
919 CGIHTTPServerTestCase, 921 CGIHTTPServerTestCase,
920 SimpleHTTPRequestHandlerTestCase, 922 SimpleHTTPRequestHandlerTestCase,
921 MiscTestCase, 923 MiscTestCase,
922 ) 924 )
923 finally: 925 finally:
924 os.chdir(cwd) 926 os.chdir(cwd)
925 927
926 if __name__ == '__main__': 928 if __name__ == '__main__':
927 test_main() 929 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_gdb.py ('k') | Lib/test/test_import/__init__.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+