Commits

tarek  committed 8a16a45

fixed another sandbox viloation issue

  • Participants
  • Parent commits 15a2f5d
  • Branches 0.6-maintenance

Comments (0)

Files changed (2)

 0.6.11
 ------
 
+* Found another case of SandboxViolation - fixed
 
 
 ------

File distribute_setup.py

                 dst.close()
     return os.path.realpath(saveto)
 
+def _no_sandbox(function):
+    def __no_sandbox(*args, **kw):
+        try:
+            from setuptools.sandbox import DirectorySandbox
+            if not hasattr(DirectorySandbox, '_old'):
+                def violation(*args):
+                    pass
+                DirectorySandbox._old = DirectorySandbox._violation
+                DirectorySandbox._violation = violation
+                patched = True
+            else:
+                patched = False
+        except ImportError:
+            patched = False
 
+        try:
+            return function(*args, **kw)
+        finally:
+            if patched:
+                DirectorySandbox._violation = DirectorySandbox._old
+                del DirectorySandbox._old
+
+    return __no_sandbox
+
+@_no_sandbox
 def _patch_file(path, content):
     """Will backup the file then patch it"""
     existing_content = open(path).read()
 def _same_content(path, content):
     return open(path).read() == content
 
-def _no_sandbox(function):
-    def __no_sandbox(*args, **kw):
-        try:
-            from setuptools.sandbox import DirectorySandbox
-            def violation(*args):
-                pass
-            DirectorySandbox._old = DirectorySandbox._violation
-            DirectorySandbox._violation = violation
-            patched = True
-        except ImportError:
-            patched = False
-
-        try:
-            return function(*args, **kw)
-        finally:
-            if patched:
-                DirectorySandbox._violation = DirectorySandbox._old
-                del DirectorySandbox._old
-
-    return __no_sandbox
-
-@_no_sandbox
 def _rename_path(path):
     new_name = path + '.OLD.%s' % time.time()
     log.warn('Renaming %s into %s', path, new_name)
     os.rename(path, new_name)
     return new_name
 
+@_no_sandbox
 def _remove_flat_installation(placeholder):
     if not os.path.isdir(placeholder):
         log.warn('Unkown installation at %s', placeholder)
     finally:
         f.close()
 
+@_no_sandbox
 def _patch_egg_dir(path):
     # let's check if it's already patched
     pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')