MCPcopy Create free account
hub / github.com/enthought/comtypes / GUID

Class GUID

comtypes/GUID.py:19–83  ·  view source on GitHub ↗

Globally unique identifier structure.

Source from the content-addressed store, hash-verified

17
18
19class GUID(Structure):
20 """Globally unique identifier structure."""
21
22 _fields_ = [("Data1", DWORD), ("Data2", WORD), ("Data3", WORD), ("Data4", BYTE * 8)]
23
24 def __init__(self, name=None):
25 if name is not None:
26 _CLSIDFromString(str(name), byref(self))
27
28 def __repr__(self):
29 return f'GUID("{str(self)}")'
30
31 def __str__(self) -> str:
32 p = c_wchar_p()
33 _StringFromCLSID(byref(self), byref(p))
34 result = p.value
35 _CoTaskMemFree(p)
36 # stringified `GUID_null` would be '{00000000-0000-0000-0000-000000000000}'
37 # Should we do `assert result is not None`?
38 return result # type: ignore
39
40 def __bool__(self) -> bool:
41 return self != GUID_null
42
43 def __eq__(self, other) -> bool:
44 return isinstance(other, GUID) and binary(self) == binary(other)
45
46 def __hash__(self) -> int:
47 # We make GUID instances hashable, although they are mutable.
48 return hash(binary(self))
49
50 def copy(self) -> "GUID":
51 return GUID(str(self))
52
53 @classmethod
54 def from_progid(cls, progid: Any) -> "hints.Self":
55 """Get guid from progid, ..."""
56 if hasattr(progid, "_reg_clsid_"):
57 progid = progid._reg_clsid_
58 if isinstance(progid, cls):
59 return progid
60 elif isinstance(progid, str):
61 if progid.startswith("{"):
62 return cls(progid)
63 inst = cls()
64 _CLSIDFromProgID(str(progid), byref(inst))
65 return inst
66 else:
67 raise TypeError(f"Cannot construct guid from {progid!r}")
68
69 def as_progid(self) -> str:
70 """Convert a GUID into a progid"""
71 progid = c_wchar_p()
72 _ProgIDFromCLSID(byref(self), byref(progid))
73 result = progid.value
74 _CoTaskMemFree(progid)
75 # Should we do `assert result is not None`?
76 return result # type: ignore

Callers 15

IConnectionPointClass · 0.90
IEnumConnectionsClass · 0.90
ITypeLibClass · 0.90
ITypeInfoClass · 0.90
ITypeCompClass · 0.90
ICreateTypeLibClass · 0.90
ICreateTypeLib2Class · 0.90
ICreateTypeInfoClass · 0.90
IRecordInfoClass · 0.90
GetRecordInfoFromGuidsFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_imfattributesMethod · 0.72
test_com_interfaceMethod · 0.72
test_installerMethod · 0.72
test_installerMethod · 0.72
test_com_refcountsMethod · 0.72
test_com_pointersMethod · 0.72
test_product_stateMethod · 0.72
test_ienumMethod · 0.72
test_GUID_nullMethod · 0.72
test_dunder_eqMethod · 0.72
test_duner_strMethod · 0.72
test_dunder_reprMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…