Use Jython compatible syntax (v2.5).
Move flatten() to misc package.