'print a line of python, indenting it according to the current
indent level.
this also adjusts the indentation counter according to the
content of the line.'

def writeline(self, line):

    if (not self.in_indent_lines):
        self._flush_adjusted_lines()
        self.in_indent_lines = True
    if ((line is None) or re.match('^\\s*#', line) or re.match('^\\s*$', line)):
        hastext = False
    else:
        hastext = True
    is_comment = (line and len(line) and (line[0] == '#'))
    if ((not is_comment) and ((not hastext) or self._is_unindentor(line))):
        if (self.indent > 0):
            self.indent -= 1
            if (len(self.indent_detail) == 0):
                raise exceptions.SyntaxException('Too    many    whitespace    closures')
            self.indent_detail.pop()
    if (line is None):
        return
    self.stream.write((self._indent_line(line) + '\n'))
    if re.search(':[    \\t]*(?:#.*)?$', line):
        match = re.match('^\\s*(if|try|elif|while|for|with)', line)
        if match:
            indentor = match.group(1)
            self.indent += 1
            self.indent_detail.append(indentor)
        else:
            indentor = None
            m2 = re.match('^\\s*(def|class|else|elif|except|finally)', line)
            if m2:
                self.indent += 1
                self.indent_detail.append(indentor)
