'Password request wrapper.  The password is passed to the function
as the \'password\' named argument.  "None" indicates either an
unencrypted wallet, or the user cancelled the password request.
An empty input is passed as the empty string.'

def protected(func):

    def request_password(self, *args, **kwargs):
        parent = self.top_level_window()
        password = None
        while self.wallet.has_password():
            password = self.password_dialog(parent=parent)
            if (password is None):
                return
            try:
                self.wallet.check_password(password)
                break
            except Exception as e:
                self.show_error(str(e), parent=parent)
                continue
        kwargs['password'] = password
        return func(self, *args, **kwargs)
    return request_password
