Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r73262:b97c7d6f7fd8
Date: 2014-09-01 10:07 +0200
http://bitbucket.org/pypy/pypy/changeset/b97c7d6f7fd8/

Log:    Move the test to a function and use it from two places.

diff --git a/pypy/module/sys/initpath.py b/pypy/module/sys/initpath.py
--- a/pypy/module/sys/initpath.py
+++ b/pypy/module/sys/initpath.py
@@ -18,6 +18,13 @@
 _WIN32 = sys.platform == 'win32'
 
 
+def _exists_and_is_executable(fn):
+    # os.access checks using the user's real uid and gid.
+    # Since pypy should not be run setuid/setgid, this
+    # should be sufficient.
+    return os.path.isfile(fn) and os.access(fn, os.X_OK)
+
+
 def find_executable(executable):
     """
     Return the absolute path of the executable, by looking into PATH and
@@ -34,18 +41,14 @@
         if path:
             for dir in path.split(os.pathsep):
                 fn = os.path.join(dir, executable)
-                if os.path.isfile(fn):
-                    # os.access checks using the user's real uid and gid.
-                    # Since pypy should not be run setuid/setgid, this
-                    # should be sufficient.
-                    if os.access(fn, os.X_OK):
-                        executable = fn
-                        break
+                if _exists_and_is_executable(fn):
+                    executable = fn
+                    break
     executable = rpath.rabspath(executable)
 
     # 'sys.executable' should not end up being an non-existing file;
     # just use '' in this case. (CPython issue #7774)
-    return executable if os.path.isfile(executable) else ''
+    return executable if _exists_and_is_executable(executable) else ''
 
 
 def _readlink_maybe(filename):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to