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