Update of /cvsroot/pywin32/pywin32/win32/Lib
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25570
Modified Files:
pywintypes.py
Log Message:
have the system loader work on py3k and document/assert how things work on both versions
Index: pywintypes.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Lib/pywintypes.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** pywintypes.py 14 Nov 2008 00:22:25 -0000 1.14
--- pywintypes.py 25 Jan 2009 05:04:07 -0000 1.15
***************
*** 1,5 ****
# Magic utility that "redirects" to pywintypesxx.dll
import imp, sys, os
- sys.modules['pywintypes_loader']=sys.modules['pywintypes']
def __import_pywin32_system_module__(modname, globs):
# This has been through a number of iterations. The problem: how to
--- 1,4 ----
***************
*** 32,35 ****
--- 31,36 ----
(ext, mode, ext_type))
# and fill our namespace with it.
+ # XXX - if this ever moves to py3k, this will probably
+ # need similar adjustments as below...
globs.update(mod.__dict__)
return
***************
*** 96,104 ****
# give up in disgust.
raise ImportError("No system module '%s' (%s)" % (modname, filename))
# Python can load the module
! mod = imp.load_module(modname, None, found,
! ('.dll', 'rb', imp.C_EXTENSION))
! # and fill our namespace with it.
! globs.update(mod.__dict__)
__import_pywin32_system_module__("pywintypes", globals())
--- 97,124 ----
# give up in disgust.
raise ImportError("No system module '%s' (%s)" % (modname, filename))
+ # py2k and py3k differences:
+ # On py2k, after doing "imp.load_module('pywintypes')", sys.modules
+ # is unchanged - ie, sys.modules['pywintypes'] still refers to *this*
+ # .py module - but the module's __dict__ has *already* need updated
+ # with the new module's contents.
+ # However, on py3k, sys.modules *is* changed - sys.modules['pywintypes']
+ # will be changed to the new module object.
+ # SO: * on py2k don't need to update any globals.
+ # * on py3k we update our module dict with the new module's dict and
+ # copy its globals to ours.
+ old_mod = sys.modules[modname]
# Python can load the module
! mod = imp.load_dynamic(modname, found)
! # Check the sys.modules[] behaviour we describe above is true...
! if sys.version_info < (3,0):
! assert sys.modules[modname] is old_mod
! assert mod is old_mod
! else:
! assert sys.modules[modname] is not old_mod
! assert sys.modules[modname] is mod
! # as above - re-reset to the *old* module object then update globs.
! sys.modules[modname] = old_mod
! globs.update(mod.__dict__)
!
__import_pywin32_system_module__("pywintypes", globals())
|