code: def _get_tough_method(self, method):
          
          def tough_method(*args, **kwargs):
              transaction = self._transaction
              if not transaction:
                  try:  # check whether connection status is bad
                      if not self._con.db.status:
                          raise AttributeError
                      if self._maxusage:  # or connection used too often
                          if self._usage >= self._maxusage:
                              raise AttributeError
                  except Exception:
                      self.reset()  # then reset the connection
              try:
                  result = method(*args, **kwargs)  # try connection method
              except Exception:  # error in query
                  if transaction:  # inside a transaction
                      self._transaction = False
                      raise  # propagate the error
                  elif self._con.db.status:  # if it was not a connection problem
                      raise  # then propagate the error
                  else:  # otherwise
                      self.reset()  # reset the connection
                      result = method(*args, **kwargs)  # and try one more time
              self._usage += 1
              return result
          return tough_method
docs: Return a "tough" version of a connection class method.
  
          The tough version checks whether the connection is bad (lost)
          and automatically and transparently tries to reset the connection
          if this is the case (for instance, the database has been restarted).