def _delete_key_if_empty(self, service):
    key_name = ('Software\\%s\\Keyring' % service)
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0, winreg.KEY_ALL_ACCESS)
    try:
        winreg.EnumValue(key, 0)
        return
    except WindowsError:
        pass
    winreg.CloseKey(key)
    while (key_name != 'Software'):
        (parent, sep, base) = key_name.rpartition('\\')
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, parent, 0, winreg.KEY_ALL_ACCESS)
        winreg.DeleteKey(key, base)
        winreg.CloseKey(key)
        key_name = parent
def _delete_key_if_empty(self, service):
    key_name = ('Software\\%s\\Keyring' % service)
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_name, 0, winreg.KEY_ALL_ACCESS)
    try:
        winreg.EnumValue(key, 0)
        return
    except WindowsError:
        pass
    winreg.CloseKey(key)
    while (key_name != 'Software'):
        (parent, sep, base) = key_name.rpartition('\\')
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, parent, 0, winreg.KEY_ALL_ACCESS)
        winreg.DeleteKey(key, base)
        winreg.CloseKey(key)
        key_name = parent