1 package org.python.core; 3 4 import java.text.MessageFormat ; 5 6 12 13 public class PyObject implements java.io.Serializable { 14 15 16 public static final String exposed_name = "object"; 17 18 public static void typeSetup(PyObject dict, PyType.Newstyle marker) { 19 dict.__setitem__("__class__", new PyGetSetDescr("__class__", 20 PyObject.class, "getType", null)); 21 dict.__setitem__("__doc__", new PyGetSetDescr("__doc__", 22 PyObject.class, "getDoc", null)); 23 class exposed___str__ extends PyBuiltinFunctionNarrow { 24 25 private PyObject self; 26 27 public PyObject getSelf() { 28 return self; 29 } 30 31 exposed___str__(PyObject self, PyBuiltinFunction.Info info) { 32 super(info); 33 this.self = self; 34 } 35 36 public PyBuiltinFunction makeBound(PyObject self) { 37 return new exposed___str__((PyObject) self, info); 38 } 39 40 public PyObject __call__() { 41 return self.__repr__(); 42 } 43 44 public PyObject inst_call(PyObject gself) { 45 PyObject self = (PyObject) gself; 46 return self.__repr__(); 47 } 48 49 } 50 dict.__setitem__("__str__", new PyMethodDescr("__str__", 51 PyObject.class, 0, 0, new exposed___str__(null, null))); 52 class exposed___getattribute__ extends PyBuiltinFunctionNarrow { 53 54 private PyObject self; 55 56 public PyObject getSelf() { 57 return self; 58 } 59 60 exposed___getattribute__(PyObject self, PyBuiltinFunction.Info info) { 61 super(info); 62 this.self = self; 63 } 64 65 public PyBuiltinFunction makeBound(PyObject self) { 66 return new exposed___getattribute__((PyObject) self, info); 67 } 68 69 public PyObject __call__(PyObject arg0) { 70 try { 71 String name = (arg0.asName(0)); 72 PyObject ret = self.object___findattr__(name); 73 if (ret == null) 74 self.noAttributeError(name); 75 return ret; 76 } catch (PyObject.ConversionException e) { 77 String msg; 78 switch (e.index) { 79 case 0: 80 msg = "attribute name must be string"; 81 break; 82 default: 83 msg = "xxx"; 84 } 85 throw Py.TypeError(msg); 86 } 87 } 88 89 public PyObject inst_call(PyObject gself, PyObject arg0) { 90 PyObject self = (PyObject) gself; 91 try { 92 String name = (arg0.asName(0)); 93 PyObject ret = self.object___findattr__(name); 94 if (ret == null) 95 self.noAttributeError(name); 96 return ret; 97 } catch (PyObject.ConversionException e) { 98 String msg; 99 switch (e.index) { 100 case 0: 101 msg = "attribute name must be string"; 102 break; 103 default: 104 msg = "xxx"; 105 } 106 throw Py.TypeError(msg); 107 } 108 } 109 110 } 111 dict.__setitem__("__getattribute__", new PyMethodDescr( 112 "__getattribute__", PyObject.class, 1, 1, 113 new exposed___getattribute__(null, null))); 114 class exposed___setattr__ extends PyBuiltinFunctionNarrow { 115 116 private PyObject self; 117 118 public PyObject getSelf() { 119 return self; 120 } 121 122 exposed___setattr__(PyObject self, PyBuiltinFunction.Info info) { 123 super(info); 124 this.self = self; 125 } 126 127 public PyBuiltinFunction makeBound(PyObject self) { 128 return new exposed___setattr__((PyObject) self, info); 129 } 130 131 public PyObject __call__(PyObject arg0, PyObject arg1) { 132 try { 133 self.object___setattr__(arg0.asName(0), arg1); 134 return Py.None; 135 } catch (PyObject.ConversionException e) { 136 String msg; 137 switch (e.index) { 138 case 0: 139 msg = "attribute name must be string"; 140 break; 141 default: 142 msg = "xxx"; 143 } 144 throw Py.TypeError(msg); 145 } 146 } 147 148 public PyObject inst_call(PyObject gself, PyObject arg0, 149 PyObject arg1) { 150 PyObject self = (PyObject) gself; 151 try { 152 self.object___setattr__(arg0.asName(0), arg1); 153 return Py.None; 154 } catch (PyObject.ConversionException e) { 155 String msg; 156 switch (e.index) { 157 case 0: 158 msg = "attribute name must be string"; 159 break; 160 default: 161 msg = "xxx"; 162 } 163 throw Py.TypeError(msg); 164 } 165 } 166 167 } 168 dict.__setitem__("__setattr__", new PyMethodDescr("__setattr__", 169 PyObject.class, 2, 2, new exposed___setattr__(null, null))); 170 class exposed___delattr__ extends PyBuiltinFunctionNarrow { 171 172 private PyObject self; 173 174 public PyObject getSelf() { 175 return self; 176 } 177 178 exposed___delattr__(PyObject self, PyBuiltinFunction.Info info) { 179 super(info); 180 this.self = self; 181 } 182 183 public PyBuiltinFunction makeBound(PyObject self) { 184 return new exposed___delattr__((PyObject) self, info); 185 } 186 187 public PyObject __call__(PyObject arg0) { 188 try { 189 self.object___delattr__(arg0.asName(0)); 190 return Py.None; 191 } catch (PyObject.ConversionException e) { 192 String msg; 193 switch (e.index) { 194 case 0: 195 msg = "attribute name must be string"; 196 break; 197 default: 198 msg = "xxx"; 199 } 200 throw Py.TypeError(msg); 201 } 202 } 203 204 public PyObject inst_call(PyObject gself, PyObject arg0) { 205 PyObject self = (PyObject) gself; 206 try { 207 self.object___delattr__(arg0.asName(0)); 208 return Py.None; 209 } catch (PyObject.ConversionException e) { 210 String msg; 211 switch (e.index) { 212 case 0: 213 msg = "attribute name must be string"; 214 break; 215 default: 216 msg = "xxx"; 217 } 218 throw Py.TypeError(msg); 219 } 220 } 221 222 } 223 dict.__setitem__("__delattr__", new PyMethodDescr("__delattr__", 224 PyObject.class, 1, 1, new exposed___delattr__(null, null))); 225 class exposed___hash__ extends PyBuiltinFunctionNarrow { 226 227 private PyObject self; 228 229 public PyObject getSelf() { 230 return self; 231 } 232 233 exposed___hash__(PyObject self, PyBuiltinFunction.Info info) { 234 super(info); 235 this.self = self; 236 } 237 238 public PyBuiltinFunction makeBound(PyObject self) { 239 return new exposed___hash__((PyObject) self, info); 240 } 241 242 public PyObject __call__() { 243 return new PyInteger(self.object_hashCode()); 244 } 245 246 public PyObject inst_call(PyObject gself) { 247 PyObject self = (PyObject) gself; 248 return new PyInteger(self.object_hashCode()); 249 } 250 251 } 252 dict.__setitem__("__hash__", new PyMethodDescr("__hash__", 253 PyObject.class, 0, 0, new exposed___hash__(null, null))); 254 class exposed___repr__ extends PyBuiltinFunctionNarrow { 255 256 private PyObject self; 257 258 public PyObject getSelf() { 259 return self; 260 } 261 262 exposed___repr__(PyObject self, PyBuiltinFunction.Info info) { 263 super(info); 264 this.self = self; 265 } 266 267 public PyBuiltinFunction makeBound(PyObject self) { 268 return new exposed___repr__((PyObject) self, info); 269 } 270 271 public PyObject __call__() { 272 return new PyString(self.object_toString()); 273 } 274 275 public PyObject inst_call(PyObject gself) { 276 PyObject self = (PyObject) gself; 277 return new PyString(self.object_toString()); 278 } 279 280 } 281 dict.__setitem__("__repr__", new PyMethodDescr("__repr__", 282 PyObject.class, 0, 0, new exposed___repr__(null, null))); 283 class exposed___init__ extends PyBuiltinFunctionWide { 284 285 private PyObject self; 286 287 public PyObject getSelf() { 288 return self; 289 } 290 291 exposed___init__(PyObject self, PyBuiltinFunction.Info info) { 292 super(info); 293 this.self = self; 294 } 295 296 public PyBuiltinFunction makeBound(PyObject self) { 297 return new exposed___init__((PyObject) self, info); 298 } 299 300 public PyObject inst_call(PyObject self, PyObject[] args) { 301 return inst_call(self, args, Py.NoKeywords); 302 } 303 304 public PyObject __call__(PyObject[] args) { 305 return __call__(args, Py.NoKeywords); 306 } 307 308 public PyObject __call__(PyObject[] args, String [] keywords) { 309 self.object_init(args, keywords); 310 return Py.None; 311 } 312 313 public PyObject inst_call(PyObject gself, PyObject[] args, 314 String [] keywords) { 315 PyObject self = (PyObject) gself; 316 self.object_init(args, keywords); 317 return Py.None; 318 } 319 320 } 321 dict.__setitem__("__init__", new PyMethodDescr("__init__", 322 PyObject.class, -1, -1, new exposed___init__(null, null))); 323 dict.__setitem__("__new__", new PyNewWrapper(PyObject.class, "__new__", 324 -1, -1) { 325 326 public PyObject new_impl(boolean init, PyType subtype, 327 PyObject[] args, String [] keywords) { 328 PyObject newobj; 329 if (for_type == subtype) { 330 newobj = new PyObject(); 331 if (init) 332 newobj.object_init(args, keywords); 333 } else { 334 newobj = new PyObjectDerived(subtype); 335 } 336 return newobj; 337 } 338 339 }); 340 } 341 342 final void object_init(PyObject[] args, String [] keywords) { 343 } 345 346 private transient PyType objtype; 349 350 public PyType getType() { 351 return objtype; 352 } 353 354 public PyObject fastGetClass() { 356 return objtype; 357 } 358 359 public PyObject getDoc() { 360 PyObject doc = fastGetDict().__finditem__("__doc__"); 361 if(doc == null) { 362 return Py.None; 363 } 364 return doc; 365 } 366 367 368 private void readObject(java.io.ObjectInputStream in) 369 throws java.io.IOException , ClassNotFoundException { 370 in.defaultReadObject(); 371 objtype = PyType.fromClass(getClass()); 372 } 373 374 public PyObject(PyType objtype) { 375 this.objtype = objtype; 376 } 377 378 PyObject(boolean dummy) { 381 objtype = (PyType) this; 382 } 383 384 389 public PyObject() { 390 objtype = PyType.fromClass(getClass()); 395 } 396 397 416 417 420 public void dispatch__init__(PyType type,PyObject[] args,String [] keywords) { 421 } 422 423 424 430 public PyString __repr__() { 431 return new PyString(toString()); 432 } 433 434 public String toString() { 435 return object_toString(); 436 } 437 438 final String object_toString() { 439 if (getType() == null) { 440 return "unknown object"; 441 } 442 443 String name = getType().getFullName(); 444 if (name == null) 445 return "unknown object"; 446 447 return "<"+name+" object "+Py.idstr(this)+">"; 448 } 449 450 public String safeRepr() throws PyIgnoreMethodTag { 451 if (getType() == null) { 452 return "unknown object"; 453 } 454 455 String name = getType().getFullName(); 456 if (name == null) 457 return "unknown object"; 458 459 return "'" + name + "' object"; 460 } 461 462 468 public PyString __str__() { 469 return __repr__(); 470 } 471 472 478 public final PyInteger __hash__() { 479 return new PyInteger(hashCode()); 480 } 481 482 public int hashCode() { 483 return object_hashCode(); 484 } 485 486 final int object_hashCode() { 487 return System.identityHashCode(this); 488 } 489 490 495 public boolean equals(Object ob_other) { 496 return (ob_other instanceof PyObject) 497 && _eq((PyObject) ob_other).__nonzero__(); 498 } 499 500 505 public boolean __nonzero__() { 506 return true; 507 } 508 509 518 public Object __tojava__(Class c) { 519 if (c.isInstance(this)) 520 return this; 521 return Py.NoConversion; 522 } 523 524 535 public PyObject __call__(PyObject args[], String keywords[]) { 536 throw Py.TypeError("call of non-function (" + safeRepr() + ")"); 537 } 538 539 553 public PyObject __call__( 554 PyObject arg1, 555 PyObject args[], 556 String keywords[]) { 557 PyObject[] newArgs = new PyObject[args.length + 1]; 558 System.arraycopy(args, 0, newArgs, 1, args.length); 559 newArgs[0] = arg1; 560 return __call__(newArgs, keywords); 561 } 562 563 571 public PyObject __call__(PyObject args[]) { 572 return __call__(args, Py.NoKeywords); 573 } 574 575 581 public PyObject __call__() { 582 return __call__(Py.EmptyObjects, Py.NoKeywords); 583 } 584 585 593 public PyObject __call__(PyObject arg0) { 594 return __call__(new PyObject[] { arg0 }, Py.NoKeywords); 595 } 596 597 606 public PyObject __call__(PyObject arg0, PyObject arg1) { 607 return __call__(new PyObject[] { arg0, arg1 }, Py.NoKeywords); 608 } 609 610 620 public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2) { 621 return __call__(new PyObject[] { arg0, arg1, arg2 }, Py.NoKeywords); 622 } 623 624 635 public PyObject __call__( 636 PyObject arg0, 637 PyObject arg1, 638 PyObject arg2, 639 PyObject arg3) { 640 return __call__( 641 new PyObject[] { arg0, arg1, arg2, arg3 }, 642 Py.NoKeywords); 643 } 644 645 646 public PyObject _callextra( PyObject[] args, 648 String [] keywords, 649 PyObject starargs, 650 PyObject kwargs) { 651 652 int argslen = args.length; 653 int nstar = 0; 654 655 String name = ""; 656 if (this instanceof PyFunction) 657 name = ((PyFunction) this).__name__ + "() "; 658 659 if (kwargs != null) { 660 PyObject keys = kwargs.__findattr__("keys"); 661 if (keys == null) 662 throw Py.TypeError( 663 name + "argument after ** must be " + "a dictionary"); 664 for (int i = 0; i < keywords.length; i++) 665 if (kwargs.__finditem__(keywords[i]) != null) 666 throw Py.TypeError( 667 name 668 + "got multiple values for " 669 + "keyword argument '" 670 + keywords[i] 671 + "'"); 672 argslen += kwargs.__len__(); 673 } 674 if (starargs != null) { 675 if (!(starargs instanceof PySequence 676 || starargs instanceof PyInstance)) throw Py.TypeError( 678 name + "argument after * must " + "be a sequence"); 679 nstar = starargs.__len__(); 680 argslen += nstar; 681 } 682 683 PyObject[] newargs = new PyObject[argslen]; 684 int argidx = args.length - keywords.length; 685 System.arraycopy(args, 0, newargs, 0, argidx); 686 687 if (starargs != null) { 688 PyObject a; 689 for (int i = 0; 690 (a = starargs.__finditem__(i)) != null && i < nstar; 691 i++) { 692 newargs[argidx++] = a; 693 } 694 } 695 System.arraycopy( 696 args, 697 args.length - keywords.length, 698 newargs, 699 argidx, 700 keywords.length); 701 argidx += keywords.length; 702 703 if (kwargs != null) { 704 String [] newkeywords = 705 new String [keywords.length + kwargs.__len__()]; 706 System.arraycopy(keywords, 0, newkeywords, 0, keywords.length); 707 708 PyObject keys = kwargs.invoke("keys"); 709 PyObject key; 710 for (int i = 0;(key = keys.__finditem__(i)) != null; i++) { 711 if (!(key instanceof PyString)) 712 throw Py.TypeError(name + "keywords must be strings"); 713 newkeywords[keywords.length + i] = 714 ((PyString) key).internedString(); 715 newargs[argidx++] = kwargs.__finditem__(key); 716 } 717 keywords = newkeywords; 718 } 719 720 if (newargs.length != argidx) { 721 args = new PyObject[argidx]; 722 System.arraycopy(newargs, 0, args, 0, argidx); 723 } else 724 args = newargs; 725 return __call__(args, keywords); 726 } 727 728 729 730 public boolean isCallable() { 731 return __findattr__("__call__") != null; 732 } 733 public boolean isMappingType() { 734 return true; 735 } 736 public boolean isNumberType() { 737 return true; 738 } 739 public boolean isSequenceType() { 740 return true; 741 } 742 743 744 745 746 747 753 public int __len__() { 754 throw Py.AttributeError("__len__"); 755 } 756 757 770 public PyObject __finditem__(PyObject key) { 771 throw Py.AttributeError("__getitem__"); 772 } 773 774 785 public PyObject __finditem__(int key) { 786 return __finditem__(new PyInteger(key)); 787 } 788 789 803 public PyObject __finditem__(String key) { 804 return __finditem__(new PyString(key)); 805 } 806 807 819 public PyObject __getitem__(int key) { 820 PyObject ret = __finditem__(key); 821 if (ret == null) 822 throw Py.KeyError("" + key); 823 return ret; 824 } 825 826 837 public PyObject __getitem__(PyObject key) { 838 PyObject ret = __finditem__(key); 839 if (ret == null) 840 throw Py.KeyError(key.toString()); 841 return ret; 842 } 843 844 850 public void __setitem__(PyObject key, PyObject value) { 851 throw Py.AttributeError("__setitem__"); 852 } 853 854 868 public void __setitem__(String key, PyObject value) { 869 __setitem__(new PyString(key), value); 870 } 871 872 885 public void __setitem__(int key, PyObject value) { 886 __setitem__(new PyInteger(key), value); 887 } 888 889 895 public void __delitem__(PyObject key) { 896 throw Py.AttributeError("__delitem__"); 897 } 898 899 913 public void __delitem__(String key) { 914 __delitem__(new PyString(key)); 915 } 916 917 public PyObject __getslice__( 918 PyObject s_start, 919 PyObject s_stop, 920 PyObject s_step) { 921 PySlice s = new PySlice(s_start, s_stop, s_step); 922 return __getitem__(s); 923 } 924 925 public void __setslice__( 926 PyObject s_start, 927 PyObject s_stop, 928 PyObject s_step, 929 PyObject value) { 930 PySlice s = new PySlice(s_start, s_stop, s_step); 931 __setitem__(s, value); 932 } 933 934 public void __delslice__( 935 PyObject s_start, 936 PyObject s_stop, 937 PyObject s_step) { 938 PySlice s = new PySlice(s_start, s_stop, s_step); 939 __delitem__(s); 940 } 941 942 public PyObject __getslice__(PyObject start, PyObject stop) { 943 return __getslice__(start, stop, Py.One); 944 } 945 946 public void __setslice__(PyObject start, PyObject stop, PyObject value) { 947 __setslice__(start, stop, Py.One, value); 948 } 949 950 public void __delslice__(PyObject start, PyObject stop) { 951 __delslice__(start, stop, Py.One); 952 } 953 954 955 956 982 public PyObject __iter__() { 983 throw Py.TypeError("iteration over non-sequence"); 984 } 985 986 992 public PyObject __iternext__() { 993 return null; 994 } 995 996 997 998 1011 public final PyObject __findattr__(PyString name) { 1012 if (name == null) { 1013 return null; 1014 } 1015 return __findattr__(name.internedString()); 1016 } 1017 1018 1034 public PyObject __findattr__(String name) { 1039 1043 1044 return object___findattr__(name); 1045 } 1046 1047 1058 public final PyObject __getattr__(PyString name) { 1059 PyObject ret = __findattr__(name); 1060 if (ret == null) 1061 noAttributeError(name.toString()); 1062 return ret; 1063 } 1064 1065 1080 public final PyObject __getattr__(String name) { 1081 PyObject ret = __findattr__(name); 1082 if (ret == null) 1083 noAttributeError(name); 1084 return ret; 1085 } 1086 1087 public void noAttributeError(String name) { 1088 throw Py.AttributeError( 1089 safeRepr() + " has no attribute '" + name + "'"); 1090 } 1091 1092 public void readonlyAttributeError(String name) { 1093 throw Py.AttributeError( 1094 safeRepr() + " attribute '" + name + "' is read-only"); 1095 } 1096 1097 1106 public final void __setattr__(PyString name, PyObject value) { 1107 __setattr__(name.internedString(), value); 1108 } 1109 1110 1120 public void __setattr__(String name, PyObject value) { 1121 object___setattr__(name, value); 1122 } 1123 1124 1133 public final void __delattr__(PyString name) { 1134 __delattr__(name.internedString()); 1135 } 1136 1137 1151 public void __delattr__(String name) { 1152 object___delattr__(name); 1153 } 1154 1155 protected PyObject impAttr(String name) { 1157 return __findattr__(name); 1158 } 1159 1160 protected void addKeys(PyDictionary accum, String attr) { 1161 PyObject obj = __findattr__(attr); 1162 if (obj == null) 1163 return; 1164 if (obj instanceof PyList) { 1165 PyObject lst_iter = obj.__iter__(); 1166 PyObject name; 1167 for (; (name = lst_iter.__iternext__())!= null; ) { 1168 accum.__setitem__(name, Py.None); 1169 } 1170 } 1171 accum.update(obj); 1172 } 1173 1174 protected void __rawdir__(PyDictionary accum) { 1175 addKeys(accum, "__dict__"); 1176 addKeys(accum, "__methods__"); 1177 addKeys(accum, "__members__"); 1178 fastGetClass().__rawdir__(accum); 1179 } 1180 1181 1186 public PyObject __dir__() { 1187 PyDictionary accum = new PyDictionary(); 1188 __rawdir__(accum); 1189 PyList ret = accum.keys(); 1190 ret.sort(); 1191 return ret; 1192 } 1193 1194 public PyObject _doget(PyObject container) { 1195 return this; 1196 } 1197 1198 public PyObject _doget(PyObject container, PyObject wherefound) { 1199 return _doget(container); 1200 } 1201 1202 public boolean _doset(PyObject container, PyObject value) { 1203 return false; 1204 } 1205 1206 boolean jtryset(PyObject container, PyObject value) { 1207 return _doset(container, value); 1208 } 1209 1210 boolean jdontdel() { 1211 return false; 1212 } 1213 1214 1215 1216 1224 public Object __coerce_ex__(PyObject o) { 1225 return null; 1226 } 1227 1228 1233 PyObject[] _coerce(PyObject other) { 1234 Object result; 1235 if (this.getType() == other.getType() && 1236 !(this instanceof PyInstance)) { 1237 return new PyObject[] {this, other}; 1238 } 1239 result = this.__coerce_ex__(other); 1240 if (result != null && result != Py.None) { 1241 if (result instanceof PyObject[]) { 1242 return (PyObject[])result; 1243 } else { 1244 return new PyObject[] {this, (PyObject)result}; 1245 } 1246 } 1247 result = other.__coerce_ex__(this); 1248 if (result != null && result != Py.None) { 1249 if (result instanceof PyObject[]) { 1250 return (PyObject[])result; 1251 } else { 1252 return new PyObject[] {(PyObject)result, other}; 1253 } 1254 } 1255 return null; 1256 1257 } 1258 1259 1270 public final PyObject __coerce__(PyObject pyo) { 1271 Object o = __coerce_ex__(pyo); 1272 if (o == null) 1273 throw Py.AttributeError("__coerce__"); 1274 if (o == Py.None) 1275 return (PyObject) o; 1276 if (o instanceof PyObject[]) 1277 return new PyTuple((PyObject[]) o); 1278 else 1279 return new PyTuple(new PyObject[] { this, (PyObject) o }); 1280 } 1281 1282 1283 1284 1285 1286 1293 public int __cmp__(PyObject other) { 1294 return -2; 1295 } 1296 1297 1303 public PyObject __eq__(PyObject other) { 1304 return null; 1305 } 1306 1307 1313 public PyObject __ne__(PyObject other) { 1314 return null; 1315 } 1316 1317 1323 public PyObject __le__(PyObject other) { 1324 return null; 1325 } 1326 1327 1333 public PyObject __lt__(PyObject other) { 1334 return null; 1335 } 1336 1337 1343 public PyObject __ge__(PyObject other) { 1344 return null; 1345 } 1346 1347 1353 public PyObject __gt__(PyObject other) { 1354 return null; 1355 } 1356 1357 1363 public final int _cmp(PyObject o) { 1364 PyObject token = null; 1365 ThreadState ts = Py.getThreadState(); 1366 try { 1367 if (++ts.compareStateNesting > 500) { 1368 if ((token = check_recursion(ts, this, o)) == null) 1369 return 0; 1370 } 1371 1372 PyObject r; 1373 r = __eq__(o); 1374 if (r != null && r.__nonzero__()) 1375 return 0; 1376 r = o.__eq__(this); 1377 if (r != null && r.__nonzero__()) 1378 return 0; 1379 1380 r = __lt__(o); 1381 if (r != null && r.__nonzero__()) 1382 return -1; 1383 r = o.__gt__(this); 1384 if (r != null && r.__nonzero__()) 1385 return -1; 1386 1387 r = __gt__(o); 1388 if (r != null && r.__nonzero__()) 1389 return 1; 1390 r = o.__lt__(this); 1391 if (r != null && r.__nonzero__()) 1392 return 1; 1393 1394 return _cmp_unsafe(o); 1395 } finally { 1396 delete_token(ts, token); 1397 ts.compareStateNesting--; 1398 } 1399 } 1400 1401 private PyObject make_pair(PyObject o) { 1402 if (System.identityHashCode(this) < System.identityHashCode(o)) 1403 return new PyIdentityTuple(new PyObject[] { this, o }); 1404 else 1405 return new PyIdentityTuple(new PyObject[] { o, this }); 1406 } 1407 1408 private final int _default_cmp(PyObject other) { 1409 int result; 1410 if (this._is(other).__nonzero__()) 1411 return 0; 1412 1413 1414 if (this == Py.None) 1415 return -1; 1416 if (other == Py.None) 1417 return 1; 1418 1419 PyType this_type = this.getType(); 1421 PyType other_type = other.getType(); 1422 if (this_type == other_type) { 1423 return Py.id(this) < Py.id(other)? -1: 1; 1424 } 1425 result = this_type.fastGetName().compareTo(other_type.fastGetName()); 1426 if (result == 0) 1427 return Py.id(this_type)<Py.id(other_type)? -1: 1; 1428 return result < 0? -1: 1; 1429 } 1430 1431 private final int _cmp_unsafe(PyObject other) { 1432 if (this == other) 1434 return 0; 1435 1436 int result; 1437 result = this.__cmp__(other); 1438 if (result != -2) 1439 return result; 1440 1441 if (!(this instanceof PyInstance)) { 1442 result = other.__cmp__(this); 1443 if (result != -2) 1444 return -result; 1445 } 1446 1447 return this._default_cmp(other); 1448 } 1449 1450 1454 private final int _cmpeq_unsafe(PyObject other) { 1455 if (this == other) 1457 return 0; 1458 1459 int result; 1460 result = this.__cmp__(other); 1461 if (result != -2) 1462 return result; 1463 1464 if (!(this instanceof PyInstance)) { 1465 result = other.__cmp__(this); 1466 if (result != -2) 1467 return -result; 1468 } 1469 1470 return this._is(other).__nonzero__()?0:1; 1471 } 1472 1473 1474 1475 private final static PyObject check_recursion( 1476 ThreadState ts, 1477 PyObject o1, 1478 PyObject o2) { 1479 PyDictionary stateDict = ts.getCompareStateDict(); 1480 1481 PyObject pair = o1.make_pair(o2); 1482 1483 if (stateDict.__finditem__(pair) != null) 1484 return null; 1485 1486 stateDict.__setitem__(pair, pair); 1487 return pair; 1488 } 1489 1490 private final static void delete_token(ThreadState ts, PyObject token) { 1491 if (token == null) 1492 return; 1493 PyDictionary stateDict = ts.getCompareStateDict(); 1494 1495 stateDict.__delitem__(token); 1496 } 1497 1498 1504 public final PyObject _eq(PyObject o) { 1505 PyObject token = null; 1506 1507 ThreadState ts = Py.getThreadState(); 1508 try { 1509 if (++ts.compareStateNesting > 10) { 1510 if ((token = check_recursion(ts, this, o)) == null) 1511 return Py.One; 1512 } 1513 PyObject res = __eq__(o); 1514 if (res != null) 1515 return res; 1516 res = o.__eq__(this); 1517 if (res != null) 1518 return res; 1519 return _cmpeq_unsafe(o) == 0 ? Py.One : Py.Zero; 1520 } catch (PyException e) { 1521 if (Py.matchException(e, Py.AttributeError)) { 1522 return Py.Zero; 1523 } 1524 throw e; 1525 } finally { 1526 delete_token(ts, token); 1527 ts.compareStateNesting--; 1528 } 1529 } 1530 1531 1537 public final PyObject _ne(PyObject o) { 1538 PyObject token = null; 1539 1540 ThreadState ts = Py.getThreadState(); 1541 try { 1542 if (++ts.compareStateNesting > 10) { 1543 if ((token = check_recursion(ts, this, o)) == null) 1544 return Py.Zero; 1545 } 1546 PyObject res = __ne__(o); 1547 if (res != null) 1548 return res; 1549 res = o.__ne__(this); 1550 if (res != null) 1551 return res; 1552 return _cmpeq_unsafe(o) != 0 ? Py.One : Py.Zero; 1553 } finally { 1554 delete_token(ts, token); 1555 ts.compareStateNesting--; 1556 } 1557 } 1558 1559 1565 public final PyObject _le(PyObject o) { 1566 PyObject token = null; 1567 1568 ThreadState ts = Py.getThreadState(); 1569 try { 1570 if (++ts.compareStateNesting > 10) { 1571 if ((token = check_recursion(ts, this, o)) == null) 1572 throw Py.ValueError("can't order recursive values"); 1573 } 1574 PyObject res = __le__(o); 1575 if (res != null) 1576 return res; 1577 res = o.__ge__(this); 1578 if (res != null) 1579 return res; 1580 return _cmp_unsafe(o) <= 0 ? Py.One : Py.Zero; 1581 } finally { 1582 delete_token(ts, token); 1583 ts.compareStateNesting--; 1584 } 1585 } 1586 1587 1593 public final PyObject _lt(PyObject o) { 1594 PyObject token = null; 1595 1596 ThreadState ts = Py.getThreadState(); 1597 try { 1598 if (++ts.compareStateNesting > 10) { 1599 if ((token = check_recursion(ts, this, o)) == null) 1600 throw Py.ValueError("can't order recursive values"); 1601 } 1602 PyObject res = __lt__(o); 1603 if (res != null) 1604 return res; 1605 res = o.__gt__(this); 1606 if (res != null) 1607 return res; 1608 return _cmp_unsafe(o) < 0 ? Py.One : Py.Zero; 1609 } finally { 1610 delete_token(ts, token); 1611 ts.compareStateNesting--; 1612 } 1613 } 1614 1615 1621 public final PyObject _ge(PyObject o) { 1622 PyObject token = null; 1623 1624 ThreadState ts = Py.getThreadState(); 1625 try { 1626 if (++ts.compareStateNesting > 10) { 1627 if ((token = check_recursion(ts, this, o)) == null) 1628 throw Py.ValueError("can't order recursive values"); 1629 } 1630 PyObject res = __ge__(o); 1631 if (res != null) 1632 return res; 1633 res = o.__le__(this); 1634 if (res != null) 1635 return res; 1636 return _cmp_unsafe(o) >= 0 ? Py.One : Py.Zero; 1637 } finally { 1638 delete_token(ts, token); 1639 ts.compareStateNesting--; 1640 } 1641 } 1642 1643 1649 public final PyObject _gt(PyObject o) { 1650 PyObject token = null; 1651 1652 ThreadState ts = Py.getThreadState(); 1653 try { 1654 if (++ts.compareStateNesting > 10) { 1655 if ((token = check_recursion(ts, this, o)) == null) 1656 throw Py.ValueError("can't order recursive values"); 1657 } 1658 PyObject res = __gt__(o); 1659 if (res != null) 1660 return res; 1661 res = o.__lt__(this); 1662 if (res != null) 1663 return res; 1664 return _cmp_unsafe(o) > 0 ? Py.One : Py.Zero; 1665 } finally { 1666 delete_token(ts, token); 1667 ts.compareStateNesting--; 1668 } 1669 1670 } 1671 1672 1678 public PyObject _is(PyObject o) { 1679 return this == o ? Py.One : Py.Zero; 1680 } 1681 1682 1688 public PyObject _isnot(PyObject o) { 1689 return this != o ? Py.One : Py.Zero; 1690 } 1691 1692 1698 public final PyObject _in(PyObject o) { 1699 return Py.newBoolean(o.__contains__(this)); 1700 } 1701 1702 1708 public final PyObject _notin(PyObject o) { 1709 return Py.newBoolean(!o.__contains__(this)); 1710 } 1711 1712 1718 public boolean __contains__(PyObject o) { 1719 return object___contains__(o); 1720 } 1721 1722 final boolean object___contains__(PyObject o) { 1723 PyObject iter = __iter__(); 1724 for (PyObject item = null;(item = iter.__iternext__()) != null;) { 1725 if (o._eq(item).__nonzero__()) 1726 return true; 1727 } 1728 return false; 1729 } 1730 1731 1736 public PyObject __not__() { 1737 return __nonzero__() ? Py.Zero : Py.One; 1738 } 1739 1740 1741 1742 1749 public PyString __hex__() { 1750 throw Py.AttributeError("__hex__"); 1751 } 1752 1753 1760 public PyString __oct__() { 1761 throw Py.AttributeError("__oct__"); 1762 } 1763 1764 1771 public PyObject __int__() { 1772 throw Py.AttributeError("__int__"); 1773 } 1774 1775 1782 public PyLong __long__() { 1783 throw Py.AttributeError("__long__"); 1784 } 1785 1786 1793 public PyFloat __float__() { 1794 throw Py.AttributeError("__float__"); 1795 } 1796 1797 1804 public PyComplex __complex__() { 1805 throw Py.AttributeError("__complex__"); 1806 } 1807 1808 1813 public PyObject __pos__() { 1814 throw Py.AttributeError("__pos__"); 1815 } 1816 1817 1822 public PyObject __neg__() { 1823 throw Py.AttributeError("__neg__"); 1824 } 1825 1826 1831 public PyObject __abs__() { 1832 throw Py.AttributeError("__abs__"); 1833 } 1834 1835 1840 public PyObject __invert__() { 1841 throw Py.AttributeError("__invert__"); 1842 } 1843 1844 1852 public PyObject __pow__(PyObject o2, PyObject o3) { 1853 return null; 1854 } 1855 1856 1858 1865 public PyObject __add__(PyObject other) { 1866 return null; 1867 } 1868 1869 1876 public PyObject __radd__(PyObject other) { 1877 return null; 1878 } 1879 1880 1887 public PyObject __iadd__(PyObject other) { 1888 return _add(other); 1889 } 1890 1891 1898 public final PyObject _add(PyObject o2) { 1899 PyObject x = __add__(o2); 1900 if (x != null) { 1901 return x; 1902 } 1903 x = o2.__radd__(this); 1904 if (x != null) { 1905 return x; 1906 } 1907 throw Py.TypeError(_unsupportedop("+", o2)); 1908 } 1909 1910 1914 protected final String _unsupportedop(String op, PyObject o2) { 1915 Object [] args = {op, getType().fastGetName(), o2.getType().fastGetName()}; 1916 String msg = unsupportedopMessage(op, o2); 1917 if (msg == null) { 1918 msg = o2.runsupportedopMessage(op, o2); 1919 } 1920 if (msg == null) { 1921 msg = "unsupported operand type(s) for {0}: ''{1}'' and ''{2}''"; 1922 } 1923 return MessageFormat.format(msg, args); 1924 } 1925 1926 1933 protected String unsupportedopMessage(String op, PyObject o2) { 1934 return null; 1935 } 1936 1937 1944 protected String runsupportedopMessage(String op, PyObject o2) { 1945 return null; 1946 } 1947 1948 1949 1956 public PyObject __sub__(PyObject other) { 1957 return null; 1958 } 1959 1960 1967 public PyObject __rsub__(PyObject other) { 1968 return null; 1969 } 1970 1971 1978 public PyObject __isub__(PyObject other) { 1979 return _sub(other); 1980 } 1981 1982 1989 public final PyObject _sub(PyObject o2) { 1990 PyObject x = __sub__(o2); 1991 if (x != null) 1992 return x; 1993 x = o2.__rsub__(this); 1994 if (x != null) 1995 return x; 1996 throw Py.TypeError(_unsupportedop("-", o2)); 1997 } 1998 1999 2006 public PyObject __mul__(PyObject other) { 2007 return null; 2008 } 2009 2010 2017 public PyObject __rmul__(PyObject other) { 2018 return null; 2019 } 2020 2021 2028 public PyObject __imul__(PyObject other) { 2029 return _mul(other); 2030 } 2031 2032 2039 public final PyObject _mul(PyObject o2) { 2040 PyObject x = __mul__(o2); 2041 if (x != null) 2042 return x; 2043 x = o2.__rmul__(this); 2044 if (x != null) 2045 return x; 2046 throw Py.TypeError(_unsupportedop("*", o2)); 2047 } 2048 2049 2056 public PyObject __div__(PyObject other) { 2057 return null; 2058 } 2059 2060 2067 public PyObject __rdiv__(PyObject other) { 2068 return null; 2069 } 2070 2071 2078 public PyObject __idiv__(PyObject other) { 2079 return _div(other); 2080 } 2081 2082 2089 public final PyObject _div(PyObject o2) { 2090 if (Options.Qnew) 2091 return _truediv(o2); 2092 PyObject x = __div__(o2); 2093 if (x != null) 2094 return x; 2095 x = o2.__rdiv__(this); 2096 if (x != null) 2097 return x; 2098 throw Py.TypeError(_unsupportedop("/", o2)); 2099 } 2100 2101 2108 public PyObject __floordiv__(PyObject other) { 2109 return null; 2110 } 2111 2112 2119 public PyObject __rfloordiv__(PyObject other) { 2120 return null; 2121 } 2122 2123 2130 public PyObject __ifloordiv__(PyObject other) { 2131 return _floordiv(other); 2132 } 2133 2134 2141 public final PyObject _floordiv(PyObject o2) { 2142 PyObject x = __floordiv__(o2); 2143 if (x != null) 2144 return x; 2145 x = o2.__rfloordiv__(this); 2146 if (x != null) 2147 return x; 2148 throw Py.TypeError(_unsupportedop("//", o2)); 2149 } 2150 2151 2158 public PyObject __truediv__(PyObject other) { 2159 return null; 2160 } 2161 2162 2169 public PyObject __rtruediv__(PyObject other) { 2170 return null; 2171 } 2172 2173 2180 public PyObject __itruediv__(PyObject other) { 2181 return _truediv(other); 2182 } 2183 2184 2191 public final PyObject _truediv(PyObject o2) { 2192 PyObject x = __truediv__(o2); 2193 if (x != null) 2194 return x; 2195 x = o2.__rtruediv__(this); 2196 if (x != null) 2197 return x; 2198 throw Py.TypeError(_unsupportedop("/", o2)); 2199 } 2200 2201 2208 public PyObject __mod__(PyObject other) { 2209 return null; 2210 } 2211 2212 2219 public PyObject __rmod__(PyObject other) { 2220 return null; 2221 } 2222 2223 2230 public PyObject __imod__(PyObject other) { 2231 return _mod(other); 2232 } 2233 2234 2241 public final PyObject _mod(PyObject o2) { 2242 PyObject x = __mod__(o2); 2243 if (x != null) 2244 return x; 2245 x = o2.__rmod__(this); 2246 if (x != null) 2247 return x; 2248 throw Py.TypeError(_unsupportedop("%", o2)); 2249 } 2250 2251 2258 public PyObject __divmod__(PyObject other) { 2259 return null; 2260 } 2261 2262 2269 public PyObject __rdivmod__(PyObject other) { 2270 return null; 2271 } 2272 2273 2280 public PyObject __idivmod__(PyObject other) { 2281 return _divmod(other); 2282 } 2283 2284 2291 public final PyObject _divmod(PyObject o2) { 2292 PyObject x = __divmod__(o2); 2293 if (x != null) 2294 return x; 2295 x = o2.__rdivmod__(this); 2296 if (x != null) 2297 return x; 2298 throw Py.TypeError(_unsupportedop("divmod", o2)); 2300 } 2301 2302 2309 public PyObject __pow__(PyObject other) { 2310 return __pow__(other, null); 2311 } 2312 2313 2320 public PyObject __rpow__(PyObject other) { 2321 return null; 2322 } 2323 2324 2331 public PyObject __ipow__(PyObject other) { 2332 return _pow(other); 2333 } 2334 2335 2342 public final PyObject _pow(PyObject o2) { 2343 PyObject x = __pow__(o2); 2344 if (x != null) 2345 return x; 2346 x = o2.__rpow__(this); 2347 if (x != null) 2348 return x; 2349 throw Py.TypeError(_unsupportedop("**", o2)); 2350 } 2351 2352 2359 public PyObject __lshift__(PyObject other) { 2360 return null; 2361 } 2362 2363 2370 public PyObject __rlshift__(PyObject other) { 2371 return null; 2372 } 2373 2374 2381 public PyObject __ilshift__(PyObject other) { 2382 return _lshift(other); 2383 } 2384 2385 2392 public final PyObject _lshift(PyObject o2) { 2393 PyObject x = __lshift__(o2); 2394 if (x != null) 2395 return x; 2396 x = o2.__rlshift__(this); 2397 if (x != null) 2398 return x; 2399 throw Py.TypeError(_unsupportedop("<<", o2)); 2400 } 2401 2402 2409 public PyObject __rshift__(PyObject other) { 2410 return null; 2411 } 2412 2413 2420 public PyObject __rrshift__(PyObject other) { 2421 return null; 2422 } 2423 2424 2431 public PyObject __irshift__(PyObject other) { 2432 return _rshift(other); 2433 } 2434 2435 2442 public final PyObject _rshift(PyObject o2) { 2443 PyObject x = __rshift__(o2); 2444 if (x != null) 2445 return x; 2446 x = o2.__rrshift__(this); 2447 if (x != null) 2448 return x; 2449 throw Py.TypeError(_unsupportedop(">>", o2)); 2450 } 2451 2452 2459 public PyObject __and__(PyObject other) { 2460 return null; 2461 } 2462 2463 2470 public PyObject __rand__(PyObject other) { 2471 return null; 2472 } 2473 2474 2481 public PyObject __iand__(PyObject other) { 2482 return _and(other); 2483 } 2484 2485 2492 public final PyObject _and(PyObject o2) { 2493 PyObject x = __and__(o2); 2494 if (x != null) 2495 return x; 2496 x = o2.__rand__(this); 2497 if (x != null) 2498 return x; 2499 throw Py.TypeError(_unsupportedop("&", o2)); 2500 } 2501 2502 2509 public PyObject __or__(PyObject other) { 2510 return null; 2511 } 2512 2513 2520 public PyObject __ror__(PyObject other) { 2521 return null; 2522 } 2523 2524 2531 public PyObject __ior__(PyObject other) { 2532 return _or(other); 2533 } 2534 2535 2542 public final PyObject _or(PyObject o2) { 2543 PyObject x = __or__(o2); 2544 if (x != null) 2545 return x; 2546 x = o2.__ror__(this); 2547 if (x != null) 2548 return x; 2549 throw Py.TypeError(_unsupportedop("|", o2)); 2550 } 2551 2552 2559 public PyObject __xor__(PyObject other) { 2560 return null; 2561 } 2562 2563 2570 public PyObject __rxor__(PyObject other) { 2571 return null; 2572 } 2573 2574 2581 public PyObject __ixor__(PyObject other) { 2582 return _xor(other); 2583 } 2584 2585 2592 public final PyObject _xor(PyObject o2) { 2593 PyObject x = __xor__(o2); 2594 if (x != null) 2595 return x; 2596 x = o2.__rxor__(this); 2597 if (x != null) 2598 return x; 2599 throw Py.TypeError(_unsupportedop("^", o2)); 2600 } 2601 2602 2604 2605 2611 public PyObject _jcallexc(Object [] args) throws Throwable { 2612 PyObject[] pargs = new PyObject[args.length]; 2613 try { 2614 int n = args.length; 2615 for (int i = 0; i < n; i++) 2616 pargs[i] = Py.java2py(args[i]); 2617 return __call__(pargs); 2618 } catch (PyException e) { 2619 if (e.value instanceof PyJavaInstance) { 2620 Object t = e.value.__tojava__(Throwable .class); 2621 if (t != null && t != Py.NoConversion) { 2622 throw (Throwable ) t; 2623 } 2624 } else { 2625 ThreadState ts = Py.getThreadState(); 2626 if (ts.frame == null) { 2627 Py.maybeSystemExit(e); 2628 } 2629 if (Options.showPythonProxyExceptions) { 2630 Py.stderr.println( 2631 "Exception in Python proxy returning to Java:"); 2632 Py.printException(e); 2633 } 2634 } 2635 throw e; 2636 } 2637 } 2638 2639 public void _jthrow(Throwable t) { 2640 if (t instanceof RuntimeException ) 2641 throw (RuntimeException ) t; 2642 if (t instanceof Error ) 2643 throw (Error ) t; 2644 throw Py.JavaError(t); 2645 } 2646 2647 public PyObject _jcall(Object [] args) { 2648 try { 2649 return _jcallexc(args); 2650 } catch (Throwable t) { 2651 _jthrow(t); 2652 return null; 2653 } 2654 } 2655 2656 2657 2658 2668 public PyObject invoke(String name, PyObject[] args, String [] keywords) { 2669 PyObject f = __getattr__(name); 2670 return f.__call__(args, keywords); 2671 } 2672 2673 public PyObject invoke(String name, PyObject[] args) { 2674 PyObject f = __getattr__(name); 2675 return f.__call__(args); 2676 } 2677 2678 2685 public PyObject invoke(String name) { 2686 PyObject f = __getattr__(name); 2687 return f.__call__(); 2688 } 2689 2690 2698 public PyObject invoke(String name, PyObject arg1) { 2699 PyObject f = __getattr__(name); 2700 return f.__call__(arg1); 2701 } 2702 2703 2712 public PyObject invoke(String name, PyObject arg1, PyObject arg2) { 2713 PyObject f = __getattr__(name); 2714 return f.__call__(arg1, arg2); 2715 } 2716 2717 2718 2719 2722 public PyObject fastGetDict() { 2723 return null; 2724 } 2725 2726 2729 public PyObject getDict() { 2730 return null; 2731 } 2732 2733 2734 public boolean implementsDescrSet() { 2735 return objtype.has_set; 2736 } 2737 2738 public boolean implementsDescrDelete() { 2739 return objtype.has_delete; 2740 } 2741 2742 public boolean isDataDescr() { return objtype.has_set || objtype.has_delete; 2744 } 2745 2746 2749 public PyObject __get__(PyObject obj, PyObject type) { 2751 return _doget(obj, type); 2752 } 2753 2754 public void __set__(PyObject obj, PyObject value) { 2755 throw Py.RuntimeError("object internal __set__ impl is abstract"); 2756 } 2757 2758 public void __delete__(PyObject obj) { 2759 throw Py.RuntimeError("object internal __delete__ impl is abstract"); 2760 } 2761 2762 final PyObject object___findattr__(String name) { 2764 2765 PyObject descr = objtype.lookup(name); 2766 PyObject res; 2767 2768 if (descr != null) { 2769 if (descr.isDataDescr()) { 2770 res = descr.__get__(this, objtype); 2771 if (res != null) 2772 return res; 2773 } 2774 } 2775 2776 PyObject obj_dict = fastGetDict(); 2777 if (obj_dict != null) { 2778 res = obj_dict.__finditem__(name); 2779 if (res != null) 2780 return res; 2781 } 2782 2783 if (descr != null) { 2784 return descr.__get__(this, objtype); 2785 } 2786 2787 return null; 2788 } 2789 2790 final void object___setattr__(String name, PyObject value) { 2791 PyObject descr = objtype.lookup(name); 2792 2793 boolean set = false; 2794 2795 if (descr != null) { 2796 set = descr.implementsDescrSet(); 2797 if (set && descr.isDataDescr()) { 2798 descr.__set__(this, value); 2799 return; 2800 } 2801 } 2802 2803 PyObject obj_dict = fastGetDict(); 2804 if (obj_dict != null) { 2805 obj_dict.__setitem__(name, value); 2806 return; 2807 } 2808 2809 if (set) { 2810 descr.__set__(this, value); 2811 } 2812 2813 if (descr != null) 2814 readonlyAttributeError(name); 2815 2816 noAttributeError(name); 2817 } 2818 2819 final void object___delattr__(String name) { 2820 PyObject descr = objtype.lookup(name); 2821 2822 boolean delete = false; 2823 2824 if (descr != null) { 2825 delete = descr.implementsDescrDelete(); 2826 if (delete && descr.isDataDescr()) { 2827 descr.__delete__(this); 2828 return; 2829 } 2830 } 2831 2832 PyObject obj_dict = fastGetDict(); 2833 if (obj_dict != null) { 2834 try { 2835 obj_dict.__delitem__(name); 2836 } catch (PyException exc) { 2837 if (Py.matchException(exc, Py.KeyError)) 2838 noAttributeError(name); 2839 else 2840 throw exc; 2841 } 2842 return; 2843 } 2844 2845 if (delete) { 2846 descr.__delete__(this); 2847 } 2848 2849 if (descr != null) 2850 readonlyAttributeError(name); 2851 2852 noAttributeError(name); 2853 } 2854 2855 2856 2857 public static class ConversionException extends Exception { 2858 2859 public int index; 2860 2861 public ConversionException(int index) { 2862 this.index = index; 2863 } 2864 2865 } 2866 2867 public String asString(int index) throws ConversionException { 2868 throw new ConversionException(index); 2869 } 2870 2871 public String asStringOrNull(int index) throws ConversionException { 2872 return asString(index); 2873 } 2874 2875 public String asName(int index) throws ConversionException { 2876 throw new ConversionException(index); 2877 } 2878 2879 public int asInt(int index) throws ConversionException { 2880 throw new ConversionException(index); 2881 } 2882 2883 public long asLong(int index) throws ConversionException { 2884 throw new ConversionException(index); 2885 } 2886 2887} 2888 2889 2894 2895class PyIdentityTuple extends PyObject { 2896 2897 PyObject[] list; 2898 2899 public PyIdentityTuple(PyObject elements[]) { 2900 list = elements; 2901 } 2902 2903 public int hashCode() { 2904 int x, y; 2905 int len = list.length; 2906 x = 0x345678; 2907 2908 for (len--; len >= 0; len--) { 2909 y = System.identityHashCode(list[len]); 2910 x = (x + x + x) ^ y; 2911 } 2912 x ^= list.length; 2913 return x; 2914 } 2915 2916 public boolean equals(Object o) { 2917 if (!(o instanceof PyIdentityTuple)) 2918 return false; 2919 PyIdentityTuple that = (PyIdentityTuple) o; 2920 if (list.length != that.list.length) 2921 return false; 2922 for (int i = 0; i < list.length; i++) { 2923 if (list[i] != that.list[i]) 2924 return false; 2925 } 2926 return true; 2927 } 2928 2929} 2930 | Popular Tags |