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