Skip to content

Commit

Permalink
Turn RegistryEntries into an ABC and create subclasses for frozen…
Browse files Browse the repository at this point in the history
… and non-frozen cases (part4 of #738). (#742)

* Split more functions.

* Split more functions.

* Small fix.
  • Loading branch information
junkmd authored Jan 14, 2025
1 parent 1d57ae8 commit 5e608d4
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions comtypes/server/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,19 @@ def _iter_ctx_entries(
yield from _iter_frozen_local_ctx_entries(cls, reg_clsid)
if inprocsvr_ctx and frozen in (None, "dll"):
yield from _iter_inproc_ctx_entries(cls, reg_clsid, frozendllhandle)
# only for non-frozen inproc servers the PythonPath/PythonClass is needed.
if frozendllhandle is None or not _clsid_to_class:
yield from _iter_inproc_python_entries(cls, reg_clsid)
yield from _iter_inproc_threading_model_entries(cls, reg_clsid)
yield from _iter_tlib_entries(cls, reg_clsid)


def _iter_interp_local_ctx_entries(cls: Type, reg_clsid: str) -> Iterator[_Entry]:
exe = sys.executable
exe = f'"{exe}"' if " " in exe else exe
if not __debug__:
exe = f"{exe} -O"
exe = f"{exe} -O" if not __debug__ else exe
script = os.path.abspath(sys.modules[cls.__module__].__file__) # type: ignore
if " " in script:
script = f'"{script}"'
script = f'"{script}"' if " " in script else script
yield (HKCR, rf"CLSID\{reg_clsid}\LocalServer32", "", f"{exe} {script}")


Expand All @@ -392,21 +394,25 @@ def _iter_inproc_ctx_entries(
"",
_get_serverdll(frozendllhandle),
)


def _iter_inproc_python_entries(cls: Type, reg_clsid: str) -> Iterator[_Entry]:
# only for non-frozen inproc servers the PythonPath/PythonClass is needed.
if frozendllhandle is None or not _clsid_to_class:
yield (
HKCR,
rf"CLSID\{reg_clsid}\InprocServer32",
"PythonClass",
_get_full_classname(cls),
)
yield (
HKCR,
rf"CLSID\{reg_clsid}\InprocServer32",
"PythonPath",
_get_pythonpath(cls),
)
yield (
HKCR,
rf"CLSID\{reg_clsid}\InprocServer32",
"PythonClass",
_get_full_classname(cls),
)
yield (
HKCR,
rf"CLSID\{reg_clsid}\InprocServer32",
"PythonPath",
_get_pythonpath(cls),
)


def _iter_inproc_threading_model_entries(cls: Type, reg_clsid: str) -> Iterator[_Entry]:
reg_threading = getattr(cls, "_reg_threading_", None)
if reg_threading is not None:
yield (
Expand Down

0 comments on commit 5e608d4

Please sign in to comment.