[Python-checkins] r56249 - sandbox/trunk/import_in_py/_importlib.py sandbox/trunk/import_in_py/importlib.py

brett.cannon python-checkins at python.org
Wed Jul 11 02:27:42 CEST 2007


Author: brett.cannon
Date: Wed Jul 11 02:27:42 2007
New Revision: 56249

Modified:
   sandbox/trunk/import_in_py/_importlib.py
   sandbox/trunk/import_in_py/importlib.py
Log:
Remove os.path.abspath dependency.  That should remove os module dependency
entirely from _importlib (still have one in _case_ok, but that will be exposed
through imp).


Modified: sandbox/trunk/import_in_py/_importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/_importlib.py	(original)
+++ sandbox/trunk/import_in_py/_importlib.py	Wed Jul 11 02:27:42 2007
@@ -60,6 +60,7 @@
 from __future__ import with_statement
 # The injected modules are 'imp', 'sys', 'marshal', 'posix' (aka 'nt' & 'os2').
 
+# XXX Could also expose Modules/getpath.c:joinpath()
 def _path_join(*args):
     """Replacement for os.path.join so as to remove dependency on os module."""
     return path_sep.join(args)
@@ -82,14 +83,26 @@
         return False
     return (stat_info.st_mode & 0170000) == mode
 
+# XXX Could also expose Modules/getpath.c:isfile()
 def _path_isfile(path):
     """Replacement for os.path.isfile."""
     return _path_is_mode_type(path, 0100000)
 
+# XXX Could also expose Modules/getpath.c:isdir()
 def _path_isdir(path):
     """Replacement for os.path.isdir."""
     return _path_is_mode_type(path, 0040000)
 
+def _path_absolute(path):
+    """Replacement for os.path.abspath."""
+    try:
+        return posix._getfullpathname(path)
+    except AttributeError:
+        if path.startswith('/'):
+            return path
+        else:
+            return _path_join(posix.getcwd(), path)
+
 
 class _BuiltinFrozenBaseImporter(object):
 
@@ -180,7 +193,7 @@
         interactive interpreter usage).
     
         """
-        absolute_path = os.path.abspath(path_entry)
+        absolute_path = _path_absolute(path_entry)
         if _path_isdir(absolute_path):
             return FileSystemImporter(absolute_path, *self.handlers)
         else:

Modified: sandbox/trunk/import_in_py/importlib.py
==============================================================================
--- sandbox/trunk/import_in_py/importlib.py	(original)
+++ sandbox/trunk/import_in_py/importlib.py	Wed Jul 11 02:27:42 2007
@@ -30,7 +30,9 @@
 """
 import _importlib
 
-#XXX Temporary functions that should eventually be removed.
+# XXX Temporary functions that should eventually be removed.
+import os
+
 def _set__import__():
     """Set __import__ to an instance of Import."""
     global original__import__
@@ -117,17 +119,16 @@
 # XXX These all need to either go away or become built-in modules
 # (<cough>Neal</cough>).
 from errno import EACCES
-import os
+from os import sep
 import warnings
 
 _importlib._r_long = _r_long  #XXX Expose original from marshal.
 _importlib._w_long = _w_long  #XXX Expose original from marshal.
 _importlib._case_ok = _case_ok  #XXX Expose original from imp.
-_importlib.path_sep = os.sep  # For os.path.join replacement.
+_importlib.path_sep = sep  # For os.path.join replacement.
 # For allowing silent failure of .pyc creation when permission is denied.
 _importlib.EACCES = EACCES
 
-_importlib.os = os
 _importlib.warnings = warnings
 
 del _importlib


More information about the Python-checkins mailing list