'Parse and send the colorized source'

def format(self, form=None):

    if (form in ('snip', 'code')):
        self.addEnds = 0
    elif (form == 'embed'):
        self.addEnds = 0
        self.external = 1
    else:
        if (form == 'external'):
            self.external = 1
        self.addEnds = 1
    self.lines = [0, 0]
    pos = 0
    if self.dolinenums:
        start = ((self.LINENUMHOLDER + '    ') + self.extraspace)
    else:
        start = ('' + self.extraspace)
    newlines = []
    lines = self.raw.splitlines(0)
    for l in lines:
        if (l.startswith('#$#') or l.startswith('#%#') or l.startswith('#@#')):
            newlines.append(l)
        elif (self.markup in ['XHTML', 'CSS']):
            newlines.append((((self.LINESTART + '    ') + start) + l))
        else:
            newlines.append((start + l))
    self.raw = ('\n'.join(newlines) + '\n')
    while 1:
        pos = (self.raw.find('\n', pos) + 1)
        if (not pos):
            break
        self.lines.append(pos)
    self.lines.append(len(self.raw))
    self.pos = 0
    text = StringIO.StringIO(self.raw)
    if self.addEnds:
        self._doPageStart()
    else:
        self._doSnippetStart()
    try:
        tokenize.tokenize(text.readline, self)
    except tokenize.TokenError as ex:
        msg = ex[0]
        line = ex[1][0]
        self.out.write(('<h3>ERROR:    %s</h3>%s\n' % (msg, self.raw[self.lines[line]:])))
    if self.addEnds:
        self._doPageEnd()
    else:
        self._doSnippetEnd()
