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