Commit 88c60c96 authored by Antoine Pitrou's avatar Antoine Pitrou Committed by GitHub

Trivial cleanups following bpo-31370 (#3649)

* Trivial cleanups following bpo-31370

* Also cleanup the "importlib._bootstrap_external" module
parent b43c4caf
......@@ -431,10 +431,7 @@ _rounding_modes = (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_CEILING,
##### Context Functions ##################################################
# The getcontext() and setcontext() function manage access to a thread-local
# current context. Py2.4 offers direct support for thread locals. If that
# is not available, use threading.current_thread() which is slower but will
# work for older Pythons. If threads are not part of the build, create a
# mock threading object with threading.local() returning the module namespace.
# current context.
import threading
......
......@@ -1121,25 +1121,13 @@ def _setup(sys_module, _imp_module):
# Directly load built-in modules needed during bootstrap.
self_module = sys.modules[__name__]
for builtin_name in ('_warnings',):
for builtin_name in ('_thread', '_warnings', '_weakref'):
if builtin_name not in sys.modules:
builtin_module = _builtin_from_name(builtin_name)
else:
builtin_module = sys.modules[builtin_name]
setattr(self_module, builtin_name, builtin_module)
# Directly load the _thread module (needed during bootstrap).
try:
thread_module = _builtin_from_name('_thread')
except ImportError:
# Python was built without threads
thread_module = None
setattr(self_module, '_thread', thread_module)
# Directly load the _weakref module (needed during bootstrap).
weakref_module = _builtin_from_name('_weakref')
setattr(self_module, '_weakref', weakref_module)
def _install(sys_module, _imp_module):
"""Install importers for builtin and frozen modules"""
......
......@@ -1411,11 +1411,7 @@ def _setup(_bootstrap_module):
setattr(self_module, 'path_separators', ''.join(path_separators))
# Directly load the _thread module (needed during bootstrap).
try:
thread_module = _bootstrap._builtin_from_name('_thread')
except ImportError:
# Python was built without threads
thread_module = None
thread_module = _bootstrap._builtin_from_name('_thread')
setattr(self_module, '_thread', thread_module)
# Directly load the _weakref module (needed during bootstrap).
......
......@@ -2,13 +2,13 @@ import os
import sys
import ssl
import pprint
import threading
import urllib.parse
# Rename HTTPServer to _HTTPServer so as to avoid confusion with HTTPSServer.
from http.server import (HTTPServer as _HTTPServer,
SimpleHTTPRequestHandler, BaseHTTPRequestHandler)
from test import support
threading = support.import_module("threading")
here = os.path.dirname(__file__)
......
......@@ -2060,7 +2060,6 @@ def threading_cleanup(*original_values):
def reap_threads(func):
"""Use this function when threads are being used. This will
ensure that the threads are cleaned up even when the test fails.
If threading is unavailable this function does nothing.
"""
@functools.wraps(func)
def decorator(*args):
......
......@@ -5,6 +5,7 @@ import itertools
import os
import array
import socket
import threading
import unittest
TestCase = unittest.TestCase
......@@ -1077,8 +1078,6 @@ class BasicTest(TestCase):
def test_response_fileno(self):
# Make sure fd returned by fileno is valid.
threading = support.import_module("threading")
serv = socket.socket(
socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
self.addCleanup(serv.close)
......
import unittest
from test.support import import_module
# Skip test if _thread or _tkinter wasn't built, if idlelib is missing,
# Skip test if _tkinter wasn't built, if idlelib is missing,
# or if tcl/tk is not the 8.5+ needed for ttk widgets.
tk = import_module('tkinter') # imports _tkinter
if tk.TkVersion < 8.5:
......
# tests __main__ module handling in multiprocessing
from test import support
# Skip tests if _thread or _multiprocessing wasn't built.
support.import_module('_thread')
# Skip tests if _multiprocessing wasn't built.
support.import_module('_multiprocessing')
import importlib
......
......@@ -2,7 +2,7 @@ import os
import unittest
import random
from test import support
thread = support.import_module('_thread')
import _thread as thread
import time
import sys
import weakref
......
......@@ -5,7 +5,7 @@ import signal
import os
import sys
from test import support
thread = support.import_module('_thread')
import _thread as thread
import time
if (sys.platform[:3] == 'win'):
......
......@@ -40,7 +40,6 @@ class TestSundryScripts(unittest.TestCase):
for name in self.windows_only:
import_tool(name)
@unittest.skipIf(not support.threading, "test requires _thread module")
def test_analyze_dxp_import(self):
if hasattr(sys, 'getdxp'):
import_tool('analyze_dxp')
......
......@@ -4,7 +4,7 @@
import os, sys, errno
import unittest
from test import support
threading = support.import_module("threading")
import threading
from platform import machine
# Do this first so test will be skipped if module doesn't exist
......
......@@ -18,6 +18,7 @@ import os
import re
import signal
import sys
import threading
import unittest
......@@ -253,7 +254,6 @@ class IntegrationTests(TestCase):
# BaseHandler._write() and _flush() have to write all data, even if
# it takes multiple send() calls. Test this by interrupting a send()
# call with a Unix signal.
threading = support.import_module("threading")
pthread_kill = support.get_attribute(signal, "pthread_kill")
def app(environ, start_response):
......
......@@ -1175,13 +1175,7 @@ class GzipUtilTestCase(unittest.TestCase):
class ServerProxyTestCase(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
if threading:
self.url = URL
else:
# Without threading, http_server() and http_multi_server() will not
# be executed and URL is still equal to None. 'http://' is a just
# enough to choose the scheme (HTTP)
self.url = 'http://'
self.url = URL
def test_close(self):
p = xmlrpclib.ServerProxy(self.url)
......
This diff is collapsed.
......@@ -2289,7 +2289,7 @@ const unsigned char _Py_M__importlib_external[] = {
0,114,159,0,0,0,80,5,0,0,115,8,0,0,0,0,
5,12,1,8,1,8,1,114,159,0,0,0,99,1,0,0,
0,0,0,0,0,12,0,0,0,12,0,0,0,67,0,0,
0,115,188,1,0,0,124,0,97,0,116,0,106,1,97,1,
0,115,156,1,0,0,124,0,97,0,116,0,106,1,97,1,
116,0,106,2,97,2,116,1,106,3,116,4,25,0,125,1,
120,56,100,26,68,0,93,48,125,2,124,2,116,1,106,3,
107,7,114,58,116,0,160,5,124,2,161,1,125,3,110,10,
......@@ -2306,17 +2306,15 @@ const unsigned char _Py_M__importlib_external[] = {
116,9,100,12,131,1,130,1,116,6,124,1,100,13,124,8,
131,3,1,0,116,6,124,1,100,14,124,7,131,3,1,0,
116,6,124,1,100,15,100,16,160,10,124,6,161,1,131,3,
1,0,121,14,116,0,160,5,100,17,161,1,125,9,87,0,
110,26,4,0,116,9,107,10,144,1,114,52,1,0,1,0,
1,0,100,18,125,9,89,0,110,2,88,0,116,6,124,1,
100,17,124,9,131,3,1,0,116,0,160,5,100,19,161,1,
125,10,116,6,124,1,100,19,124,10,131,3,1,0,124,5,
100,7,107,2,144,1,114,120,116,0,160,5,100,20,161,1,
125,11,116,6,124,1,100,21,124,11,131,3,1,0,116,6,
124,1,100,22,116,11,131,0,131,3,1,0,116,12,160,13,
1,0,116,0,160,5,100,17,161,1,125,9,116,6,124,1,
100,17,124,9,131,3,1,0,116,0,160,5,100,18,161,1,
125,10,116,6,124,1,100,18,124,10,131,3,1,0,124,5,
100,7,107,2,144,1,114,88,116,0,160,5,100,19,161,1,
125,11,116,6,124,1,100,20,124,11,131,3,1,0,116,6,
124,1,100,21,116,11,131,0,131,3,1,0,116,12,160,13,
116,2,160,14,161,0,161,1,1,0,124,5,100,7,107,2,
144,1,114,184,116,15,160,16,100,23,161,1,1,0,100,24,
116,12,107,6,144,1,114,184,100,25,116,17,95,18,100,18,
144,1,114,152,116,15,160,16,100,22,161,1,1,0,100,23,
116,12,107,6,144,1,114,152,100,24,116,17,95,18,100,25,
83,0,41,27,122,205,83,101,116,117,112,32,116,104,101,32,
112,97,116,104,45,98,97,115,101,100,32,105,109,112,111,114,
116,101,114,115,32,102,111,114,32,105,109,112,111,114,116,108,
......@@ -2345,10 +2343,10 @@ const unsigned char _Py_M__importlib_external[] = {
111,114,116,108,105,98,32,114,101,113,117,105,114,101,115,32,
112,111,115,105,120,32,111,114,32,110,116,114,3,0,0,0,
114,27,0,0,0,114,23,0,0,0,114,32,0,0,0,90,
7,95,116,104,114,101,97,100,78,90,8,95,119,101,97,107,
114,101,102,90,6,119,105,110,114,101,103,114,167,0,0,0,
114,7,0,0,0,122,4,46,112,121,119,122,6,95,100,46,
112,121,100,84,41,4,114,52,0,0,0,114,63,0,0,0,
7,95,116,104,114,101,97,100,90,8,95,119,101,97,107,114,
101,102,90,6,119,105,110,114,101,103,114,167,0,0,0,114,
7,0,0,0,122,4,46,112,121,119,122,6,95,100,46,112,
121,100,84,78,41,4,114,52,0,0,0,114,63,0,0,0,
114,24,1,0,0,114,140,0,0,0,41,19,114,118,0,0,
0,114,8,0,0,0,114,143,0,0,0,114,235,0,0,0,
114,109,0,0,0,90,18,95,98,117,105,108,116,105,110,95,
......@@ -2368,64 +2366,64 @@ const unsigned char _Py_M__importlib_external[] = {
101,90,14,119,101,97,107,114,101,102,95,109,111,100,117,108,
101,90,13,119,105,110,114,101,103,95,109,111,100,117,108,101,
114,4,0,0,0,114,4,0,0,0,114,6,0,0,0,218,
6,95,115,101,116,117,112,91,5,0,0,115,82,0,0,0,
6,95,115,101,116,117,112,91,5,0,0,115,76,0,0,0,
0,8,4,1,6,1,6,3,10,1,10,1,10,1,12,2,
10,1,16,3,22,1,14,2,22,1,8,1,10,1,10,1,
4,2,2,1,10,1,6,1,14,1,12,2,8,1,12,1,
12,1,18,3,2,1,14,1,16,2,10,1,12,3,10,1,
12,3,10,1,10,1,12,3,14,1,14,1,10,1,10,1,
10,1,114,30,1,0,0,99,1,0,0,0,0,0,0,0,
2,0,0,0,4,0,0,0,67,0,0,0,115,50,0,0,
0,116,0,124,0,131,1,1,0,116,1,131,0,125,1,116,
2,106,3,160,4,116,5,106,6,124,1,142,0,103,1,161,
1,1,0,116,2,106,7,160,8,116,9,161,1,1,0,100,
1,83,0,41,2,122,41,73,110,115,116,97,108,108,32,116,
104,101,32,112,97,116,104,45,98,97,115,101,100,32,105,109,
112,111,114,116,32,99,111,109,112,111,110,101,110,116,115,46,
78,41,10,114,30,1,0,0,114,159,0,0,0,114,8,0,
0,0,114,252,0,0,0,114,147,0,0,0,114,4,1,0,
0,114,17,1,0,0,218,9,109,101,116,97,95,112,97,116,
104,114,161,0,0,0,114,247,0,0,0,41,2,114,29,1,
0,0,90,17,115,117,112,112,111,114,116,101,100,95,108,111,
97,100,101,114,115,114,4,0,0,0,114,4,0,0,0,114,
6,0,0,0,218,8,95,105,110,115,116,97,108,108,159,5,
0,0,115,8,0,0,0,0,2,8,1,6,1,20,1,114,
32,1,0,0,41,1,114,0,0,0,0,41,2,114,1,0,
0,0,114,2,0,0,0,41,1,114,49,0,0,0,41,1,
78,41,3,78,78,78,41,3,78,78,78,41,2,114,62,0,
0,0,114,62,0,0,0,41,1,78,41,1,78,41,58,114,
111,0,0,0,114,12,0,0,0,90,37,95,67,65,83,69,
95,73,78,83,69,78,83,73,84,73,86,69,95,80,76,65,
84,70,79,82,77,83,95,66,89,84,69,83,95,75,69,89,
114,11,0,0,0,114,13,0,0,0,114,19,0,0,0,114,
21,0,0,0,114,30,0,0,0,114,40,0,0,0,114,41,
0,0,0,114,45,0,0,0,114,46,0,0,0,114,48,0,
0,0,114,58,0,0,0,218,4,116,121,112,101,218,8,95,
95,99,111,100,101,95,95,114,142,0,0,0,114,17,0,0,
0,114,132,0,0,0,114,16,0,0,0,114,20,0,0,0,
90,17,95,82,65,87,95,77,65,71,73,67,95,78,85,77,
66,69,82,114,77,0,0,0,114,76,0,0,0,114,88,0,
0,0,114,78,0,0,0,90,23,68,69,66,85,71,95,66,
89,84,69,67,79,68,69,95,83,85,70,70,73,88,69,83,
90,27,79,80,84,73,77,73,90,69,68,95,66,89,84,69,
67,79,68,69,95,83,85,70,70,73,88,69,83,114,83,0,
0,0,114,89,0,0,0,114,95,0,0,0,114,99,0,0,
0,114,101,0,0,0,114,120,0,0,0,114,127,0,0,0,
114,139,0,0,0,114,145,0,0,0,114,148,0,0,0,114,
153,0,0,0,218,6,111,98,106,101,99,116,114,160,0,0,
0,114,165,0,0,0,114,166,0,0,0,114,181,0,0,0,
114,191,0,0,0,114,206,0,0,0,114,214,0,0,0,114,
219,0,0,0,114,225,0,0,0,114,220,0,0,0,114,226,
0,0,0,114,245,0,0,0,114,247,0,0,0,114,4,1,
0,0,114,22,1,0,0,114,159,0,0,0,114,30,1,0,
0,114,32,1,0,0,114,4,0,0,0,114,4,0,0,0,
114,4,0,0,0,114,6,0,0,0,218,8,60,109,111,100,
117,108,101,62,24,0,0,0,115,108,0,0,0,4,0,4,
1,4,1,2,1,6,3,8,17,8,5,8,5,8,6,8,
12,8,10,8,9,8,5,8,7,10,22,10,124,16,1,12,
2,4,1,4,2,6,2,6,2,8,2,16,45,8,34,8,
19,8,12,8,12,8,28,8,17,10,55,10,12,10,10,8,
14,6,3,4,1,14,67,14,64,14,29,16,110,14,41,18,
45,18,16,4,3,18,53,14,60,14,42,14,127,0,5,14,
127,0,22,10,23,8,11,8,68,
12,1,18,3,10,1,12,3,10,1,12,3,10,1,10,1,
12,3,14,1,14,1,10,1,10,1,10,1,114,30,1,0,
0,99,1,0,0,0,0,0,0,0,2,0,0,0,4,0,
0,0,67,0,0,0,115,50,0,0,0,116,0,124,0,131,
1,1,0,116,1,131,0,125,1,116,2,106,3,160,4,116,
5,106,6,124,1,142,0,103,1,161,1,1,0,116,2,106,
7,160,8,116,9,161,1,1,0,100,1,83,0,41,2,122,
41,73,110,115,116,97,108,108,32,116,104,101,32,112,97,116,
104,45,98,97,115,101,100,32,105,109,112,111,114,116,32,99,
111,109,112,111,110,101,110,116,115,46,78,41,10,114,30,1,
0,0,114,159,0,0,0,114,8,0,0,0,114,252,0,0,
0,114,147,0,0,0,114,4,1,0,0,114,17,1,0,0,
218,9,109,101,116,97,95,112,97,116,104,114,161,0,0,0,
114,247,0,0,0,41,2,114,29,1,0,0,90,17,115,117,
112,112,111,114,116,101,100,95,108,111,97,100,101,114,115,114,
4,0,0,0,114,4,0,0,0,114,6,0,0,0,218,8,
95,105,110,115,116,97,108,108,155,5,0,0,115,8,0,0,
0,0,2,8,1,6,1,20,1,114,32,1,0,0,41,1,
114,0,0,0,0,41,2,114,1,0,0,0,114,2,0,0,
0,41,1,114,49,0,0,0,41,1,78,41,3,78,78,78,
41,3,78,78,78,41,2,114,62,0,0,0,114,62,0,0,
0,41,1,78,41,1,78,41,58,114,111,0,0,0,114,12,
0,0,0,90,37,95,67,65,83,69,95,73,78,83,69,78,
83,73,84,73,86,69,95,80,76,65,84,70,79,82,77,83,
95,66,89,84,69,83,95,75,69,89,114,11,0,0,0,114,
13,0,0,0,114,19,0,0,0,114,21,0,0,0,114,30,
0,0,0,114,40,0,0,0,114,41,0,0,0,114,45,0,
0,0,114,46,0,0,0,114,48,0,0,0,114,58,0,0,
0,218,4,116,121,112,101,218,8,95,95,99,111,100,101,95,
95,114,142,0,0,0,114,17,0,0,0,114,132,0,0,0,
114,16,0,0,0,114,20,0,0,0,90,17,95,82,65,87,
95,77,65,71,73,67,95,78,85,77,66,69,82,114,77,0,
0,0,114,76,0,0,0,114,88,0,0,0,114,78,0,0,
0,90,23,68,69,66,85,71,95,66,89,84,69,67,79,68,
69,95,83,85,70,70,73,88,69,83,90,27,79,80,84,73,
77,73,90,69,68,95,66,89,84,69,67,79,68,69,95,83,
85,70,70,73,88,69,83,114,83,0,0,0,114,89,0,0,
0,114,95,0,0,0,114,99,0,0,0,114,101,0,0,0,
114,120,0,0,0,114,127,0,0,0,114,139,0,0,0,114,
145,0,0,0,114,148,0,0,0,114,153,0,0,0,218,6,
111,98,106,101,99,116,114,160,0,0,0,114,165,0,0,0,
114,166,0,0,0,114,181,0,0,0,114,191,0,0,0,114,
206,0,0,0,114,214,0,0,0,114,219,0,0,0,114,225,
0,0,0,114,220,0,0,0,114,226,0,0,0,114,245,0,
0,0,114,247,0,0,0,114,4,1,0,0,114,22,1,0,
0,114,159,0,0,0,114,30,1,0,0,114,32,1,0,0,
114,4,0,0,0,114,4,0,0,0,114,4,0,0,0,114,
6,0,0,0,218,8,60,109,111,100,117,108,101,62,24,0,
0,0,115,108,0,0,0,4,0,4,1,4,1,2,1,6,
3,8,17,8,5,8,5,8,6,8,12,8,10,8,9,8,
5,8,7,10,22,10,124,16,1,12,2,4,1,4,2,6,
2,6,2,8,2,16,45,8,34,8,19,8,12,8,12,8,
28,8,17,10,55,10,12,10,10,8,14,6,3,4,1,14,
67,14,64,14,29,16,110,14,41,18,45,18,16,4,3,18,
53,14,60,14,42,14,127,0,5,14,127,0,22,10,23,8,
11,8,64,
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment