Commits

Jeff Allen  committed 537524c

Support file descriptor in _io.open and _io.FileIO
Replaced the constructors in PyFileIO to accept Jython-style fds. Corresponding changes to open() and some tests. Also, a lot of fun with mode strings. test_io.py now scores fail/error/skip = 15/15/99.

  • Participants
  • Parent commits 2ccd73a

Comments (0)

Files changed (7)

File Lib/test/test_fileio.py

 
     def testInvalidFd(self):
         if is_jython:
-            self.assertRaises(TypeError, _FileIO, -10)
-            self.assertRaises(TypeError, _FileIO, make_bad_fd())
+            self.assertRaises(TypeError, _FileIO, -10)  # file descriptor not int in Jython
         else:
             self.assertRaises(ValueError, _FileIO, -10)
-            self.assertRaises(OSError, _FileIO, make_bad_fd())
+        self.assertRaises(OSError, _FileIO, make_bad_fd())
         if sys.platform == 'win32':
             import msvcrt
             self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd())

File Lib/test/test_io.py

 
         f = self.open(support.TESTFN, "w+")
         self.assertEqual(f.mode,            "w+")
-        #If next doesn't matter - does it matter it doesn't work in Jython?
-        #self.assertEqual(f.buffer.mode,     "rb+") # Does it really matter?
-        #self.assertEqual(f.buffer.raw.mode, "rb+")
+        self.assertEqual(f.buffer.mode,     "rb+") # Does it really matter?
+        self.assertEqual(f.buffer.raw.mode, "rb+")
 
         g = self.open(f.fileno(), "wb", closefd=False)
         self.assertEqual(g.mode,     "wb")

File src/org/python/modules/_io/OpenMode.java

     /** Set true when any invalid symbol or combination is discovered */
     public boolean invalid;
 
+    /** Set true when stream must be <code>readable = reading | updating</code> */
+    public boolean readable;
+
+    /** Set true when stream must be <code>writable = writing | updating | appending</code> */
+    public boolean writable;
+
     /**
      * Error message describing the way in which the mode is invalid, or null if no problem has been
      * found. This field may be set by the constructor (in the case of duplicate or unrecognised
 
         // Implications
         reading |= universal;
+        readable = reading | updating;
+        writable = writing | updating | appending;
 
         // Standard tests
         if (!invalid) {
     }
 
     /**
-     * Call {@link #validate()} and raise an exception if the mode string is not valid,
-     * as signalled by either {@link #invalid}
-     * or {@link #other} being <code>true</code> after that call. If no more specific message has been assigned in
-     * {@link #message}, report the original mode string.
+     * Call {@link #validate()} and raise an exception if the mode string is not valid, as signalled
+     * by either {@link #invalid} or {@link #other} being <code>true</code> after that call. If no
+     * more specific message has been assigned in {@link #message}, report the original mode string.
      *
      * @throws PyException (ValueError) if the mode string was invalid.
      */
         }
     }
 
