The HKEY object implements __enter__() and __exit__() and thus supports the context protocol for the with statement:
winreg/PyHKEY.__enter__
PyHKEY.__enter__