[python-win32] Why the strange frozen dance in win32com/__init__.py?

Mark Hammond mhammond at skippinet.com.au
Thu Oct 11 23:53:29 CEST 2007


Note that nothing ever writes this stuff to the registry, so it is really
old, dead code that can be removed.  By all means, upload a tested patch to
sourceforge and I'd be happy to look at it.

Cheers,

Mark

> -----Original Message-----
> From: python-win32-bounces at python.org [mailto:python-win32-
> bounces at python.org] On Behalf Of quest at openend.se
> Sent: Monday, 8 October 2007 6:32 PM
> To: python-win32 at python.org
> Subject: [python-win32] Why the strange frozen dance in
> win32com/__init__.py?
> 
> (My appologies if this has been discussed earlier; my Google-fu may be
> weak.)
> 
> pywin32's win32com/__init__.py does this (slightly compacted for
> brevity):
> 
>   def SetupEnvironment():
>       try:
>           keyName =
> "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
>           key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0,
>                                     KEY_QUERY_VALUE)
>       except (win32api.error, AttributeError):
>           key = None
> 
>       try:
>           found = 0
>           if key is not None:
>               try:
>                   __path__.append(win32api.RegQueryValue(key,
> "Extensions" ))
>                   found = 1
>               except win32api.error:
>                   pass
>           if not found:
>               try:
>                   __path__.append( win32api.GetFullPathName(__path__[0]
> + "\\.\
> .\\win32comext") )
>               except win32api.error:
>                   pass
> 
>   if not sys.frozen:
>       SetupEnvironment()
> 
> Being a developer of a commercial Python application, I have beef with
> this:
> 
> I would much prefer this code to work in the opposite fashion: first
> look at the place relative to __path__, then fallback to registry
> lookup. My reason is of course, that I have no wish to install a
> "standalone" python on the user's box, nor do I want to be tripped by
> the presence of one. E.g.:
> 
>   cand_extdir = os.path.join(os.path.dirname(__path__[0]),
> 'win32comext')
>   if not os.path.exists(cand_extdir):
>       keyName =
> "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % \
>                 sys.winver
>       key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0,
>                                 KEY_QUERY_VALUE)
>       try:
>           cand_extdir = win32api.RegQueryValue(key, "Extensions" )
>       except win32api.error:
>           cand_extdir = None
> 
>   if cand_extdir:
>       __path__.append(cand_extdir)
> 
> The above disregards that SetupEnvironment code is not executed at all
> in a frozen state, but I don't have a problem with explicitly calling
> a method to get this inited; e.g:
> 
>   if getattr(sys, 'frozen', False):
>       win32com.SetupEnvironment()
> --
> Anders Qvist, Open End AB
> 
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32



More information about the python-win32 mailing list