-    public String rawmode() {
+    /**
+     * The mode string that a raw file should claim to have, when initialised with the present mode.
+     * Note that this is not the same as the open mode because it omits the text-based attributes,
+     * even if set, and always asserts it is binary.
+     *
+     * @return "rb", "rb+", or "wb".
+     */
+    public String raw() {
+        if (readable) {
+            return writable ? "rb+" : "rb";
+        } else {
+            return "wb";
+        }
+    }
+
+    /**
+     * The mode string we need when constructing a <code>FileIO</code> initialised with the present
+     * mode. Note that this is not the same as the full open mode because it omits the text-based
+     * attributes, and not the same as {@link #raw()}.
+     *
+     * @return "r", "w", or "a" with optional "+".
+     */
+    public String forFileIO() {
         StringBuilder m = new StringBuilder(2);
         if (appending) {
             m.append('a');
         return m.toString();
     }
 
+    /**
+     * The mode string that a text file should claim to have, when initialised with the present
+     * mode. Note that this only contains text-based attributes. Since mode 't' has no effect,
+     * except to produce an error if specified with 'b', we don't reproduce it.
+     *
+     * @return "", or "U".
+     */
+    public String text() {
+        return universal ? "U" : "";
+    }
+
     @Override
     public String toString() {
         StringBuilder m = new StringBuilder(4);

File src/org/python/modules/_io/PyFileIO.java

 package org.python.modules._io;
 
 import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.FileChannel;
 
 import org.python.core.ArgParser;
-import org.python.core.BaseBytes;
 import org.python.core.BuiltinDocs;
 import org.python.core.Py;
-import org.python.core.PyArray;
 import org.python.core.PyBuffer;
-import org.python.core.PyInteger;
 import org.python.core.PyJavaType;
 import org.python.core.PyLong;
+import org.python.core.PyNewWrapper;
 import org.python.core.PyObject;
 import org.python.core.PyString;
 import org.python.core.PyType;
 import org.python.core.PyUnicode;
 import org.python.core.io.FileIO;
-import org.python.core.util.StringUtil;
+import org.python.core.io.RawIOBase;
 import org.python.expose.ExposedGet;
 import org.python.expose.ExposedMethod;
 import org.python.expose.ExposedNew;
 import org.python.expose.ExposedType;
 
+import com.kenai.constantine.platform.Errno;
+
 @ExposedType(name = "_io.FileIO", base = PyRawIOBase.class)
 public class PyFileIO extends PyRawIOBase {
 
     public static final PyType TYPE = PyType.fromClass(PyFileIO.class);
 
-    private FileIO ioDelegate;  // XXX final?
-    private PyObject name;
+    /** The FileIO to which we delegate operations not complete locally. */
+    private final FileIO ioDelegate;
+
+    /** The name of the file */
+    @ExposedGet(doc = BuiltinDocs.file_name_doc)
+    protected PyObject name;
+
     private Boolean seekable;
 
+    /** Whether to close the underlying stream on closing this object. */
     @ExposedGet
-    public boolean closefd;
+    public final boolean closefd;
 
-    /** The mode string */
-    @ExposedGet(doc = BuiltinDocs.file_mode_doc)
-    public String mode;
+    /** The mode as given to the constructor */
+    private OpenMode openMode;
+    @ExposedGet(doc = BuiltinDocs.file_mode_doc)    // and as a PyString
+    public PyString mode() { return new PyString(openMode.raw()); }
+    private static final PyString defaultMode = new PyString("r");
 
-    public PyFileIO() {
-        super(TYPE);
+    /**
+     * Construct an open <code>_io.FileIO</code> starting with an object that may be a file name or
+     * a file descriptor (actually a {@link RawIOBase}). Only the relevant flags within the parsed
+     * mode object are consulted (so that flags meaningful to this sub-class need not be processed
+     * out).
+     *
+     * @param fd on which this should be constructed
+     * @param mode type of access specified
+     * @param closefd if <code>false</code>, do not close <code>fd</code> on call to
+     *            <code>close()</code>
+     */
+    public PyFileIO(PyObject file, OpenMode mode, boolean closefd) {
+        this(TYPE, file, mode, closefd);
     }
 
-    public PyFileIO(PyType subType) {
-        super(subType);
+    /**
+     * Construct an open <code>_io.FileIO</code> for a sub-class constructor starting with an object
+     * that may be a file name or a file descriptor (actually a {@link RawIOBase}). Only the
+     * relevant flags within the parsed mode object are consulted (so that flags meaningful to this
+     * sub-class need not be processed out).
+     *
+     * @param subtype for which construction is occurring
+     * @param file on which this should be constructed
+     * @param mode type of access specified
+     * @param closefd if <code>false</code>, do not close <code>file</code> on call to
+     *            <code>close()</code>
+     */
+    public PyFileIO(PyType subtype, PyObject file, OpenMode mode, boolean closefd) {
+        super(subtype);
+        this.ioDelegate = getFileIO(file, mode, closefd);
+        this.closefd = closefd;
+        this.name = file;
+        this.openMode = mode;
     }
 
-    public PyFileIO(String name, String mode, boolean closefd) {
-        this();
-        FileIO___init__(Py.newString(name), mode, closefd);
+    /**
+     * Helper function that turns the arguments of the most general constructor, or
+     * <code>__new__</code>, into a {@link FileIO}. This places the logic of those several
+     * operations in one place.
+     * <p>
+     * In many cases (such as construction from a file name, the FileIO is a newly-opened file. When
+     * the file object passed in is a file descriptor, the FileIO may be created to wrap that
+     * existing stream.
+     *
+     * @param file name or descriptor
+     * @param mode parsed file open mode
+     * @param closefd must be true if file is in fact a name (checked, not used)
+     * @return
+     */
+    private static FileIO getFileIO(PyObject file, OpenMode mode, boolean closefd) {
+
+        if (file instanceof PyString) {
+            // Open a file by name
+            if (!closefd) {
+                throw Py.ValueError("Cannot use closefd=False with file name");
+            }
+            String name = file.asString();
+            return new FileIO(name, mode.forFileIO());
+
+        } else {
+            /*
+             * Build an _io.FileIO from an existing "file descriptor", which we may or may not want
+             * closed at the end. A CPython file descriptor is an int, but this is not the natural
+             * choice in Jython, and file descriptors should be treated as opaque.
+             */
+            Object fd = file.__tojava__(Object.class);
+            if (fd instanceof RawIOBase) {
+                // It is the "Jython file descriptor" from which we can get a channel.
+                /*
+                 * If the argument were a FileIO, could we return it directly? I think not: there
+                 * would be a problem with close and closefd=False since it is not the PyFileIO that
+                 * keeps state.
+                 */
+                Channel channel = ((RawIOBase)fd).getChannel();
+                if (channel instanceof FileChannel) {
+                    if  (channel.isOpen()){
+                    FileChannel fc = (FileChannel)channel;
+                    return new FileIO(fc, mode.forFileIO());
+                    } else {
+                        // File not open (we have to check as FileIO doesn't)
+                        throw Py.OSError(Errno.EBADF);
+                    }
+                }
+            }
+            // The file was a type we don't know how to use
+            throw Py.TypeError(String.format("invalid file: %s", file.__repr__().asString()));
+        }
     }
 
-    public PyFileIO(String name, String mode) {
-        this(name, mode, true);
+    private static final String[] openArgs = {"file", "mode", "closefd"};
+
+    /**
+     * Create a {@link PyFileIO} and its <code>FileIO</code> delegate from the arguments.
+     */
+    @ExposedNew
+    static PyObject FileIO___new__(PyNewWrapper new_, boolean init, PyType subtype,
+            PyObject[] args, String[] keywords) {
+        ArgParser ap = new ArgParser("FileIO", args, keywords, openArgs, 1);
+        PyObject file = ap.getPyObject(0);
+        PyObject m = ap.getPyObject(1, defaultMode);
+        boolean closefd = Py.py2boolean(ap.getPyObject(2, Py.True));
+
+        // Decode the mode string and check it
+        OpenMode mode = new OpenMode(m.asString()) {
+
+            {
+                invalid |= universal | text;    // These other modes are invalid
+            }
+        };
+        mode.checkValid();
+
+        if (subtype == TYPE) {
+            return new PyFileIO(subtype, file, mode, closefd);
+        } else {
+            return new PyFileIODerived(subtype, file, mode, closefd);
+        }
+
     }
 
-    @ExposedNew
-    @ExposedMethod(doc = BuiltinDocs.file___init___doc)
-    final void FileIO___init__(PyObject[] args, String[] kwds) {
-        ArgParser ap =
-                new ArgParser("file", args, kwds, new String[] {"name", "mode", "closefd"}, 1);
-        PyObject name = ap.getPyObject(0);
-        if (!(name instanceof PyString)) {
-            throw Py.TypeError("coercing to Unicode: need string, '" + name.getType().fastGetName()
-                    + "' type found");
-        }
-        String mode = ap.getString(1, "r");
-        boolean closefd = Py.py2boolean(ap.getPyObject(2, Py.True));
-        // TODO: make this work with file channels so closefd=False can be used
-        if (!closefd) {
-            throw Py.ValueError("Cannot use closefd=False with file name");
-        }
-
-        FileIO___init__((PyString)name, mode, closefd);
-    }
-
-    private void FileIO___init__(PyString name, String mode, boolean closefd) {
-        mode = parseMode(mode);
-        this.name = name;
-        this.mode = mode;
-        this.closefd = closefd;
-        this.ioDelegate = new FileIO(name, mode.replaceAll("b", ""));
-    }
-
-    private String parseMode(String mode) {
-        if (mode.length() == 0) {
-            throw Py.ValueError("empty mode string");
-        }
-
-        String origMode = mode;
-        if ("rwa".indexOf(mode.charAt(0)) == -1) {
-            throw Py.ValueError("mode string must begin with one of 'r', 'w', 'a' or 'U', not '"
-                    + origMode + "'");
-        }
-
-        boolean reading = mode.contains("r");
-        boolean writing = mode.contains("w");
-        boolean appending = mode.contains("a");
-        boolean updating = mode.contains("+");
-
-        return (reading ? "r" : "") + (writing ? "w" : "") + (appending ? "a" : "") + "b"
-                + (updating ? "+" : "");
-    }
 
     /*
      * ===========================================================================================
     final String FileIO_toString() {
         if (name instanceof PyUnicode) {
             String escapedName = PyString.encode_UnicodeEscape(name.toString(), false);
-            return String.format("<_io.FileIO name='%s', mode='%s'>", escapedName, mode);
+            return String.format("<_io.FileIO name='%s', mode='%s'>", escapedName, mode());
         }
-        return String.format("<_io.FileIO name='%s', mode='%s'>", name, mode);
+        return String.format("<_io.FileIO name='%s', mode='%s'>", name, mode());
     }
 
     @Override

File src/org/python/modules/_io/PyFileIODerived.java

-/* Generated file, do not modify. See jython/src/templates/gderived.py. */
+/* Generated file, do not modify.  See jython/src/templates/gderived.py. */
 package org.python.modules._io;
 
 import java.io.Serializable;
 import org.python.core.Py;
 import org.python.core.PyBoolean;
 import org.python.core.PyComplex;
-import org.python.core.PyDictionary;
 import org.python.core.PyException;
 import org.python.core.PyFloat;
 import org.python.core.PyInteger;
 import org.python.core.PySequenceIter;
 import org.python.core.PySlice;
 import org.python.core.PyString;
-import org.python.core.PyStringMap;
 import org.python.core.PyTuple;
 import org.python.core.PyType;
 import org.python.core.PyUnicode;
     }
 
     @Override
-    public void setSlot(int index, PyObject value) {
-        slots[index] = value;
+    public void setSlot(int index,PyObject value) {
+        slots[index]=value;
     }
 
-    private PyObject[] slots;
+    private PyObject[]slots;
 
-    private PyObject dict;
-
-    @Override
-    public PyObject fastGetDict() {
-        return dict;
-    }
-
-    @Override
-    public PyObject getDict() {
-        return dict;
-    }
-
-    @Override
-    public void setDict(PyObject newDict) {
-        if (newDict instanceof PyStringMap || newDict instanceof PyDictionary) {
-            dict = newDict;
-        } else {
-            throw Py.TypeError("__dict__ must be set to a Dictionary "
-                    + newDict.getClass().getName());
-        }
-    }
-
-    @Override
-    public void delDict() {
-        // deleting an object's instance dict makes it grow a new one
-        dict = new PyStringMap();
-    }
-
-    public PyFileIODerived(PyType subtype) {
-        super(subtype);
-        slots = new PyObject[subtype.getNumSlots()];
-        dict = subtype.instDict();
+    public PyFileIODerived(PyType subtype,PyObject file,OpenMode mode,boolean closefd) {
+        super(subtype,file,mode,closefd);
+        slots=new PyObject[subtype.getNumSlots()];
     }
 
     @Override
     public PyString __str__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__str__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__str__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyString) {
-                return (PyString)res;
+                return(PyString)res;
             }
-            throw Py.TypeError("__str__" + " returned non-" + "string" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__str__();
     }
 
     @Override
     public PyString __repr__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__repr__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__repr__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyString) {
-                return (PyString)res;
+                return(PyString)res;
             }
-            throw Py.TypeError("__repr__" + " returned non-" + "string" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__repr__();
     }
 
     @Override
     public PyString __hex__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__hex__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__hex__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyString) {
-                return (PyString)res;
+                return(PyString)res;
             }
-            throw Py.TypeError("__hex__" + " returned non-" + "string" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__hex__();
     }
 
     @Override
     public PyString __oct__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__oct__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__oct__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyString) {
-                return (PyString)res;
+                return(PyString)res;
             }
-            throw Py.TypeError("__oct__" + " returned non-" + "string" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__oct__();
     }
 
     @Override
     public PyFloat __float__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__float__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__float__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyFloat) {
-                return (PyFloat)res;
+                return(PyFloat)res;
             }
-            throw Py.TypeError("__float__" + " returned non-" + "float" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__float__();
     }
 
     @Override
     public PyComplex __complex__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__complex__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__complex__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyComplex) {
-                return (PyComplex)res;
+                return(PyComplex)res;
             }
-            throw Py.TypeError("__complex__" + " returned non-" + "complex" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__complex__();
     }
 
     @Override
     public PyObject __pos__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__pos__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__pos__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
         return super.__pos__();
     }
 
     @Override
     public PyObject __neg__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__neg__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__neg__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
         return super.__neg__();
     }
 
     @Override
     public PyObject __abs__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__abs__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__abs__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
         return super.__abs__();
     }
 
     @Override
     public PyObject __invert__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__invert__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__invert__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
         return super.__invert__();
     }
 
     @Override
     public PyObject __reduce__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__reduce__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__reduce__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
         return super.__reduce__();
     }
 
     @Override
     public PyObject __dir__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__dir__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__dir__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
         return super.__dir__();
     }
 
     @Override
     public PyObject __add__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__add__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__add__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __radd__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__radd__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__radd__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __sub__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__sub__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__sub__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rsub__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rsub__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rsub__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __mul__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__mul__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__mul__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rmul__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rmul__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rmul__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __div__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__div__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__div__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rdiv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rdiv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rdiv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __floordiv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__floordiv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__floordiv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rfloordiv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rfloordiv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rfloordiv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __truediv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__truediv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__truediv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rtruediv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rtruediv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rtruediv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __mod__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__mod__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__mod__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rmod__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rmod__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rmod__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __divmod__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__divmod__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__divmod__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rdivmod__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rdivmod__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rdivmod__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rpow__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rpow__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rpow__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __lshift__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__lshift__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__lshift__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rlshift__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rlshift__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rlshift__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rshift__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rshift__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rshift__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rrshift__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rrshift__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rrshift__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __and__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__and__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__and__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rand__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rand__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rand__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __or__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__or__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__or__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ror__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ror__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ror__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __xor__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__xor__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__xor__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __rxor__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__rxor__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__rxor__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __lt__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__lt__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__lt__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __le__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__le__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__le__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __gt__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__gt__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__gt__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ge__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ge__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ge__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __eq__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__eq__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__eq__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ne__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ne__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ne__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __format__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__format__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__format__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __iadd__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__iadd__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__iadd__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __isub__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__isub__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__isub__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __imul__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__imul__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__imul__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __idiv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__idiv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__idiv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ifloordiv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ifloordiv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ifloordiv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __itruediv__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__itruediv__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__itruediv__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __imod__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__imod__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__imod__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ipow__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ipow__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ipow__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ilshift__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ilshift__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ilshift__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __irshift__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__irshift__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__irshift__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __iand__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__iand__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__iand__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ior__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ior__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ior__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __ixor__(PyObject other) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__ixor__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__(other);
