'Token handler. Order is important do not rearrange.'

def __call__(self, toktype, toktext, srow_col, erow_col, line):

    self.line = line
    (srow, scol) = srow_col
    (erow, ecol) = erow_col
    oldpos = self.pos
    newpos = (self.lines[srow] + scol)
    self.pos = (newpos + len(toktext))
    if (toktype in (token.NEWLINE, tokenize.NL)):
        self.decoratorFlag = self.argFlag = 0
        if (self.markup in ['XHTML', 'CSS']):
            self.out.write('</span>')
        self.out.write('\n')
        return
    if (newpos > oldpos):
        if self.raw[oldpos:newpos].isspace():
            if ((self.lasttext != self.LINESTART) and (self.lasttext != self.LINENUMHOLDER)):
                self.out.write(self.raw[oldpos:newpos])
            else:
                self.out.write(self.raw[(oldpos + 1):newpos])
        else:
            slash = (self.raw[oldpos:newpos].find('\\') + oldpos)
            self.out.write(self.raw[oldpos:slash])
            getattr(self, ('_send%sText' % self.markup))(OPERATOR, '\\')
            self.linenum += 1
            if (self.markup in ['XHTML', 'CSS']):
                self.out.write('</span>')
            self.out.write(self.raw[(slash + 1):newpos])
    if (toktype in (token.INDENT, token.DEDENT)):
        self.pos = newpos
        return
    if ((token.LPAR <= toktype) and (toktype <= token.OP)):
        if (toktext == '@'):
            toktype = DECORATOR
            self.decoratorFlag = self.argFlag = 1
        else:
            if self.doArgs:
                if ((toktext == '(') and self.argFlag):
                    self.argFlag = 2
                elif (toktext == ':'):
                    self.argFlag = 0
            if (self.doBrackets and (toktext in ['[', ']', '(', ')', '{', '}'])):
                toktype = BRACKETS
            elif (self.doMathOps and (toktext in ['*=', '**=', '-=', '+=', '|=', '%=', '>>=', '<<=', '=', '^=', '/=', '+', '-', '**', '*', '/', '%'])):
                toktype = MATH_OPERATOR
            else:
                toktype = OPERATOR
                if ((toktext == '=') and (self.argFlag == 2)):
                    self.argFlag = 1
                elif ((toktext == ',') and (self.argFlag == 1)):
                    self.argFlag = 2
    elif ((toktype == NAME) and keyword.iskeyword(toktext)):
        toktype = KEYWORD
        if (toktext in ['class', 'def']):
            if ((toktext == 'class') and (not line[:line.find('class')].endswith('.'))):
                self.classFlag = self.argFlag = 1
            elif ((toktext == 'def') and (not line[:line.find('def')].endswith('.'))):
                self.defFlag = self.argFlag = 1
            else:
                toktype = ERRORTOKEN
    elif ((self.classFlag or self.defFlag or self.decoratorFlag) and self.doNames):
        if self.classFlag:
            self.classFlag = 0
            toktype = CLASS_NAME
        elif self.defFlag:
            self.defFlag = 0
            toktype = DEF_NAME
        elif self.decoratorFlag:
            self.decoratorFlag = 0
            toktype = DECORATOR_NAME
    elif (toktype == token.STRING):
        text = toktext.lower()
        if (text[:3] == '"""'):
            toktype = TRIPLEDOUBLEQUOTE
        elif (text[:4] == 'r"""'):
            toktype = TRIPLEDOUBLEQUOTE_R
        elif ((text[:4] == 'u"""') or (text[:5] == 'ur"""')):
            toktype = TRIPLEDOUBLEQUOTE_U
        elif (text[:1] == '"'):
            toktype = DOUBLEQUOTE
        elif (text[:2] == 'r"'):
            toktype = DOUBLEQUOTE_R
        elif ((text[:2] == 'u"') or (text[:3] == 'ur"')):
            toktype = DOUBLEQUOTE_U
        elif (text[:3] == "'''"):
            toktype = TRIPLESINGLEQUOTE
        elif (text[:4] == "r'''"):
            toktype = TRIPLESINGLEQUOTE_R
        elif ((text[:4] == "u'''") or (text[:5] == "ur'''")):
            toktype = TRIPLESINGLEQUOTE_U
        elif (text[:1] == "'"):
            toktype = SINGLEQUOTE
        elif (text[:2] == "r'"):
            toktype = SINGLEQUOTE_R
        elif ((text[:2] == "u'") or (text[:3] == "ur'")):
            toktype = SINGLEQUOTE_U
        if (self.lasttext.lower() == 'ru'):
            toktype = ERRORTOKEN
    elif (toktype == COMMENT):
        if (toktext[:2] == '##'):
            toktype = DOUBLECOMMENT
        elif (toktext[:3] == '#$#'):
            toktype = TEXT
            self.textFlag = 'SPAN'
            toktext = toktext[3:]
        elif (toktext[:3] == '#%#'):
            toktype = TEXT
            self.textFlag = 'DIV'
            toktext = toktext[3:]
        elif (toktext[:3] == '#@#'):
            toktype = TEXT
            self.textFlag = 'RAW'
            toktext = toktext[3:]
        if self.doURL:
            url_pos = toktext.find('url(')
            if (url_pos != (-1)):
                before = toktext[:url_pos]
                url = toktext[(url_pos + 4):]
                splitpoint = url.find(',')
                endpoint = url.find(')')
                after = url[(endpoint + 1):]
                url = url[:endpoint]
                if (splitpoint != (-1)):
                    urlparts = url.split(',', 1)
                    toktext = ('%s<a    href="%s">%s</a>%s' % (before, urlparts[0], urlparts[1].lstrip(), after))
                else:
                    toktext = ('%s<a    href="%s">%s</a>%s' % (before, url, url, after))
    elif (toktype == ERRORTOKEN):
        if (self.argFlag and toktext.isspace()):
            self.out.write(toktext)
            return
        elif toktext.isspace():
            if self.skip:
                self.skip = 0
                return
            else:
                self.out.write(toktext)
                return
        elif (toktext == '@'):
            toktype = DECORATOR
            self.decoratorFlag = self.argFlag = 1
    elif ((self.argFlag == 2) and (toktype == NAME) and (toktext != 'None') and self.doArgs):
        toktype = ARGS
    if (toktext in [self.LINENUMHOLDER, self.LINESTART]):
        toktype = LINENUMBER
        if (((toktext == self.LINESTART) and (not self.dolinenums)) or (toktext == self.LINENUMHOLDER)):
            self.skip = 1
    if (toktext == ''):
        return
    self.lasttext = toktext
    if (toktype in (DOUBLECOMMENT, COMMENT)):
        if (toktext.find('<a    href=') == (-1)):
            toktext = escape(toktext)
        else:
            pass
    elif (toktype == TEXT):
        pass
    else:
        toktext = escape(toktext)
    getattr(self, ('_send%sText' % self.markup))(toktype, toktext)
    return
