'Wait for an operation to succeed'

def _wait_operation(self, id, timeout=DEFAULT_TIMEOUT, check_interval=DEFAULT_INTERVAL):

    for i in range(0, timeout, check_interval):
        try:
            op = self.connection.request('operation.info', int(id)).object
            if (op['step'] == 'DONE'):
                return True
            if (op['step'] in ['ERROR', 'CANCEL']):
                return False
        except (KeyError, IndexError):
            pass
        except Exception:
            e = sys.exc_info()[1]
            raise GandiException(1002, e)
        time.sleep(check_interval)
    return False
