Largely automated print function style in the doctests.

Plus some manual tweaking to ensure the doctests still pass
(e.g. on Jython 2.7b1, see last commit).

import os
from lib2to3.main import main

for dirpath, dirnames, filenames in os.walk("."):
    if dirpath.startswith("./build/") or dirpath.startwith("./.git/"):
        continue
    print("=" * len(dirpath))
    print(dirpath)
    print("=" *len(dirpath))
    for f in filenames:
        if not f.endswith(".py"):
            continue
        filename = os.path.join(dirpath, f)
        with open(filename) as h:
            data = h.read()
            if "print " not in data:
                continue
            if "print(" in data:
                continue
        print(filename)
        e = main("lib2to3.fixes", ["-d", filename, "-f", "print", "-w", "-n"])
        if e != 0:
            os.remove(filename)
            raise RuntimeError("Error %i from 2to3 (doctests) on %s"
                               % (e, filename))
A few more modules needing print function style
Avoid using print >> sys.stderr
Print function style in comments (no code changes)
No longer needs to convert print statements via 2to3

Also by removing this fixer, any accidental print
statements should be caught via the Python 3 tests.
Use print function spacing in setup.py
Add: from __future__ import print_statement

This is currently redundant as we are carefully only
using this simple print style which is both a print
statement (with redundant brackets) under Python 2
and a print function under Python 3:

print(variable)

However, adding the __future__ import to any file using
a print should catch any accidental usage of the print
statement in the near future (even if not testing under
Python 3 where it would be spotted since we've turned
off the print fixer during the 2to3 conversion).

This was automated as follows:

<python>
MAGIC = "from __future__ import print_function"

import os
import sys

def should_mark(filename):
    handle = open(filename, "rU")
    lines = [line.strip() for line in handle if "print" in line]
    handle.close()
    if MAGIC in lines:
        #print("%s is marked" % filename)
        return False
    if "print" in lines:
        print("TODO - %s has a naked print" % filename)
        sys.exit(1)
    for line in lines:
        if "print" not in line:
            continue
        #print(line)
        line = line.strip(" #")
        if line.startswith(">>>") or line.startswith("..."):
            #doctest
            line = line[3:].strip()
        if line.startswith("print ") or line.startswith("print("):
            return True
    print("%s has no print statements" % filename)
    return False

def mark_file(filename, marker=MAGIC):
    with open(filename, "rU") as h:
        lines = list(h.readlines())
    with open(filename, "w") as h:
        while (lines[0].startswith("#") or not lines[0].strip()):
            h.write(lines.pop(0))
        if lines[0].startswith('"""') or lines[0].startswith('r"""'):
            # Module docstring
            if lines[0].strip() == '"""':
                print("Non-PEP8 module docstring in %s" % filename)
            if lines[0].rstrip().endswith('"""') and lines[0].strip() != '"""':
                # One liner
                print("One line module docstring in %s" % filename)
                h.write(lines.pop(0))
            else:
                h.write(lines.pop(0))
                while not lines[0].strip().endswith('"""'):
                    h.write(lines.pop(0))
                h.write(lines.pop(0))
        while (lines[0].startswith("#") or not lines[0].strip()):
            h.write(lines.pop(0))
        h.write(marker + "\n\n")
        h.write("".join(lines))

for dirpath, dirnames, filenames in os.walk("."):
    if dirpath.startswith("./build/"):
        continue
    for f in filenames:
        if not f.endswith(".py"):
            continue
        f = os.path.join(dirpath, f)
        if should_mark(f):
            print("Marking %s" % f)
            mark_file(f)
</python>