0001: package org.python.core;
0002:
0003: public class PyTupleDerived extends PyTuple implements Slotted {
0004:
0005: public PyObject getSlot(int index) {
0006: return slots[index];
0007: }
0008:
0009: public void setSlot(int index, PyObject value) {
0010: slots[index] = value;
0011: }
0012:
0013: private PyObject[] slots;
0014:
0015: private PyObject dict;
0016:
0017: public PyObject fastGetDict() {
0018: return dict;
0019: }
0020:
0021: public PyObject getDict() {
0022: return dict;
0023: }
0024:
0025: public void setDict(PyObject newDict) {
0026: if (newDict instanceof PyStringMap
0027: || newDict instanceof PyDictionary) {
0028: dict = newDict;
0029: } else {
0030: throw Py.TypeError("__dict__ must be set to a Dictionary "
0031: + newDict.getClass().getName());
0032: }
0033: }
0034:
0035: public void delDict() {
0036: // deleting an object's instance dict makes it grow a new one
0037: dict = new PyStringMap();
0038: }
0039:
0040: public PyTupleDerived(PyType subtype, PyObject[] elements) {
0041: super (subtype, elements);
0042: slots = new PyObject[subtype.getNumSlots()];
0043: dict = subtype.instDict();
0044: }
0045:
0046: public PyString __str__() {
0047: PyType self_type = getType();
0048: PyObject impl = self_type.lookup("__str__");
0049: if (impl != null) {
0050: PyObject res = impl.__get__(this , self_type).__call__();
0051: if (res instanceof PyString)
0052: return (PyString) res;
0053: throw Py.TypeError("__str__" + " should return a "
0054: + "string");
0055: }
0056: return super .__str__();
0057: }
0058:
0059: public PyString __repr__() {
0060: PyType self_type = getType();
0061: PyObject impl = self_type.lookup("__repr__");
0062: if (impl != null) {
0063: PyObject res = impl.__get__(this , self_type).__call__();
0064: if (res instanceof PyString)
0065: return (PyString) res;
0066: throw Py.TypeError("__repr__" + " should return a "
0067: + "string");
0068: }
0069: return super .__repr__();
0070: }
0071:
0072: public PyString __hex__() {
0073: PyType self_type = getType();
0074: PyObject impl = self_type.lookup("__hex__");
0075: if (impl != null) {
0076: PyObject res = impl.__get__(this , self_type).__call__();
0077: if (res instanceof PyString)
0078: return (PyString) res;
0079: throw Py.TypeError("__hex__" + " should return a "
0080: + "string");
0081: }
0082: return super .__hex__();
0083: }
0084:
0085: public PyString __oct__() {
0086: PyType self_type = getType();
0087: PyObject impl = self_type.lookup("__oct__");
0088: if (impl != null) {
0089: PyObject res = impl.__get__(this , self_type).__call__();
0090: if (res instanceof PyString)
0091: return (PyString) res;
0092: throw Py.TypeError("__oct__" + " should return a "
0093: + "string");
0094: }
0095: return super .__oct__();
0096: }
0097:
0098: public PyFloat __float__() {
0099: PyType self_type = getType();
0100: PyObject impl = self_type.lookup("__float__");
0101: if (impl != null) {
0102: PyObject res = impl.__get__(this , self_type).__call__();
0103: if (res instanceof PyFloat)
0104: return (PyFloat) res;
0105: throw Py.TypeError("__float__" + " should return a "
0106: + "float");
0107: }
0108: return super .__float__();
0109: }
0110:
0111: public PyLong __long__() {
0112: PyType self_type = getType();
0113: PyObject impl = self_type.lookup("__long__");
0114: if (impl != null) {
0115: PyObject res = impl.__get__(this , self_type).__call__();
0116: if (res instanceof PyLong)
0117: return (PyLong) res;
0118: throw Py.TypeError("__long__" + " should return a "
0119: + "long");
0120: }
0121: return super .__long__();
0122: }
0123:
0124: public PyComplex __complex__() {
0125: PyType self_type = getType();
0126: PyObject impl = self_type.lookup("__complex__");
0127: if (impl != null) {
0128: PyObject res = impl.__get__(this , self_type).__call__();
0129: if (res instanceof PyComplex)
0130: return (PyComplex) res;
0131: throw Py.TypeError("__complex__" + " should return a "
0132: + "complex");
0133: }
0134: return super .__complex__();
0135: }
0136:
0137: public PyObject __pos__() {
0138: PyType self_type = getType();
0139: PyObject impl = self_type.lookup("__pos__");
0140: if (impl != null)
0141: return impl.__get__(this , self_type).__call__();
0142: return super .__pos__();
0143: }
0144:
0145: public PyObject __neg__() {
0146: PyType self_type = getType();
0147: PyObject impl = self_type.lookup("__neg__");
0148: if (impl != null)
0149: return impl.__get__(this , self_type).__call__();
0150: return super .__neg__();
0151: }
0152:
0153: public PyObject __abs__() {
0154: PyType self_type = getType();
0155: PyObject impl = self_type.lookup("__abs__");
0156: if (impl != null)
0157: return impl.__get__(this , self_type).__call__();
0158: return super .__abs__();
0159: }
0160:
0161: public PyObject __invert__() {
0162: PyType self_type = getType();
0163: PyObject impl = self_type.lookup("__invert__");
0164: if (impl != null)
0165: return impl.__get__(this , self_type).__call__();
0166: return super .__invert__();
0167: }
0168:
0169: public PyObject __reduce__() {
0170: PyType self_type = getType();
0171: PyObject impl = self_type.lookup("__reduce__");
0172: if (impl != null)
0173: return impl.__get__(this , self_type).__call__();
0174: return super .__reduce__();
0175: }
0176:
0177: public PyObject __add__(PyObject other) {
0178: PyType self_type = getType();
0179: PyObject impl = self_type.lookup("__add__");
0180: if (impl != null) {
0181: PyObject res = impl.__get__(this , self_type)
0182: .__call__(other);
0183: if (res == Py.NotImplemented)
0184: return null;
0185: return res;
0186: }
0187: return super .__add__(other);
0188: }
0189:
0190: public PyObject __radd__(PyObject other) {
0191: PyType self_type = getType();
0192: PyObject impl = self_type.lookup("__radd__");
0193: if (impl != null) {
0194: PyObject res = impl.__get__(this , self_type)
0195: .__call__(other);
0196: if (res == Py.NotImplemented)
0197: return null;
0198: return res;
0199: }
0200: return super .__radd__(other);
0201: }
0202:
0203: public PyObject __sub__(PyObject other) {
0204: PyType self_type = getType();
0205: PyObject impl = self_type.lookup("__sub__");
0206: if (impl != null) {
0207: PyObject res = impl.__get__(this , self_type)
0208: .__call__(other);
0209: if (res == Py.NotImplemented)
0210: return null;
0211: return res;
0212: }
0213: return super .__sub__(other);
0214: }
0215:
0216: public PyObject __rsub__(PyObject other) {
0217: PyType self_type = getType();
0218: PyObject impl = self_type.lookup("__rsub__");
0219: if (impl != null) {
0220: PyObject res = impl.__get__(this , self_type)
0221: .__call__(other);
0222: if (res == Py.NotImplemented)
0223: return null;
0224: return res;
0225: }
0226: return super .__rsub__(other);
0227: }
0228:
0229: public PyObject __mul__(PyObject other) {
0230: PyType self_type = getType();
0231: PyObject impl = self_type.lookup("__mul__");
0232: if (impl != null) {
0233: PyObject res = impl.__get__(this , self_type)
0234: .__call__(other);
0235: if (res == Py.NotImplemented)
0236: return null;
0237: return res;
0238: }
0239: return super .__mul__(other);
0240: }
0241:
0242: public PyObject __rmul__(PyObject other) {
0243: PyType self_type = getType();
0244: PyObject impl = self_type.lookup("__rmul__");
0245: if (impl != null) {
0246: PyObject res = impl.__get__(this , self_type)
0247: .__call__(other);
0248: if (res == Py.NotImplemented)
0249: return null;
0250: return res;
0251: }
0252: return super .__rmul__(other);
0253: }
0254:
0255: public PyObject __div__(PyObject other) {
0256: PyType self_type = getType();
0257: PyObject impl = self_type.lookup("__div__");
0258: if (impl != null) {
0259: PyObject res = impl.__get__(this , self_type)
0260: .__call__(other);
0261: if (res == Py.NotImplemented)
0262: return null;
0263: return res;
0264: }
0265: return super .__div__(other);
0266: }
0267:
0268: public PyObject __rdiv__(PyObject other) {
0269: PyType self_type = getType();
0270: PyObject impl = self_type.lookup("__rdiv__");
0271: if (impl != null) {
0272: PyObject res = impl.__get__(this , self_type)
0273: .__call__(other);
0274: if (res == Py.NotImplemented)
0275: return null;
0276: return res;
0277: }
0278: return super .__rdiv__(other);
0279: }
0280:
0281: public PyObject __floordiv__(PyObject other) {
0282: PyType self_type = getType();
0283: PyObject impl = self_type.lookup("__floordiv__");
0284: if (impl != null) {
0285: PyObject res = impl.__get__(this , self_type)
0286: .__call__(other);
0287: if (res == Py.NotImplemented)
0288: return null;
0289: return res;
0290: }
0291: return super .__floordiv__(other);
0292: }
0293:
0294: public PyObject __rfloordiv__(PyObject other) {
0295: PyType self_type = getType();
0296: PyObject impl = self_type.lookup("__rfloordiv__");
0297: if (impl != null) {
0298: PyObject res = impl.__get__(this , self_type)
0299: .__call__(other);
0300: if (res == Py.NotImplemented)
0301: return null;
0302: return res;
0303: }
0304: return super .__rfloordiv__(other);
0305: }
0306:
0307: public PyObject __truediv__(PyObject other) {
0308: PyType self_type = getType();
0309: PyObject impl = self_type.lookup("__truediv__");
0310: if (impl != null) {
0311: PyObject res = impl.__get__(this , self_type)
0312: .__call__(other);
0313: if (res == Py.NotImplemented)
0314: return null;
0315: return res;
0316: }
0317: return super .__truediv__(other);
0318: }
0319:
0320: public PyObject __rtruediv__(PyObject other) {
0321: PyType self_type = getType();
0322: PyObject impl = self_type.lookup("__rtruediv__");
0323: if (impl != null) {
0324: PyObject res = impl.__get__(this , self_type)
0325: .__call__(other);
0326: if (res == Py.NotImplemented)
0327: return null;
0328: return res;
0329: }
0330: return super .__rtruediv__(other);
0331: }
0332:
0333: public PyObject __mod__(PyObject other) {
0334: PyType self_type = getType();
0335: PyObject impl = self_type.lookup("__mod__");
0336: if (impl != null) {
0337: PyObject res = impl.__get__(this , self_type)
0338: .__call__(other);
0339: if (res == Py.NotImplemented)
0340: return null;
0341: return res;
0342: }
0343: return super .__mod__(other);
0344: }
0345:
0346: public PyObject __rmod__(PyObject other) {
0347: PyType self_type = getType();
0348: PyObject impl = self_type.lookup("__rmod__");
0349: if (impl != null) {
0350: PyObject res = impl.__get__(this , self_type)
0351: .__call__(other);
0352: if (res == Py.NotImplemented)
0353: return null;
0354: return res;
0355: }
0356: return super .__rmod__(other);
0357: }
0358:
0359: public PyObject __divmod__(PyObject other) {
0360: PyType self_type = getType();
0361: PyObject impl = self_type.lookup("__divmod__");
0362: if (impl != null) {
0363: PyObject res = impl.__get__(this , self_type)
0364: .__call__(other);
0365: if (res == Py.NotImplemented)
0366: return null;
0367: return res;
0368: }
0369: return super .__divmod__(other);
0370: }
0371:
0372: public PyObject __rdivmod__(PyObject other) {
0373: PyType self_type = getType();
0374: PyObject impl = self_type.lookup("__rdivmod__");
0375: if (impl != null) {
0376: PyObject res = impl.__get__(this , self_type)
0377: .__call__(other);
0378: if (res == Py.NotImplemented)
0379: return null;
0380: return res;
0381: }
0382: return super .__rdivmod__(other);
0383: }
0384:
0385: public PyObject __pow__(PyObject other) {
0386: PyType self_type = getType();
0387: PyObject impl = self_type.lookup("__pow__");
0388: if (impl != null) {
0389: PyObject res = impl.__get__(this , self_type)
0390: .__call__(other);
0391: if (res == Py.NotImplemented)
0392: return null;
0393: return res;
0394: }
0395: return super .__pow__(other);
0396: }
0397:
0398: public PyObject __rpow__(PyObject other) {
0399: PyType self_type = getType();
0400: PyObject impl = self_type.lookup("__rpow__");
0401: if (impl != null) {
0402: PyObject res = impl.__get__(this , self_type)
0403: .__call__(other);
0404: if (res == Py.NotImplemented)
0405: return null;
0406: return res;
0407: }
0408: return super .__rpow__(other);
0409: }
0410:
0411: public PyObject __lshift__(PyObject other) {
0412: PyType self_type = getType();
0413: PyObject impl = self_type.lookup("__lshift__");
0414: if (impl != null) {
0415: PyObject res = impl.__get__(this , self_type)
0416: .__call__(other);
0417: if (res == Py.NotImplemented)
0418: return null;
0419: return res;
0420: }
0421: return super .__lshift__(other);
0422: }
0423:
0424: public PyObject __rlshift__(PyObject other) {
0425: PyType self_type = getType();
0426: PyObject impl = self_type.lookup("__rlshift__");
0427: if (impl != null) {
0428: PyObject res = impl.__get__(this , self_type)
0429: .__call__(other);
0430: if (res == Py.NotImplemented)
0431: return null;
0432: return res;
0433: }
0434: return super .__rlshift__(other);
0435: }
0436:
0437: public PyObject __rshift__(PyObject other) {
0438: PyType self_type = getType();
0439: PyObject impl = self_type.lookup("__rshift__");
0440: if (impl != null) {
0441: PyObject res = impl.__get__(this , self_type)
0442: .__call__(other);
0443: if (res == Py.NotImplemented)
0444: return null;
0445: return res;
0446: }
0447: return super .__rshift__(other);
0448: }
0449:
0450: public PyObject __rrshift__(PyObject other) {
0451: PyType self_type = getType();
0452: PyObject impl = self_type.lookup("__rrshift__");
0453: if (impl != null) {
0454: PyObject res = impl.__get__(this , self_type)
0455: .__call__(other);
0456: if (res == Py.NotImplemented)
0457: return null;
0458: return res;
0459: }
0460: return super .__rrshift__(other);
0461: }
0462:
0463: public PyObject __and__(PyObject other) {
0464: PyType self_type = getType();
0465: PyObject impl = self_type.lookup("__and__");
0466: if (impl != null) {
0467: PyObject res = impl.__get__(this , self_type)
0468: .__call__(other);
0469: if (res == Py.NotImplemented)
0470: return null;
0471: return res;
0472: }
0473: return super .__and__(other);
0474: }
0475:
0476: public PyObject __rand__(PyObject other) {
0477: PyType self_type = getType();
0478: PyObject impl = self_type.lookup("__rand__");
0479: if (impl != null) {
0480: PyObject res = impl.__get__(this , self_type)
0481: .__call__(other);
0482: if (res == Py.NotImplemented)
0483: return null;
0484: return res;
0485: }
0486: return super .__rand__(other);
0487: }
0488:
0489: public PyObject __or__(PyObject other) {
0490: PyType self_type = getType();
0491: PyObject impl = self_type.lookup("__or__");
0492: if (impl != null) {
0493: PyObject res = impl.__get__(this , self_type)
0494: .__call__(other);
0495: if (res == Py.NotImplemented)
0496: return null;
0497: return res;
0498: }
0499: return super .__or__(other);
0500: }
0501:
0502: public PyObject __ror__(PyObject other) {
0503: PyType self_type = getType();
0504: PyObject impl = self_type.lookup("__ror__");
0505: if (impl != null) {
0506: PyObject res = impl.__get__(this , self_type)
0507: .__call__(other);
0508: if (res == Py.NotImplemented)
0509: return null;
0510: return res;
0511: }
0512: return super .__ror__(other);
0513: }
0514:
0515: public PyObject __xor__(PyObject other) {
0516: PyType self_type = getType();
0517: PyObject impl = self_type.lookup("__xor__");
0518: if (impl != null) {
0519: PyObject res = impl.__get__(this , self_type)
0520: .__call__(other);
0521: if (res == Py.NotImplemented)
0522: return null;
0523: return res;
0524: }
0525: return super .__xor__(other);
0526: }
0527:
0528: public PyObject __rxor__(PyObject other) {
0529: PyType self_type = getType();
0530: PyObject impl = self_type.lookup("__rxor__");
0531: if (impl != null) {
0532: PyObject res = impl.__get__(this , self_type)
0533: .__call__(other);
0534: if (res == Py.NotImplemented)
0535: return null;
0536: return res;
0537: }
0538: return super .__rxor__(other);
0539: }
0540:
0541: public PyObject __lt__(PyObject other) {
0542: PyType self_type = getType();
0543: PyObject impl = self_type.lookup("__lt__");
0544: if (impl != null) {
0545: PyObject res = impl.__get__(this , self_type)
0546: .__call__(other);
0547: if (res == Py.NotImplemented)
0548: return null;
0549: return res;
0550: }
0551: return super .__lt__(other);
0552: }
0553:
0554: public PyObject __le__(PyObject other) {
0555: PyType self_type = getType();
0556: PyObject impl = self_type.lookup("__le__");
0557: if (impl != null) {
0558: PyObject res = impl.__get__(this , self_type)
0559: .__call__(other);
0560: if (res == Py.NotImplemented)
0561: return null;
0562: return res;
0563: }
0564: return super .__le__(other);
0565: }
0566:
0567: public PyObject __gt__(PyObject other) {
0568: PyType self_type = getType();
0569: PyObject impl = self_type.lookup("__gt__");
0570: if (impl != null) {
0571: PyObject res = impl.__get__(this , self_type)
0572: .__call__(other);
0573: if (res == Py.NotImplemented)
0574: return null;
0575: return res;
0576: }
0577: return super .__gt__(other);
0578: }
0579:
0580: public PyObject __ge__(PyObject other) {
0581: PyType self_type = getType();
0582: PyObject impl = self_type.lookup("__ge__");
0583: if (impl != null) {
0584: PyObject res = impl.__get__(this , self_type)
0585: .__call__(other);
0586: if (res == Py.NotImplemented)
0587: return null;
0588: return res;
0589: }
0590: return super .__ge__(other);
0591: }
0592:
0593: public PyObject __eq__(PyObject other) {
0594: PyType self_type = getType();
0595: PyObject impl = self_type.lookup("__eq__");
0596: if (impl != null) {
0597: PyObject res = impl.__get__(this , self_type)
0598: .__call__(other);
0599: if (res == Py.NotImplemented)
0600: return null;
0601: return res;
0602: }
0603: return super .__eq__(other);
0604: }
0605:
0606: public PyObject __ne__(PyObject other) {
0607: PyType self_type = getType();
0608: PyObject impl = self_type.lookup("__ne__");
0609: if (impl != null) {
0610: PyObject res = impl.__get__(this , self_type)
0611: .__call__(other);
0612: if (res == Py.NotImplemented)
0613: return null;
0614: return res;
0615: }
0616: return super .__ne__(other);
0617: }
0618:
0619: public PyObject __iadd__(PyObject other) {
0620: PyType self_type = getType();
0621: PyObject impl = self_type.lookup("__iadd__");
0622: if (impl != null)
0623: return impl.__get__(this , self_type).__call__(other);
0624: return super .__iadd__(other);
0625: }
0626:
0627: public PyObject __isub__(PyObject other) {
0628: PyType self_type = getType();
0629: PyObject impl = self_type.lookup("__isub__");
0630: if (impl != null)
0631: return impl.__get__(this , self_type).__call__(other);
0632: return super .__isub__(other);
0633: }
0634:
0635: public PyObject __imul__(PyObject other) {
0636: PyType self_type = getType();
0637: PyObject impl = self_type.lookup("__imul__");
0638: if (impl != null)
0639: return impl.__get__(this , self_type).__call__(other);
0640: return super .__imul__(other);
0641: }
0642:
0643: public PyObject __idiv__(PyObject other) {
0644: PyType self_type = getType();
0645: PyObject impl = self_type.lookup("__idiv__");
0646: if (impl != null)
0647: return impl.__get__(this , self_type).__call__(other);
0648: return super .__idiv__(other);
0649: }
0650:
0651: public PyObject __ifloordiv__(PyObject other) {
0652: PyType self_type = getType();
0653: PyObject impl = self_type.lookup("__ifloordiv__");
0654: if (impl != null)
0655: return impl.__get__(this , self_type).__call__(other);
0656: return super .__ifloordiv__(other);
0657: }
0658:
0659: public PyObject __itruediv__(PyObject other) {
0660: PyType self_type = getType();
0661: PyObject impl = self_type.lookup("__itruediv__");
0662: if (impl != null)
0663: return impl.__get__(this , self_type).__call__(other);
0664: return super .__itruediv__(other);
0665: }
0666:
0667: public PyObject __imod__(PyObject other) {
0668: PyType self_type = getType();
0669: PyObject impl = self_type.lookup("__imod__");
0670: if (impl != null)
0671: return impl.__get__(this , self_type).__call__(other);
0672: return super .__imod__(other);
0673: }
0674:
0675: public PyObject __ipow__(PyObject other) {
0676: PyType self_type = getType();
0677: PyObject impl = self_type.lookup("__ipow__");
0678: if (impl != null)
0679: return impl.__get__(this , self_type).__call__(other);
0680: return super .__ipow__(other);
0681: }
0682:
0683: public PyObject __ilshift__(PyObject other) {
0684: PyType self_type = getType();
0685: PyObject impl = self_type.lookup("__ilshift__");
0686: if (impl != null)
0687: return impl.__get__(this , self_type).__call__(other);
0688: return super .__ilshift__(other);
0689: }
0690:
0691: public PyObject __irshift__(PyObject other) {
0692: PyType self_type = getType();
0693: PyObject impl = self_type.lookup("__irshift__");
0694: if (impl != null)
0695: return impl.__get__(this , self_type).__call__(other);
0696: return super .__irshift__(other);
0697: }
0698:
0699: public PyObject __iand__(PyObject other) {
0700: PyType self_type = getType();
0701: PyObject impl = self_type.lookup("__iand__");
0702: if (impl != null)
0703: return impl.__get__(this , self_type).__call__(other);
0704: return super .__iand__(other);
0705: }
0706:
0707: public PyObject __ior__(PyObject other) {
0708: PyType self_type = getType();
0709: PyObject impl = self_type.lookup("__ior__");
0710: if (impl != null)
0711: return impl.__get__(this , self_type).__call__(other);
0712: return super .__ior__(other);
0713: }
0714:
0715: public PyObject __ixor__(PyObject other) {
0716: PyType self_type = getType();
0717: PyObject impl = self_type.lookup("__ixor__");
0718: if (impl != null)
0719: return impl.__get__(this , self_type).__call__(other);
0720: return super .__ixor__(other);
0721: }
0722:
0723: public PyObject __int__() {
0724: PyType self_type = getType();
0725: PyObject impl = self_type.lookup("__int__");
0726: if (impl != null) {
0727: PyObject res = impl.__get__(this , self_type).__call__();
0728: if (res instanceof PyInteger || res instanceof PyLong)
0729: return (PyObject) res;
0730: throw Py.TypeError("__int__" + " should return an integer");
0731: }
0732: return super .__int__();
0733: }
0734:
0735: public String toString() {
0736: PyType self_type = getType();
0737: PyObject impl = self_type.lookup("__repr__");
0738: if (impl != null) {
0739: PyObject res = impl.__get__(this , self_type).__call__();
0740: if (!(res instanceof PyString))
0741: throw Py.TypeError("__repr__ should return a string");
0742: return ((PyString) res).toString();
0743: }
0744: return super .toString();
0745: }
0746:
0747: public int hashCode() {
0748: PyType self_type = getType();
0749: PyObject impl = self_type.lookup("__hash__");
0750: if (impl != null) {
0751: PyObject res = impl.__get__(this , self_type).__call__();
0752: if (res instanceof PyInteger)
0753: return ((PyInteger) res).getValue();
0754: throw Py.TypeError("__hash__ should return a int");
0755: }
0756: if (self_type.lookup("__eq__") != null
0757: || self_type.lookup("__cmp__") != null)
0758: throw Py.TypeError("unhashable type");
0759: return super .hashCode();
0760: }
0761:
0762: public PyUnicode __unicode__() {
0763: PyType self_type = getType();
0764: PyObject impl = self_type.lookup("__unicode__");
0765: if (impl != null) {
0766: PyObject res = impl.__get__(this , self_type).__call__();
0767: if (res instanceof PyUnicode)
0768: return (PyUnicode) res;
0769: if (res instanceof PyString)
0770: return new PyUnicode((PyString) res);
0771: throw Py.TypeError("__unicode__" + " should return a "
0772: + "unicode");
0773: }
0774: return super .__unicode__();
0775: }
0776:
0777: public int __cmp__(PyObject other) {
0778: PyType self_type = getType();
0779: PyObject impl = self_type.lookup("__cmp__");
0780: if (impl != null) {
0781: PyObject res = impl.__get__(this , self_type)
0782: .__call__(other);
0783: if (res instanceof PyInteger) {
0784: int v = ((PyInteger) res).getValue();
0785: return v < 0 ? -1 : v > 0 ? 1 : 0;
0786: }
0787: throw Py.TypeError("__cmp__ should return a int");
0788: }
0789: return super .__cmp__(other);
0790: }
0791:
0792: public boolean __nonzero__() {
0793: PyType self_type = getType();
0794: PyObject impl = self_type.lookup("__nonzero__");
0795: if (impl == null) {
0796: impl = self_type.lookup("__len__");
0797: if (impl == null)
0798: return super .__nonzero__();
0799: }
0800: return impl.__get__(this , self_type).__call__().__nonzero__();
0801: }
0802:
0803: public boolean __contains__(PyObject o) {
0804: PyType self_type = getType();
0805: PyObject impl = self_type.lookup("__contains__");
0806: if (impl == null)
0807: return super .__contains__(o);
0808: return impl.__get__(this , self_type).__call__(o).__nonzero__();
0809: }
0810:
0811: public int __len__() {
0812: PyType self_type = getType();
0813: PyObject impl = self_type.lookup("__len__");
0814: if (impl != null) {
0815: PyObject res = impl.__get__(this , self_type).__call__();
0816: if (res instanceof PyInteger)
0817: return ((PyInteger) res).getValue();
0818: throw Py.TypeError("__len__ should return a int");
0819: }
0820: return super .__len__();
0821: }
0822:
0823: public PyObject __iter__() {
0824: PyType self_type = getType();
0825: PyObject impl = self_type.lookup("__iter__");
0826: if (impl != null)
0827: return impl.__get__(this , self_type).__call__();
0828: impl = self_type.lookup("__getitem__");
0829: if (impl == null)
0830: return super .__iter__();
0831: return new PySequenceIter(this );
0832: }
0833:
0834: public PyObject __iternext__() {
0835: PyType self_type = getType();
0836: PyObject impl = self_type.lookup("next");
0837: if (impl != null) {
0838: try {
0839: return impl.__get__(this , self_type).__call__();
0840: } catch (PyException exc) {
0841: if (Py.matchException(exc, Py.StopIteration))
0842: return null;
0843: throw exc;
0844: }
0845: }
0846: return super .__iternext__(); // ???
0847: }
0848:
0849: public PyObject __finditem__(PyObject key) { // ???
0850: PyType self_type = getType();
0851: PyObject impl = self_type.lookup("__getitem__");
0852: if (impl != null)
0853: try {
0854: return impl.__get__(this , self_type).__call__(key);
0855: } catch (PyException exc) {
0856: if (Py.matchException(exc, Py.LookupError))
0857: return null;
0858: throw exc;
0859: }
0860: return super .__finditem__(key);
0861: }
0862:
0863: public void __setitem__(PyObject key, PyObject value) { // ???
0864: PyType self_type = getType();
0865: PyObject impl = self_type.lookup("__setitem__");
0866: if (impl != null) {
0867: impl.__get__(this , self_type).__call__(key, value);
0868: return;
0869: }
0870: super .__setitem__(key, value);
0871: }
0872:
0873: public PyObject __getslice__(PyObject start, PyObject stop,
0874: PyObject step) { // ???
0875: PyType self_type = getType();
0876: PyObject impl = self_type.lookup("__getslice__");
0877: if (impl != null)
0878: try {
0879: return impl.__get__(this , self_type).__call__(start,
0880: stop);
0881: } catch (PyException exc) {
0882: if (Py.matchException(exc, Py.LookupError))
0883: return null;
0884: throw exc;
0885: }
0886: return super .__getslice__(start, stop, step);
0887: }
0888:
0889: public void __delitem__(PyObject key) { // ???
0890: PyType self_type = getType();
0891: PyObject impl = self_type.lookup("__delitem__");
0892: if (impl != null) {
0893: impl.__get__(this , self_type).__call__(key);
0894: return;
0895: }
0896: super .__delitem__(key);
0897: }
0898:
0899: public PyObject __call__(PyObject args[], String keywords[]) {
0900: ThreadState ts = Py.getThreadState();
0901: if (ts.recursion_depth++ > ts.systemState.getrecursionlimit())
0902: throw Py
0903: .RuntimeError("maximum __call__ recursion depth exceeded");
0904: try {
0905: PyType self_type = getType();
0906: PyObject impl = self_type.lookup("__call__");
0907: if (impl != null)
0908: return impl.__get__(this , self_type).__call__(args,
0909: keywords);
0910: return super .__call__(args, keywords);
0911: } finally {
0912: --ts.recursion_depth;
0913: }
0914: }
0915:
0916: public PyObject __findattr__(String name) {
0917: PyType self_type = getType();
0918: PyObject getattribute = self_type.lookup("__getattribute__");
0919: PyString py_name = null;
0920: try {
0921: if (getattribute != null) {
0922: return getattribute.__get__(this , self_type).__call__(
0923: py_name = new PyString(name));
0924: } else {
0925: return super .__findattr__(name);
0926: }
0927: } catch (PyException e) {
0928: if (Py.matchException(e, Py.AttributeError)) {
0929: PyObject getattr = self_type.lookup("__getattr__");
0930: if (getattr != null)
0931: try {
0932: return getattr.__get__(this , self_type)
0933: .__call__(
0934: py_name != null ? py_name
0935: : new PyString(name));
0936: } catch (PyException e1) {
0937: if (!Py.matchException(e1, Py.AttributeError))
0938: throw e1;
0939: }
0940: return null;
0941: }
0942: throw e;
0943: }
0944: }
0945:
0946: public void __setattr__(String name, PyObject value) {
0947: PyType self_type = getType();
0948: PyObject impl = self_type.lookup("__setattr__");
0949: if (impl != null) {
0950: impl.__get__(this , self_type).__call__(new PyString(name),
0951: value);
0952: return;
0953: }
0954: super .__setattr__(name, value);
0955: }
0956:
0957: public void __delattr__(String name) {
0958: PyType self_type = getType();
0959: PyObject impl = self_type.lookup("__delattr__");
0960: if (impl != null) {
0961: impl.__get__(this , self_type).__call__(new PyString(name));
0962: return;
0963: }
0964: super .__delattr__(name);
0965: }
0966:
0967: public PyObject __get__(PyObject obj, PyObject type) {
0968: PyType self_type = getType();
0969: PyObject impl = self_type.lookup("__get__");
0970: if (impl != null) {
0971: if (obj == null)
0972: obj = Py.None;
0973: if (type == null)
0974: type = Py.None;
0975: return impl.__get__(this , self_type).__call__(obj, type);
0976: }
0977: return super .__get__(obj, type);
0978: }
0979:
0980: public void __set__(PyObject obj, PyObject value) {
0981: PyType self_type = getType();
0982: PyObject impl = self_type.lookup("__set__");
0983: if (impl != null) {
0984: impl.__get__(this , self_type).__call__(obj, value);
0985: return;
0986: }
0987: super .__set__(obj, value);
0988: }
0989:
0990: public void __delete__(PyObject obj) {
0991: PyType self_type = getType();
0992: PyObject impl = self_type.lookup("__delete__");
0993: if (impl != null) {
0994: impl.__get__(this , self_type).__call__(obj);
0995: return;
0996: }
0997: super .__delete__(obj);
0998: }
0999:
1000: public void dispatch__init__(PyType type, PyObject[] args,
1001: String[] keywords) {
1002: PyType self_type = getType();
1003: if (self_type.isSubType(type)) {
1004: PyObject impl = self_type.lookup("__init__");
1005: if (impl != null)
1006: impl.__get__(this, self_type).__call__(args, keywords);
1007: }
1008: }
1009:
1010: }
|