7
7
8
8
"""
9
9
10
+ from __future__ import annotations
11
+
10
12
import os
11
13
import sys
12
14
17
19
18
20
CATID_PythonCOMServer = "{B3EF80D0-68E2-11D0-A689-00C04FD658FF}"
19
21
22
+ __frozen : str | bool = getattr (sys , "frozen" , False )
23
+
20
24
21
25
def _set_subkeys (keyName , valueDict , base = win32con .HKEY_CLASSES_ROOT ):
22
26
hkey = win32api .RegCreateKey (base , keyName )
@@ -207,13 +211,9 @@ def RegisterServer(
207
211
# Set default clsctx.
208
212
if not clsctx :
209
213
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" :
217
217
clsctx &= pythoncom .CLSCTX_INPROC_SERVER
218
218
else :
219
219
clsctx &= pythoncom .CLSCTX_LOCAL_SERVER
@@ -223,7 +223,7 @@ def RegisterServer(
223
223
# nod to Gordon's installer - if sys.frozen and sys.frozendllhandle
224
224
# exist, then we are being registered via a DLL - use this DLL as the
225
225
# file name.
226
- if pythoncom . frozen :
226
+ if __frozen :
227
227
if hasattr (sys , "frozendllhandle" ):
228
228
dllName = win32api .GetModuleFileName (sys .frozendllhandle )
229
229
else :
@@ -261,9 +261,8 @@ def RegisterServer(
261
261
_remove_key (keyNameRoot + "\\ InprocServer32" )
262
262
263
263
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
267
266
exeName = win32api .GetShortPathName (sys .executable )
268
267
command = f"{ exeName } /Automate"
269
268
else :
@@ -302,7 +301,7 @@ def RegisterServer(
302
301
_remove_key (keyNameRoot + "\\ PythonCOMPath" )
303
302
304
303
if addPyComCat is None :
305
- addPyComCat = pythoncom . frozen == 0
304
+ addPyComCat = __frozen == False
306
305
if addPyComCat :
307
306
catids = catids + [CATID_PythonCOMServer ]
308
307
@@ -422,7 +421,7 @@ def RegisterClasses(*classes, **flags):
422
421
clsctx = _get (cls , "_reg_clsctx_" )
423
422
tlb_filename = _get (cls , "_reg_typelib_filename_" )
424
423
# 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 )
426
425
addnPath = None
427
426
if debugging :
428
427
# If the class has a debugging dispatcher specified, use it, otherwise
@@ -455,7 +454,7 @@ def RegisterClasses(*classes, **flags):
455
454
456
455
spec = moduleName + "." + cls .__name__
457
456
# Frozen apps don't need their directory on sys.path
458
- if not pythoncom . frozen :
457
+ if not __frozen :
459
458
scriptDir = os .path .split (sys .argv [0 ])[0 ]
460
459
if not scriptDir :
461
460
scriptDir = "."
@@ -664,7 +663,7 @@ def RegisterPyComCategory():
664
663
regCat .RegisterCategories ([(CATID_PythonCOMServer , 0x0409 , "Python COM Server" )])
665
664
666
665
667
- if not pythoncom . frozen :
666
+ if not __frozen :
668
667
try :
669
668
win32api .RegQueryValue (
670
669
win32con .HKEY_CLASSES_ROOT ,
0 commit comments