<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_matching_symbols_pairs(self, cursor, opening_symbol, closing_symbol, backward=False):
 """ Returns the cursor for matching given symbols pairs. :param cursor: Cursor to match from. :type cursor: QTextCursor :param opening_symbol: Opening symbol. :type opening_symbol: unicode :param closing_symbol: Closing symbol to match. :type closing_symbol: unicode :return: Matching cursor. :rtype: QTextCursor """


        if cursor.hasSelection():
            start_position = cursor.selectionEnd() if backward else cursor.selectionStart()
        else:
            start_position = cursor.position()

        flags = QTextDocument.FindFlags()
        if backward:
            flags = flags | QTextDocument.FindBackward

        start_cursor = previous_start_cursor = cursor.document().find(opening_symbol, start_position, flags)
        end_cursor = previous_end_cursor = cursor.document().find(closing_symbol, start_position, flags)
        if backward:
            while start_cursor > end_cursor:
                start_cursor = cursor.document().find(opening_symbol, start_cursor.selectionStart(), flags)
                if start_cursor > end_cursor:
                    end_cursor = cursor.document().find(closing_symbol, end_cursor.selectionStart(), flags)
        else:
            while start_cursor < end_cursor:
                start_cursor = cursor.document().find(opening_symbol, start_cursor.selectionEnd(), flags)
                if start_cursor < end_cursor:
                    end_cursor = cursor.document().find(closing_symbol, end_cursor.selectionEnd(), flags)

        return end_cursor if end_cursor.position() != -1 else previous_end_cursor