[Python-checkins] CVS: python/dist/src/Lib site.py,1.31,1.32

Fred L. Drake fdrake@users.sourceforge.net
2001年7月20日 13:06:19 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv25448
Modified Files:
	site.py 
Log Message:
Make the add*() helper functions more robust for use after intialization
is complete: recompute _dirs_in_sys_path each time these functions are
entered after module initialization is complete, and reset before 
returning to user code.
This closes SF patch #442983.
Index: site.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/site.py,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -r1.31 -r1.32
*** site.py	2001年07月20日 14:57:12	1.31
--- site.py	2001年07月20日 20:06:17	1.32
***************
*** 78,82 ****
 # only absolute pathnames, even if we're running from the build directory.
 L = []
! dirs_in_sys_path = {}
 for dir in sys.path:
 # Filter out paths that don't exist, but leave in the empty string
--- 78,82 ----
 # only absolute pathnames, even if we're running from the build directory.
 L = []
! _dirs_in_sys_path = {}
 for dir in sys.path:
 # Filter out paths that don't exist, but leave in the empty string
***************
*** 85,91 ****
 continue
 dir, dircase = makepath(dir)
! if not dirs_in_sys_path.has_key(dircase):
 L.append(dir)
! dirs_in_sys_path[dircase] = 1
 sys.path[:] = L
 del dir, L
--- 85,91 ----
 continue
 dir, dircase = makepath(dir)
! if not _dirs_in_sys_path.has_key(dircase):
 L.append(dir)
! _dirs_in_sys_path[dircase] = 1
 sys.path[:] = L
 del dir, L
***************
*** 100,106 ****
 del get_platform, s
 
 def addsitedir(sitedir):
 sitedir, sitedircase = makepath(sitedir)
! if not dirs_in_sys_path.has_key(sitedircase):
 sys.path.append(sitedir) # Add path component
 try:
--- 100,121 ----
 del get_platform, s
 
+ def _init_pathinfo():
+ global _dirs_in_sys_path
+ _dirs_in_sys_path = d = {}
+ for dir in sys.path:
+ if dir and not os.path.isdir(dir):
+ continue
+ dir, dircase = makepath(dir)
+ d[dircase] = 1
+ 
 def addsitedir(sitedir):
+ global _dirs_in_sys_path
+ if _dirs_in_sys_path is None:
+ _init_pathinfo()
+ reset = 1
+ else:
+ reset = 0
 sitedir, sitedircase = makepath(sitedir)
! if not _dirs_in_sys_path.has_key(sitedircase):
 sys.path.append(sitedir) # Add path component
 try:
***************
*** 112,117 ****
--- 127,140 ----
 if name[-4:] == endsep + "pth":
 addpackage(sitedir, name)
+ if reset:
+ _dirs_in_sys_path = None
 
 def addpackage(sitedir, name):
+ global _dirs_in_sys_path
+ if _dirs_in_sys_path is None:
+ _init_pathinfo()
+ reset = 1
+ else:
+ reset = 0
 fullname = os.path.join(sitedir, name)
 try:
***************
*** 131,137 ****
 dir = dir[:-1]
 dir, dircase = makepath(sitedir, dir)
! if not dirs_in_sys_path.has_key(dircase) and os.path.exists(dir):
 sys.path.append(dir)
! dirs_in_sys_path[dircase] = 1
 
 prefixes = [sys.prefix]
--- 154,162 ----
 dir = dir[:-1]
 dir, dircase = makepath(sitedir, dir)
! if not _dirs_in_sys_path.has_key(dircase) and os.path.exists(dir):
 sys.path.append(dir)
! _dirs_in_sys_path[dircase] = 1
! if reset:
! _dirs_in_sys_path = None
 
 prefixes = [sys.prefix]
***************
*** 151,154 ****
--- 176,181 ----
 if os.path.isdir(sitedir):
 addsitedir(sitedir)
+ 
+ _dirs_in_sys_path = None
 
 

AltStyle によって変換されたページ (->オリジナル) /