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 (part1 of #738). (#739)

* Move `RegistryEntries` docstring.

* Add the `_Entry` type alias.
  • Loading branch information
junkmd authored Jan 14, 2025
1 parent 9853ac4 commit 3132f8f
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions comtypes/server/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def _explain(hkey: int) -> Union[str, int]:
return _KEYS.get(hkey, hkey)


_Entry = Tuple[int, str, str, str]


class Registrar(object):
"""COM class registration.
Expand Down Expand Up @@ -251,6 +254,27 @@ def _get_serverdll(handle: Optional[int]) -> str:


class RegistryEntries(object):
"""Iterator of tuples containing registry entries.
The tuples must be (key, subkey, name, value).
Required entries:
=================
_reg_clsid_ - a string or GUID instance
_reg_clsctx_ - server type(s) to register
Optional entries:
=================
_reg_desc_ - a string
_reg_progid_ - a string naming the progid, typically 'MyServer.MyObject.1'
_reg_novers_progid_ - version independend progid, typically 'MyServer.MyObject'
_reg_typelib_ - an tuple (libid, majorversion, minorversion) specifying a typelib.
_reg_threading_ - a string specifying the threading model
Note that the first part of the progid string is typically the
IDL library name of the type library containing the coclass.
"""

def __init__(
self,
cls: Type,
Expand All @@ -275,27 +299,7 @@ def _get_pythonpath(self, cls: Type) -> str:
dirname = os.path.dirname(sys.modules[modname].__file__) # type: ignore
return os.path.abspath(dirname)

def __iter__(self) -> Iterator[Tuple[int, str, str, str]]:
"""Return a iterator of tuples containing registry entries.
The tuples must be (key, subkey, name, value).
Required entries:
=================
_reg_clsid_ - a string or GUID instance
_reg_clsctx_ - server type(s) to register
Optional entries:
=================
_reg_desc_ - a string
_reg_progid_ - a string naming the progid, typically 'MyServer.MyObject.1'
_reg_novers_progid_ - version independend progid, typically 'MyServer.MyObject'
_reg_typelib_ - an tuple (libid, majorversion, minorversion) specifying a typelib.
_reg_threading_ - a string specifying the threading model
Note that the first part of the progid string is typically the
IDL library name of the type library containing the coclass.
"""
def __iter__(self) -> Iterator[_Entry]:
cls = self._cls
HKCR = winreg.HKEY_CLASSES_ROOT

Expand Down

0 comments on commit 3132f8f

Please sign in to comment.