[Python-checkins] commit of r41701 - sandbox/trunk/setuptools/pkg_resources.py

phillip.eby python-checkins at python.org
Thu Dec 15 20:49:04 CET 2005


Author: phillip.eby
Date: Thu Dec 15 20:49:03 2005
New Revision: 41701

Modified:
   sandbox/trunk/setuptools/pkg_resources.py
Log:
Modify resource extraction to bypass sandbox control so that egg
extraction during setup runs is not restricted.


Modified: sandbox/trunk/setuptools/pkg_resources.py
==============================================================================
--- sandbox/trunk/setuptools/pkg_resources.py	(original)
+++ sandbox/trunk/setuptools/pkg_resources.py	Thu Dec 15 20:49:03 2005
@@ -15,8 +15,8 @@
 
 import sys, os, zipimport, time, re, imp, new
 from sets import ImmutableSet
-
-
+from os import utime, rename, unlink    # capture these to bypass sandboxing
+from os import open as os_open
 
 
 
@@ -1084,13 +1084,12 @@
             if stat.st_size==size and stat.st_mtime==timestamp:
                 # size and stamp match, don't bother extracting
                 return real_path
-        from tempfile import mkstemp
-        outf, tmpnam = mkstemp(".$extract", dir=os.path.dirname(real_path))
+        outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path))
         os.write(outf, self.loader.get_data(zip_path))
         os.close(outf)
-        os.utime(tmpnam, (timestamp,timestamp))
+        utime(tmpnam, (timestamp,timestamp))
         manager.postprocess(tmpnam, real_path)
-        try: os.rename(tmpnam, real_path)
+        try: rename(tmpnam, real_path)
         except os.error:
             if os.path.isfile(real_path):
                 stat = os.stat(real_path)
@@ -1099,12 +1098,13 @@
                     # so we're done
                     return real_path
                 elif os.name=='nt':     # Windows, delete old file and retry
-                    os.unlink(real_path)
-                    os.rename(tmpnam, real_path)
+                    unlink(real_path)
+                    rename(tmpnam, real_path)
                     return real_path
             raise
         return real_path
 
+
     def _get_eager_resources(self):
         if self.eagers is None:
             eagers = []
@@ -2136,7 +2136,6 @@
     if not os.path.isdir(dirname):
         os.makedirs(dirname)
 
-
 def split_sections(s):
     """Split a string or iterable thereof into (section,content) pairs
 
@@ -2162,13 +2161,14 @@
     # wrap up last segment
     yield section, content
 
-
-
-
-
-
-
-
+def _mkstemp(*args,**kw):
+    from tempfile import mkstemp
+    old_open = os.open
+    try:
+        os.open = os_open   # temporarily bypass sandboxing
+        return mkstemp(*args,**kw)
+    finally:
+        os.open = old_open  # and then put it back
 
 
 # Set up global resource manager


More information about the Python-checkins mailing list