-            if (res == Py.NotImplemented) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__ixor__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__(other);
+            if (res==Py.NotImplemented) {
                 return null;
             }
             return res;
 
     @Override
     public PyObject __int__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__int__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
-            if (res instanceof PyInteger || res instanceof PyLong) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__int__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
+            if (res instanceof PyInteger||res instanceof PyLong) {
                 return res;
             }
-            throw Py.TypeError("__int__" + " should return an integer");
+            throw Py.TypeError("__int__"+" should return an integer");
         }
         return super.__int__();
     }
 
     @Override
     public PyObject __long__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__long__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
-            if (res instanceof PyLong || res instanceof PyInteger) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__long__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
+            if (res instanceof PyLong||res instanceof PyInteger) {
                 return res;
             }
-            throw Py.TypeError("__long__" + " returned non-" + "long" + " (type "
-                    + res.getType().fastGetName() + ")");
+            throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")");
         }
         return super.__long__();
     }
 
     @Override
     public int hashCode() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__hash__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__hash__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyInteger) {
-                return ((PyInteger)res).getValue();
-            } else if (res instanceof PyLong) {
-                return ((PyLong)res).getValue().intValue();
-            }
+                return((PyInteger)res).getValue();
+            } else
+                if (res instanceof PyLong) {
+                    return((PyLong)res).getValue().intValue();
+                }
             throw Py.TypeError("__hash__ should return a int");
         }
