Issue #18200: Update the stdlib (except tests) to use
ModuleNotFoundError.
This commit is contained in:
parent
9702a17a6a
commit
0a140668fa
|
@ -7,7 +7,7 @@ Suggested usage is::
|
|||
|
||||
try:
|
||||
import _thread
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
import _dummy_thread as _thread
|
||||
|
||||
"""
|
||||
|
|
|
@ -62,7 +62,7 @@ def _read_output(commandstring):
|
|||
try:
|
||||
import tempfile
|
||||
fp = tempfile.NamedTemporaryFile()
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
fp = open("/tmp/_osx_support.%s"%(
|
||||
os.getpid(),), "w+b")
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import errno
|
|||
# Import _thread instead of threading to reduce startup cost
|
||||
try:
|
||||
from _thread import allocate_lock as Lock
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from _dummy_thread import allocate_lock as Lock
|
||||
|
||||
import io
|
||||
|
@ -1486,7 +1486,7 @@ class TextIOWrapper(TextIOBase):
|
|||
if encoding is None:
|
||||
try:
|
||||
import locale
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Importing locale may fail if Python is being built
|
||||
encoding = "ascii"
|
||||
else:
|
||||
|
|
|
@ -21,7 +21,7 @@ from datetime import (date as datetime_date,
|
|||
timezone as datetime_timezone)
|
||||
try:
|
||||
from _thread import allocate_lock as _thread_allocate_lock
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from _dummy_thread import allocate_lock as _thread_allocate_lock
|
||||
|
||||
__all__ = []
|
||||
|
|
|
@ -88,5 +88,5 @@ def bisect_left(a, x, lo=0, hi=None):
|
|||
# Overwrite above definitions with a fast C implementation
|
||||
try:
|
||||
from _bisect import *
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
|
|
@ -14,7 +14,7 @@ import warnings
|
|||
|
||||
try:
|
||||
from threading import RLock
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from dummy_threading import RLock
|
||||
|
||||
from _bz2 import BZ2Compressor, BZ2Decompressor
|
||||
|
|
|
@ -109,7 +109,7 @@ class Cmd:
|
|||
self.old_completer = readline.get_completer()
|
||||
readline.set_completer(self.complete)
|
||||
readline.parse_and_bind(self.completekey+": complete")
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
try:
|
||||
if intro is not None:
|
||||
|
@ -143,7 +143,7 @@ class Cmd:
|
|||
try:
|
||||
import readline
|
||||
readline.set_completer(self.old_completer)
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ def interact(banner=None, readfunc=None, local=None):
|
|||
else:
|
||||
try:
|
||||
import readline
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
console.interact(banner)
|
||||
|
||||
|
|
|
@ -395,7 +395,7 @@ def _count_elements(mapping, iterable):
|
|||
|
||||
try: # Load C helper function if available
|
||||
from _collections import _count_elements
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
class Counter(dict):
|
||||
|
|
|
@ -59,7 +59,7 @@ error = Error # backward compatibility
|
|||
|
||||
try:
|
||||
from org.python.core import PyStringMap
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
PyStringMap = None
|
||||
|
||||
__all__ = ["Error", "copy", "deepcopy"]
|
||||
|
|
|
@ -2116,7 +2116,7 @@ _EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)
|
|||
|
||||
try:
|
||||
from _datetime import *
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
# Clean up unused names
|
||||
|
|
|
@ -149,7 +149,7 @@ import sys
|
|||
try:
|
||||
from collections import namedtuple as _namedtuple
|
||||
DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent')
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
DecimalTuple = lambda *args: args
|
||||
|
||||
# Rounding
|
||||
|
@ -430,7 +430,7 @@ _rounding_modes = (ROUND_DOWN, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_CEILING,
|
|||
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Python was compiled without threads; create a mock object instead
|
||||
class MockThreading(object):
|
||||
def local(self, sys=sys):
|
||||
|
@ -6147,7 +6147,7 @@ del re
|
|||
# don't care too much if locale isn't present.
|
||||
try:
|
||||
import locale as _locale
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
def _parse_format_specifier(format_spec, _localeconv=None):
|
||||
|
@ -6391,7 +6391,7 @@ del sys
|
|||
|
||||
try:
|
||||
import _decimal
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
s1 = set(dir())
|
||||
|
|
|
@ -9,7 +9,7 @@ import sys
|
|||
|
||||
try:
|
||||
import zipfile
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
zipfile = None
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Contains CCompiler, an abstract base class that defines the interface
|
||||
for the Distutils compiler abstraction model."""
|
||||
|
||||
import sys, os, re
|
||||
import importlib, sys, os, re
|
||||
from distutils.errors import *
|
||||
from distutils.spawn import spawn
|
||||
from distutils.file_util import move_file
|
||||
|
@ -1013,10 +1013,9 @@ def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
|
|||
|
||||
try:
|
||||
module_name = "distutils." + module_name
|
||||
__import__ (module_name)
|
||||
module = sys.modules[module_name]
|
||||
module = importlib.import_module(module_name)
|
||||
klass = vars(module)[class_name]
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise DistutilsModuleError(
|
||||
"can't compile C/C++ code: unable to load module '%s'" % \
|
||||
module_name)
|
||||
|
|
|
@ -4,11 +4,11 @@ Provides the Distribution class, which represents the module distribution
|
|||
being built/installed/distributed.
|
||||
"""
|
||||
|
||||
import sys, os, re
|
||||
import importlib, sys, os, re
|
||||
|
||||
try:
|
||||
import warnings
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
warnings = None
|
||||
|
||||
from distutils.errors import *
|
||||
|
@ -788,9 +788,8 @@ Common commands: (see '--help-commands' for more)
|
|||
klass_name = command
|
||||
|
||||
try:
|
||||
__import__ (module_name)
|
||||
module = sys.modules[module_name]
|
||||
except ImportError:
|
||||
module = importlib.import_module(module_name)
|
||||
except ModuleNotFoundError:
|
||||
continue
|
||||
|
||||
try:
|
||||
|
|
|
@ -28,7 +28,7 @@ try:
|
|||
RegEnumValue = winreg.EnumValue
|
||||
RegError = winreg.error
|
||||
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
try:
|
||||
import win32api
|
||||
import win32con
|
||||
|
@ -39,7 +39,7 @@ except ImportError:
|
|||
RegEnumKey = win32api.RegEnumKey
|
||||
RegEnumValue = win32api.RegEnumValue
|
||||
RegError = win32api.error
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
log.info("Warning: Can't read registry to find the "
|
||||
"necessary compiler setting\n"
|
||||
"Make sure that Python modules winreg, "
|
||||
|
|
|
@ -388,7 +388,7 @@ def byte_compile (py_files,
|
|||
try:
|
||||
from tempfile import mkstemp
|
||||
(script_fd, script_name) = mkstemp(".py")
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from tempfile import mktemp
|
||||
(script_fd, script_name) = None, mktemp(".py")
|
||||
log.info("writing byte-compilation script '%s'", script_name)
|
||||
|
|
|
@ -29,11 +29,11 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
|
|||
"""#"
|
||||
|
||||
import codecs
|
||||
import importlib
|
||||
from . import aliases
|
||||
|
||||
_cache = {}
|
||||
_unknown = '--unknown--'
|
||||
_import_tail = ['*']
|
||||
_aliases = aliases.aliases
|
||||
|
||||
class CodecRegistryError(LookupError, SystemError):
|
||||
|
@ -94,9 +94,8 @@ def search_function(encoding):
|
|||
try:
|
||||
# Import is absolute to prevent the possibly malicious import of a
|
||||
# module with side-effects that is not in the 'encodings' package.
|
||||
mod = __import__('encodings.' + modname, fromlist=_import_tail,
|
||||
level=0)
|
||||
except ImportError:
|
||||
mod = importlib.import_module('encodings.' + modname)
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
|
|
|
@ -667,7 +667,7 @@ class FTP:
|
|||
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_SSLSocket = None
|
||||
else:
|
||||
_SSLSocket = ssl.SSLSocket
|
||||
|
|
|
@ -15,7 +15,7 @@ __all__ = ['update_wrapper', 'wraps', 'WRAPPER_ASSIGNMENTS', 'WRAPPER_UPDATES',
|
|||
|
||||
try:
|
||||
from _functools import reduce
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
from abc import get_cache_token
|
||||
from collections import namedtuple
|
||||
|
@ -143,7 +143,7 @@ def cmp_to_key(mycmp):
|
|||
|
||||
try:
|
||||
from _functools import cmp_to_key
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ def partial(func, *args, **keywords):
|
|||
|
||||
try:
|
||||
from _functools import partial
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ __all__ = ["GetoptError","error","getopt","gnu_getopt"]
|
|||
import os
|
||||
try:
|
||||
from gettext import gettext as _
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Bootstrapping Python: gettext's dependencies not built yet
|
||||
def _(s): return s
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ try:
|
|||
except (ImportError, AttributeError):
|
||||
try:
|
||||
import msvcrt
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
getpass = fallback_getpass
|
||||
else:
|
||||
getpass = win_getpass
|
||||
|
|
|
@ -98,7 +98,7 @@ def __get_builtin_constructor(name):
|
|||
return _sha3.sha3_384
|
||||
elif bs == '512':
|
||||
return _sha3.sha3_512
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass # no extension module, this hash is unsupported.
|
||||
|
||||
raise ValueError('unsupported hash type ' + name)
|
||||
|
@ -143,7 +143,7 @@ try:
|
|||
__get_hash = __get_openssl_constructor
|
||||
algorithms_available = algorithms_available.union(
|
||||
_hashlib.openssl_md_meth_names)
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
new = __py_new
|
||||
__get_hash = __get_builtin_constructor
|
||||
|
||||
|
|
|
@ -343,7 +343,7 @@ def _siftup_max(heap, pos):
|
|||
# If available, use C implementation
|
||||
try:
|
||||
from _heapq import *
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
def merge(*iterables):
|
||||
|
|
|
@ -1156,7 +1156,7 @@ class HTTPConnection:
|
|||
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
class HTTPSConnection(HTTPConnection):
|
||||
|
|
|
@ -35,7 +35,7 @@ import time
|
|||
import urllib.parse, urllib.request
|
||||
try:
|
||||
import threading as _threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
import dummy_threading as _threading
|
||||
import http.client # only for the default HTTP port
|
||||
from calendar import timegm
|
||||
|
|
|
@ -904,7 +904,7 @@ def nobody_uid():
|
|||
return nobody
|
||||
try:
|
||||
import pwd
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return -1
|
||||
try:
|
||||
nobody = pwd.getpwnam('nobody')[2]
|
||||
|
|
|
@ -29,7 +29,7 @@ from io import DEFAULT_BUFFER_SIZE
|
|||
try:
|
||||
import ssl
|
||||
HAVE_SSL = True
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
HAVE_SSL = False
|
||||
|
||||
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple",
|
||||
|
|
|
@ -12,7 +12,7 @@ from _imp import (lock_held, acquire_lock, release_lock,
|
|||
_fix_co_filename)
|
||||
try:
|
||||
from _imp import load_dynamic
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Platform doesn't support dynamic loading.
|
||||
load_dynamic = None
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import sys
|
|||
|
||||
try:
|
||||
import _frozen_importlib as _bootstrap
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from . import _bootstrap
|
||||
_bootstrap._setup(sys, _imp)
|
||||
else:
|
||||
|
|
|
@ -3,7 +3,7 @@ from . import _bootstrap
|
|||
from . import machinery
|
||||
try:
|
||||
import _frozen_importlib
|
||||
except ImportError as exc:
|
||||
except ModuleNotFoundError as exc:
|
||||
if exc.name != '_frozen_importlib':
|
||||
raise
|
||||
_frozen_importlib = None
|
||||
|
|
|
@ -51,7 +51,7 @@ from collections import namedtuple, OrderedDict
|
|||
# back to hardcording so the dependency is optional
|
||||
try:
|
||||
from dis import COMPILER_FLAG_NAMES as _flag_names
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
CO_OPTIMIZED, CO_NEWLOCALS = 0x1, 0x2
|
||||
CO_VARARGS, CO_VARKEYWORDS = 0x4, 0x8
|
||||
CO_NESTED, CO_GENERATOR, CO_NOFREE = 0x10, 0x20, 0x40
|
||||
|
|
|
@ -5,7 +5,7 @@ import re
|
|||
from json import scanner
|
||||
try:
|
||||
from _json import scanstring as c_scanstring
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
c_scanstring = None
|
||||
|
||||
__all__ = ['JSONDecoder']
|
||||
|
|
|
@ -4,11 +4,11 @@ import re
|
|||
|
||||
try:
|
||||
from _json import encode_basestring_ascii as c_encode_basestring_ascii
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
c_encode_basestring_ascii = None
|
||||
try:
|
||||
from _json import make_encoder as c_make_encoder
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
c_make_encoder = None
|
||||
|
||||
ESCAPE = re.compile(r'[\x00-\x1f\\"\b\f\n\r\t]')
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import re
|
||||
try:
|
||||
from _json import make_scanner as c_make_scanner
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
c_make_scanner = None
|
||||
|
||||
__all__ = ['make_scanner']
|
||||
|
|
|
@ -706,7 +706,7 @@ class MultiprocessRefactoringTool(RefactoringTool):
|
|||
items, write, doctests_only)
|
||||
try:
|
||||
import multiprocessing
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise MultiprocessingUnsupported
|
||||
if self.queue is not None:
|
||||
raise RuntimeError("already doing multiple processes")
|
||||
|
|
|
@ -47,7 +47,7 @@ try:
|
|||
|
||||
from _locale import *
|
||||
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
|
||||
# Locale emulation
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
|
|||
|
||||
try:
|
||||
import threading
|
||||
except ImportError: #pragma: no cover
|
||||
except ModuleNotFoundError: #pragma: no cover
|
||||
threading = None
|
||||
|
||||
__author__ = "Vinay Sajip <vinay_sajip@red-dove.com>"
|
||||
|
|
|
@ -30,7 +30,7 @@ import io
|
|||
try:
|
||||
import _thread as thread
|
||||
import threading
|
||||
except ImportError: #pragma: no cover
|
||||
except ModuleNotFoundError: #pragma: no cover
|
||||
thread = None
|
||||
|
||||
from socketserver import ThreadingTCPServer, StreamRequestHandler
|
||||
|
|
|
@ -29,7 +29,7 @@ from stat import ST_DEV, ST_INO, ST_MTIME
|
|||
import queue
|
||||
try:
|
||||
import threading
|
||||
except ImportError: #pragma: no cover
|
||||
except ModuleNotFoundError: #pragma: no cover
|
||||
threading = None
|
||||
|
||||
#
|
||||
|
@ -995,7 +995,7 @@ class NTEventLogHandler(logging.Handler):
|
|||
logging.ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,
|
||||
logging.CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,
|
||||
}
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
print("The Python Win32 extensions for NT (service, event "\
|
||||
"logging) appear not to be available.")
|
||||
self._welu = None
|
||||
|
|
|
@ -187,7 +187,7 @@ def realpath(path):
|
|||
path = abspath(path)
|
||||
try:
|
||||
import Carbon.File
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return path
|
||||
if not path:
|
||||
return path
|
||||
|
|
|
@ -23,7 +23,7 @@ import io
|
|||
import contextlib
|
||||
try:
|
||||
import fcntl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
fcntl = None
|
||||
|
||||
__all__ = [ 'Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF',
|
||||
|
|
|
@ -29,7 +29,7 @@ import posixpath
|
|||
import urllib.parse
|
||||
try:
|
||||
import winreg as _winreg
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_winreg = None
|
||||
|
||||
__all__ = [
|
||||
|
|
|
@ -27,7 +27,7 @@ from multiprocessing.forking import ForkingPickler
|
|||
try:
|
||||
import _winapi
|
||||
from _winapi import WAIT_OBJECT_0, WAIT_TIMEOUT, INFINITE
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
if sys.platform == 'win32':
|
||||
raise
|
||||
_winapi = None
|
||||
|
|
|
@ -73,7 +73,7 @@ ForkingPickler.register(type(int.__add__), _reduce_method_descriptor)
|
|||
|
||||
try:
|
||||
from functools import partial
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
def _reduce_partial(p):
|
||||
|
|
|
@ -71,7 +71,7 @@ import warnings
|
|||
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_have_ssl = False
|
||||
else:
|
||||
_have_ssl = True
|
||||
|
|
|
@ -566,7 +566,7 @@ def normpath(path):
|
|||
try:
|
||||
from nt import _getfullpathname
|
||||
|
||||
except ImportError: # not running on Windows - mock up something sensible
|
||||
except ModuleNotFoundError: # not running on Windows - mock up something sensible
|
||||
def abspath(path):
|
||||
"""Return the absolute version of a path."""
|
||||
if not isabs(path):
|
||||
|
@ -659,6 +659,6 @@ try:
|
|||
# This is overkill on Windows - just pass the path to GetFileAttributes
|
||||
# and check the attribute from there.
|
||||
from nt import _isdir as isdir
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Use genericpath.isdir as imported above.
|
||||
pass
|
||||
|
|
|
@ -360,7 +360,7 @@ def ixor(a, b):
|
|||
|
||||
try:
|
||||
from _operator import *
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
from _operator import __doc__
|
||||
|
|
|
@ -87,7 +87,7 @@ def _repr(self):
|
|||
|
||||
try:
|
||||
from gettext import gettext, ngettext
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
def gettext(message):
|
||||
return message
|
||||
|
||||
|
|
14
Lib/os.py
14
Lib/os.py
|
@ -52,13 +52,13 @@ if 'posix' in _names:
|
|||
try:
|
||||
from posix import _exit
|
||||
__all__.append('_exit')
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
import posixpath as path
|
||||
|
||||
try:
|
||||
from posix import _have_functions
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
elif 'nt' in _names:
|
||||
|
@ -68,7 +68,7 @@ elif 'nt' in _names:
|
|||
try:
|
||||
from nt import _exit
|
||||
__all__.append('_exit')
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
import ntpath as path
|
||||
|
||||
|
@ -78,7 +78,7 @@ elif 'nt' in _names:
|
|||
|
||||
try:
|
||||
from nt import _have_functions
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
elif 'ce' in _names:
|
||||
|
@ -88,7 +88,7 @@ elif 'ce' in _names:
|
|||
try:
|
||||
from ce import _exit
|
||||
__all__.append('_exit')
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
# We can use the standard Windows path.
|
||||
import ntpath as path
|
||||
|
@ -99,11 +99,11 @@ elif 'ce' in _names:
|
|||
|
||||
try:
|
||||
from ce import _have_functions
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
else:
|
||||
raise ImportError('no os specific module found')
|
||||
raise ModuleNotFoundError('no os specific module found')
|
||||
|
||||
sys.modules['os.path'] = path
|
||||
from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
|
||||
|
|
|
@ -158,7 +158,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
import readline
|
||||
# remove some common file name delimiters
|
||||
readline.set_completer_delims(' \t\n`@#$%^&*()=+[{]}\\|;:\'",<>?')
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
self.allow_kbdint = False
|
||||
self.nosigint = nosigint
|
||||
|
|
|
@ -90,7 +90,7 @@ class _Stop(Exception):
|
|||
# Jython has PyStringMap; it's a dict subclass with string keys
|
||||
try:
|
||||
from org.python.core import PyStringMap
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
PyStringMap = None
|
||||
|
||||
# Pickle opcodes. See pickletools.py for extensive docs. The listing
|
||||
|
@ -1296,7 +1296,7 @@ def loads(s, *, fix_imports=True, encoding="ASCII", errors="strict"):
|
|||
# Use the faster _pickle if possible
|
||||
try:
|
||||
from _pickle import *
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
Pickler, Unpickler = _Pickler, _Unpickler
|
||||
|
||||
# Doctest
|
||||
|
|
|
@ -460,7 +460,7 @@ def _win32_getvalue(key,name,default=''):
|
|||
try:
|
||||
# Use win32api if available
|
||||
from win32api import RegQueryValueEx
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# On Python 2.0 and later, emulate using winreg
|
||||
import winreg
|
||||
RegQueryValueEx = winreg.QueryValueEx
|
||||
|
@ -503,7 +503,7 @@ def win32_ver(release='',version='',csd='',ptype=''):
|
|||
RegCloseKey, GetVersionEx
|
||||
from win32con import HKEY_LOCAL_MACHINE, VER_PLATFORM_WIN32_NT, \
|
||||
VER_PLATFORM_WIN32_WINDOWS, VER_NT_WORKSTATION
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Emulate the win32api module using Python APIs
|
||||
try:
|
||||
sys.getwindowsversion
|
||||
|
@ -661,7 +661,7 @@ def _mac_ver_gestalt():
|
|||
# Check whether the version info module is available
|
||||
try:
|
||||
import _gestalt
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return None
|
||||
# Get the infos
|
||||
sysv, sysa = _mac_ver_lookup(('sysv','sysa'))
|
||||
|
@ -697,7 +697,7 @@ def _mac_ver_xml():
|
|||
|
||||
try:
|
||||
import plistlib
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return None
|
||||
|
||||
pl = plistlib.readPlist(fn)
|
||||
|
@ -762,7 +762,7 @@ def java_ver(release='',vendor='',vminfo=('','',''),osinfo=('','','')):
|
|||
# Import the needed APIs
|
||||
try:
|
||||
import java.lang
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return release,vendor,vminfo,osinfo
|
||||
|
||||
vendor = _java_getprop('java.vendor', vendor)
|
||||
|
@ -874,7 +874,7 @@ def _node(default=''):
|
|||
"""
|
||||
try:
|
||||
import socket
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# No sockets...
|
||||
return default
|
||||
try:
|
||||
|
@ -1138,7 +1138,7 @@ def uname():
|
|||
# Get processor information
|
||||
try:
|
||||
import vms_lib
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
csid, cpu_number = vms_lib.getsyi('SYI$_CPU',0)
|
||||
|
|
|
@ -20,7 +20,7 @@ import socket
|
|||
try:
|
||||
import ssl
|
||||
HAVE_SSL = True
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
HAVE_SSL = False
|
||||
|
||||
__all__ = ["POP3","error_proto"]
|
||||
|
|
|
@ -528,7 +528,7 @@ if __name__ == '__main__':
|
|||
import cmd
|
||||
try:
|
||||
import readline
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
|
||||
class ProfileBrowser(cmd.Cmd):
|
||||
|
|
|
@ -67,7 +67,7 @@ def slave_open(tty_name):
|
|||
result = os.open(tty_name, os.O_RDWR)
|
||||
try:
|
||||
from fcntl import ioctl, I_PUSH
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return result
|
||||
try:
|
||||
ioctl(result, I_PUSH, "ptem")
|
||||
|
|
|
@ -1893,7 +1893,7 @@ Here is a list of available topics. Enter any topic name to get more help.
|
|||
def showtopic(self, topic, more_xrefs=''):
|
||||
try:
|
||||
import pydoc_data.topics
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
self.output.write('''
|
||||
Sorry, topic and keyword documentation is not available because the
|
||||
module "pydoc_data.topics" could not be found.
|
||||
|
@ -1933,7 +1933,7 @@ module "pydoc_data.topics" could not be found.
|
|||
"""
|
||||
try:
|
||||
import pydoc_data.topics
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return('''
|
||||
Sorry, topic and keyword documentation is not available because the
|
||||
module "pydoc_data.topics" could not be found.
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
import dummy_threading as threading
|
||||
from collections import deque
|
||||
from heapq import heappush, heappop
|
||||
try:
|
||||
from time import monotonic as time
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from time import time
|
||||
|
||||
__all__ = ['Empty', 'Full', 'Queue', 'PriorityQueue', 'LifoQueue']
|
||||
|
|
|
@ -13,7 +13,7 @@ EMPTYSTRING = b''
|
|||
|
||||
try:
|
||||
from binascii import a2b_qp, b2a_qp
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
a2b_qp = None
|
||||
b2a_qp = None
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import builtins
|
|||
from itertools import islice
|
||||
try:
|
||||
from _thread import get_ident
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from _dummy_thread import get_ident
|
||||
|
||||
def recursive_repr(fillvalue='...'):
|
||||
|
|
|
@ -154,7 +154,7 @@ def get_class_members(klass):
|
|||
|
||||
try:
|
||||
import readline
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
readline.set_completer(Completer().complete)
|
||||
|
|
|
@ -33,11 +33,11 @@ import heapq
|
|||
from collections import namedtuple
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
import dummy_threading as threading
|
||||
try:
|
||||
from time import monotonic as _time
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from time import time as _time
|
||||
|
||||
__all__ = ["scheduler"]
|
||||
|
|
|
@ -17,17 +17,17 @@ try:
|
|||
import bz2
|
||||
del bz2
|
||||
_BZ2_SUPPORTED = True
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_BZ2_SUPPORTED = False
|
||||
|
||||
try:
|
||||
from pwd import getpwnam
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
getpwnam = None
|
||||
|
||||
try:
|
||||
from grp import getgrnam
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
getgrnam = None
|
||||
|
||||
__all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2",
|
||||
|
@ -668,7 +668,7 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
|
|||
# command.
|
||||
try:
|
||||
import zipfile
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
zipfile = None
|
||||
|
||||
if zipfile is None:
|
||||
|
@ -858,7 +858,7 @@ def _unpack_zipfile(filename, extract_dir):
|
|||
"""
|
||||
try:
|
||||
import zipfile
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise ReadError('zlib not supported, cannot unpack this archive.')
|
||||
|
||||
if not zipfile.is_zipfile(filename):
|
||||
|
|
|
@ -469,7 +469,7 @@ def enablerlcompleter():
|
|||
try:
|
||||
import readline
|
||||
import rlcompleter
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return
|
||||
|
||||
# Reading the initialization (config) file may not be enough to set a
|
||||
|
@ -570,7 +570,7 @@ def execsitecustomize():
|
|||
"""Run custom site specific code, if available."""
|
||||
try:
|
||||
import sitecustomize
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
except Exception as err:
|
||||
if os.environ.get("PYTHONVERBOSE"):
|
||||
|
@ -586,7 +586,7 @@ def execusercustomize():
|
|||
"""Run custom user specific code, if available."""
|
||||
try:
|
||||
import usercustomize
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
except Exception as err:
|
||||
if os.environ.get("PYTHONVERBOSE"):
|
||||
|
|
|
@ -846,7 +846,7 @@ if __name__ == '__main__':
|
|||
if options.setuid:
|
||||
try:
|
||||
import pwd
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
print('Cannot import module "pwd"; try running with -n option.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
nobody = pwd.getpwnam('nobody')[2]
|
||||
|
|
|
@ -171,7 +171,7 @@ def _fix_eols(data):
|
|||
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_have_ssl = False
|
||||
else:
|
||||
_have_ssl = True
|
||||
|
|
|
@ -51,7 +51,7 @@ import os, sys, io
|
|||
|
||||
try:
|
||||
import errno
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
errno = None
|
||||
EBADF = getattr(errno, 'EBADF', 9)
|
||||
EAGAIN = getattr(errno, 'EAGAIN', 11)
|
||||
|
|
|
@ -136,7 +136,7 @@ import os
|
|||
import errno
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
import dummy_threading as threading
|
||||
|
||||
__all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer",
|
||||
|
|
|
@ -25,7 +25,7 @@ import unittest
|
|||
import sqlite3 as sqlite
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
threading = None
|
||||
|
||||
from test.support import TESTFN, unlink
|
||||
|
|
|
@ -26,7 +26,7 @@ import unittest
|
|||
import sqlite3 as sqlite
|
||||
try:
|
||||
import zlib
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
zlib = None
|
||||
|
||||
|
||||
|
|
|
@ -295,7 +295,7 @@ def _mk_bitmap(bits):
|
|||
def _optimize_unicode(charset, fixup):
|
||||
try:
|
||||
import array
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
return charset
|
||||
charmap = [0]*65536
|
||||
negate = 0
|
||||
|
|
|
@ -127,14 +127,14 @@ _PROTOCOL_NAMES = {
|
|||
try:
|
||||
from _ssl import PROTOCOL_SSLv2
|
||||
_SSLv2_IF_EXISTS = PROTOCOL_SSLv2
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_SSLv2_IF_EXISTS = None
|
||||
else:
|
||||
_PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2"
|
||||
|
||||
try:
|
||||
from _ssl import PROTOCOL_TLSv1_1, PROTOCOL_TLSv1_2
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
pass
|
||||
else:
|
||||
_PROTOCOL_NAMES[PROTOCOL_TLSv1_1] = "TLSv1.1"
|
||||
|
|
|
@ -353,7 +353,7 @@ import warnings
|
|||
import errno
|
||||
try:
|
||||
from time import monotonic as _time
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from time import time as _time
|
||||
|
||||
# Exception classes used by this module.
|
||||
|
|
|
@ -50,7 +50,7 @@ import re
|
|||
|
||||
try:
|
||||
import grp, pwd
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
grp = pwd = None
|
||||
|
||||
# os.symlink on Windows prior to 6.0 raises NotImplementedError
|
||||
|
@ -381,7 +381,7 @@ class _Stream:
|
|||
if comptype == "gz":
|
||||
try:
|
||||
import zlib
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise CompressionError("zlib module is not available")
|
||||
self.zlib = zlib
|
||||
self.crc = zlib.crc32(b"")
|
||||
|
@ -394,7 +394,7 @@ class _Stream:
|
|||
elif comptype == "bz2":
|
||||
try:
|
||||
import bz2
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise CompressionError("bz2 module is not available")
|
||||
if mode == "r":
|
||||
self.dbuf = b""
|
||||
|
@ -406,7 +406,7 @@ class _Stream:
|
|||
elif comptype == "xz":
|
||||
try:
|
||||
import lzma
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise CompressionError("lzma module is not available")
|
||||
if mode == "r":
|
||||
self.dbuf = b""
|
||||
|
@ -1654,7 +1654,7 @@ class TarFile(object):
|
|||
|
||||
try:
|
||||
import bz2
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise CompressionError("bz2 module is not available")
|
||||
|
||||
fileobj = bz2.BZ2File(fileobj or name, mode,
|
||||
|
@ -1678,7 +1678,7 @@ class TarFile(object):
|
|||
|
||||
try:
|
||||
import lzma
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise CompressionError("lzma module is not available")
|
||||
|
||||
fileobj = lzma.LZMAFile(fileobj or name, mode, preset=preset)
|
||||
|
|
|
@ -36,7 +36,7 @@ from random import Random as _Random
|
|||
|
||||
try:
|
||||
import fcntl as _fcntl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
def _set_cloexec(fd):
|
||||
pass
|
||||
else:
|
||||
|
@ -53,7 +53,7 @@ else:
|
|||
|
||||
try:
|
||||
import _thread
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
import _dummy_thread as _thread
|
||||
_allocate_lock = _thread.allocate_lock
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@ import _thread
|
|||
from time import sleep as _sleep
|
||||
try:
|
||||
from time import monotonic as _time
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from time import time as _time
|
||||
from traceback import format_exc as _format_exc
|
||||
from _weakrefset import WeakSet
|
||||
from itertools import islice as _islice
|
||||
try:
|
||||
from _collections import deque as _deque
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from collections import deque as _deque
|
||||
|
||||
# Note regarding PEP 8 compliant names
|
||||
|
@ -922,7 +922,7 @@ _shutdown = _MainThread()._exitfunc
|
|||
|
||||
try:
|
||||
from _thread import _local as local
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from _threading_local import local
|
||||
|
||||
|
||||
|
|
|
@ -61,12 +61,12 @@ import pickle
|
|||
from warnings import warn as _warn
|
||||
try:
|
||||
from time import monotonic as _time
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
from time import time as _time
|
||||
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_settrace = sys.settrace
|
||||
|
||||
def _unsettrace():
|
||||
|
|
|
@ -110,7 +110,7 @@ from urllib.response import addinfourl, addclosehook
|
|||
# check for SSL
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
_have_ssl = False
|
||||
else:
|
||||
_have_ssl = True
|
||||
|
@ -2512,7 +2512,7 @@ elif os.name == 'nt':
|
|||
proxies = {}
|
||||
try:
|
||||
import winreg
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Std module, so should be around - but you never know!
|
||||
return proxies
|
||||
try:
|
||||
|
@ -2560,7 +2560,7 @@ elif os.name == 'nt':
|
|||
def proxy_bypass_registry(host):
|
||||
try:
|
||||
import winreg
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
# Std modules, so should be around - but you never know!
|
||||
return 0
|
||||
try:
|
||||
|
|
|
@ -35,7 +35,7 @@ import sys
|
|||
import sysconfig
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
threading = None
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
@ -144,8 +144,8 @@ def _getcategory(category):
|
|||
module = category[:i]
|
||||
klass = category[i+1:]
|
||||
try:
|
||||
m = __import__(module, None, None, [klass])
|
||||
except ImportError:
|
||||
m = __import__(module, fromlist[klass])
|
||||
except ModuleNotFoundError:
|
||||
raise _OptionError("invalid module name: %r" % (module,))
|
||||
try:
|
||||
cat = getattr(m, klass)
|
||||
|
@ -362,7 +362,7 @@ try:
|
|||
defaultaction = _defaultaction
|
||||
onceregistry = _onceregistry
|
||||
_warnings_defaults = True
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
filters = []
|
||||
defaultaction = "default"
|
||||
onceregistry = {}
|
||||
|
|
|
@ -1439,13 +1439,13 @@ class XMLParser:
|
|||
def __init__(self, html=0, target=None, encoding=None):
|
||||
try:
|
||||
from xml.parsers import expat
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
try:
|
||||
import pyexpat as expat
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"No module named expat; use SimpleXMLTreeBuilder instead"
|
||||
)
|
||||
except ModuleNotFoundError:
|
||||
raise ModuleNotFoundError(
|
||||
"No module named expat; use SimpleXMLTreeBuilder instead",
|
||||
name='expat')
|
||||
parser = expat.ParserCreate(encoding, "}")
|
||||
if target is None:
|
||||
target = TreeBuilder()
|
||||
|
|
|
@ -20,7 +20,7 @@ del sys
|
|||
|
||||
try:
|
||||
from xml.parsers import expat
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
raise SAXReaderNotAvailable("expat not supported", None)
|
||||
else:
|
||||
if not hasattr(expat, "ParserCreate"):
|
||||
|
@ -30,18 +30,7 @@ from xml.sax import xmlreader, saxutils, handler
|
|||
AttributesImpl = xmlreader.AttributesImpl
|
||||
AttributesNSImpl = xmlreader.AttributesNSImpl
|
||||
|
||||
# If we're using a sufficiently recent version of Python, we can use
|
||||
# weak references to avoid cycles between the parser and content
|
||||
# handler, otherwise we'll just have to pretend.
|
||||
try:
|
||||
import _weakref
|
||||
except ImportError:
|
||||
def _mkproxy(o):
|
||||
return o
|
||||
else:
|
||||
import weakref
|
||||
_mkproxy = weakref.proxy
|
||||
del weakref, _weakref
|
||||
import weakref
|
||||
|
||||
# --- ExpatLocator
|
||||
|
||||
|
@ -52,7 +41,7 @@ class ExpatLocator(xmlreader.Locator):
|
|||
a circular reference between the parser and the content handler.
|
||||
"""
|
||||
def __init__(self, parser):
|
||||
self._ref = _mkproxy(parser)
|
||||
self._ref = weakref.proxy(parser)
|
||||
|
||||
def getColumnNumber(self):
|
||||
parser = self._ref
|
||||
|
|
|
@ -139,7 +139,7 @@ import errno
|
|||
from io import BytesIO
|
||||
try:
|
||||
import gzip
|
||||
except ImportError:
|
||||
except ModuleNotFoundError:
|
||||
gzip = None #python can be built without zlib/gzip support
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue