'Implement specific highlight for Python.'

def highlight_block(self, text):

    text = to_text_string(text)
    prev_state = tbh.get_state(self.currentBlock().previous())
    if (prev_state == self.INSIDE_DQ3STRING):
        offset = (-4)
        text = ('"""    ' + text)
    elif (prev_state == self.INSIDE_SQ3STRING):
        offset = (-4)
        text = ("'''    " + text)
    elif (prev_state == self.INSIDE_DQSTRING):
        offset = (-2)
        text = ('"    ' + text)
    elif (prev_state == self.INSIDE_SQSTRING):
        offset = (-2)
        text = ("'    " + text)
    else:
        offset = 0
        prev_state = self.NORMAL
    oedata = None
    import_stmt = None
    self.setFormat(0, len(text), self.formats['normal'])
    state = self.NORMAL
    match = self.PROG.search(text)
    while match:
        for (key, value) in list(match.groupdict().items()):
            if value:
                (start, end) = match.span(key)
                start = max([0, (start + offset)])
                end = max([0, (end + offset)])
                if (key == 'uf_sq3string'):
                    self.setFormat(start, (end - start), self.formats['string'])
                    state = self.INSIDE_SQ3STRING
                elif (key == 'uf_dq3string'):
                    self.setFormat(start, (end - start), self.formats['string'])
                    state = self.INSIDE_DQ3STRING
                elif (key == 'uf_sqstring'):
                    self.setFormat(start, (end - start), self.formats['string'])
                    state = self.INSIDE_SQSTRING
                elif (key == 'uf_dqstring'):
                    self.setFormat(start, (end - start), self.formats['string'])
                    state = self.INSIDE_DQSTRING
                else:
                    self.setFormat(start, (end - start), self.formats[key])
                    if (key == 'comment'):
                        if text.lstrip().startswith(self.cell_separators):
                            self.found_cell_separators = True
                            oedata = OutlineExplorerData()
                            oedata.text = to_text_string(text).strip()
                            oedata.fold_level = start
                            oedata.def_type = OutlineExplorerData.CELL
                            oedata.def_name = text.strip()
                        elif self.OECOMMENT.match(text.lstrip()):
                            oedata = OutlineExplorerData()
                            oedata.text = to_text_string(text).strip()
                            oedata.fold_level = start
                            oedata.def_type = OutlineExplorerData.COMMENT
                            oedata.def_name = text.strip()
                    elif (key == 'keyword'):
                        if (value in ('def', 'class')):
                            match1 = self.IDPROG.match(text, end)
                            if match1:
                                (start1, end1) = match1.span(1)
                                self.setFormat(start1, (end1 - start1), self.formats['definition'])
                                oedata = OutlineExplorerData()
                                oedata.text = to_text_string(text)
                                oedata.fold_level = start
                                oedata.def_type = self.DEF_TYPES[to_text_string(value)]
                                oedata.def_name = text[start1:end1]
                                oedata.color = self.formats['definition']
                        elif (value in ('elif', 'else', 'except', 'finally', 'for', 'if', 'try', 'while', 'with')):
                            if text.lstrip().startswith(value):
                                oedata = OutlineExplorerData()
                                oedata.text = to_text_string(text).strip()
                                oedata.fold_level = start
                                oedata.def_type = OutlineExplorerData.STATEMENT
                                oedata.def_name = text.strip()
                        elif (value == 'import'):
                            import_stmt = text.strip()
                            if ('#' in text):
                                endpos = text.index('#')
                            else:
                                endpos = len(text)
                            while True:
                                match1 = self.ASPROG.match(text, end, endpos)
                                if (not match1):
                                    break
                                (start, end) = match1.span(1)
                                self.setFormat(start, (end - start), self.formats['keyword'])
        match = self.PROG.search(text, match.end())
    tbh.set_state(self.currentBlock(), state)
    self.formats['leading'] = self.formats['normal']
    self.formats['trailing'] = self.formats['normal']
    self.highlight_spaces(text, offset)
    if (oedata is not None):
        block_nb = self.currentBlock().blockNumber()
        self.outlineexplorer_data[block_nb] = oedata
        self.outlineexplorer_data['found_cell_separators'] = self.found_cell_separators
    if (import_stmt is not None):
        block_nb = self.currentBlock().blockNumber()
        self.import_statements[block_nb] = import_stmt
