util.py 884 B

12345678910111213141516171819202122232425262728293031
  1. """General utility functions common to client and server.
  2. This module contains a collection of general purpose utility functions.
  3. """
  4. import pythoncom
  5. import win32api, win32con
  6. def IIDToInterfaceName(iid):
  7. """Converts an IID to a string interface name.
  8. Used primarily for debugging purposes, this allows a cryptic IID to
  9. be converted to a useful string name. This will firstly look for interfaces
  10. known (ie, registered) by pythoncom. If not known, it will look in the
  11. registry for a registered interface.
  12. iid -- An IID object.
  13. Result -- Always a string - either an interface name, or '<Unregistered interface>'
  14. """
  15. try:
  16. return pythoncom.ServerInterfaces[iid]
  17. except KeyError:
  18. try:
  19. try:
  20. return win32api.RegQueryValue(win32con.HKEY_CLASSES_ROOT, "Interface\\%s" % iid)
  21. except win32api.error:
  22. pass
  23. except ImportError:
  24. pass
  25. return str(iid)