Update of /cvsroot/pywin32/pywin32/com/win32com/client
In directory sc8-pr-cvs1:/tmp/cvs-serv5425
Modified Files:
gencache.py
Log Message:
From Thomas Heller, to make "readonly" checking of the gencache more
robust, and compatible with both py2exe and PEP302.
Index: gencache.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/client/gencache.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** gencache.py 2 Nov 2003 11:43:28 -0000 1.25
--- gencache.py 20 Jan 2004 08:31:14 -0000 1.26
***************
*** 41,45 ****
# We don't want to use isdir() though, as we have always gracefully
# created this directory when we could.
! is_readonly = win32com.__gen_path__.find(".zip\\") >= 0
# A dictionary of ITypeLibrary objects for demand generation explicitly handed to us
--- 41,45 ----
# We don't want to use isdir() though, as we have always gracefully
# created this directory when we could.
! is_readonly = getattr(win32com, "__loader__", None) or (1 == 0)
# A dictionary of ITypeLibrary objects for demand generation explicitly handed to us
***************
*** 71,85 ****
import cPickle
# Load the dictionary from a .zip file if that is where we live.
! zip_pos = win32com.__gen_path__.find(".zip\\")
! if zip_pos >= 0:
! import zipfile, cStringIO
! zip_file = win32com.__gen_path__[:zip_pos+4]
! zip_path = win32com.__gen_path__[zip_pos+5:]
! zip_path = os.path.join(zip_path, "dicts.dat").replace("\\", "/")
try:
! zf = zipfile.ZipFile(zip_file)
! f = cStringIO.StringIO(zf.read(zip_path))
! zf.close()
! except KeyError:
# Our gencache is in a .zip file (and almost certainly readonly)
# but no dicts file. That actually needn't be fatal for a frozen
--- 71,90 ----
import cPickle
# Load the dictionary from a .zip file if that is where we live.
! if hasattr(win32com, "__loader__"):
! import cStringIO
! loader = win32com.__loader__
! arc_path = loader.archive
! dicts_path = os.path.join(win32com.__gen_path__, "dicts.dat")
! if dicts_path.startswith(arc_path):
! dicts_path = dicts_path[len(arc_path)+1:]
! else:
! # Hm. See below.
! return
try:
! data = loader.get_data(dicts_path)
! except AttributeError:
! # The __loader__ has no get_data method. See below.
! return
! except IOError:
# Our gencache is in a .zip file (and almost certainly readonly)
# but no dicts file. That actually needn't be fatal for a frozen
***************
*** 94,97 ****
--- 99,103 ----
# the dict)
return
+ f = cStringIO.StringIO(data)
else:
# NOTE: IOError on file open must be caught by caller.
|