[Python-checkins] r60046 - in sandbox/trunk/pep370/Lib: site.py test/test_site.py
christian.heimes
python-checkins at python.org
Fri Jan 18 12:09:23 CET 2008
Author: christian.heimes
Date: Fri Jan 18 12:09:22 2008
New Revision: 60046
Modified:
sandbox/trunk/pep370/Lib/site.py
sandbox/trunk/pep370/Lib/test/test_site.py
Log:
Follow up on PEP 370 update
Modified: sandbox/trunk/pep370/Lib/site.py
==============================================================================
--- sandbox/trunk/pep370/Lib/site.py (original)
+++ sandbox/trunk/pep370/Lib/site.py Fri Jan 18 12:09:22 2008
@@ -190,7 +190,7 @@
"""Check if user site directory is safe for inclusion
The functions tests for the command line flag (including environment var),
- process uid equal to effective uid.
+ process uid/gid equal to effective uid/gid.
None: Disabled for security reasons
False: Disabled by user (command line option)
@@ -203,6 +203,10 @@
# check process uid == effective uid
if os.geteuid() != os.getuid():
return None
+ if hasattr(os, "getgid") and hasattr(os, "getegid"):
+ # check process gid == effective gid
+ if os.getegid() != os.getgid():
+ return None
return True
@@ -219,6 +223,8 @@
configuration data.
"""
global USER_BASE, USER_SITE
+ env_base = os.environ.get("PYTHONUSERBASE", None)
+
def joinuser(*args):
return os.path.expanduser(os.path.join(*args))
@@ -226,21 +232,17 @@
# # Don't know what to put here
# USER_BASE = ''
# USER_SITE = ''
- if sys.platform == "darwin":
- USER_BASE = joinuser("~", "Library", "Python")
- USER_SITE = os.path.join(USER_BASE, sys.version[:3],
- "site-packages")
- elif os.name == "nt":
+ if os.name == "nt":
base = os.environ.get("APPDATA") or "~"
- USER_BASE = joinuser(base, "Python")
+ USER_BASE = env_base if env_base else joinuser(base, "Python")
USER_SITE = os.path.join(USER_BASE,
"Python" + sys.version[0] + sys.version[2],
"site-packages")
else:
- USER_BASE = joinuser("~", ".local")
- USER_SITE = os.path.join(USER_BASE, "lib",
- "python" + sys.version[:3],
- "site-packages")
+ USER_BASE = env_base if env_base else joinuser("~", ".local")
+ USER_SITE = os.path.join(USER_BASE, "lib",
+ "python" + sys.version[:3],
+ "site-packages")
if os.path.isdir(USER_SITE):
addsitedir(USER_SITE, known_paths)
@@ -268,15 +270,15 @@
sitedirs.append(prefix)
sitedirs.append(os.path.join(prefix, "lib", "site-packages"))
- #if sys.platform == "darwin":
- # # for framework builds *only* we add the standard Apple
- # # locations. Currently only per-user, but /Library and
- # # /Network/Library could be added too
- # if 'Python.framework' in prefix:
- # sitedirs.append(
- # os.path.expanduser(
- # os.path.join("~", "Library", "Python",
- # sys.version[:3], "site-packages")))
+ if sys.platform == "darwin":
+ # for framework builds *only* we add the standard Apple
+ # locations. Currently only per-user, but /Library and
+ # /Network/Library could be added too
+ if 'Python.framework' in prefix:
+ sitedirs.append(
+ os.path.expanduser(
+ os.path.join("~", "Library", "Python",
+ sys.version[:3], "site-packages")))
for sitedir in sitedirs:
if os.path.isdir(sitedir):
Modified: sandbox/trunk/pep370/Lib/test/test_site.py
==============================================================================
--- sandbox/trunk/pep370/Lib/test/test_site.py (original)
+++ sandbox/trunk/pep370/Lib/test/test_site.py Fri Jan 18 12:09:22 2008
@@ -111,6 +111,13 @@
env=env)
self.assertEqual(rc, 0)
+ env = os.environ.copy()
+ env["PYTHONUSERBASE"] = "/tmp"
+ rc = subprocess.call([sys.executable, '-c',
+ 'import sys, user; sys.exit(user.USER_BASE.startswith("tmp"))'],
+ env=env)
+ self.assertEqual(rc, 1)
+
class PthFile(object):
"""Helper class for handling testing of .pth files"""
More information about the Python-checkins
mailing list