Source Code Cross Referenced for PyObject.java in  » Scripting » jython » org » python » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jython » org.python.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // Copyright (c) Corporation for National Research Initiatives
0002:        package org.python.core;
0003:
0004:        import java.text.MessageFormat;
0005:        import java.util.ArrayList;
0006:        import java.util.Iterator;
0007:        import java.util.List;
0008:
0009:        /**
0010:         * All objects known to the Jython runtime system are represented
0011:         * by an instance of the class <code>PyObject</code> or one of
0012:         * its subclasses.
0013:         *
0014:         **/
0015:
0016:        public class PyObject implements  java.io.Serializable {
0017:            //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py
0018:            /* type info */
0019:
0020:            public static final String exposed_name = "object";
0021:
0022:            public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
0023:                dict.__setitem__("__class__", new PyGetSetDescr("__class__",
0024:                        PyObject.class, "getType", "setType", "delType"));
0025:                dict.__setitem__("__doc__", new PyGetSetDescr("__doc__",
0026:                        PyObject.class, "getDoc", null, null));
0027:                class exposed___reduce__ extends PyBuiltinMethodNarrow {
0028:
0029:                    exposed___reduce__(PyObject self,
0030:                            PyBuiltinFunction.Info info) {
0031:                        super (self, info);
0032:                    }
0033:
0034:                    public PyBuiltinFunction bind(PyObject self) {
0035:                        return new exposed___reduce__(self, info);
0036:                    }
0037:
0038:                    public PyObject __call__() {
0039:                        return ((PyObject) self).object___reduce__();
0040:                    }
0041:
0042:                }
0043:                dict.__setitem__("__reduce__", new PyMethodDescr("__reduce__",
0044:                        PyObject.class, 0, 0,
0045:                        new exposed___reduce__(null, null)));
0046:                class exposed___str__ extends PyBuiltinMethodNarrow {
0047:
0048:                    exposed___str__(PyObject self, PyBuiltinFunction.Info info) {
0049:                        super (self, info);
0050:                    }
0051:
0052:                    public PyBuiltinFunction bind(PyObject self) {
0053:                        return new exposed___str__(self, info);
0054:                    }
0055:
0056:                    public PyObject __call__() {
0057:                        return self.__repr__();
0058:                    }
0059:
0060:                }
0061:                dict.__setitem__("__str__", new PyMethodDescr("__str__",
0062:                        PyObject.class, 0, 0, new exposed___str__(null, null)));
0063:                class exposed___getattribute__ extends PyBuiltinMethodNarrow {
0064:
0065:                    exposed___getattribute__(PyObject self,
0066:                            PyBuiltinFunction.Info info) {
0067:                        super (self, info);
0068:                    }
0069:
0070:                    public PyBuiltinFunction bind(PyObject self) {
0071:                        return new exposed___getattribute__(self, info);
0072:                    }
0073:
0074:                    public PyObject __call__(PyObject arg0) {
0075:                        try {
0076:                            String name = (arg0.asName(0));
0077:                            PyObject ret = self.object___findattr__(name);
0078:                            if (ret == null)
0079:                                self.noAttributeError(name);
0080:                            return ret;
0081:                        } catch (PyObject.ConversionException e) {
0082:                            String msg;
0083:                            switch (e.index) {
0084:                            case 0:
0085:                                msg = "attribute name must be a string";
0086:                                break;
0087:                            default:
0088:                                msg = "xxx";
0089:                            }
0090:                            throw Py.TypeError(msg);
0091:                        }
0092:                    }
0093:
0094:                }
0095:                dict.__setitem__("__getattribute__", new PyMethodDescr(
0096:                        "__getattribute__", PyObject.class, 1, 1,
0097:                        new exposed___getattribute__(null, null)));
0098:                class exposed___setattr__ extends PyBuiltinMethodNarrow {
0099:
0100:                    exposed___setattr__(PyObject self,
0101:                            PyBuiltinFunction.Info info) {
0102:                        super (self, info);
0103:                    }
0104:
0105:                    public PyBuiltinFunction bind(PyObject self) {
0106:                        return new exposed___setattr__(self, info);
0107:                    }
0108:
0109:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0110:                        try {
0111:                            ((PyObject) self).object___setattr__(
0112:                                    arg0.asName(0), arg1);
0113:                            return Py.None;
0114:                        } catch (PyObject.ConversionException e) {
0115:                            String msg;
0116:                            switch (e.index) {
0117:                            case 0:
0118:                                msg = "attribute name must be a string";
0119:                                break;
0120:                            default:
0121:                                msg = "xxx";
0122:                            }
0123:                            throw Py.TypeError(msg);
0124:                        }
0125:                    }
0126:
0127:                }
0128:                dict.__setitem__("__setattr__", new PyMethodDescr(
0129:                        "__setattr__", PyObject.class, 2, 2,
0130:                        new exposed___setattr__(null, null)));
0131:                class exposed___delattr__ extends PyBuiltinMethodNarrow {
0132:
0133:                    exposed___delattr__(PyObject self,
0134:                            PyBuiltinFunction.Info info) {
0135:                        super (self, info);
0136:                    }
0137:
0138:                    public PyBuiltinFunction bind(PyObject self) {
0139:                        return new exposed___delattr__(self, info);
0140:                    }
0141:
0142:                    public PyObject __call__(PyObject arg0) {
0143:                        try {
0144:                            ((PyObject) self)
0145:                                    .object___delattr__(arg0.asName(0));
0146:                            return Py.None;
0147:                        } catch (PyObject.ConversionException e) {
0148:                            String msg;
0149:                            switch (e.index) {
0150:                            case 0:
0151:                                msg = "attribute name must be a string";
0152:                                break;
0153:                            default:
0154:                                msg = "xxx";
0155:                            }
0156:                            throw Py.TypeError(msg);
0157:                        }
0158:                    }
0159:
0160:                }
0161:                dict.__setitem__("__delattr__", new PyMethodDescr(
0162:                        "__delattr__", PyObject.class, 1, 1,
0163:                        new exposed___delattr__(null, null)));
0164:                class exposed___hash__ extends PyBuiltinMethodNarrow {
0165:
0166:                    exposed___hash__(PyObject self, PyBuiltinFunction.Info info) {
0167:                        super (self, info);
0168:                    }
0169:
0170:                    public PyBuiltinFunction bind(PyObject self) {
0171:                        return new exposed___hash__(self, info);
0172:                    }
0173:
0174:                    public PyObject __call__() {
0175:                        return new PyInteger(self.object_hashCode());
0176:                    }
0177:
0178:                }
0179:                dict
0180:                        .__setitem__("__hash__", new PyMethodDescr("__hash__",
0181:                                PyObject.class, 0, 0, new exposed___hash__(
0182:                                        null, null)));
0183:                class exposed___repr__ extends PyBuiltinMethodNarrow {
0184:
0185:                    exposed___repr__(PyObject self, PyBuiltinFunction.Info info) {
0186:                        super (self, info);
0187:                    }
0188:
0189:                    public PyBuiltinFunction bind(PyObject self) {
0190:                        return new exposed___repr__(self, info);
0191:                    }
0192:
0193:                    public PyObject __call__() {
0194:                        return new PyString(self.object_toString());
0195:                    }
0196:
0197:                }
0198:                dict
0199:                        .__setitem__("__repr__", new PyMethodDescr("__repr__",
0200:                                PyObject.class, 0, 0, new exposed___repr__(
0201:                                        null, null)));
0202:                class exposed___unicode__ extends PyBuiltinMethodNarrow {
0203:
0204:                    exposed___unicode__(PyObject self,
0205:                            PyBuiltinFunction.Info info) {
0206:                        super (self, info);
0207:                    }
0208:
0209:                    public PyBuiltinFunction bind(PyObject self) {
0210:                        return new exposed___unicode__(self, info);
0211:                    }
0212:
0213:                    public PyObject __call__() {
0214:                        return new PyUnicode(self.__str__());
0215:                    }
0216:
0217:                }
0218:                dict.__setitem__("__unicode__", new PyMethodDescr(
0219:                        "__unicode__", PyObject.class, 0, 0,
0220:                        new exposed___unicode__(null, null)));
0221:                class exposed___init__ extends PyBuiltinMethod {
0222:
0223:                    exposed___init__(PyObject self, PyBuiltinFunction.Info info) {
0224:                        super (self, info);
0225:                    }
0226:
0227:                    public PyBuiltinFunction bind(PyObject self) {
0228:                        return new exposed___init__(self, info);
0229:                    }
0230:
0231:                    public PyObject __call__(PyObject[] args) {
0232:                        return __call__(args, Py.NoKeywords);
0233:                    }
0234:
0235:                    public PyObject __call__(PyObject[] args, String[] keywords) {
0236:                        ((PyObject) self).object_init(args, keywords);
0237:                        return Py.None;
0238:                    }
0239:
0240:                }
0241:                dict.__setitem__("__init__", new PyMethodDescr("__init__",
0242:                        PyObject.class, -1, -1,
0243:                        new exposed___init__(null, null)));
0244:                dict.__setitem__("__new__", new PyNewWrapper(PyObject.class,
0245:                        "__new__", -1, -1) {
0246:
0247:                    public PyObject new_impl(boolean init, PyType subtype,
0248:                            PyObject[] args, String[] keywords) {
0249:                        PyObject newobj;
0250:                        if (for_type == subtype) {
0251:                            newobj = new PyObject();
0252:                            if (init)
0253:                                newobj.object_init(args, keywords);
0254:                        } else {
0255:                            newobj = new PyObjectDerived(subtype);
0256:                        }
0257:                        return newobj;
0258:                    }
0259:
0260:                });
0261:            }
0262:
0263:            //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py
0264:
0265:            final void object_init(PyObject[] args, String[] keywords) {
0266:                // xxx
0267:            }
0268:
0269:            // getType may become not necessary
0270:            private PyType objtype;
0271:
0272:            public PyType getType() {
0273:                return objtype;
0274:            }
0275:
0276:            public void setType(PyType type) {
0277:                if (getType().layoutAligns(type)
0278:                        && !type.equals(PyType.fromClass(PyObject.class))) {
0279:                    this .objtype = type;
0280:                } else {
0281:                    throw Py
0282:                            .TypeError("Can only assign subtypes of object to __class__ on subclasses of object");
0283:                }
0284:            }
0285:
0286:            public void delType() {
0287:                throw Py.TypeError("Can't delete __class__ attribute");
0288:            }
0289:
0290:            // xxx
0291:            public PyObject fastGetClass() {
0292:                return objtype;
0293:            }
0294:
0295:            public PyObject getDoc() {
0296:                PyObject d = fastGetDict();
0297:                if (d != null) {
0298:                    PyObject doc = d.__finditem__("__doc__");
0299:                    if (doc != null) {
0300:                        return doc;
0301:                    }
0302:                }
0303:                return Py.None;
0304:            }
0305:
0306:            public PyObject(PyType objtype) {
0307:                this .objtype = objtype;
0308:            }
0309:
0310:            // A package private constructor used by PyJavaClass
0311:            // xxx will need variants for PyType of PyType and still PyJavaClass of PyJavaClass
0312:            PyObject(boolean dummy) {
0313:                objtype = (PyType) this ;
0314:            }
0315:
0316:            /**
0317:             * The standard constructor for a <code>PyObject</code>.  It will set
0318:             * the <code>__class__</code> field to correspond to the specific
0319:             * subclass of <code>PyObject</code> being instantiated.
0320:             **/
0321:            public PyObject() {
0322:                // xxx for now no such caching
0323:                // PyClass c = getPyClass();
0324:                // if (c == null)
0325:                //    c = PyJavaClass.lookup(getClass());
0326:                objtype = PyType.fromClass(getClass());
0327:            }
0328:
0329:            /* xxx will be replaced.
0330:             * This method is provided to efficiently initialize the __class__
0331:             * attribute.  If the following boilerplate is added to a subclass of
0332:             * PyObject, the instantiation time for the object will be greatly
0333:             * reduced.
0334:             *
0335:             * <blockquote><pre>
0336:             * // __class__ boilerplate -- see PyObject for details
0337:             * public static PyClass __class__;
0338:             * protected PyClass getPyClass() { return __class__; }
0339:             * </pre></blockquote>
0340:             *
0341:             * With PyIntegers this leads to a 50% faster instantiation time.
0342:             * This replaces the PyObject(PyClass c) constructor which is now
0343:             * deprecated.
0344:             *
0345:            protected PyClass getPyClass() {
0346:                return null;
0347:            } */
0348:
0349:            /**
0350:             * Dispatch __init__ behavior
0351:             */
0352:            public void dispatch__init__(PyType type, PyObject[] args,
0353:                    String[] keywords) {
0354:            }
0355:
0356:            /**
0357:             * Equivalent to the standard Python __repr__ method.  This method
0358:             * should not typically need to be overrriden.  The easiest way to
0359:             * configure the string representation of a <code>PyObject</code> is to
0360:             * override the standard Java <code>toString</code> method.
0361:             **/
0362:            public PyString __repr__() {
0363:                return new PyString(toString());
0364:            }
0365:
0366:            public String toString() {
0367:                return object_toString();
0368:            }
0369:
0370:            final String object_toString() {
0371:                if (getType() == null) {
0372:                    return "unknown object";
0373:                }
0374:
0375:                String name = getType().getFullName();
0376:                if (name == null)
0377:                    return "unknown object";
0378:
0379:                return "<" + name + " object " + Py.idstr(this ) + ">";
0380:            }
0381:
0382:            public String safeRepr() throws PyIgnoreMethodTag {
0383:                if (getType() == null) {
0384:                    return "unknown object";
0385:                }
0386:
0387:                String name = getType().getFullName();
0388:                if (name == null)
0389:                    return "unknown object";
0390:
0391:                return "'" + name + "' object";
0392:            }
0393:
0394:            /**
0395:             * Equivalent to the standard Python __str__ method.  This method
0396:             * should not typically need to be overridden.  The easiest way to
0397:             * configure the string representation of a <code>PyObject</code> is to
0398:             * override the standard Java <code>toString</code> method.
0399:             **/
0400:            public PyString __str__() {
0401:                return __repr__();
0402:            }
0403:
0404:            public PyUnicode __unicode__() {
0405:                return new PyUnicode(__str__());
0406:            }
0407:
0408:            /**
0409:             * Equivalent to the standard Python __hash__ method.  This method can
0410:             * not be overridden.  Instead, you should override the standard Java
0411:             * <code>hashCode</code> method to return an appropriate hash code for
0412:             * the <code>PyObject</code>.
0413:             **/
0414:            public final PyInteger __hash__() {
0415:                return new PyInteger(hashCode());
0416:            }
0417:
0418:            public int hashCode() {
0419:                return object_hashCode();
0420:            }
0421:
0422:            final int object_hashCode() {
0423:                return System.identityHashCode(this );
0424:            }
0425:
0426:            /**
0427:             * Should almost never be overridden.
0428:             * If overridden, it is the subclasses responsibility to ensure that
0429:             * <code>a.equals(b) == true</code> iff <code>cmp(a,b) == 0</code>
0430:             **/
0431:            public boolean equals(Object ob_other) {
0432:                return (ob_other instanceof  PyObject)
0433:                        && _eq((PyObject) ob_other).__nonzero__();
0434:            }
0435:
0436:            /**
0437:             * Equivalent to the standard Python __nonzero__ method.
0438:             * Returns whether of not a given <code>PyObject</code> is
0439:             * considered true.
0440:             **/
0441:            public boolean __nonzero__() {
0442:                return true;
0443:            }
0444:
0445:            /**
0446:             * Equivalent to the Jython __tojava__ method.
0447:             * Tries to coerce this object to an instance of the requested Java class.
0448:             * Returns the special object <code>Py.NoConversion</code>
0449:             * if this <code>PyObject</code> can not be converted to the
0450:             * desired Java class.
0451:             *
0452:             * @param c the Class to convert this <code>PyObject</code> to.
0453:             **/
0454:            public Object __tojava__(Class c) {
0455:                if (c.isInstance(this ))
0456:                    return this ;
0457:                return Py.NoConversion;
0458:            }
0459:
0460:            /**
0461:             * The basic method to override when implementing a callable object.
0462:             *
0463:             * The first len(args)-len(keywords) members of args[] are plain
0464:             * arguments.  The last len(keywords) arguments are the values of the
0465:             * keyword arguments.
0466:             *
0467:             * @param args     all arguments to the function (including
0468:             *                 keyword arguments).
0469:             * @param keywords the keywords used for all keyword arguments.
0470:             **/
0471:            public PyObject __call__(PyObject args[], String keywords[]) {
0472:                throw Py.TypeError("call of non-function (" + safeRepr() + ")");
0473:            }
0474:
0475:            /**
0476:             * A variant of the __call__ method with one extra initial argument.
0477:             * This variant is used to allow method invocations to be performed
0478:             * efficiently.
0479:             *
0480:             * The default behavior is to invoke <code>__call__(args,
0481:             * keywords)</code> with the appropriate arguments.  The only reason to
0482:             * override this function would be for improved performance.
0483:             *
0484:             * @param arg1     the first argument to the function.
0485:             * @param args     the last arguments to the function (including
0486:             *                 keyword arguments).
0487:             * @param keywords the keywords used for all keyword arguments.
0488:             **/
0489:            public PyObject __call__(PyObject arg1, PyObject args[],
0490:                    String keywords[]) {
0491:                PyObject[] newArgs = new PyObject[args.length + 1];
0492:                System.arraycopy(args, 0, newArgs, 1, args.length);
0493:                newArgs[0] = arg1;
0494:                return __call__(newArgs, keywords);
0495:            }
0496:
0497:            /**
0498:             * A variant of the __call__ method when no keywords are passed.  The
0499:             * default behavior is to invoke <code>__call__(args, keywords)</code>
0500:             * with the appropriate arguments.  The only reason to override this
0501:             * function would be for improved performance.
0502:             *
0503:             * @param args     all arguments to the function.
0504:             **/
0505:            public PyObject __call__(PyObject args[]) {
0506:                return __call__(args, Py.NoKeywords);
0507:            }
0508:
0509:            /**
0510:             * A variant of the __call__ method with no arguments.  The default
0511:             * behavior is to invoke <code>__call__(args, keywords)</code> with the
0512:             * appropriate arguments.  The only reason to override this function
0513:             * would be for improved performance.
0514:             **/
0515:            public PyObject __call__() {
0516:                return __call__(Py.EmptyObjects, Py.NoKeywords);
0517:            }
0518:
0519:            /**
0520:             * A variant of the __call__ method with one argument.  The default
0521:             * behavior is to invoke <code>__call__(args, keywords)</code> with the
0522:             * appropriate arguments.  The only reason to override this function
0523:             * would be for improved performance.
0524:             *
0525:             * @param arg0     the single argument to the function.
0526:             **/
0527:            public PyObject __call__(PyObject arg0) {
0528:                return __call__(new PyObject[] { arg0 }, Py.NoKeywords);
0529:            }
0530:
0531:            /**
0532:             * A variant of the __call__ method with two arguments.  The default
0533:             * behavior is to invoke <code>__call__(args, keywords)</code> with the
0534:             * appropriate arguments.  The only reason to override this function
0535:             * would be for improved performance.
0536:             *
0537:             * @param arg0     the first argument to the function.
0538:             * @param arg1     the second argument to the function.
0539:             **/
0540:            public PyObject __call__(PyObject arg0, PyObject arg1) {
0541:                return __call__(new PyObject[] { arg0, arg1 }, Py.NoKeywords);
0542:            }
0543:
0544:            /**
0545:             * A variant of the __call__ method with three arguments.  The default
0546:             * behavior is to invoke <code>__call__(args, keywords)</code> with the
0547:             * appropriate arguments.  The only reason to override this function
0548:             * would be for improved performance.
0549:             *
0550:             * @param arg0     the first argument to the function.
0551:             * @param arg1     the second argument to the function.
0552:             * @param arg2     the third argument to the function.
0553:             **/
0554:            public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) {
0555:                return __call__(new PyObject[] { arg0, arg1, arg2 },
0556:                        Py.NoKeywords);
0557:            }
0558:
0559:            /**
0560:             * A variant of the __call__ method with four arguments.  The default
0561:             * behavior is to invoke <code>__call__(args, keywords)</code> with the
0562:             * appropriate arguments.  The only reason to override this function
0563:             * would be for improved performance.
0564:             *
0565:             * @param arg0     the first argument to the function.
0566:             * @param arg1     the second argument to the function.
0567:             * @param arg2     the third argument to the function.
0568:             * @param arg3     the fourth argument to the function.
0569:             **/
0570:            public PyObject __call__(PyObject arg0, PyObject arg1,
0571:                    PyObject arg2, PyObject arg3) {
0572:                return __call__(new PyObject[] { arg0, arg1, arg2, arg3 },
0573:                        Py.NoKeywords);
0574:            }
0575:
0576:            /** @deprecated **/
0577:            public PyObject _callextra(PyObject[] args, String[] keywords,
0578:                    PyObject starargs, PyObject kwargs) {
0579:
0580:                int argslen = args.length;
0581:
0582:                String name = "";
0583:                if (this  instanceof  PyFunction) {
0584:                    name = ((PyFunction) this ).__name__ + "() ";
0585:                } else {
0586:                    name = getType().fastGetName() + " ";
0587:                }
0588:                if (kwargs != null) {
0589:                    PyObject keys = kwargs.__findattr__("keys");
0590:                    if (keys == null)
0591:                        throw Py.TypeError(name
0592:                                + "argument after ** must be a dictionary");
0593:                    for (int i = 0; i < keywords.length; i++)
0594:                        if (kwargs.__finditem__(keywords[i]) != null)
0595:                            throw Py.TypeError(name
0596:                                    + "got multiple values for "
0597:                                    + "keyword argument '" + keywords[i] + "'");
0598:                    argslen += kwargs.__len__();
0599:                }
0600:                List starObjs = null;
0601:                if (starargs != null) {
0602:                    if (starargs.__findattr__("__iter__") != null) {
0603:                        PyObject iter = starargs.__iter__();
0604:                        starObjs = new ArrayList();
0605:                        PyObject cur;
0606:                        while ((cur = iter.__iternext__()) != null) {
0607:                            starObjs.add(cur);
0608:                        }
0609:                    } else {
0610:                        try {
0611:                            int nstar = starargs.__len__();
0612:                            PyObject cur;
0613:                            starObjs = new ArrayList(nstar);
0614:                            for (int i = 0; (cur = starargs.__finditem__(i)) != null
0615:                                    && i < nstar; i++) {
0616:                                starObjs.add(cur);
0617:                            }
0618:                        } catch (PyException e) {
0619:                            if (Py.matchException(e, Py.AttributeError)) {
0620:                                throw Py.TypeError(name
0621:                                        + "argument after * must "
0622:                                        + "be a sequence");
0623:                            }
0624:                            throw e;
0625:                        }
0626:                    }
0627:                    argslen += starObjs.size();
0628:                }
0629:                PyObject[] newargs = new PyObject[argslen];
0630:                int argidx = args.length - keywords.length;
0631:                System.arraycopy(args, 0, newargs, 0, argidx);
0632:                if (starObjs != null) {
0633:                    Iterator it = starObjs.iterator();
0634:                    while (it.hasNext()) {
0635:                        newargs[argidx++] = (PyObject) it.next();
0636:                    }
0637:                }
0638:                System.arraycopy(args, args.length - keywords.length, newargs,
0639:                        argidx, keywords.length);
0640:                argidx += keywords.length;
0641:
0642:                if (kwargs != null) {
0643:                    String[] newkeywords = new String[keywords.length
0644:                            + kwargs.__len__()];
0645:                    System.arraycopy(keywords, 0, newkeywords, 0,
0646:                            keywords.length);
0647:
0648:                    PyObject keys = kwargs.invoke("keys");
0649:                    PyObject key;
0650:                    for (int i = 0; (key = keys.__finditem__(i)) != null; i++) {
0651:                        if (!(key instanceof  PyString))
0652:                            throw Py.TypeError(name
0653:                                    + "keywords must be strings");
0654:                        newkeywords[keywords.length + i] = ((PyString) key)
0655:                                .internedString();
0656:                        newargs[argidx++] = kwargs.__finditem__(key);
0657:                    }
0658:                    keywords = newkeywords;
0659:                }
0660:
0661:                if (newargs.length != argidx) {
0662:                    args = new PyObject[argidx];
0663:                    System.arraycopy(newargs, 0, args, 0, argidx);
0664:                } else
0665:                    args = newargs;
0666:                return __call__(args, keywords);
0667:            }
0668:
0669:            /* xxx fix these around */
0670:
0671:            public boolean isCallable() {
0672:                return __findattr__("__call__") != null;
0673:            }
0674:
0675:            public boolean isMappingType() {
0676:                return true;
0677:            }
0678:
0679:            public boolean isNumberType() {
0680:                return true;
0681:            }
0682:
0683:            public boolean isSequenceType() {
0684:                return true;
0685:            }
0686:
0687:            /* . */
0688:
0689:            /* The basic functions to implement a mapping */
0690:
0691:            /**
0692:             * Equivalent to the standard Python __len__ method.
0693:             * Part of the mapping discipline.
0694:             *
0695:             * @return the length of the object
0696:             **/
0697:            public int __len__() {
0698:                throw Py.AttributeError("__len__");
0699:            }
0700:
0701:            /**
0702:             * Very similar to the standard Python __getitem__ method.
0703:             * Instead of throwing a KeyError if the item isn't found,
0704:             * this just returns null.
0705:             *
0706:             * Classes that wish to implement __getitem__ should
0707:             * override this method instead (with the appropriate
0708:             * semantics.
0709:             *
0710:             * @param key the key to lookup in this container
0711:             *
0712:             * @return the value corresponding to key or null if key is not found
0713:             **/
0714:            public PyObject __finditem__(PyObject key) {
0715:                throw Py.AttributeError("__getitem__");
0716:            }
0717:
0718:            /**
0719:             * A variant of the __finditem__ method which accepts a primitive
0720:             * <code>int</code> as the key.  By default, this method will call
0721:             * <code>__finditem__(PyObject key)</code> with the appropriate args.
0722:             * The only reason to override this method is for performance.
0723:             *
0724:             * @param key the key to lookup in this sequence.
0725:             * @return the value corresponding to key or null if key is not found.
0726:             *
0727:             * @see #__finditem__(PyObject)
0728:             **/
0729:            public PyObject __finditem__(int key) {
0730:                return __finditem__(new PyInteger(key));
0731:            }
0732:
0733:            /**
0734:             * A variant of the __finditem__ method which accepts a Java
0735:             * <code>String</code> as the key.  By default, this method will call
0736:             * <code>__finditem__(PyObject key)</code> with the appropriate args.
0737:             * The only reason to override this method is for performance.
0738:             *
0739:             * <b>Warning: key must be an interned string!!!!!!!!</b>
0740:             *
0741:             * @param key the key to lookup in this sequence -
0742:             *            <b> must be an interned string </b>.
0743:             * @return the value corresponding to key or null if key is not found.
0744:             *
0745:             * @see #__finditem__(PyObject)
0746:             **/
0747:            public PyObject __finditem__(String key) {
0748:                return __finditem__(new PyString(key));
0749:            }
0750:
0751:            /**
0752:             * Equivalent to the standard Python __getitem__ method.
0753:             * This variant takes a primitive <code>int</code> as the key.
0754:             * This method should not be overridden.
0755:             * Override the <code>__finditem__</code> method instead.
0756:             *
0757:             * @param key the key to lookup in this container.
0758:             * @return the value corresponding to that key.
0759:             * @exception Py.KeyError if the key is not found.
0760:             *
0761:             * @see #__finditem__(int)
0762:             **/
0763:            public PyObject __getitem__(int key) {
0764:                PyObject ret = __finditem__(key);
0765:                if (ret == null)
0766:                    throw Py.KeyError("" + key);
0767:                return ret;
0768:            }
0769:
0770:            /**
0771:             * Equivalent to the standard Python __getitem__ method.
0772:             * This method should not be overridden.
0773:             * Override the <code>__finditem__</code> method instead.
0774:             *
0775:             * @param key the key to lookup in this container.
0776:             * @return the value corresponding to that key.
0777:             * @exception Py.KeyError if the key is not found.
0778:             *
0779:             * @see #__finditem__(PyObject)
0780:             **/
0781:            public PyObject __getitem__(PyObject key) {
0782:                PyObject ret = __finditem__(key);
0783:                if (ret == null)
0784:                    throw Py.KeyError(key.toString());
0785:                return ret;
0786:            }
0787:
0788:            /**
0789:             * Equivalent to the standard Python __setitem__ method.
0790:             *
0791:             * @param key the key whose value will be set
0792:             * @param value the value to set this key to
0793:             **/
0794:            public void __setitem__(PyObject key, PyObject value) {
0795:                throw Py.AttributeError("__setitem__");
0796:            }
0797:
0798:            /**
0799:             * A variant of the __setitem__ method which accepts a String
0800:             * as the key.  <b>This String must be interned</b>.
0801:             * By default, this will call
0802:             * <code>__setitem__(PyObject key, PyObject value)</code>
0803:             * with the appropriate args.
0804:             * The only reason to override this method is for performance.
0805:             *
0806:             * @param key the key whose value will be set -
0807:             *            <b> must be an interned string </b>.
0808:             * @param value the value to set this key to
0809:             *
0810:             * @see #__setitem__(PyObject, PyObject)
0811:             **/
0812:            public void __setitem__(String key, PyObject value) {
0813:                __setitem__(new PyString(key), value);
0814:            }
0815:
0816:            /**
0817:             * A variant of the __setitem__ method which accepts a primitive
0818:             * <code>int</code> as the key.
0819:             * By default, this will call
0820:             * <code>__setitem__(PyObject key, PyObject value)</code>
0821:             * with the appropriate args.
0822:             * The only reason to override this method is for performance.
0823:             *
0824:             * @param key the key whose value will be set
0825:             * @param value the value to set this key to
0826:             *
0827:             * @see #__setitem__(PyObject, PyObject)
0828:             **/
0829:            public void __setitem__(int key, PyObject value) {
0830:                __setitem__(new PyInteger(key), value);
0831:            }
0832:
0833:            /**
0834:             * Equivalent to the standard Python __delitem__ method.
0835:             *
0836:             * @param key the key to be removed from the container
0837:             * @exception Py.KeyError if the key is not found in the container
0838:             **/
0839:            public void __delitem__(PyObject key) {
0840:                throw Py.AttributeError("__delitem__");
0841:            }
0842:
0843:            /**
0844:             * A variant of the __delitem__ method which accepts a String
0845:             * as the key.  <b>This String must be interned</b>.
0846:             * By default, this will call
0847:             * <code>__delitem__(PyObject key)</code>
0848:             * with the appropriate args.
0849:             * The only reason to override this method is for performance.
0850:             *
0851:             * @param key the key who will be removed -
0852:             *            <b> must be an interned string </b>.
0853:             * @exception Py.KeyError if the key is not found in the container
0854:             *
0855:             * @see #__delitem__(PyObject)
0856:             **/
0857:            public void __delitem__(String key) {
0858:                __delitem__(new PyString(key));
0859:            }
0860:
0861:            public PyObject __getslice__(PyObject s_start, PyObject s_stop,
0862:                    PyObject s_step) {
0863:                PySlice s = new PySlice(s_start, s_stop, s_step);
0864:                return __getitem__(s);
0865:            }
0866:
0867:            public void __setslice__(PyObject s_start, PyObject s_stop,
0868:                    PyObject s_step, PyObject value) {
0869:                PySlice s = new PySlice(s_start, s_stop, s_step);
0870:                __setitem__(s, value);
0871:            }
0872:
0873:            public void __delslice__(PyObject s_start, PyObject s_stop,
0874:                    PyObject s_step) {
0875:                PySlice s = new PySlice(s_start, s_stop, s_step);
0876:                __delitem__(s);
0877:            }
0878:
0879:            public PyObject __getslice__(PyObject start, PyObject stop) {
0880:                return __getslice__(start, stop, Py.One);
0881:            }
0882:
0883:            public void __setslice__(PyObject start, PyObject stop,
0884:                    PyObject value) {
0885:                __setslice__(start, stop, Py.One, value);
0886:            }
0887:
0888:            public void __delslice__(PyObject start, PyObject stop) {
0889:                __delslice__(start, stop, Py.One);
0890:            }
0891:
0892:            /*The basic functions to implement an iterator */
0893:
0894:            /**
0895:             * Return an iterator that is used to iterate the element of this
0896:             * sequence.
0897:             * From version 2.2, this method is the primary protocol for looping
0898:             * over sequences.
0899:             * <p>
0900:             * If a PyObject subclass should support iteration based in the
0901:             * __finditem__() method, it must supply an implementation of __iter__()
0902:             * like this:
0903:             * <pre>
0904:             *    public PyObject __iter__() {
0905:             *        return new PySequenceIter(this);
0906:             *    }
0907:             * </pre>
0908:             *
0909:             * When iterating over a python sequence from java code, it should be
0910:             * done with code like this:
0911:             * <pre>
0912:             *    PyObject iter = seq.__iter__();
0913:             *    for (PyObject item; (item = iter.__iternext__()) != null;)  {
0914:             *        // Do somting with item
0915:             *    }
0916:             * </pre>
0917:             *
0918:             * @since 2.2
0919:             */
0920:            public PyObject __iter__() {
0921:                throw Py.TypeError("iteration over non-sequence");
0922:            }
0923:
0924:            /**
0925:             * Return the next element of the sequence that this is an iterator
0926:             * for. Returns null when the end of the sequence is reached.
0927:             *
0928:             * @since 2.2
0929:             */
0930:            public PyObject __iternext__() {
0931:                return null;
0932:            }
0933:
0934:            /*The basic functions to implement a namespace*/
0935:
0936:            /**
0937:             * Very similar to the standard Python __getattr__ method. Instead of
0938:             * throwing a AttributeError if the item isn't found, this just returns
0939:             * null.
0940:             * 
0941:             * By default, this method will call
0942:             * <code>__findattr__(name.internedString)</code> with the appropriate
0943:             * args. 
0944:             * 
0945:             * Classes that wish to implement __getattr__ should override this method
0946:             * instead (with the appropriate semantics.
0947:             * 
0948:             * @param name
0949:             *            the name to lookup in this namespace
0950:             * 
0951:             * @return the value corresponding to name or null if name is not found
0952:             */
0953:            public final PyObject __findattr__(PyString name) {
0954:                if (name == null) {
0955:                    return null;
0956:                }
0957:                return __findattr__(name.internedString());
0958:            }
0959:
0960:            /**
0961:             * A variant of the __findattr__ method which accepts a Java
0962:             * <code>String</code> as the name.
0963:             * 
0964:             * <b>Warning: name must be an interned string!</b>
0965:             *
0966:             * @param name the name to lookup in this namespace
0967:             * <b> must be an interned string </b>.
0968:             * @return the value corresponding to name or null if name is not found
0969:             *
0970:             * @see #__findattr__(PyString)
0971:             **/
0972:            public PyObject __findattr__(String name) { // xxx accelerators/ expose
0973:                /*if (getType() == null)
0974:                    return null;
0975:                if (name == "__class__")
0976:                    return getType();*/
0977:                /*PyObject ret = getType().lookup(name, false);
0978:                if (ret != null)
0979:                    return ret._doget(this);
0980:                return null;*/
0981:
0982:                return object___findattr__(name);
0983:            }
0984:
0985:            /**
0986:             * Equivalent to the standard Python __getattr__ method.
0987:             * This method can not be overridden.
0988:             * Override the <code>__findattr__</code> method instead.
0989:             *
0990:             * @param name the name to lookup in this namespace
0991:             * @return the value corresponding to name
0992:             * @exception Py.AttributeError if the name is not found.
0993:             *
0994:             * @see #__findattr__(PyString)
0995:             **/
0996:            public final PyObject __getattr__(PyString name) {
0997:                PyObject ret = __findattr__(name);
0998:                if (ret == null)
0999:                    noAttributeError(name.toString());
1000:                return ret;
1001:            }
1002:
1003:            /**
1004:             * A variant of the __getattr__ method which accepts a Java
1005:             * <code>String</code> as the name.
1006:             * This method can not be overridden.
1007:             * Override the <code>__findattr__</code> method instead.
1008:             *
1009:             * <b>Warning: name must be an interned string!!!!!!!!</b>
1010:             *
1011:             * @param name the name to lookup in this namespace
1012:             *             <b> must be an interned string </b>.
1013:             * @return the value corresponding to name
1014:             * @exception Py.AttributeError if the name is not found.
1015:             *
1016:             * @see #__findattr__(java.lang.String)
1017:             **/
1018:            public final PyObject __getattr__(String name) {
1019:                PyObject ret = __findattr__(name);
1020:                if (ret == null)
1021:                    noAttributeError(name);
1022:                return ret;
1023:            }
1024:
1025:            public void noAttributeError(String name) {
1026:                throw Py.AttributeError(safeRepr() + " has no attribute '"
1027:                        + name + "'");
1028:            }
1029:
1030:            public void readonlyAttributeError(String name) {
1031:                throw Py.AttributeError(safeRepr() + " attribute '" + name
1032:                        + "' is read-only");
1033:            }
1034:
1035:            /**
1036:             * Equivalent to the standard Python __setattr__ method.
1037:             * This method can not be overridden.
1038:             *
1039:             * @param name the name to lookup in this namespace
1040:             * @exception Py.AttributeError if the name is not found.
1041:             *
1042:             * @see #__setattr__(java.lang.String, PyObject)
1043:             **/
1044:            public final void __setattr__(PyString name, PyObject value) {
1045:                __setattr__(name.internedString(), value);
1046:            }
1047:
1048:            /**
1049:             * A variant of the __setattr__ method which accepts a String
1050:             * as the key.  <b>This String must be interned</b>.
1051:             *
1052:             * @param name  the name whose value will be set -
1053:             *              <b> must be an interned string </b>.
1054:             * @param value the value to set this name to
1055:             *
1056:             * @see #__setattr__(PyString, PyObject)
1057:             **/
1058:            public void __setattr__(String name, PyObject value) {
1059:                object___setattr__(name, value);
1060:            }
1061:
1062:            /**
1063:             * Equivalent to the standard Python __delattr__ method.
1064:             * This method can not be overridden.
1065:             *
1066:             * @param name the name to which will be removed
1067:             * @exception Py.AttributeError if the name doesn't exist
1068:             *
1069:             * @see #__delattr__(java.lang.String)
1070:             **/
1071:            public final void __delattr__(PyString name) {
1072:                __delattr__(name.internedString());
1073:            }
1074:
1075:            /**
1076:             * A variant of the __delattr__ method which accepts a String
1077:             * as the key.  <b>This String must be interned</b>.
1078:             * By default, this will call
1079:             * <code>__delattr__(PyString name)</code>
1080:             * with the appropriate args.
1081:             * The only reason to override this method is for performance.
1082:             *
1083:             * @param name the name which will be removed -
1084:             *             <b> must be an interned string </b>.
1085:             * @exception Py.AttributeError if the name doesn't exist
1086:             *
1087:             * @see #__delattr__(PyString)
1088:             **/
1089:            public void __delattr__(String name) {
1090:                object___delattr__(name);
1091:            }
1092:
1093:            // Used by import logic.
1094:            protected PyObject impAttr(String name) {
1095:                return __findattr__(name);
1096:            }
1097:
1098:            protected void addKeys(PyDictionary accum, String attr) {
1099:                PyObject obj = __findattr__(attr);
1100:                if (obj == null)
1101:                    return;
1102:                if (obj instanceof  PyList) {
1103:                    PyObject lst_iter = obj.__iter__();
1104:                    PyObject name;
1105:                    for (; (name = lst_iter.__iternext__()) != null;) {
1106:                        accum.__setitem__(name, Py.None);
1107:                    }
1108:                } else {
1109:                    accum.update(obj);
1110:                }
1111:            }
1112:
1113:            protected void __rawdir__(PyDictionary accum) {
1114:                addKeys(accum, "__dict__");
1115:                addKeys(accum, "__methods__");
1116:                addKeys(accum, "__members__");
1117:                fastGetClass().__rawdir__(accum);
1118:            }
1119:
1120:            /**
1121:             * Equivalent to the standard Python __dir__ method.
1122:             *
1123:             * @return a list of names defined by this object.
1124:             **/
1125:            public PyObject __dir__() {
1126:                PyDictionary accum = new PyDictionary();
1127:                __rawdir__(accum);
1128:                PyList ret = accum.keys();
1129:                ret.sort();
1130:                return ret;
1131:            }
1132:
1133:            public PyObject _doget(PyObject container) {
1134:                return this ;
1135:            }
1136:
1137:            public PyObject _doget(PyObject container, PyObject wherefound) {
1138:                return _doget(container);
1139:            }
1140:
1141:            public boolean _doset(PyObject container, PyObject value) {
1142:                return false;
1143:            }
1144:
1145:            boolean jtryset(PyObject container, PyObject value) {
1146:                return _doset(container, value);
1147:            }
1148:
1149:            boolean jdontdel() {
1150:                return false;
1151:            }
1152:
1153:            /* Numeric coercion */
1154:
1155:            /**
1156:             * Implements numeric coercion
1157:             *
1158:             * @param o the other object involved in the coercion
1159:             * @return null if no coercion is possible;
1160:             * a single PyObject to use to replace o if this is unchanged;
1161:             * or a PyObject[2] consisting of replacements for this and o.
1162:             **/
1163:            public Object __coerce_ex__(PyObject o) {
1164:                return null;
1165:            }
1166:
1167:            /**
1168:             * Implements coerce(this,other), result as PyObject[]
1169:             * @param other
1170:             * @return PyObject[]
1171:             */
1172:            PyObject[] _coerce(PyObject other) {
1173:                Object result;
1174:                if (this .getType() == other.getType()
1175:                        && !(this  instanceof  PyInstance)) {
1176:                    return new PyObject[] { this , other };
1177:                }
1178:                result = this .__coerce_ex__(other);
1179:                if (result != null && result != Py.None) {
1180:                    if (result instanceof  PyObject[]) {
1181:                        return (PyObject[]) result;
1182:                    } else {
1183:                        return new PyObject[] { this , (PyObject) result };
1184:                    }
1185:                }
1186:                result = other.__coerce_ex__(this );
1187:                if (result != null && result != Py.None) {
1188:                    if (result instanceof  PyObject[]) {
1189:                        return (PyObject[]) result;
1190:                    } else {
1191:                        return new PyObject[] { (PyObject) result, other };
1192:                    }
1193:                }
1194:                return null;
1195:
1196:            }
1197:
1198:            /**
1199:             * Equivalent to the standard Python __coerce__ method.
1200:             *
1201:             * This method can not be overridden.
1202:             * To implement __coerce__ functionality, override __coerce_ex__ instead.
1203:             *
1204:             * @param pyo the other object involved in the coercion.
1205:             * @return a tuple of this object and pyo coerced to the same type
1206:             *         or Py.None if no coercion is possible.
1207:             * @see org.python.core.PyObject#__coerce_ex__(org.python.core.PyObject)
1208:             **/
1209:            public final PyObject __coerce__(PyObject pyo) {
1210:                Object o = __coerce_ex__(pyo);
1211:                if (o == null)
1212:                    throw Py.AttributeError("__coerce__");
1213:                if (o == Py.None)
1214:                    return (PyObject) o;
1215:                if (o instanceof  PyObject[])
1216:                    return new PyTuple((PyObject[]) o);
1217:                else
1218:                    return new PyTuple(new PyObject[] { this , (PyObject) o });
1219:            }
1220:
1221:            /* The basic comparision operations */
1222:
1223:            /**
1224:             * Equivalent to the standard Python __cmp__ method.
1225:             *
1226:             * @param other the object to compare this with.
1227:             * @return -1 if this < 0; 0 if this == o; +1 if this > o; -2 if no
1228:             * comparison is implemented
1229:             **/
1230:            public int __cmp__(PyObject other) {
1231:                return -2;
1232:            }
1233:
1234:            /**
1235:             * Equivalent to the standard Python __eq__ method.
1236:             *
1237:             * @param other the object to compare this with.
1238:             * @return the result of the comparison.
1239:             **/
1240:            public PyObject __eq__(PyObject other) {
1241:                return null;
1242:            }
1243:
1244:            /**
1245:             * Equivalent to the standard Python __ne__ method.
1246:             *
1247:             * @param other the object to compare this with.
1248:             * @return the result of the comparison.
1249:             **/
1250:            public PyObject __ne__(PyObject other) {
1251:                return null;
1252:            }
1253:
1254:            /**
1255:             * Equivalent to the standard Python __le__ method.
1256:             *
1257:             * @param other the object to compare this with.
1258:             * @return the result of the comparison.
1259:             **/
1260:            public PyObject __le__(PyObject other) {
1261:                return null;
1262:            }
1263:
1264:            /**
1265:             * Equivalent to the standard Python __lt__ method.
1266:             *
1267:             * @param other the object to compare this with.
1268:             * @return the result of the comparison.
1269:             **/
1270:            public PyObject __lt__(PyObject other) {
1271:                return null;
1272:            }
1273:
1274:            /**
1275:             * Equivalent to the standard Python __ge__ method.
1276:             *
1277:             * @param other the object to compare this with.
1278:             * @return the result of the comparison.
1279:             **/
1280:            public PyObject __ge__(PyObject other) {
1281:                return null;
1282:            }
1283:
1284:            /**
1285:             * Equivalent to the standard Python __gt__ method.
1286:             *
1287:             * @param other the object to compare this with.
1288:             * @return the result of the comparison.
1289:             **/
1290:            public PyObject __gt__(PyObject other) {
1291:                return null;
1292:            }
1293:
1294:            /**
1295:             * Implements cmp(this, other)
1296:             *
1297:             * @param o the object to compare this with.
1298:             * @return -1 if this < 0; 0 if this == o; +1 if this > o
1299:             **/
1300:            public final int _cmp(PyObject o) {
1301:                PyObject token = null;
1302:                ThreadState ts = Py.getThreadState();
1303:                try {
1304:                    if (++ts.compareStateNesting > 500) {
1305:                        if ((token = check_recursion(ts, this , o)) == null)
1306:                            return 0;
1307:                    }
1308:
1309:                    PyObject r;
1310:                    r = __eq__(o);
1311:                    if (r != null && r.__nonzero__())
1312:                        return 0;
1313:                    r = o.__eq__(this );
1314:                    if (r != null && r.__nonzero__())
1315:                        return 0;
1316:
1317:                    r = __lt__(o);
1318:                    if (r != null && r.__nonzero__())
1319:                        return -1;
1320:                    r = o.__gt__(this );
1321:                    if (r != null && r.__nonzero__())
1322:                        return -1;
1323:
1324:                    r = __gt__(o);
1325:                    if (r != null && r.__nonzero__())
1326:                        return 1;
1327:                    r = o.__lt__(this );
1328:                    if (r != null && r.__nonzero__())
1329:                        return 1;
1330:
1331:                    return _cmp_unsafe(o);
1332:                } finally {
1333:                    delete_token(ts, token);
1334:                    ts.compareStateNesting--;
1335:                }
1336:            }
1337:
1338:            private PyObject make_pair(PyObject o) {
1339:                if (System.identityHashCode(this ) < System.identityHashCode(o))
1340:                    return new PyIdentityTuple(new PyObject[] { this , o });
1341:                else
1342:                    return new PyIdentityTuple(new PyObject[] { o, this  });
1343:            }
1344:
1345:            private final int _default_cmp(PyObject other) {
1346:                int result;
1347:                if (this ._is(other).__nonzero__())
1348:                    return 0;
1349:
1350:                /* None is smaller than anything */
1351:                if (this  == Py.None)
1352:                    return -1;
1353:                if (other == Py.None)
1354:                    return 1;
1355:
1356:                // No rational way to compare these, so ask their classes to compare
1357:                PyType this _type = this .getType();
1358:                PyType other_type = other.getType();
1359:                if (this _type == other_type) {
1360:                    return Py.id(this ) < Py.id(other) ? -1 : 1;
1361:                }
1362:                result = this _type.fastGetName().compareTo(
1363:                        other_type.fastGetName());
1364:                if (result == 0)
1365:                    return Py.id(this _type) < Py.id(other_type) ? -1 : 1;
1366:                return result < 0 ? -1 : 1;
1367:            }
1368:
1369:            private final int _cmp_unsafe(PyObject other) {
1370:                // Shortcut for equal objects
1371:                if (this  == other)
1372:                    return 0;
1373:
1374:                int result;
1375:                result = this .__cmp__(other);
1376:                if (result != -2)
1377:                    return result;
1378:
1379:                if (!(this  instanceof  PyInstance)) {
1380:                    result = other.__cmp__(this );
1381:                    if (result != -2)
1382:                        return -result;
1383:                }
1384:
1385:                return this ._default_cmp(other);
1386:            }
1387:
1388:            /*
1389:             *  Like _cmp_unsafe but limited to ==/!= as 0/!=0,
1390:             *  avoids to invoke Py.id
1391:             */
1392:            private final int _cmpeq_unsafe(PyObject other) {
1393:                // Shortcut for equal objects
1394:                if (this  == other)
1395:                    return 0;
1396:
1397:                int result;
1398:                result = this .__cmp__(other);
1399:                if (result != -2)
1400:                    return result;
1401:
1402:                if (!(this  instanceof  PyInstance)) {
1403:                    result = other.__cmp__(this );
1404:                    if (result != -2)
1405:                        return -result;
1406:                }
1407:
1408:                return this ._is(other).__nonzero__() ? 0 : 1;
1409:            }
1410:
1411:            private final static PyObject check_recursion(ThreadState ts,
1412:                    PyObject o1, PyObject o2) {
1413:                PyDictionary stateDict = ts.getCompareStateDict();
1414:
1415:                PyObject pair = o1.make_pair(o2);
1416:
1417:                if (stateDict.__finditem__(pair) != null)
1418:                    return null;
1419:
1420:                stateDict.__setitem__(pair, pair);
1421:                return pair;
1422:            }
1423:
1424:            private final static void delete_token(ThreadState ts,
1425:                    PyObject token) {
1426:                if (token == null)
1427:                    return;
1428:                PyDictionary stateDict = ts.getCompareStateDict();
1429:
1430:                stateDict.__delitem__(token);
1431:            }
1432:
1433:            /**
1434:             * Implements the Python expression <code>this == other</code>.
1435:             *
1436:             * @param o the object to compare this with.
1437:             * @return the result of the comparison
1438:             **/
1439:            public final PyObject _eq(PyObject o) {
1440:                PyObject token = null;
1441:                PyType t1 = this .getType();
1442:                PyType t2 = o.getType();
1443:
1444:                if (t1 != t2 && t2.isSubType(t1)) {
1445:                    return o._eq(this );
1446:                }
1447:
1448:                ThreadState ts = Py.getThreadState();
1449:                try {
1450:                    if (++ts.compareStateNesting > 10) {
1451:                        if ((token = check_recursion(ts, this , o)) == null)
1452:                            return Py.One;
1453:                    }
1454:                    PyObject res = __eq__(o);
1455:                    if (res != null)
1456:                        return res;
1457:                    res = o.__eq__(this );
1458:                    if (res != null)
1459:                        return res;
1460:                    return _cmpeq_unsafe(o) == 0 ? Py.One : Py.Zero;
1461:                } catch (PyException e) {
1462:                    if (Py.matchException(e, Py.AttributeError)) {
1463:                        return Py.Zero;
1464:                    }
1465:                    throw e;
1466:                } finally {
1467:                    delete_token(ts, token);
1468:                    ts.compareStateNesting--;
1469:                }
1470:            }
1471:
1472:            /**
1473:             * Implements the Python expression <code>this != other</code>.
1474:             *
1475:             * @param o the object to compare this with.
1476:             * @return the result of the comparison
1477:             **/
1478:            public final PyObject _ne(PyObject o) {
1479:                PyObject token = null;
1480:                PyType t1 = this .getType();
1481:                PyType t2 = o.getType();
1482:
1483:                if (t1 != t2 && t2.isSubType(t1)) {
1484:                    return o._ne(this );
1485:                }
1486:
1487:                ThreadState ts = Py.getThreadState();
1488:                try {
1489:                    if (++ts.compareStateNesting > 10) {
1490:                        if ((token = check_recursion(ts, this , o)) == null)
1491:                            return Py.Zero;
1492:                    }
1493:                    PyObject res = __ne__(o);
1494:                    if (res != null)
1495:                        return res;
1496:                    res = o.__ne__(this );
1497:                    if (res != null)
1498:                        return res;
1499:                    return _cmpeq_unsafe(o) != 0 ? Py.One : Py.Zero;
1500:                } finally {
1501:                    delete_token(ts, token);
1502:                    ts.compareStateNesting--;
1503:                }
1504:            }
1505:
1506:            /**
1507:             * Implements the Python expression <code>this &lt;= other</code>.
1508:             *
1509:             * @param o the object to compare this with.
1510:             * @return the result of the comparison
1511:             **/
1512:            public final PyObject _le(PyObject o) {
1513:                PyObject token = null;
1514:                PyType t1 = this .getType();
1515:                PyType t2 = o.getType();
1516:
1517:                if (t1 != t2 && t2.isSubType(t1)) {
1518:                    return o._ge(this );
1519:                }
1520:
1521:                ThreadState ts = Py.getThreadState();
1522:                try {
1523:                    if (++ts.compareStateNesting > 10) {
1524:                        if ((token = check_recursion(ts, this , o)) == null)
1525:                            throw Py.ValueError("can't order recursive values");
1526:                    }
1527:                    PyObject res = __le__(o);
1528:                    if (res != null)
1529:                        return res;
1530:                    res = o.__ge__(this );
1531:                    if (res != null)
1532:                        return res;
1533:                    return _cmp_unsafe(o) <= 0 ? Py.One : Py.Zero;
1534:                } finally {
1535:                    delete_token(ts, token);
1536:                    ts.compareStateNesting--;
1537:                }
1538:            }
1539:
1540:            /**
1541:             * Implements the Python expression <code>this &lt; other</code>.
1542:             *
1543:             * @param o the object to compare this with.
1544:             * @return the result of the comparison
1545:             **/
1546:            public final PyObject _lt(PyObject o) {
1547:                PyObject token = null;
1548:                PyType t1 = this .getType();
1549:                PyType t2 = o.getType();
1550:
1551:                if (t1 != t2 && t2.isSubType(t1)) {
1552:                    return o._gt(this );
1553:                }
1554:
1555:                ThreadState ts = Py.getThreadState();
1556:                try {
1557:                    if (++ts.compareStateNesting > 10) {
1558:                        if ((token = check_recursion(ts, this , o)) == null)
1559:                            throw Py.ValueError("can't order recursive values");
1560:                    }
1561:                    PyObject res = __lt__(o);
1562:                    if (res != null)
1563:                        return res;
1564:                    res = o.__gt__(this );
1565:                    if (res != null)
1566:                        return res;
1567:                    return _cmp_unsafe(o) < 0 ? Py.One : Py.Zero;
1568:                } finally {
1569:                    delete_token(ts, token);
1570:                    ts.compareStateNesting--;
1571:                }
1572:            }
1573:
1574:            /**
1575:             * Implements the Python expression <code>this &gt;= other</code>.
1576:             *
1577:             * @param o the object to compare this with.
1578:             * @return the result of the comparison
1579:             **/
1580:            public final PyObject _ge(PyObject o) {
1581:                PyObject token = null;
1582:                PyType t1 = this .getType();
1583:                PyType t2 = o.getType();
1584:
1585:                if (t1 != t2 && t2.isSubType(t1)) {
1586:                    return o._le(this );
1587:                }
1588:
1589:                ThreadState ts = Py.getThreadState();
1590:                try {
1591:                    if (++ts.compareStateNesting > 10) {
1592:                        if ((token = check_recursion(ts, this , o)) == null)
1593:                            throw Py.ValueError("can't order recursive values");
1594:                    }
1595:                    PyObject res = __ge__(o);
1596:                    if (res != null)
1597:                        return res;
1598:                    res = o.__le__(this );
1599:                    if (res != null)
1600:                        return res;
1601:                    return _cmp_unsafe(o) >= 0 ? Py.One : Py.Zero;
1602:                } finally {
1603:                    delete_token(ts, token);
1604:                    ts.compareStateNesting--;
1605:                }
1606:            }
1607:
1608:            /**
1609:             * Implements the Python expression <code>this &gt; other</code>.
1610:             *
1611:             * @param o the object to compare this with.
1612:             * @return the result of the comparison
1613:             **/
1614:            public final PyObject _gt(PyObject o) {
1615:                PyObject token = null;
1616:                PyType t1 = this .getType();
1617:                PyType t2 = o.getType();
1618:
1619:                if (t1 != t2 && t2.isSubType(t1)) {
1620:                    return o._lt(this );
1621:                }
1622:
1623:                ThreadState ts = Py.getThreadState();
1624:                try {
1625:                    if (++ts.compareStateNesting > 10) {
1626:                        if ((token = check_recursion(ts, this , o)) == null)
1627:                            throw Py.ValueError("can't order recursive values");
1628:                    }
1629:                    PyObject res = __gt__(o);
1630:                    if (res != null)
1631:                        return res;
1632:                    res = o.__lt__(this );
1633:                    if (res != null)
1634:                        return res;
1635:                    return _cmp_unsafe(o) > 0 ? Py.One : Py.Zero;
1636:                } finally {
1637:                    delete_token(ts, token);
1638:                    ts.compareStateNesting--;
1639:                }
1640:
1641:            }
1642:
1643:            /**
1644:             * Implements <code>is</code> operator.
1645:             *
1646:             * @param o the object to compare this with.
1647:             * @return the result of the comparison
1648:             **/
1649:            public PyObject _is(PyObject o) {
1650:                return this  == o ? Py.One : Py.Zero;
1651:            }
1652:
1653:            /**
1654:             * Implements <code>is not</code> operator.
1655:             *
1656:             * @param o the object to compare this with.
1657:             * @return the result of the comparison
1658:             **/
1659:            public PyObject _isnot(PyObject o) {
1660:                return this  != o ? Py.One : Py.Zero;
1661:            }
1662:
1663:            /**
1664:             * Implements <code>in</code> operator.
1665:             *
1666:             * @param o the container to search for this element.
1667:             * @return the result of the search.
1668:             **/
1669:            public final PyObject _in(PyObject o) {
1670:                return Py.newBoolean(o.__contains__(this ));
1671:            }
1672:
1673:            /**
1674:             * Implements <code>not in</code> operator.
1675:             *
1676:             * @param o the container to search for this element.
1677:             * @return the result of the search.
1678:             **/
1679:            public final PyObject _notin(PyObject o) {
1680:                return Py.newBoolean(!o.__contains__(this ));
1681:            }
1682:
1683:            /**
1684:             * Equivalent to the standard Python __contains__ method.
1685:             *
1686:             * @param o the element to search for in this container.
1687:             * @return the result of the search.
1688:             **/
1689:            public boolean __contains__(PyObject o) {
1690:                return object___contains__(o);
1691:            }
1692:
1693:            final boolean object___contains__(PyObject o) {
1694:                PyObject iter = __iter__();
1695:                for (PyObject item = null; (item = iter.__iternext__()) != null;) {
1696:                    if (o._eq(item).__nonzero__())
1697:                        return true;
1698:                }
1699:                return false;
1700:            }
1701:
1702:            /**
1703:             * Implements boolean not
1704:             *
1705:             * @return not this.
1706:             **/
1707:            public PyObject __not__() {
1708:                return __nonzero__() ? Py.Zero : Py.One;
1709:            }
1710:
1711:            /* The basic numeric operations */
1712:
1713:            /**
1714:             * Equivalent to the standard Python __hex__ method
1715:             * Should only be overridden by numeric objects that can be
1716:             * reasonably represented as a hexadecimal string.
1717:             *
1718:             * @return a string representing this object as a hexadecimal number.
1719:             **/
1720:            public PyString __hex__() {
1721:                throw Py.AttributeError("__hex__");
1722:            }
1723:
1724:            /**
1725:             * Equivalent to the standard Python __oct__ method.
1726:             * Should only be overridden by numeric objects that can be
1727:             * reasonably represented as an octal string.
1728:             *
1729:             * @return a string representing this object as an octal number.
1730:             **/
1731:            public PyString __oct__() {
1732:                throw Py.AttributeError("__oct__");
1733:            }
1734:
1735:            /**
1736:             * Equivalent to the standard Python __int__ method.
1737:             * Should only be overridden by numeric objects that can be
1738:             * reasonably coerced into an integer.
1739:             *
1740:             * @return an integer corresponding to the value of this object.
1741:             **/
1742:            public PyObject __int__() {
1743:                throw Py.AttributeError("__int__");
1744:            }
1745:
1746:            /**
1747:             * Equivalent to the standard Python __long__ method.
1748:             * Should only be overridden by numeric objects that can be
1749:             * reasonably coerced into a python long.
1750:             *
1751:             * @return a PyLong corresponding to the value of this object.
1752:             **/
1753:            public PyLong __long__() {
1754:                throw Py.AttributeError("__long__");
1755:            }
1756:
1757:            /**
1758:             * Equivalent to the standard Python __float__ method.
1759:             * Should only be overridden by numeric objects that can be
1760:             * reasonably coerced into a python float.
1761:             *
1762:             * @return a float corresponding to the value of this object.
1763:             **/
1764:            public PyFloat __float__() {
1765:                throw Py.AttributeError("__float__");
1766:            }
1767:
1768:            /**
1769:             * Equivalent to the standard Python __complex__ method.
1770:             * Should only be overridden by numeric objects that can be
1771:             * reasonably coerced into a python complex number.
1772:             *
1773:             * @return a complex number corresponding to the value of this object.
1774:             **/
1775:            public PyComplex __complex__() {
1776:                throw Py.AttributeError("__complex__");
1777:            }
1778:
1779:            /**
1780:             * Equivalent to the standard Python __pos__ method.
1781:             *
1782:             * @return +this.
1783:             **/
1784:            public PyObject __pos__() {
1785:                throw Py.AttributeError("__pos__");
1786:            }
1787:
1788:            /**
1789:             * Equivalent to the standard Python __neg__ method.
1790:             *
1791:             * @return -this.
1792:             **/
1793:            public PyObject __neg__() {
1794:                throw Py.AttributeError("__neg__");
1795:            }
1796:
1797:            /**
1798:             * Equivalent to the standard Python __abs__ method.
1799:             *
1800:             * @return abs(this).
1801:             **/
1802:            public PyObject __abs__() {
1803:                throw Py.AttributeError("__abs__");
1804:            }
1805:
1806:            /**
1807:             * Equivalent to the standard Python __invert__ method.
1808:             *
1809:             * @return ~this.
1810:             **/
1811:            public PyObject __invert__() {
1812:                throw Py.AttributeError("__invert__");
1813:            }
1814:
1815:            /**
1816:             * @param op the String form of the op (e.g. "+")
1817:             * @param o2 the right operand
1818:             */
1819:            protected final String _unsupportedop(String op, PyObject o2) {
1820:                Object[] args = { op, getType().fastGetName(),
1821:                        o2.getType().fastGetName() };
1822:                String msg = unsupportedopMessage(op, o2);
1823:                if (msg == null) {
1824:                    msg = o2.runsupportedopMessage(op, o2);
1825:                }
1826:                if (msg == null) {
1827:                    msg = "unsupported operand type(s) for {0}: ''{1}'' and ''{2}''";
1828:                }
1829:                return MessageFormat.format(msg, args);
1830:            }
1831:
1832:            /**
1833:             * Should return an error message suitable for substitution where.
1834:             *
1835:             * {0} is the op name.
1836:             * {1} is the left operand type.
1837:             * {2} is the right operand type.
1838:             */
1839:            protected String unsupportedopMessage(String op, PyObject o2) {
1840:                return null;
1841:            }
1842:
1843:            /**
1844:             * Should return an error message suitable for substitution where.
1845:             *
1846:             * {0} is the op name.
1847:             * {1} is the left operand type.
1848:             * {2} is the right operand type.
1849:             */
1850:            protected String runsupportedopMessage(String op, PyObject o2) {
1851:                return null;
1852:            }
1853:
1854:            /**
1855:             * Implements the three argument power function.
1856:             *
1857:             * @param o2 the power to raise this number to.
1858:             * @param o3 the modulus to perform this operation in or null if no
1859:             *           modulo is to be used
1860:             * @return this object raised to the given power in the given modulus
1861:             **/
1862:            public PyObject __pow__(PyObject o2, PyObject o3) {
1863:                return null;
1864:            }
1865:
1866:            private PyObject _binop_rule(PyType t1, PyObject o2, PyType t2,
1867:                    String left, String right, String op) {
1868:                /*
1869:                 * this is the general rule for binary operation dispatching try first
1870:                 * __xxx__ with this and then __rxxx__ with o2 unless o2 is an instance
1871:                 * of subclass of the type of this, and further __xxx__ and __rxxx__ are
1872:                 * unrelated ( checked here by looking at where in the hierarchy they
1873:                 * are defined), in that case try them in the reverse order. This is the
1874:                 * same formulation as used by PyPy, see also
1875:                 * test_descr.subclass_right_op.
1876:                 */
1877:                PyObject o1 = this ;
1878:                PyObject[] where = new PyObject[1];
1879:                PyObject where1 = null, where2 = null;
1880:                PyObject impl1 = t1.lookup_where(left, where);
1881:                where1 = where[0];
1882:                PyObject impl2 = t2.lookup_where(right, where);
1883:                where2 = where[0];
1884:                if (impl2 != null && where1 != where2 && t2.isSubType(t1)) {
1885:                    PyObject tmp = o1;
1886:                    o1 = o2;
1887:                    o2 = tmp;
1888:                    tmp = impl1;
1889:                    impl1 = impl2;
1890:                    impl2 = tmp;
1891:                    PyType ttmp;
1892:                    ttmp = t1;
1893:                    t1 = t2;
1894:                    t2 = ttmp;
1895:                }
1896:                PyObject res = null;
1897:                if (impl1 != null) {
1898:                    res = impl1.__get__(o1, t1).__call__(o2);
1899:                    if (res != Py.NotImplemented) {
1900:                        return res;
1901:                    }
1902:                }
1903:                if (impl2 != null) {
1904:                    res = impl2.__get__(o2, t2).__call__(o1);
1905:                    if (res != Py.NotImplemented) {
1906:                        return res;
1907:                    }
1908:                }
1909:                throw Py.TypeError(_unsupportedop(op, o2));
1910:            }
1911:
1912:            // Generated by make_binops.py (Begin)
1913:
1914:            /**
1915:             * Equivalent to the standard Python __add__ method
1916:             * @param     other the object to perform this binary operation with
1917:             *            (the right-hand operand).
1918:             * @return    the result of the add, or null if this operation
1919:             *            is not defined
1920:             **/
1921:            public PyObject __add__(PyObject other) {
1922:                return null;
1923:            }
1924:
1925:            /**
1926:             * Equivalent to the standard Python __radd__ method
1927:             * @param     other the object to perform this binary operation with
1928:             *            (the left-hand operand).
1929:             * @return    the result of the add, or null if this operation
1930:             *            is not defined.
1931:             **/
1932:            public PyObject __radd__(PyObject other) {
1933:                return null;
1934:            }
1935:
1936:            /**
1937:             * Equivalent to the standard Python __iadd__ method
1938:             * @param     other the object to perform this binary operation with
1939:             *            (the right-hand operand).
1940:             * @return    the result of the add, or null if this operation
1941:             *            is not defined
1942:             **/
1943:            public PyObject __iadd__(PyObject other) {
1944:                return _add(other);
1945:            }
1946:
1947:            /**
1948:             * Implements the Python expression <code>this + o2</code>
1949:             * @param     o2 the object to perform this binary operation with.
1950:             * @return    the result of the add.
1951:             * @exception Py.TypeError if this operation can't be performed
1952:             *            with these operands.
1953:             **/
1954:            public final PyObject _add(PyObject o2) {
1955:                PyType t1 = this .getType();
1956:                PyType t2 = o2.getType();
1957:                if (t1 == t2 || t1.builtin && t2.builtin) {
1958:                    return this ._basic_add(o2);
1959:                }
1960:                return _binop_rule(t1, o2, t2, "__add__", "__radd__", "+");
1961:            }
1962:
1963:            /**
1964:             * Implements the Python expression <code>this + o2</code>
1965:             * when this and o2 have the same type or are builtin types.
1966:             * @param     o2 the object to perform this binary operation with.
1967:             * @return    the result of the add.
1968:             * @exception Py.TypeError if this operation can't be performed
1969:             *            with these operands.
1970:             **/
1971:            final PyObject _basic_add(PyObject o2) {
1972:                PyObject x = __add__(o2);
1973:                if (x != null)
1974:                    return x;
1975:                x = o2.__radd__(this );
1976:                if (x != null)
1977:                    return x;
1978:                throw Py.TypeError(_unsupportedop("+", o2));
1979:            }
1980:
1981:            /**
1982:             * Equivalent to the standard Python __sub__ method
1983:             * @param     other the object to perform this binary operation with
1984:             *            (the right-hand operand).
1985:             * @return    the result of the sub, or null if this operation
1986:             *            is not defined
1987:             **/
1988:            public PyObject __sub__(PyObject other) {
1989:                return null;
1990:            }
1991:
1992:            /**
1993:             * Equivalent to the standard Python __rsub__ method
1994:             * @param     other the object to perform this binary operation with
1995:             *            (the left-hand operand).
1996:             * @return    the result of the sub, or null if this operation
1997:             *            is not defined.
1998:             **/
1999:            public PyObject __rsub__(PyObject other) {
2000:                return null;
2001:            }
2002:
2003:            /**
2004:             * Equivalent to the standard Python __isub__ method
2005:             * @param     other the object to perform this binary operation with
2006:             *            (the right-hand operand).
2007:             * @return    the result of the sub, or null if this operation
2008:             *            is not defined
2009:             **/
2010:            public PyObject __isub__(PyObject other) {
2011:                return _sub(other);
2012:            }
2013:
2014:            /**
2015:             * Implements the Python expression <code>this - o2</code>
2016:             * @param     o2 the object to perform this binary operation with.
2017:             * @return    the result of the sub.
2018:             * @exception Py.TypeError if this operation can't be performed
2019:             *            with these operands.
2020:             **/
2021:            public final PyObject _sub(PyObject o2) {
2022:                PyType t1 = this .getType();
2023:                PyType t2 = o2.getType();
2024:                if (t1 == t2 || t1.builtin && t2.builtin) {
2025:                    return this ._basic_sub(o2);
2026:                }
2027:                return _binop_rule(t1, o2, t2, "__sub__", "__rsub__", "-");
2028:            }
2029:
2030:            /**
2031:             * Implements the Python expression <code>this - o2</code>
2032:             * when this and o2 have the same type or are builtin types.
2033:             * @param     o2 the object to perform this binary operation with.
2034:             * @return    the result of the sub.
2035:             * @exception Py.TypeError if this operation can't be performed
2036:             *            with these operands.
2037:             **/
2038:            final PyObject _basic_sub(PyObject o2) {
2039:                PyObject x = __sub__(o2);
2040:                if (x != null)
2041:                    return x;
2042:                x = o2.__rsub__(this );
2043:                if (x != null)
2044:                    return x;
2045:                throw Py.TypeError(_unsupportedop("-", o2));
2046:            }
2047:
2048:            /**
2049:             * Equivalent to the standard Python __mul__ method
2050:             * @param     other the object to perform this binary operation with
2051:             *            (the right-hand operand).
2052:             * @return    the result of the mul, or null if this operation
2053:             *            is not defined
2054:             **/
2055:            public PyObject __mul__(PyObject other) {
2056:                return null;
2057:            }
2058:
2059:            /**
2060:             * Equivalent to the standard Python __rmul__ method
2061:             * @param     other the object to perform this binary operation with
2062:             *            (the left-hand operand).
2063:             * @return    the result of the mul, or null if this operation
2064:             *            is not defined.
2065:             **/
2066:            public PyObject __rmul__(PyObject other) {
2067:                return null;
2068:            }
2069:
2070:            /**
2071:             * Equivalent to the standard Python __imul__ method
2072:             * @param     other the object to perform this binary operation with
2073:             *            (the right-hand operand).
2074:             * @return    the result of the mul, or null if this operation
2075:             *            is not defined
2076:             **/
2077:            public PyObject __imul__(PyObject other) {
2078:                return _mul(other);
2079:            }
2080:
2081:            /**
2082:             * Implements the Python expression <code>this * o2</code>
2083:             * @param     o2 the object to perform this binary operation with.
2084:             * @return    the result of the mul.
2085:             * @exception Py.TypeError if this operation can't be performed
2086:             *            with these operands.
2087:             **/
2088:            public final PyObject _mul(PyObject o2) {
2089:                PyType t1 = this .getType();
2090:                PyType t2 = o2.getType();
2091:                if (t1 == t2 || t1.builtin && t2.builtin) {
2092:                    return this ._basic_mul(o2);
2093:                }
2094:                return _binop_rule(t1, o2, t2, "__mul__", "__rmul__", "*");
2095:            }
2096:
2097:            /**
2098:             * Implements the Python expression <code>this * o2</code>
2099:             * when this and o2 have the same type or are builtin types.
2100:             * @param     o2 the object to perform this binary operation with.
2101:             * @return    the result of the mul.
2102:             * @exception Py.TypeError if this operation can't be performed
2103:             *            with these operands.
2104:             **/
2105:            final PyObject _basic_mul(PyObject o2) {
2106:                PyObject x = __mul__(o2);
2107:                if (x != null)
2108:                    return x;
2109:                x = o2.__rmul__(this );
2110:                if (x != null)
2111:                    return x;
2112:                throw Py.TypeError(_unsupportedop("*", o2));
2113:            }
2114:
2115:            /**
2116:             * Equivalent to the standard Python __div__ method
2117:             * @param     other the object to perform this binary operation with
2118:             *            (the right-hand operand).
2119:             * @return    the result of the div, or null if this operation
2120:             *            is not defined
2121:             **/
2122:            public PyObject __div__(PyObject other) {
2123:                return null;
2124:            }
2125:
2126:            /**
2127:             * Equivalent to the standard Python __rdiv__ method
2128:             * @param     other the object to perform this binary operation with
2129:             *            (the left-hand operand).
2130:             * @return    the result of the div, or null if this operation
2131:             *            is not defined.
2132:             **/
2133:            public PyObject __rdiv__(PyObject other) {
2134:                return null;
2135:            }
2136:
2137:            /**
2138:             * Equivalent to the standard Python __idiv__ method
2139:             * @param     other the object to perform this binary operation with
2140:             *            (the right-hand operand).
2141:             * @return    the result of the div, or null if this operation
2142:             *            is not defined
2143:             **/
2144:            public PyObject __idiv__(PyObject other) {
2145:                return _div(other);
2146:            }
2147:
2148:            /**
2149:             * Implements the Python expression <code>this / o2</code>
2150:             * @param     o2 the object to perform this binary operation with.
2151:             * @return    the result of the div.
2152:             * @exception Py.TypeError if this operation can't be performed
2153:             *            with these operands.
2154:             **/
2155:            public final PyObject _div(PyObject o2) {
2156:                PyType t1 = this .getType();
2157:                PyType t2 = o2.getType();
2158:                if (t1 == t2 || t1.builtin && t2.builtin) {
2159:                    return this ._basic_div(o2);
2160:                }
2161:                return _binop_rule(t1, o2, t2, "__div__", "__rdiv__", "/");
2162:            }
2163:
2164:            /**
2165:             * Implements the Python expression <code>this / o2</code>
2166:             * when this and o2 have the same type or are builtin types.
2167:             * @param     o2 the object to perform this binary operation with.
2168:             * @return    the result of the div.
2169:             * @exception Py.TypeError if this operation can't be performed
2170:             *            with these operands.
2171:             **/
2172:            final PyObject _basic_div(PyObject o2) {
2173:                if (Options.Qnew)
2174:                    return _truediv(o2);
2175:                PyObject x = __div__(o2);
2176:                if (x != null)
2177:                    return x;
2178:                x = o2.__rdiv__(this );
2179:                if (x != null)
2180:                    return x;
2181:                throw Py.TypeError(_unsupportedop("/", o2));
2182:            }
2183:
2184:            /**
2185:             * Equivalent to the standard Python __floordiv__ method
2186:             * @param     other the object to perform this binary operation with
2187:             *            (the right-hand operand).
2188:             * @return    the result of the floordiv, or null if this operation
2189:             *            is not defined
2190:             **/
2191:            public PyObject __floordiv__(PyObject other) {
2192:                return null;
2193:            }
2194:
2195:            /**
2196:             * Equivalent to the standard Python __rfloordiv__ method
2197:             * @param     other the object to perform this binary operation with
2198:             *            (the left-hand operand).
2199:             * @return    the result of the floordiv, or null if this operation
2200:             *            is not defined.
2201:             **/
2202:            public PyObject __rfloordiv__(PyObject other) {
2203:                return null;
2204:            }
2205:
2206:            /**
2207:             * Equivalent to the standard Python __ifloordiv__ method
2208:             * @param     other the object to perform this binary operation with
2209:             *            (the right-hand operand).
2210:             * @return    the result of the floordiv, or null if this operation
2211:             *            is not defined
2212:             **/
2213:            public PyObject __ifloordiv__(PyObject other) {
2214:                return _floordiv(other);
2215:            }
2216:
2217:            /**
2218:             * Implements the Python expression <code>this // o2</code>
2219:             * @param     o2 the object to perform this binary operation with.
2220:             * @return    the result of the floordiv.
2221:             * @exception Py.TypeError if this operation can't be performed
2222:             *            with these operands.
2223:             **/
2224:            public final PyObject _floordiv(PyObject o2) {
2225:                PyType t1 = this .getType();
2226:                PyType t2 = o2.getType();
2227:                if (t1 == t2 || t1.builtin && t2.builtin) {
2228:                    return this ._basic_floordiv(o2);
2229:                }
2230:                return _binop_rule(t1, o2, t2, "__floordiv__", "__rfloordiv__",
2231:                        "//");
2232:            }
2233:
2234:            /**
2235:             * Implements the Python expression <code>this // o2</code>
2236:             * when this and o2 have the same type or are builtin types.
2237:             * @param     o2 the object to perform this binary operation with.
2238:             * @return    the result of the floordiv.
2239:             * @exception Py.TypeError if this operation can't be performed
2240:             *            with these operands.
2241:             **/
2242:            final PyObject _basic_floordiv(PyObject o2) {
2243:                PyObject x = __floordiv__(o2);
2244:                if (x != null)
2245:                    return x;
2246:                x = o2.__rfloordiv__(this );
2247:                if (x != null)
2248:                    return x;
2249:                throw Py.TypeError(_unsupportedop("//", o2));
2250:            }
2251:
2252:            /**
2253:             * Equivalent to the standard Python __truediv__ method
2254:             * @param     other the object to perform this binary operation with
2255:             *            (the right-hand operand).
2256:             * @return    the result of the truediv, or null if this operation
2257:             *            is not defined
2258:             **/
2259:            public PyObject __truediv__(PyObject other) {
2260:                return null;
2261:            }
2262:
2263:            /**
2264:             * Equivalent to the standard Python __rtruediv__ method
2265:             * @param     other the object to perform this binary operation with
2266:             *            (the left-hand operand).
2267:             * @return    the result of the truediv, or null if this operation
2268:             *            is not defined.
2269:             **/
2270:            public PyObject __rtruediv__(PyObject other) {
2271:                return null;
2272:            }
2273:
2274:            /**
2275:             * Equivalent to the standard Python __itruediv__ method
2276:             * @param     other the object to perform this binary operation with
2277:             *            (the right-hand operand).
2278:             * @return    the result of the truediv, or null if this operation
2279:             *            is not defined
2280:             **/
2281:            public PyObject __itruediv__(PyObject other) {
2282:                return _truediv(other);
2283:            }
2284:
2285:            /**
2286:             * Implements the Python expression <code>this / o2</code>
2287:             * @param     o2 the object to perform this binary operation with.
2288:             * @return    the result of the truediv.
2289:             * @exception Py.TypeError if this operation can't be performed
2290:             *            with these operands.
2291:             **/
2292:            public final PyObject _truediv(PyObject o2) {
2293:                PyType t1 = this .getType();
2294:                PyType t2 = o2.getType();
2295:                if (t1 == t2 || t1.builtin && t2.builtin) {
2296:                    return this ._basic_truediv(o2);
2297:                }
2298:                return _binop_rule(t1, o2, t2, "__truediv__", "__rtruediv__",
2299:                        "/");
2300:            }
2301:
2302:            /**
2303:             * Implements the Python expression <code>this / o2</code>
2304:             * when this and o2 have the same type or are builtin types.
2305:             * @param     o2 the object to perform this binary operation with.
2306:             * @return    the result of the truediv.
2307:             * @exception Py.TypeError if this operation can't be performed
2308:             *            with these operands.
2309:             **/
2310:            final PyObject _basic_truediv(PyObject o2) {
2311:                PyObject x = __truediv__(o2);
2312:                if (x != null)
2313:                    return x;
2314:                x = o2.__rtruediv__(this );
2315:                if (x != null)
2316:                    return x;
2317:                throw Py.TypeError(_unsupportedop("/", o2));
2318:            }
2319:
2320:            /**
2321:             * Equivalent to the standard Python __mod__ method
2322:             * @param     other the object to perform this binary operation with
2323:             *            (the right-hand operand).
2324:             * @return    the result of the mod, or null if this operation
2325:             *            is not defined
2326:             **/
2327:            public PyObject __mod__(PyObject other) {
2328:                return null;
2329:            }
2330:
2331:            /**
2332:             * Equivalent to the standard Python __rmod__ method
2333:             * @param     other the object to perform this binary operation with
2334:             *            (the left-hand operand).
2335:             * @return    the result of the mod, or null if this operation
2336:             *            is not defined.
2337:             **/
2338:            public PyObject __rmod__(PyObject other) {
2339:                return null;
2340:            }
2341:
2342:            /**
2343:             * Equivalent to the standard Python __imod__ method
2344:             * @param     other the object to perform this binary operation with
2345:             *            (the right-hand operand).
2346:             * @return    the result of the mod, or null if this operation
2347:             *            is not defined
2348:             **/
2349:            public PyObject __imod__(PyObject other) {
2350:                return _mod(other);
2351:            }
2352:
2353:            /**
2354:             * Implements the Python expression <code>this % o2</code>
2355:             * @param     o2 the object to perform this binary operation with.
2356:             * @return    the result of the mod.
2357:             * @exception Py.TypeError if this operation can't be performed
2358:             *            with these operands.
2359:             **/
2360:            public final PyObject _mod(PyObject o2) {
2361:                PyType t1 = this .getType();
2362:                PyType t2 = o2.getType();
2363:                if (t1 == t2 || t1.builtin && t2.builtin) {
2364:                    return this ._basic_mod(o2);
2365:                }
2366:                return _binop_rule(t1, o2, t2, "__mod__", "__rmod__", "%");
2367:            }
2368:
2369:            /**
2370:             * Implements the Python expression <code>this % o2</code>
2371:             * when this and o2 have the same type or are builtin types.
2372:             * @param     o2 the object to perform this binary operation with.
2373:             * @return    the result of the mod.
2374:             * @exception Py.TypeError if this operation can't be performed
2375:             *            with these operands.
2376:             **/
2377:            final PyObject _basic_mod(PyObject o2) {
2378:                PyObject x = __mod__(o2);
2379:                if (x != null)
2380:                    return x;
2381:                x = o2.__rmod__(this );
2382:                if (x != null)
2383:                    return x;
2384:                throw Py.TypeError(_unsupportedop("%", o2));
2385:            }
2386:
2387:            /**
2388:             * Equivalent to the standard Python __divmod__ method
2389:             * @param     other the object to perform this binary operation with
2390:             *            (the right-hand operand).
2391:             * @return    the result of the divmod, or null if this operation
2392:             *            is not defined
2393:             **/
2394:            public PyObject __divmod__(PyObject other) {
2395:                return null;
2396:            }
2397:
2398:            /**
2399:             * Equivalent to the standard Python __rdivmod__ method
2400:             * @param     other the object to perform this binary operation with
2401:             *            (the left-hand operand).
2402:             * @return    the result of the divmod, or null if this operation
2403:             *            is not defined.
2404:             **/
2405:            public PyObject __rdivmod__(PyObject other) {
2406:                return null;
2407:            }
2408:
2409:            /**
2410:             * Equivalent to the standard Python __idivmod__ method
2411:             * @param     other the object to perform this binary operation with
2412:             *            (the right-hand operand).
2413:             * @return    the result of the divmod, or null if this operation
2414:             *            is not defined
2415:             **/
2416:            public PyObject __idivmod__(PyObject other) {
2417:                return _divmod(other);
2418:            }
2419:
2420:            /**
2421:             * Implements the Python expression <code>this divmod o2</code>
2422:             * @param     o2 the object to perform this binary operation with.
2423:             * @return    the result of the divmod.
2424:             * @exception Py.TypeError if this operation can't be performed
2425:             *            with these operands.
2426:             **/
2427:            public final PyObject _divmod(PyObject o2) {
2428:                PyType t1 = this .getType();
2429:                PyType t2 = o2.getType();
2430:                if (t1 == t2 || t1.builtin && t2.builtin) {
2431:                    return this ._basic_divmod(o2);
2432:                }
2433:                return _binop_rule(t1, o2, t2, "__divmod__", "__rdivmod__",
2434:                        "divmod");
2435:            }
2436:
2437:            /**
2438:             * Implements the Python expression <code>this divmod o2</code>
2439:             * when this and o2 have the same type or are builtin types.
2440:             * @param     o2 the object to perform this binary operation with.
2441:             * @return    the result of the divmod.
2442:             * @exception Py.TypeError if this operation can't be performed
2443:             *            with these operands.
2444:             **/
2445:            final PyObject _basic_divmod(PyObject o2) {
2446:                PyObject x = __divmod__(o2);
2447:                if (x != null)
2448:                    return x;
2449:                x = o2.__rdivmod__(this );
2450:                if (x != null)
2451:                    return x;
2452:                throw Py.TypeError(_unsupportedop("divmod", o2));
2453:            }
2454:
2455:            /**
2456:             * Equivalent to the standard Python __pow__ method
2457:             * @param     other the object to perform this binary operation with
2458:             *            (the right-hand operand).
2459:             * @return    the result of the pow, or null if this operation
2460:             *            is not defined
2461:             **/
2462:            public PyObject __pow__(PyObject other) {
2463:                return __pow__(other, null);
2464:            }
2465:
2466:            /**
2467:             * Equivalent to the standard Python __rpow__ method
2468:             * @param     other the object to perform this binary operation with
2469:             *            (the left-hand operand).
2470:             * @return    the result of the pow, or null if this operation
2471:             *            is not defined.
2472:             **/
2473:            public PyObject __rpow__(PyObject other) {
2474:                return null;
2475:            }
2476:
2477:            /**
2478:             * Equivalent to the standard Python __ipow__ method
2479:             * @param     other the object to perform this binary operation with
2480:             *            (the right-hand operand).
2481:             * @return    the result of the pow, or null if this operation
2482:             *            is not defined
2483:             **/
2484:            public PyObject __ipow__(PyObject other) {
2485:                return _pow(other);
2486:            }
2487:
2488:            /**
2489:             * Implements the Python expression <code>this ** o2</code>
2490:             * @param     o2 the object to perform this binary operation with.
2491:             * @return    the result of the pow.
2492:             * @exception Py.TypeError if this operation can't be performed
2493:             *            with these operands.
2494:             **/
2495:            public final PyObject _pow(PyObject o2) {
2496:                PyType t1 = this .getType();
2497:                PyType t2 = o2.getType();
2498:                if (t1 == t2 || t1.builtin && t2.builtin) {
2499:                    return this ._basic_pow(o2);
2500:                }
2501:                return _binop_rule(t1, o2, t2, "__pow__", "__rpow__", "**");
2502:            }
2503:
2504:            /**
2505:             * Implements the Python expression <code>this ** o2</code>
2506:             * when this and o2 have the same type or are builtin types.
2507:             * @param     o2 the object to perform this binary operation with.
2508:             * @return    the result of the pow.
2509:             * @exception Py.TypeError if this operation can't be performed
2510:             *            with these operands.
2511:             **/
2512:            final PyObject _basic_pow(PyObject o2) {
2513:                PyObject x = __pow__(o2);
2514:                if (x != null)
2515:                    return x;
2516:                x = o2.__rpow__(this );
2517:                if (x != null)
2518:                    return x;
2519:                throw Py.TypeError(_unsupportedop("**", o2));
2520:            }
2521:
2522:            /**
2523:             * Equivalent to the standard Python __lshift__ method
2524:             * @param     other the object to perform this binary operation with
2525:             *            (the right-hand operand).
2526:             * @return    the result of the lshift, or null if this operation
2527:             *            is not defined
2528:             **/
2529:            public PyObject __lshift__(PyObject other) {
2530:                return null;
2531:            }
2532:
2533:            /**
2534:             * Equivalent to the standard Python __rlshift__ method
2535:             * @param     other the object to perform this binary operation with
2536:             *            (the left-hand operand).
2537:             * @return    the result of the lshift, or null if this operation
2538:             *            is not defined.
2539:             **/
2540:            public PyObject __rlshift__(PyObject other) {
2541:                return null;
2542:            }
2543:
2544:            /**
2545:             * Equivalent to the standard Python __ilshift__ method
2546:             * @param     other the object to perform this binary operation with
2547:             *            (the right-hand operand).
2548:             * @return    the result of the lshift, or null if this operation
2549:             *            is not defined
2550:             **/
2551:            public PyObject __ilshift__(PyObject other) {
2552:                return _lshift(other);
2553:            }
2554:
2555:            /**
2556:             * Implements the Python expression <code>this << o2</code>
2557:             * @param     o2 the object to perform this binary operation with.
2558:             * @return    the result of the lshift.
2559:             * @exception Py.TypeError if this operation can't be performed
2560:             *            with these operands.
2561:             **/
2562:            public final PyObject _lshift(PyObject o2) {
2563:                PyType t1 = this .getType();
2564:                PyType t2 = o2.getType();
2565:                if (t1 == t2 || t1.builtin && t2.builtin) {
2566:                    return this ._basic_lshift(o2);
2567:                }
2568:                return _binop_rule(t1, o2, t2, "__lshift__", "__rlshift__",
2569:                        "<<");
2570:            }
2571:
2572:            /**
2573:             * Implements the Python expression <code>this << o2</code>
2574:             * when this and o2 have the same type or are builtin types.
2575:             * @param     o2 the object to perform this binary operation with.
2576:             * @return    the result of the lshift.
2577:             * @exception Py.TypeError if this operation can't be performed
2578:             *            with these operands.
2579:             **/
2580:            final PyObject _basic_lshift(PyObject o2) {
2581:                PyObject x = __lshift__(o2);
2582:                if (x != null)
2583:                    return x;
2584:                x = o2.__rlshift__(this );
2585:                if (x != null)
2586:                    return x;
2587:                throw Py.TypeError(_unsupportedop("<<", o2));
2588:            }
2589:
2590:            /**
2591:             * Equivalent to the standard Python __rshift__ method
2592:             * @param     other the object to perform this binary operation with
2593:             *            (the right-hand operand).
2594:             * @return    the result of the rshift, or null if this operation
2595:             *            is not defined
2596:             **/
2597:            public PyObject __rshift__(PyObject other) {
2598:                return null;
2599:            }
2600:
2601:            /**
2602:             * Equivalent to the standard Python __rrshift__ method
2603:             * @param     other the object to perform this binary operation with
2604:             *            (the left-hand operand).
2605:             * @return    the result of the rshift, or null if this operation
2606:             *            is not defined.
2607:             **/
2608:            public PyObject __rrshift__(PyObject other) {
2609:                return null;
2610:            }
2611:
2612:            /**
2613:             * Equivalent to the standard Python __irshift__ method
2614:             * @param     other the object to perform this binary operation with
2615:             *            (the right-hand operand).
2616:             * @return    the result of the rshift, or null if this operation
2617:             *            is not defined
2618:             **/
2619:            public PyObject __irshift__(PyObject other) {
2620:                return _rshift(other);
2621:            }
2622:
2623:            /**
2624:             * Implements the Python expression <code>this >> o2</code>
2625:             * @param     o2 the object to perform this binary operation with.
2626:             * @return    the result of the rshift.
2627:             * @exception Py.TypeError if this operation can't be performed
2628:             *            with these operands.
2629:             **/
2630:            public final PyObject _rshift(PyObject o2) {
2631:                PyType t1 = this .getType();
2632:                PyType t2 = o2.getType();
2633:                if (t1 == t2 || t1.builtin && t2.builtin) {
2634:                    return this ._basic_rshift(o2);
2635:                }
2636:                return _binop_rule(t1, o2, t2, "__rshift__", "__rrshift__",
2637:                        ">>");
2638:            }
2639:
2640:            /**
2641:             * Implements the Python expression <code>this >> o2</code>
2642:             * when this and o2 have the same type or are builtin types.
2643:             * @param     o2 the object to perform this binary operation with.
2644:             * @return    the result of the rshift.
2645:             * @exception Py.TypeError if this operation can't be performed
2646:             *            with these operands.
2647:             **/
2648:            final PyObject _basic_rshift(PyObject o2) {
2649:                PyObject x = __rshift__(o2);
2650:                if (x != null)
2651:                    return x;
2652:                x = o2.__rrshift__(this );
2653:                if (x != null)
2654:                    return x;
2655:                throw Py.TypeError(_unsupportedop(">>", o2));
2656:            }
2657:
2658:            /**
2659:             * Equivalent to the standard Python __and__ method
2660:             * @param     other the object to perform this binary operation with
2661:             *            (the right-hand operand).
2662:             * @return    the result of the and, or null if this operation
2663:             *            is not defined
2664:             **/
2665:            public PyObject __and__(PyObject other) {
2666:                return null;
2667:            }
2668:
2669:            /**
2670:             * Equivalent to the standard Python __rand__ method
2671:             * @param     other the object to perform this binary operation with
2672:             *            (the left-hand operand).
2673:             * @return    the result of the and, or null if this operation
2674:             *            is not defined.
2675:             **/
2676:            public PyObject __rand__(PyObject other) {
2677:                return null;
2678:            }
2679:
2680:            /**
2681:             * Equivalent to the standard Python __iand__ method
2682:             * @param     other the object to perform this binary operation with
2683:             *            (the right-hand operand).
2684:             * @return    the result of the and, or null if this operation
2685:             *            is not defined
2686:             **/
2687:            public PyObject __iand__(PyObject other) {
2688:                return _and(other);
2689:            }
2690:
2691:            /**
2692:             * Implements the Python expression <code>this & o2</code>
2693:             * @param     o2 the object to perform this binary operation with.
2694:             * @return    the result of the and.
2695:             * @exception Py.TypeError if this operation can't be performed
2696:             *            with these operands.
2697:             **/
2698:            public final PyObject _and(PyObject o2) {
2699:                PyType t1 = this .getType();
2700:                PyType t2 = o2.getType();
2701:                if (t1 == t2 || t1.builtin && t2.builtin) {
2702:                    return this ._basic_and(o2);
2703:                }
2704:                return _binop_rule(t1, o2, t2, "__and__", "__rand__", "&");
2705:            }
2706:
2707:            /**
2708:             * Implements the Python expression <code>this & o2</code>
2709:             * when this and o2 have the same type or are builtin types.
2710:             * @param     o2 the object to perform this binary operation with.
2711:             * @return    the result of the and.
2712:             * @exception Py.TypeError if this operation can't be performed
2713:             *            with these operands.
2714:             **/
2715:            final PyObject _basic_and(PyObject o2) {
2716:                PyObject x = __and__(o2);
2717:                if (x != null)
2718:                    return x;
2719:                x = o2.__rand__(this );
2720:                if (x != null)
2721:                    return x;
2722:                throw Py.TypeError(_unsupportedop("&", o2));
2723:            }
2724:
2725:            /**
2726:             * Equivalent to the standard Python __or__ method
2727:             * @param     other the object to perform this binary operation with
2728:             *            (the right-hand operand).
2729:             * @return    the result of the or, or null if this operation
2730:             *            is not defined
2731:             **/
2732:            public PyObject __or__(PyObject other) {
2733:                return null;
2734:            }
2735:
2736:            /**
2737:             * Equivalent to the standard Python __ror__ method
2738:             * @param     other the object to perform this binary operation with
2739:             *            (the left-hand operand).
2740:             * @return    the result of the or, or null if this operation
2741:             *            is not defined.
2742:             **/
2743:            public PyObject __ror__(PyObject other) {
2744:                return null;
2745:            }
2746:
2747:            /**
2748:             * Equivalent to the standard Python __ior__ method
2749:             * @param     other the object to perform this binary operation with
2750:             *            (the right-hand operand).
2751:             * @return    the result of the or, or null if this operation
2752:             *            is not defined
2753:             **/
2754:            public PyObject __ior__(PyObject other) {
2755:                return _or(other);
2756:            }
2757:
2758:            /**
2759:             * Implements the Python expression <code>this | o2</code>
2760:             * @param     o2 the object to perform this binary operation with.
2761:             * @return    the result of the or.
2762:             * @exception Py.TypeError if this operation can't be performed
2763:             *            with these operands.
2764:             **/
2765:            public final PyObject _or(PyObject o2) {
2766:                PyType t1 = this .getType();
2767:                PyType t2 = o2.getType();
2768:                if (t1 == t2 || t1.builtin && t2.builtin) {
2769:                    return this ._basic_or(o2);
2770:                }
2771:                return _binop_rule(t1, o2, t2, "__or__", "__ror__", "|");
2772:            }
2773:
2774:            /**
2775:             * Implements the Python expression <code>this | o2</code>
2776:             * when this and o2 have the same type or are builtin types.
2777:             * @param     o2 the object to perform this binary operation with.
2778:             * @return    the result of the or.
2779:             * @exception Py.TypeError if this operation can't be performed
2780:             *            with these operands.
2781:             **/
2782:            final PyObject _basic_or(PyObject o2) {
2783:                PyObject x = __or__(o2);
2784:                if (x != null)
2785:                    return x;
2786:                x = o2.__ror__(this );
2787:                if (x != null)
2788:                    return x;
2789:                throw Py.TypeError(_unsupportedop("|", o2));
2790:            }
2791:
2792:            /**
2793:             * Equivalent to the standard Python __xor__ method
2794:             * @param     other the object to perform this binary operation with
2795:             *            (the right-hand operand).
2796:             * @return    the result of the xor, or null if this operation
2797:             *            is not defined
2798:             **/
2799:            public PyObject __xor__(PyObject other) {
2800:                return null;
2801:            }
2802:
2803:            /**
2804:             * Equivalent to the standard Python __rxor__ method
2805:             * @param     other the object to perform this binary operation with
2806:             *            (the left-hand operand).
2807:             * @return    the result of the xor, or null if this operation
2808:             *            is not defined.
2809:             **/
2810:            public PyObject __rxor__(PyObject other) {
2811:                return null;
2812:            }
2813:
2814:            /**
2815:             * Equivalent to the standard Python __ixor__ method
2816:             * @param     other the object to perform this binary operation with
2817:             *            (the right-hand operand).
2818:             * @return    the result of the xor, or null if this operation
2819:             *            is not defined
2820:             **/
2821:            public PyObject __ixor__(PyObject other) {
2822:                return _xor(other);
2823:            }
2824:
2825:            /**
2826:             * Implements the Python expression <code>this ^ o2</code>
2827:             * @param     o2 the object to perform this binary operation with.
2828:             * @return    the result of the xor.
2829:             * @exception Py.TypeError if this operation can't be performed
2830:             *            with these operands.
2831:             **/
2832:            public final PyObject _xor(PyObject o2) {
2833:                PyType t1 = this .getType();
2834:                PyType t2 = o2.getType();
2835:                if (t1 == t2 || t1.builtin && t2.builtin) {
2836:                    return this ._basic_xor(o2);
2837:                }
2838:                return _binop_rule(t1, o2, t2, "__xor__", "__rxor__", "^");
2839:            }
2840:
2841:            /**
2842:             * Implements the Python expression <code>this ^ o2</code>
2843:             * when this and o2 have the same type or are builtin types.
2844:             * @param     o2 the object to perform this binary operation with.
2845:             * @return    the result of the xor.
2846:             * @exception Py.TypeError if this operation can't be performed
2847:             *            with these operands.
2848:             **/
2849:            final PyObject _basic_xor(PyObject o2) {
2850:                PyObject x = __xor__(o2);
2851:                if (x != null)
2852:                    return x;
2853:                x = o2.__rxor__(this );
2854:                if (x != null)
2855:                    return x;
2856:                throw Py.TypeError(_unsupportedop("^", o2));
2857:            }
2858:
2859:            // Generated by make_binops.py (End)
2860:
2861:            /* A convenience function for PyProxy's */
2862:            // Possibly add _jcall(), _jcall(Object, ...) as future optimization
2863:            /**
2864:             * A convenience function for PyProxy's.
2865:             * @param args call arguments.
2866:             * @exception Throwable
2867:             */
2868:            public PyObject _jcallexc(Object[] args) throws Throwable {
2869:                PyObject[] pargs = new PyObject[args.length];
2870:                try {
2871:                    int n = args.length;
2872:                    for (int i = 0; i < n; i++)
2873:                        pargs[i] = Py.java2py(args[i]);
2874:                    return __call__(pargs);
2875:                } catch (PyException e) {
2876:                    if (e.value instanceof  PyJavaInstance) {
2877:                        Object t = e.value.__tojava__(Throwable.class);
2878:                        if (t != null && t != Py.NoConversion) {
2879:                            throw (Throwable) t;
2880:                        }
2881:                    } else {
2882:                        ThreadState ts = Py.getThreadState();
2883:                        if (ts.frame == null) {
2884:                            Py.maybeSystemExit(e);
2885:                        }
2886:                        if (Options.showPythonProxyExceptions) {
2887:                            Py.stderr
2888:                                    .println("Exception in Python proxy returning to Java:");
2889:                            Py.printException(e);
2890:                        }
2891:                    }
2892:                    throw e;
2893:                }
2894:            }
2895:
2896:            public void _jthrow(Throwable t) {
2897:                if (t instanceof  RuntimeException)
2898:                    throw (RuntimeException) t;
2899:                if (t instanceof  Error)
2900:                    throw (Error) t;
2901:                throw Py.JavaError(t);
2902:            }
2903:
2904:            public PyObject _jcall(Object[] args) {
2905:                try {
2906:                    return _jcallexc(args);
2907:                } catch (Throwable t) {
2908:                    _jthrow(t);
2909:                    return null;
2910:                }
2911:            }
2912:
2913:            /* Shortcut methods for calling methods from Java */
2914:
2915:            /**
2916:             * Shortcut for calling a method on a PyObject from Java.
2917:             * This form is equivalent to o.__getattr__(name).__call__(args, keywords)
2918:             *
2919:             * @param name the name of the method to call.  This must be an
2920:             *             interned string!
2921:             * @param args an array of the arguments to the call.
2922:             * @param keywords the keywords to use in the call.
2923:             * @return the result of calling the method name with args and keywords.
2924:             **/
2925:            public PyObject invoke(String name, PyObject[] args,
2926:                    String[] keywords) {
2927:                PyObject f = __getattr__(name);
2928:                return f.__call__(args, keywords);
2929:            }
2930:
2931:            public PyObject invoke(String name, PyObject[] args) {
2932:                PyObject f = __getattr__(name);
2933:                return f.__call__(args);
2934:            }
2935:
2936:            /**
2937:             * Shortcut for calling a method on a PyObject with no args.
2938:             *
2939:             * @param name the name of the method to call.  This must be an
2940:             * interned string!
2941:             * @return the result of calling the method name with no args
2942:             **/
2943:            public PyObject invoke(String name) {
2944:                PyObject f = __getattr__(name);
2945:                return f.__call__();
2946:            }
2947:
2948:            /**
2949:             * Shortcut for calling a method on a PyObject with one arg.
2950:             *
2951:             * @param name the name of the method to call.  This must be an
2952:             * interned string!
2953:             * @param arg1 the one argument of the method.
2954:             * @return the result of calling the method name with arg1
2955:             **/
2956:            public PyObject invoke(String name, PyObject arg1) {
2957:                PyObject f = __getattr__(name);
2958:                return f.__call__(arg1);
2959:            }
2960:
2961:            /**
2962:             * Shortcut for calling a method on a PyObject with two args.
2963:             *
2964:             * @param name the name of the method to call.  This must be an
2965:             *        interned string!
2966:             * @param arg1 the first argument of the method.
2967:             * @param arg2 the second argument of the method.
2968:             * @return the result of calling the method name with arg1 and arg2
2969:             **/
2970:            public PyObject invoke(String name, PyObject arg1, PyObject arg2) {
2971:                PyObject f = __getattr__(name);
2972:                return f.__call__(arg1, arg2);
2973:            }
2974:
2975:            /* descriptors and lookup protocols */
2976:
2977:            /** xxx implements where meaningful
2978:             * @return internal object per instance dict or null
2979:             */
2980:            public PyObject fastGetDict() {
2981:                return null;
2982:            }
2983:
2984:            /** xxx implements where meaningful
2985:             * @return internal object __dict__ or null
2986:             */
2987:            public PyObject getDict() {
2988:                return null;
2989:            }
2990:
2991:            public void setDict(PyObject newDict) {
2992:                // fallback if setDict not implemented in subclass
2993:                throw Py
2994:                        .TypeError("can't set attribute '__dict__' of instance of "
2995:                                + getType().safeRepr());
2996:            }
2997:
2998:            public void delDict() {
2999:                // fallback to error
3000:                throw Py
3001:                        .TypeError("can't delete attribute '__dict__' of instance of '"
3002:                                + getType().safeRepr() + "'");
3003:            }
3004:
3005:            public boolean implements DescrSet() {
3006:                return objtype.has_set;
3007:            }
3008:
3009:            public boolean implements DescrDelete() {
3010:                return objtype.has_delete;
3011:            }
3012:
3013:            public boolean isDataDescr() { // implements either __set__ or __delete__
3014:                return objtype.has_set || objtype.has_delete;
3015:            }
3016:
3017:            // doc & xxx ok this way?
3018:            // can return null meaning set-only or throw exception
3019:
3020:            // backward comp impls.
3021:            public PyObject __get__(PyObject obj, PyObject type) {
3022:                return _doget(obj, type);
3023:            }
3024:
3025:            public void __set__(PyObject obj, PyObject value) {
3026:                throw Py
3027:                        .AttributeError("object internal __set__ impl is abstract");
3028:            }
3029:
3030:            public void __delete__(PyObject obj) {
3031:                throw Py
3032:                        .AttributeError("object internal __delete__ impl is abstract");
3033:            }
3034:
3035:            // name must be interned
3036:            final PyObject object___findattr__(String name) {
3037:
3038:                PyObject descr = objtype.lookup(name);
3039:                PyObject res;
3040:
3041:                if (descr != null) {
3042:                    if (descr.isDataDescr()) {
3043:                        res = descr.__get__(this , objtype);
3044:                        if (res != null)
3045:                            return res;
3046:                    }
3047:                }
3048:
3049:                PyObject obj_dict = fastGetDict();
3050:                if (obj_dict != null) {
3051:                    res = obj_dict.__finditem__(name);
3052:                    if (res != null)
3053:                        return res;
3054:                }
3055:
3056:                if (descr != null) {
3057:                    return descr.__get__(this , objtype);
3058:                }
3059:
3060:                return null;
3061:            }
3062:
3063:            final void object___setattr__(String name, PyObject value) {
3064:                PyObject descr = objtype.lookup(name);
3065:
3066:                boolean set = false;
3067:
3068:                if (descr != null) {
3069:                    set = descr.implements DescrSet();
3070:                    if (set && descr.isDataDescr()) {
3071:                        descr.__set__(this , value);
3072:                        return;
3073:                    }
3074:                }
3075:
3076:                PyObject obj_dict = fastGetDict();
3077:                if (obj_dict != null) {
3078:                    obj_dict.__setitem__(name, value);
3079:                    return;
3080:                }
3081:
3082:                if (set) {
3083:                    descr.__set__(this , value);
3084:                }
3085:
3086:                if (descr != null) {
3087:                    readonlyAttributeError(name);
3088:                }
3089:
3090:                noAttributeError(name);
3091:            }
3092:
3093:            final void object___delattr__(String name) {
3094:                PyObject descr = objtype.lookup(name);
3095:
3096:                boolean delete = false;
3097:
3098:                if (descr != null) {
3099:                    delete = descr.implements DescrDelete();
3100:                    if (delete && descr.isDataDescr()) {
3101:                        descr.__delete__(this );
3102:                        return;
3103:                    }
3104:                }
3105:
3106:                PyObject obj_dict = fastGetDict();
3107:                if (obj_dict != null) {
3108:                    try {
3109:                        obj_dict.__delitem__(name);
3110:                    } catch (PyException exc) {
3111:                        if (Py.matchException(exc, Py.KeyError))
3112:                            noAttributeError(name);
3113:                        else
3114:                            throw exc;
3115:                    }
3116:                    return;
3117:                }
3118:
3119:                if (delete) {
3120:                    descr.__delete__(this );
3121:                }
3122:
3123:                if (descr != null) {
3124:                    readonlyAttributeError(name);
3125:                }
3126:
3127:                noAttributeError(name);
3128:            }
3129:
3130:            /**
3131:             * Used for pickling.
3132:             *
3133:             * @return a tuple of (class, tuple)
3134:             */
3135:            public PyObject __reduce__() {
3136:                return object___reduce__();
3137:            }
3138:
3139:            final PyObject object___reduce__() {
3140:                PyTuple newargs = __getnewargs__();
3141:                return new PyTuple(new PyObject[] { getType(), newargs });
3142:            }
3143:
3144:            public PyTuple __getnewargs__() {
3145:                //default is empty tuple
3146:                return new PyTuple();
3147:            }
3148:
3149:            /* arguments' conversion helpers */
3150:
3151:            public static class ConversionException extends Exception {
3152:
3153:                public int index;
3154:
3155:                public ConversionException(int index) {
3156:                    this .index = index;
3157:                }
3158:
3159:            }
3160:
3161:            public String asString(int index) throws ConversionException {
3162:                throw new ConversionException(index);
3163:            }
3164:
3165:            public String asStringOrNull(int index) throws ConversionException {
3166:                return asString(index);
3167:            }
3168:
3169:            public String asName(int index) throws ConversionException {
3170:                throw new ConversionException(index);
3171:            }
3172:
3173:            public int asInt(int index) throws ConversionException {
3174:                throw new ConversionException(index);
3175:            }
3176:
3177:            public long asLong(int index) throws ConversionException {
3178:                throw new ConversionException(index);
3179:            }
3180:
3181:        }
3182:
3183:        /*
3184:         * A very specialized tuple-like class used when detecting cycles during
3185:         * object comparisons. This classes is different from an normal tuple
3186:         * by hashing and comparing its elements by identity.
3187:         */
3188:
3189:        class PyIdentityTuple extends PyObject {
3190:
3191:            PyObject[] list;
3192:
3193:            public PyIdentityTuple(PyObject elements[]) {
3194:                list = elements;
3195:            }
3196:
3197:            public int hashCode() {
3198:                int x, y;
3199:                int len = list.length;
3200:                x = 0x345678;
3201:
3202:                for (len--; len >= 0; len--) {
3203:                    y = System.identityHashCode(list[len]);
3204:                    x = (x + x + x) ^ y;
3205:                }
3206:                x ^= list.length;
3207:                return x;
3208:            }
3209:
3210:            public boolean equals(Object o) {
3211:                if (!(o instanceof  PyIdentityTuple))
3212:                    return false;
3213:                PyIdentityTuple that = (PyIdentityTuple) o;
3214:                if (list.length != that.list.length)
3215:                    return false;
3216:                for (int i = 0; i < list.length; i++) {
3217:                    if (list[i] != that.list[i])
3218:                        return false;
3219:                }
3220:                return true;
3221:            }
3222:
3223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.