PyXR

c:\python24\lib\site-packages\win32 \ com

Subpackages:

Modules

Init code



0001 #
0002 # Initialization for the win32com package
0003 #
0004 
0005 import win32api, sys, os
0006 import pythoncom
0007 
0008 # flag if we are in a "frozen" build.
0009 _frozen = getattr(sys, "frozen", 1==0)
0010 # pythoncom dumbly defaults this to zero - we believe sys.frozen over it.
0011 if _frozen and not getattr(pythoncom, "frozen", 0):
0012         pythoncom.frozen = sys.frozen
0013 
0014 # Add support for an external "COM Extensions" path.
0015 #  Concept is that you can register a seperate path to be used for
0016 #  COM extensions, outside of the win32com directory.  These modules, however,
0017 #  look identical to win32com built-in modules.
0018 #  This is the technique that we use for the "standard" COM extensions.
0019 #  eg "win32com.mapi" or "win32com.axscript" both work, even though they do not
0020 #  live under the main win32com directory.
0021 __gen_path__ = ''
0022 __build_path__ = None
0023 ### TODO - Load _all_ \\Extensions subkeys - for now, we only read the default
0024 ### Modules will work if loaded into "win32comext" path.
0025 
0026 def SetupEnvironment():
0027         HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
0028         KEY_QUERY_VALUE = 0x1
0029         # Open the root key once, as this is quite slow on NT.
0030         try:
0031                 keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
0032                 key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE , keyName, 0, KEY_QUERY_VALUE)
0033         except (win32api.error, AttributeError):
0034                 key = None
0035                 
0036         try:
0037                 found = 0
0038                 if key is not None:
0039                         try:
0040                                 __path__.append( win32api.RegQueryValue(key, "Extensions" ))
0041                                 found = 1
0042                         except win32api.error:
0043                                 # Nothing registered
0044                                 pass
0045                 if not found:
0046                         try:
0047                                 __path__.append( win32api.GetFullPathName( __path__[0] + "\\..\\win32comext") )
0048                         except win32api.error:
0049                                 # Give up in disgust!
0050                                 pass
0051         
0052                 # For the sake of developers, we also look up a "BuildPath" key
0053                 # If extension modules add support, we can load their .pyd's from a completely
0054                 # different directory (see the comments below)
0055                 try:
0056                         if key is not None:
0057                                 global __build_path__
0058                                 __build_path__ = win32api.RegQueryValue(key, "BuildPath")
0059                                 __path__.append(__build_path__)
0060                 except win32api.error:
0061                         # __build_path__ neednt be defined.
0062                         pass
0063                 global __gen_path__
0064                 if key is not None:
0065                         try:
0066                                 __gen_path__ = win32api.RegQueryValue(key, "GenPath")
0067                         except win32api.error:
0068                                 pass
0069         finally:
0070                 if key is not None:
0071                         key.Close()
0072 
0073 # A Helper for developers.  A sub-package's __init__ can call this help function,
0074 # which allows the .pyd files for the extension to live in a special "Build" directory
0075 # (which the win32com developers do!)
0076 def __PackageSupportBuildPath__(package_path):
0077         # See if we have a special directory for the binaries (for developers)
0078         if not _frozen and __build_path__:
0079                 package_path.append(__build_path__)
0080 
0081 if not _frozen:
0082         SetupEnvironment()
0083 
0084 # If we don't have a special __gen_path__, see if we have a gen_py as a
0085 # normal module and use that (ie, "win32com.gen_py" may already exist as
0086 # a package.
0087 if not __gen_path__:
0088         try:
0089                 import win32com.gen_py
0090                 __gen_path__ = sys.modules["win32com.gen_py"].__path__[0]
0091         except ImportError:
0092                 # If a win32com\gen_py directory already exists, then we use it
0093                 # (gencache doesn't insist it have an __init__, but our __import__ 
0094                 # above does!
0095                 __gen_path__ = os.path.abspath(os.path.join(__path__[0], "gen_py"))
0096                 if not os.path.isdir(__gen_path__):
0097                         # We used to dynamically create a directory under win32com -
0098                         # but this sucks.  If the dir doesn't already exist, we we 
0099                         # create a version specific directory under the user temp 
0100                         # directory.
0101                         __gen_path__ = os.path.join(
0102                                                                 win32api.GetTempPath(), "gen_py",
0103                                                                 "%d.%d" % (sys.version_info[0], sys.version_info[1]))
0104 
0105 # we must have a __gen_path__, but may not have a gen_py module -
0106 # set that up.
0107 if not sys.modules.has_key("win32com.gen_py"):
0108         # Create a "win32com.gen_py", but with a custom __path__
0109         import new
0110         gen_py = new.module("win32com.gen_py")
0111         gen_py.__path__ = [ __gen_path__ ]
0112         sys.modules[gen_py.__name__]=gen_py
0113         del new
0114 gen_py = sys.modules["win32com.gen_py"]
0115 
0116 # get rid of these for module users
0117 del os, sys, win32api, pythoncom
0118 

Generated by PyXR 0.9.4
SourceForge.net Logo