77
88"""
99
10+ from __future__ import annotations
11+
1012import os
1113import sys
1214
1719
1820CATID_PythonCOMServer = "{B3EF80D0-68E2-11D0-A689-00C04FD658FF}"
1921
22+ __frozen : str | bool = getattr (sys , "frozen" , False )
23+
2024
2125def _set_subkeys (keyName , valueDict , base = win32con .HKEY_CLASSES_ROOT ):
2226 hkey = win32api .RegCreateKey (base , keyName )
@@ -207,13 +211,9 @@ def RegisterServer(
207211 # Set default clsctx.
208212 if not clsctx :
209213 clsctx = pythoncom .CLSCTX_INPROC_SERVER | pythoncom .CLSCTX_LOCAL_SERVER
210- # And if we are frozen, ignore the ones that don't make sense in this
211- # context.
212- if pythoncom .frozen :
213- assert sys .frozen , (
214- "pythoncom is frozen, but sys.frozen is not set - don't know the context!"
215- )
216- if sys .frozen == "dll" :
214+ # And if we are frozen, ignore the ones that don't make sense in this context.
215+ if __frozen :
216+ if __frozen == "dll" :
217217 clsctx &= pythoncom .CLSCTX_INPROC_SERVER
218218 else :
219219 clsctx &= pythoncom .CLSCTX_LOCAL_SERVER
@@ -223,7 +223,7 @@ def RegisterServer(
223223 # nod to Gordon's installer - if sys.frozen and sys.frozendllhandle
224224 # exist, then we are being registered via a DLL - use this DLL as the
225225 # file name.
226- if pythoncom . frozen :
226+ if __frozen :
227227 if hasattr (sys , "frozendllhandle" ):
228228 dllName = win32api .GetModuleFileName (sys .frozendllhandle )
229229 else :
@@ -261,9 +261,8 @@ def RegisterServer(
261261 _remove_key (keyNameRoot + "\\ InprocServer32" )
262262
263263 if clsctx & pythoncom .CLSCTX_LOCAL_SERVER :
264- if pythoncom .frozen :
265- # If we are frozen, we write "{exe} /Automate", just
266- # like "normal" .EXEs do
264+ if __frozen :
265+ # If we are frozen, we write "{exe} /Automate", just like "normal" .EXEs do
267266 exeName = win32api .GetShortPathName (sys .executable )
268267 command = f"{ exeName } /Automate"
269268 else :
@@ -302,7 +301,7 @@ def RegisterServer(
302301 _remove_key (keyNameRoot + "\\ PythonCOMPath" )
303302
304303 if addPyComCat is None :
305- addPyComCat = pythoncom . frozen == 0
304+ addPyComCat = __frozen == False
306305 if addPyComCat :
307306 catids = catids + [CATID_PythonCOMServer ]
308307
@@ -422,7 +421,7 @@ def RegisterClasses(*classes, **flags):
422421 clsctx = _get (cls , "_reg_clsctx_" )
423422 tlb_filename = _get (cls , "_reg_typelib_filename_" )
424423 # default to being a COM category only when not frozen.
425- addPyComCat = not _get (cls , "_reg_disable_pycomcat_" , pythoncom . frozen != 0 )
424+ addPyComCat = not _get (cls , "_reg_disable_pycomcat_" , __frozen )
426425 addnPath = None
427426 if debugging :
428427 # If the class has a debugging dispatcher specified, use it, otherwise
@@ -455,7 +454,7 @@ def RegisterClasses(*classes, **flags):
455454
456455 spec = moduleName + "." + cls .__name__
457456 # Frozen apps don't need their directory on sys.path
458- if not pythoncom . frozen :
457+ if not __frozen :
459458 scriptDir = os .path .split (sys .argv [0 ])[0 ]
460459 if not scriptDir :
461460 scriptDir = "."
@@ -664,7 +663,7 @@ def RegisterPyComCategory():
664663 regCat .RegisterCategories ([(CATID_PythonCOMServer , 0x0409 , "Python COM Server" )])
665664
666665
667- if not pythoncom . frozen :
666+ if not __frozen :
668667 try :
669668 win32api .RegQueryValue (
670669 win32con .HKEY_CLASSES_ROOT ,
0 commit comments