def onAutoIndentTriggered(self):
        """Indent current line or selected lines
        """
        cursor = self._qpart.textCursor()

        startBlock = self._qpart.document().findBlock(cursor.selectionStart())
        endBlock = self._qpart.document().findBlock(cursor.selectionEnd())

        if startBlock != endBlock:  # indent multiply lines
            stopBlock = endBlock.next()

            block = startBlock

            with self._qpart:
                while block != stopBlock:
                    self.autoIndentBlock(block, '')
                    block = block.next()
        else:  # indent 1 line
            self.autoIndentBlock(startBlock, '')
def _get_or_create_cached_value(self, key, getter, ttl=None):
        # happy path
        try:
            expiry, value = self._cache[key]
        except KeyError:
            pass
        else:
            if expiry is None or time.time() < expiry:
                logger.debug("Key %s from cache", key)
                return value
            logger.debug("Cache for key %s has expired", key)

        # get value
        value = getter()
        if ttl:
            expiry = time.time() + ttl
        else:
            expiry = None
        self._cache[key] = (expiry, value)
        logger.debug("Set cache for key %s", key)

        return value