-        if (self_type.lookup("__eq__") != null || self_type.lookup("__cmp__") != null) {
-            throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName()));
+        if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) {
+            throw Py.TypeError(String.format("unhashable type: '%.200s'",getType().fastGetName()));
         }
         return super.hashCode();
     }
 
     @Override
     public PyUnicode __unicode__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__unicode__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__unicode__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyUnicode) {
-                return (PyUnicode)res;
+                return(PyUnicode)res;
             }
             if (res instanceof PyString) {
                 return new PyUnicode((PyString)res);
             }
-            throw Py.TypeError("__unicode__" + " should return a " + "unicode");
+            throw Py.TypeError("__unicode__"+" should return a "+"unicode");
         }
         return super.__unicode__();
     }
 
     @Override
     public int __cmp__(PyObject other) {
-        PyType self_type = getType();
-        PyObject[] where_type = new PyObject[1];
-        PyObject impl = self_type.lookup_where("__cmp__", where_type);
+        PyType self_type=getType();
+        PyObject[]where_type=new PyObject[1];
+        PyObject impl=self_type.lookup_where("__cmp__",where_type);
         // Full Compatibility with CPython __cmp__:
         // If the derived type don't override __cmp__, the
         // *internal* super().__cmp__ should be called, not the
         // exposed one. The difference is that the exposed __cmp__
         // throws a TypeError if the argument is an instance of the same type.
-        if (impl == null || where_type[0] == TYPE || Py.isSubClass(TYPE, where_type[0])) {
+        if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) {
             return super.__cmp__(other);
         }
-        PyObject res = impl.__get__(this, self_type).__call__(other);
-        if (res == Py.NotImplemented) {
-            return -2;
+        PyObject res=impl.__get__(this,self_type).__call__(other);
+        if (res==Py.NotImplemented) {
+            return-2;
         }
-        int c = res.asInt();
-        return c < 0 ? -1 : c > 0 ? 1 : 0;
+        int c=res.asInt();
+        return c<0?-1:c>0?1:0;
     }
 
     @Override
     public boolean __nonzero__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__nonzero__");
-        if (impl == null) {
-            impl = self_type.lookup("__len__");
-            if (impl == null) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__nonzero__");
+        if (impl==null) {
+            impl=self_type.lookup("__len__");
+            if (impl==null) {
                 return super.__nonzero__();
             }
         }
-        PyObject o = impl.__get__(this, self_type).__call__();
-        Class c = o.getClass();
-        if (c != PyInteger.class && c != PyBoolean.class) {
-            throw Py.TypeError(String.format("__nonzero__ should return bool or int, returned %s",
-                    self_type.getName()));
+        PyObject o=impl.__get__(this,self_type).__call__();
+        Class c=o.getClass();
+        if (c!=PyInteger.class&&c!=PyBoolean.class) {
+            throw Py.TypeError(String.format("__nonzero__ should return bool or int, returned %s",self_type.getName()));
         }
         return o.__nonzero__();
     }
 
     @Override
     public boolean __contains__(PyObject o) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__contains__");
-        if (impl == null) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__contains__");
+        if (impl==null) {
             return super.__contains__(o);
         }
-        return impl.__get__(this, self_type).__call__(o).__nonzero__();
+        return impl.__get__(this,self_type).__call__(o).__nonzero__();
     }
 
     @Override
     public int __len__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__len__");
-        if (impl != null) {
-            PyObject res = impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__len__");
+        if (impl!=null) {
+            PyObject res=impl.__get__(this,self_type).__call__();
             if (res instanceof PyInteger) {
-                return ((PyInteger)res).getValue();
+                return((PyInteger)res).getValue();
             }
             throw Py.TypeError("__len__ should return a int");
         }
 
     @Override
     public PyObject __iter__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__iter__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__();
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__iter__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__();
         }
-        impl = self_type.lookup("__getitem__");
-        if (impl == null) {
+        impl=self_type.lookup("__getitem__");
+        if (impl==null) {
             return super.__iter__();
         }
         return new PySequenceIter(this);
 
     @Override
     public PyObject __iternext__() {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("next");
-        if (impl != null) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("next");
+        if (impl!=null) {
             try {
-                return impl.__get__(this, self_type).__call__();
+                return impl.__get__(this,self_type).__call__();
             } catch (PyException exc) {
                 if (exc.match(Py.StopIteration)) {
                     return null;
 
     @Override
     public PyObject __finditem__(PyObject key) { // ???
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__getitem__");
-        if (impl != null) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__getitem__");
+        if (impl!=null) {
             try {
-                return impl.__get__(this, self_type).__call__(key);
+                return impl.__get__(this,self_type).__call__(key);
             } catch (PyException exc) {
                 if (exc.match(Py.LookupError)) {
                     return null;
 
     @Override
     public PyObject __finditem__(int key) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__getitem__");
-        if (impl != null) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__getitem__");
+        if (impl!=null) {
             try {
-                return impl.__get__(this, self_type).__call__(new PyInteger(key));
+                return impl.__get__(this,self_type).__call__(new PyInteger(key));
             } catch (PyException exc) {
                 if (exc.match(Py.LookupError)) {
                     return null;
         // in terms of __finditem__. Therefore, we would end with an infinite
         // loop when self_type.lookup("__getitem__") returns null:
         //
-        // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__
+        //  __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__
         //
         // By duplicating the (short) lookup and call code, we are safe, because
         // the call chains will be:
         //
         // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__
 
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__getitem__");
-        if (impl != null) {
-            return impl.__get__(this, self_type).__call__(key);
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__getitem__");
+        if (impl!=null) {
+            return impl.__get__(this,self_type).__call__(key);
         }
         return super.__getitem__(key);
     }
 
     @Override
-    public void __setitem__(PyObject key, PyObject value) { // ???
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__setitem__");
-        if (impl != null) {
-            impl.__get__(this, self_type).__call__(key, value);
+    public void __setitem__(PyObject key,PyObject value) { // ???
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__setitem__");
+        if (impl!=null) {
+            impl.__get__(this,self_type).__call__(key,value);
             return;
         }
-        super.__setitem__(key, value);
+        super.__setitem__(key,value);
     }
 
     @Override
-    public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) { // ???
-        if (step != null) {
-            return __getitem__(new PySlice(start, stop, step));
+    public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ???
+        if (step!=null) {
+            return __getitem__(new PySlice(start,stop,step));
         }
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__getslice__");
-        if (impl != null) {
-            PyObject[] indices = PySlice.indices2(this, start, stop);
-            return impl.__get__(this, self_type).__call__(indices[0], indices[1]);
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__getslice__");
+        if (impl!=null) {
+            PyObject[]indices=PySlice.indices2(this,start,stop);
+            return impl.__get__(this,self_type).__call__(indices[0],indices[1]);
         }
-        return super.__getslice__(start, stop, step);
+        return super.__getslice__(start,stop,step);
     }
 
     @Override
-    public void __setslice__(PyObject start, PyObject stop, PyObject step, PyObject value) {
-        if (step != null) {
-            __setitem__(new PySlice(start, stop, step), value);
+    public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) {
+        if (step!=null) {
+            __setitem__(new PySlice(start,stop,step),value);
             return;
         }
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__setslice__");
-        if (impl != null) {
-            PyObject[] indices = PySlice.indices2(this, start, stop);
-            impl.__get__(this, self_type).__call__(indices[0], indices[1], value);
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__setslice__");
+        if (impl!=null) {
+            PyObject[]indices=PySlice.indices2(this,start,stop);
+            impl.__get__(this,self_type).__call__(indices[0],indices[1],value);
             return;
         }
-        super.__setslice__(start, stop, step, value);
+        super.__setslice__(start,stop,step,value);
     }
 
     @Override
-    public void __delslice__(PyObject start, PyObject stop, PyObject step) {
-        if (step != null) {
-            __delitem__(new PySlice(start, stop, step));
+    public void __delslice__(PyObject start,PyObject stop,PyObject step) {
+        if (step!=null) {
+            __delitem__(new PySlice(start,stop,step));
             return;
         }
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__delslice__");
-        if (impl != null) {
-            PyObject[] indices = PySlice.indices2(this, start, stop);
-            impl.__get__(this, self_type).__call__(indices[0], indices[1]);
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__delslice__");
+        if (impl!=null) {
+            PyObject[]indices=PySlice.indices2(this,start,stop);
+            impl.__get__(this,self_type).__call__(indices[0],indices[1]);
             return;
         }
-        super.__delslice__(start, stop, step);
+        super.__delslice__(start,stop,step);
     }
 
     @Override
     public void __delitem__(PyObject key) { // ???
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__delitem__");
-        if (impl != null) {
-            impl.__get__(this, self_type).__call__(key);
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__delitem__");
+        if (impl!=null) {
+            impl.__get__(this,self_type).__call__(key);
             return;
         }
         super.__delitem__(key);
     }
 
     @Override
-    public PyObject __call__(PyObject args[], String keywords[]) {
-        ThreadState ts = Py.getThreadState();
-        if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) {
+    public PyObject __call__(PyObject args[],String keywords[]) {
+        ThreadState ts=Py.getThreadState();
+        if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) {
             throw Py.RuntimeError("maximum __call__ recursion depth exceeded");
         }
         try {
-            PyType self_type = getType();
-            PyObject impl = self_type.lookup("__call__");
-            if (impl != null) {
-                return impl.__get__(this, self_type).__call__(args, keywords);
+            PyType self_type=getType();
+            PyObject impl=self_type.lookup("__call__");
+            if (impl!=null) {
+                return impl.__get__(this,self_type).__call__(args,keywords);
             }
-            return super.__call__(args, keywords);
+            return super.__call__(args,keywords);
         } finally {
             --ts.recursion_depth;
         }
 
     @Override
     public PyObject __findattr_ex__(String name) {
-        return Deriveds.__findattr_ex__(this, name);
+        return Deriveds.__findattr_ex__(this,name);
     }
 
     @Override
-    public void __setattr__(String name, PyObject value) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__setattr__");
-        if (impl != null) {
-            impl.__get__(this, self_type).__call__(PyString.fromInterned(name), value);
+    public void __setattr__(String name,PyObject value) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__setattr__");
+        if (impl!=null) {
+            impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value);
             return;
         }
-        super.__setattr__(name, value);
+        super.__setattr__(name,value);
     }
 
     @Override
     public void __delattr__(String name) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__delattr__");
-        if (impl != null) {
-            impl.__get__(this, self_type).__call__(PyString.fromInterned(name));
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__delattr__");
+        if (impl!=null) {
+            impl.__get__(this,self_type).__call__(PyString.fromInterned(name));
             return;
         }
         super.__delattr__(name);
     }
 
     @Override
-    public PyObject __get__(PyObject obj, PyObject type) {
-        PyType self_type = getType();
-        PyObject impl = self_type.lookup("__get__");
-        if (impl != null) {
-            if (obj == null) {
-                obj = Py.None;
+    public PyObject __get__(PyObject obj,PyObject type) {
+        PyType self_type=getType();
+        PyObject impl=self_type.lookup("__get__");
+        if (impl!=null) {
+            if (obj==null) {
+                obj=Py.None;
             }
-            if (type == null) {
-                type = Py.None;
+            if (type==null) {
+                type=Py.None;
             }
-            return impl.__get__(this, self_type).__call__(obj, type);
+            return impl.__get__(this,self_type).__call__(obj,type);
         }
-        return super.__get__(obj, type);
+        return super.__get__(obj,type);
     }