<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def toggle_attr(self, attr):
 """Toggles an attribute attr for current selection"""


        selection = self.grid.selection

        # Selection or single cell access?

        if selection:
            value = self.get_new_selection_attr_state(selection, attr)

        else:
            value = self.get_new_cell_attr_state(self.grid.actions.cursor,
                                                 attr)

        # Set the toggled value

        self.set_attr(attr, value)