Author: Manuel Jacob <[email protected]>
Branch: py3k
Changeset: r83233:0456e4ccb47a
Date: 2016-03-21 21:59 +0100
http://bitbucket.org/pypy/pypy/changeset/0456e4ccb47a/

Log:    Remove unused functions, classes and constants from builtin _imp
        module.

        These are already implemented in the pure Python imp module.
        `get_magic` and `get_tag` have to stay because they are used by PyPy
        additions.

diff --git a/pypy/module/imp/__init__.py b/pypy/module/imp/__init__.py
--- a/pypy/module/imp/__init__.py
+++ b/pypy/module/imp/__init__.py
@@ -8,35 +8,22 @@
     applevel_name = '_imp'
 
     interpleveldefs = {
-        'SEARCH_ERROR':    'space.wrap(importing.SEARCH_ERROR)',
-        'PY_SOURCE':       'space.wrap(importing.PY_SOURCE)',
-        'PY_COMPILED':     'space.wrap(importing.PY_COMPILED)',
-        'C_EXTENSION':     'space.wrap(importing.C_EXTENSION)',
-        'PKG_DIRECTORY':   'space.wrap(importing.PKG_DIRECTORY)',
-        'C_BUILTIN':       'space.wrap(importing.C_BUILTIN)',
-        'PY_FROZEN':       'space.wrap(importing.PY_FROZEN)',
-        'IMP_HOOK':        'space.wrap(importing.IMP_HOOK)',
-        'get_suffixes':    'interp_imp.get_suffixes',
         'extension_suffixes': 'interp_imp.extension_suffixes',
 
         'get_magic':       'interp_imp.get_magic',
         'get_tag':         'interp_imp.get_tag',
         'load_dynamic':    'interp_imp.load_dynamic',
-        'new_module':      'interp_imp.new_module',
         'init_builtin':    'interp_imp.init_builtin',
         'init_frozen':     'interp_imp.init_frozen',
         'is_builtin':      'interp_imp.is_builtin',
         'is_frozen':       'interp_imp.is_frozen',
         'get_frozen_object': 'interp_imp.get_frozen_object',
         'is_frozen_package': 'interp_imp.is_frozen_package',
-        'NullImporter':    'importing.W_NullImporter',
 
         'lock_held':       'interp_imp.lock_held',
         'acquire_lock':    'interp_imp.acquire_lock',
         'release_lock':    'interp_imp.release_lock',
 
-        'cache_from_source': 'interp_imp.cache_from_source',
-        'source_from_cache': 'interp_imp.source_from_cache',
         '_fix_co_filename': 'interp_imp.fix_co_filename',
         }
 
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -20,17 +20,6 @@
 
 _WIN32 = sys.platform == 'win32'
 
-SEARCH_ERROR = 0
-PY_SOURCE = 1
-PY_COMPILED = 2
-C_EXTENSION = 3
-# PY_RESOURCE = 4
-PKG_DIRECTORY = 5
-C_BUILTIN = 6
-PY_FROZEN = 7
-# PY_CODERESOURCE = 8
-IMP_HOOK = 9
-
 SO = '.pyd' if _WIN32 else '.so'
 PREFIX = 'pypy3-'
 DEFAULT_SOABI = '%s%d%d' % ((PREFIX,) + PYPY_VERSION[:2])
@@ -104,40 +93,6 @@
     def as_unicode(self):
         return self.path
 
-class W_NullImporter(W_Root):
-    def __init__(self, space):
-        pass
-
-    def descr_init(self, space, w_path):
-        self._descr_init(space, w_path, _WIN32)
-
-    @specialize.arg(3)
-    def _descr_init(self, space, w_path, win32):
-        path = space.unicode0_w(w_path) if win32 else space.fsencode_w(w_path)
-        if not path:
-            raise OperationError(space.w_ImportError, space.wrap(
-                "empty pathname"))
-
-        # Directory should not exist
-        try:
-            st = rposix_stat.stat(_WIN32Path(path) if win32 else path)
-        except OSError:
-            pass
-        else:
-            if stat.S_ISDIR(st.st_mode):
-                raise OperationError(space.w_ImportError, space.wrap(
-                    "existing directory"))
-
-    def find_module_w(self, space, __args__):
-        return space.wrap(None)
-
-W_NullImporter.typedef = TypeDef(
-    'imp.NullImporter',
-    __new__=generic_new_descr(W_NullImporter),
-    __init__=interp2app(W_NullImporter.descr_init),
-    find_module=interp2app(W_NullImporter.find_module_w),
-    )
-
 def _prepare_module(space, w_mod, filename, pkgdir):
     w = space.wrap
     space.sys.setmodule(w_mod)
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -12,19 +12,6 @@
 from pypy.interpreter.streamutil import wrap_streamerror
 
 
-def get_suffixes(space):
-    w = space.wrap
-    suffixes_w = []
-    if importing.has_so_extension(space):
-        suffixes_w.append(
-            space.newtuple([w(importing.get_so_extension(space)),
-                            w('rb'), w(importing.C_EXTENSION)]))
-    suffixes_w.extend([
-        space.newtuple([w('.py'), w('U'), w(importing.PY_SOURCE)]),
-        space.newtuple([w('.pyc'), w('rb'), w(importing.PY_COMPILED)]),
-        ])
-    return space.newlist(suffixes_w)
-
 def extension_suffixes(space):
     suffixes_w = []
     if space.config.objspace.usemodules.cpyext:
@@ -77,9 +64,6 @@
 
     return importing.check_sys_modules(space, w_modulename)
 
-def new_module(space, w_name):
-    return space.wrap(Module(space, w_name, add_package=False))
-
 def init_builtin(space, w_name):
     name = space.str0_w(w_name)
     if name not in space.builtin_modules:
@@ -135,34 +119,6 @@
         importing.getimportlock(space).reinit_lock()
 
 @unwrap_spec(pathname='fsencode')
-def cache_from_source(space, pathname, w_debug_override=None):
-    """cache_from_source(path, [debug_override]) -> path
-    Given the path to a .py file, return the path to its .pyc/.pyo file.
-
-    The .py file does not need to exist; this simply returns the path to the
-    .pyc/.pyo file calculated as if the .py file were imported.  The extension
-    will be .pyc unless __debug__ is not defined, then it will be .pyo.
-
-    If debug_override is not None, then it must be a boolean and is taken as
-    the value of __debug__ instead."""
-    return space.fsdecode(space.wrapbytes(
-            importing.make_compiled_pathname(pathname)))
-
-@unwrap_spec(pathname='fsencode')
-def source_from_cache(space, pathname):
-    """source_from_cache(path) -> path
-    Given the path to a .pyc./.pyo file, return the path to its .py file.
-
-    The .pyc/.pyo file does not need to exist; this simply returns the path to
-    the .py file calculated to correspond to the .pyc/.pyo file.  If path
-    does not conform to PEP 3147 format, ValueError will be raised."""
-    sourcename = importing.make_source_pathname(pathname)
-    if sourcename is None:
-        raise oefmt(space.w_ValueError,
-                    "Not a PEP 3147 pyc path: %s", pathname)
-    return space.fsdecode(space.wrapbytes(sourcename))
-
-@unwrap_spec(pathname='fsencode')
 def fix_co_filename(space, w_code, pathname):
     code_w = space.interp_w(PyCode, w_code)
     importing.update_code_filenames(space, code_w, pathname)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to