| OLD | NEW |
| 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 | 9 from http import server |
| 10 | 10 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 def setUp(self): | 316 def setUp(self): |
| 317 BaseTestCase.setUp(self) | 317 BaseTestCase.setUp(self) |
| 318 self.cwd = os.getcwd() | 318 self.cwd = os.getcwd() |
| 319 self.parent_dir = tempfile.mkdtemp() | 319 self.parent_dir = tempfile.mkdtemp() |
| 320 self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin') | 320 self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin') |
| 321 os.mkdir(self.cgi_dir) | 321 os.mkdir(self.cgi_dir) |
| 322 self.file1_path = None | 322 self.file1_path = None |
| 323 self.file2_path = None | 323 self.file2_path = None |
| 324 | 324 |
| 325 # The shebang line should be pure ASCII: use symlink if possible. | 325 #NOTE: issue 7668 is bogus |
| 326 # See issue #7668. | 326 ## The shebang line should be pure ASCII: use symlink if possible. |
| 327 if support.can_symlink(): | 327 ## See issue #7668. |
| 328 self.pythonexe = os.path.join(self.parent_dir, 'python') | 328 #if support.can_symlink(): |
| 329 os.symlink(sys.executable, self.pythonexe) | 329 # self.pythonexe = os.path.join(self.parent_dir, 'python') |
| 330 else: | 330 # os.symlink(sys.executable, self.pythonexe) |
| 331 self.pythonexe = sys.executable | 331 #else: |
| 332 # self.pythonexe = sys.executable |
| 332 | 333 |
| 333 try: | 334 try: |
| 334 # The python executable path is written as the first line of the | 335 # The python executable path is written as the first line of the |
| 335 # CGI Python script. The encoding cookie cannot be used, and so the | 336 # CGI Python script. The encoding cookie cannot be used, and so the |
| 336 # path should be encodable to the default script encoding (utf-8) | 337 # path should be encodable to the default script encoding (utf-8) |
| 337 self.pythonexe.encode('utf-8') | 338 #NOTE: issue 7668 is bogus |
| 339 #self.pythonexe.encode('utf-8') |
| 340 sys.executable.encode('utf-8') |
| 338 except UnicodeEncodeError: | 341 except UnicodeEncodeError: |
| 339 self.tearDown() | 342 self.tearDown() |
| 340 raise self.skipTest( | 343 raise self.skipTest( |
| 341 "Python executable path is not encodable to utf-8") | 344 "Python executable path is not encodable to utf-8") |
| 342 | 345 |
| 343 self.file1_path = os.path.join(self.cgi_dir, 'file1.py') | 346 self.file1_path = os.path.join(self.cgi_dir, 'file1.py') |
| 344 with open(self.file1_path, 'w', encoding='utf-8') as file1: | 347 with open(self.file1_path, 'w', encoding='utf-8') as file1: |
| 345 file1.write(cgi_file1 % self.pythonexe) | 348 #NOTE: issue 7668 is bogus |
| 349 #file1.write(cgi_file1 % self.pythonexe) |
| 350 file1.write(cgi_file1 % sys.executable) |
| 346 os.chmod(self.file1_path, 0o777) | 351 os.chmod(self.file1_path, 0o777) |
| 347 | 352 |
| 348 self.file2_path = os.path.join(self.cgi_dir, 'file2.py') | 353 self.file2_path = os.path.join(self.cgi_dir, 'file2.py') |
| 349 with open(self.file2_path, 'w', encoding='utf-8') as file2: | 354 with open(self.file2_path, 'w', encoding='utf-8') as file2: |
| 350 file2.write(cgi_file2 % self.pythonexe) | 355 #NOTE: issue 7668 is bogus |
| 356 #file2.write(cgi_file2 % self.pythonexe) |
| 357 file2.write(cgi_file2 % sys.executable) |
| 351 os.chmod(self.file2_path, 0o777) | 358 os.chmod(self.file2_path, 0o777) |
| 352 | 359 |
| 353 os.chdir(self.parent_dir) | 360 os.chdir(self.parent_dir) |
| 354 | 361 |
| 355 def tearDown(self): | 362 def tearDown(self): |
| 356 try: | 363 try: |
| 357 os.chdir(self.cwd) | 364 os.chdir(self.cwd) |
| 358 if self.pythonexe != sys.executable: | 365 #NOTE: issue 7668 is bogus |
| 359 os.remove(self.pythonexe) | 366 #if self.pythonexe != sys.executable: |
| 367 # os.remove(self.pythonexe) |
| 360 if self.file1_path: | 368 if self.file1_path: |
| 361 os.remove(self.file1_path) | 369 os.remove(self.file1_path) |
| 362 if self.file2_path: | 370 if self.file2_path: |
| 363 os.remove(self.file2_path) | 371 os.remove(self.file2_path) |
| 364 os.rmdir(self.cgi_dir) | 372 os.rmdir(self.cgi_dir) |
| 365 os.rmdir(self.parent_dir) | 373 os.rmdir(self.parent_dir) |
| 366 finally: | 374 finally: |
| 367 BaseTestCase.tearDown(self) | 375 BaseTestCase.tearDown(self) |
| 368 | 376 |
| 369 def test_url_collapse_path(self): | 377 def test_url_collapse_path(self): |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 BaseHTTPServerTestCase, | 680 BaseHTTPServerTestCase, |
| 673 SimpleHTTPServerTestCase, | 681 SimpleHTTPServerTestCase, |
| 674 CGIHTTPServerTestCase, | 682 CGIHTTPServerTestCase, |
| 675 SimpleHTTPRequestHandlerTestCase, | 683 SimpleHTTPRequestHandlerTestCase, |
| 676 ) | 684 ) |
| 677 finally: | 685 finally: |
| 678 os.chdir(cwd) | 686 os.chdir(cwd) |
| 679 | 687 |
| 680 if __name__ == '__main__': | 688 if __name__ == '__main__': |
| 681 test_main() | 689 test_main() |
| OLD | NEW |