Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn RegistryEntries into an ABC and create subclasses for frozen and non-frozen cases (part4 of #738). #742

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions comtypes/server/register.py
Original file line number Diff line number Diff line change
@@ -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}")


@@ -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 (