1 package org.python.core; 3 import java.util.Hashtable ; 4 import java.util.StringTokenizer ; 5 import java.io.Serializable ; 6 7 10 11 public class PyInstance extends PyObject 12 { 13 public transient PyClass instclass; 15 16 public PyObject fastGetClass() { 18 return instclass; 19 } 20 21 Object javaProxy; 23 24 27 public PyObject __dict__; 28 29 30 private void readObject(java.io.ObjectInputStream in) 31 throws java.io.IOException , ClassNotFoundException 32 { 33 in.defaultReadObject(); 34 35 String module = in.readUTF(); 36 String name = in.readUTF(); 37 38 39 PyObject mod = imp.importName(module.intern(), false); 41 PyClass pyc = (PyClass)mod.__getattr__(name.intern()); 42 43 instclass = pyc; 44 if (javaProxy != null) 45 ((PyProxy) javaProxy)._setPySystemState(Py.getSystemState()); 46 } 47 48 private void writeObject(java.io.ObjectOutputStream out) 49 throws java.io.IOException 50 { 51 out.defaultWriteObject(); 53 PyObject name = instclass.__findattr__("__module__"); 54 if (!(name instanceof PyString) || name == Py.None || name == null) { 55 throw Py.ValueError("Can't find module for class: "+ 56 instclass.__name__); 57 } 58 out.writeUTF(name.toString()); 59 name = instclass.__findattr__("__name__"); 60 if (!(name instanceof PyString) || name == Py.None || name == null) { 61 throw Py.ValueError("Can't find module for class with no name"); 62 } 63 64 out.writeUTF(name.toString()); 65 } 66 67 68 71 72 public PyInstance(PyClass iclass, PyObject dict) { 73 instclass = iclass; 74 __dict__ = dict; 75 } 76 77 public PyInstance(PyClass iclass) { 78 this(iclass, new PyStringMap()); 79 } 80 81 public PyInstance() {} 82 83 private static Hashtable primitiveMap; 84 85 protected void makeProxy() { 86 Class c = instclass.proxyClass; 87 PyProxy proxy; 88 ThreadState ts = Py.getThreadState(); 89 try { 90 ts.pushInitializingProxy(this); 91 try { 92 proxy = (PyProxy)c.newInstance(); 93 } catch (java.lang.InstantiationException e) { 94 Class sup = c.getSuperclass(); 95 String msg = "Default constructor failed for Java superclass"; 96 if (sup != null) 97 msg += " " + sup.getName(); 98 throw Py.TypeError(msg); 99 } catch (NoSuchMethodError nsme) { 100 throw Py.TypeError("constructor requires arguments"); 101 } catch (Exception exc) { 102 throw Py.JavaError(exc); 103 } 104 } finally { 105 ts.popInitializingProxy(); 106 } 107 108 if (javaProxy != null && javaProxy != proxy) { 109 throw Py.TypeError("Proxy instance already initialized"); 111 } 112 PyInstance proxyInstance = proxy._getPyInstance(); 113 if (proxyInstance != null && proxyInstance != this) { 114 throw Py.TypeError("Proxy initialization conflict"); 116 } 117 118 javaProxy = proxy; 119 } 120 121 public Object __tojava__(Class c) { 122 if ((c == Object .class || c == Serializable .class) && 123 javaProxy != null) { 124 return javaProxy; 125 } 126 if (c.isInstance(this)) 127 return this; 128 129 if (c.isPrimitive()) { 130 if (primitiveMap == null) { 131 primitiveMap = new Hashtable (); 132 primitiveMap.put(Character.TYPE, Character .class); 133 primitiveMap.put(Boolean.TYPE, Boolean .class); 134 primitiveMap.put(Byte.TYPE, Byte .class); 135 primitiveMap.put(Short.TYPE, Short .class); 136 primitiveMap.put(Integer.TYPE, Integer .class); 137 primitiveMap.put(Long.TYPE, Long .class); 138 primitiveMap.put(Float.TYPE, Float .class); 139 primitiveMap.put(Double.TYPE, Double .class); 140 } 141 Class tmp = (Class )primitiveMap.get(c); 142 if (tmp != null) 143 c = tmp; 144 } 145 146 if (javaProxy == null && instclass.proxyClass != null) { 147 makeProxy(); 148 } 149 if (c.isInstance(javaProxy)) 150 return javaProxy; 151 152 if (instclass.__tojava__ != null) { 153 PyObject ret = 155 instclass.__tojava__.__call__(this, PyJavaClass.lookup(c)); 156 157 if (ret == Py.None) 158 return Py.NoConversion; 159 if (ret != this) 160 return ret.__tojava__(c); 161 165 } 166 return Py.NoConversion; 167 } 168 169 public void __init__(PyObject[] args, String [] keywords) { 170 PyObject init = instclass.lookup("__init__", true); 172 PyObject ret = null; 173 if (init != null) { 174 ret = init.__call__(this, args, keywords); 175 } 176 if (ret == null) { 177 if (args.length != 0) { 178 init = instclass.lookup("__init__", false); 179 if (init != null) { 180 ret = init.__call__(this, args, keywords); 181 } else { 182 throw Py.TypeError("this constructor takes no arguments"); 183 } 184 } 185 } 186 else if (ret != Py.None) { 187 throw Py.TypeError("constructor has no return value"); 188 } 189 if (javaProxy == null && instclass.proxyClass != null) { 191 makeProxy(); 192 } 193 } 194 195 public PyObject __jfindattr__(String name) { 196 return __findattr__(name, true); 198 } 199 200 public PyObject __findattr__(String name) { 201 return __findattr__(name, false); 202 } 203 204 public PyObject __findattr__(String name, boolean stopAtJava) { 205 PyObject result = ifindlocal(name); 206 if (result != null) 207 return result; 208 PyObject[] result2 = instclass.lookupGivingClass(name, stopAtJava); 210 if (result2[0] != null) 211 return result2[0].__get__(this, instclass); 213 return ifindfunction(name); 215 } 216 217 protected PyObject ifindlocal(String name) { 218 if (name == "__dict__") return __dict__; 219 if (name == "__class__") return instclass; 220 if (__dict__ == null) return null; 221 222 return __dict__.__finditem__(name); 223 } 224 225 protected PyObject ifindclass(String name, boolean stopAtJava) { 226 return instclass.lookup(name, stopAtJava); 227 } 228 229 protected PyObject ifindfunction(String name) { 230 PyObject getter = instclass.__getattr__; 231 if (getter == null) 232 return null; 233 234 try { 235 return getter.__call__(this, new PyString(name)); 236 } catch (PyException exc) { 237 if (Py.matchException(exc, Py.AttributeError)) return null; 238 throw exc; 239 } 240 } 241 242 public PyObject invoke(String name) { 243 PyObject f = ifindlocal(name); 244 if (f == null) { 245 f = ifindclass(name, false); 246 if (f != null) { 247 if (f instanceof PyFunction) { 248 return f.__call__(this); 249 } else { 250 f = f.__get__(this, instclass); 251 } 252 } 253 } 254 if (f == null) f = ifindfunction(name); 255 if (f == null) throw Py.AttributeError(name); 256 return f.__call__(); 257 } 258 259 public PyObject invoke(String name, PyObject arg1) { 260 PyObject f = ifindlocal(name); 261 if (f == null) { 262 f = ifindclass(name, false); 263 if (f != null) { 264 if (f instanceof PyFunction) { 265 return f.__call__(this, arg1); 266 } else { 267 f = f.__get__(this, instclass); 268 } 269 } 270 } 271 if (f == null) f = ifindfunction(name); 272 if (f == null) throw Py.AttributeError(name); 273 return f.__call__(arg1); 274 } 275 276 public PyObject invoke(String name, PyObject arg1, PyObject arg2) { 277 PyObject f = ifindlocal(name); 278 if (f == null) { 279 f = ifindclass(name, false); 280 if (f != null) { 281 if (f instanceof PyFunction) { 282 return f.__call__(this, arg1, arg2); 283 } else { 284 f = f.__get__(this, instclass); 285 } 286 } 287 } 288 if (f == null) f = ifindfunction(name); 289 if (f == null) throw Py.AttributeError(name); 290 return f.__call__(arg1, arg2); 291 } 292 293 294 public void __setattr__(String name, PyObject value) { 295 if (name == "__class__") { 296 if (value instanceof PyClass) { 297 instclass = (PyClass)value; 298 } else { 299 throw Py.TypeError("__class__ must be set to a class"); 300 } 301 return; 302 } else if (name == "__dict__") { 303 __dict__ = value; 304 return; 305 } 306 307 PyObject setter = instclass.__setattr__; 308 if (setter != null) { 309 setter.__call__(this, new PyString(name), value); 310 } else { 311 if (instclass.getProxyClass() != null) { 312 PyObject field = instclass.lookup(name, false); 313 if (field == null) { 314 noField(name, value); 315 } else if (!field.jtryset(this, value)) { 316 unassignableField(name, value); 317 } 318 } else { 319 __dict__.__setitem__(name, value); 320 } 321 } 322 } 323 324 protected void noField(String name, PyObject value) { 325 __dict__.__setitem__(name, value); 326 } 327 328 protected void unassignableField(String name, PyObject value) { 329 __dict__.__setitem__(name, value); 330 } 331 332 public void __delattr__(String name) { 333 PyObject deller = instclass.__delattr__; 334 if (deller != null) { 335 deller.__call__(this, new PyString(name)); 336 } else { 337 try { 338 __dict__.__delitem__(name); 339 } catch (PyException exc) { 340 if (Py.matchException(exc, Py.KeyError)) 341 throw Py.AttributeError("class " + instclass.__name__ + 342 " has no attribute '" + name + "'"); 343 }; 344 } 345 } 346 347 public PyObject invoke_ex(String name, PyObject[] args, String [] keywords) 348 { 349 PyObject meth = __findattr__(name); 350 if (meth == null) 351 return null; 352 return meth.__call__(args, keywords); 353 } 354 355 public PyObject invoke_ex(String name) { 356 PyObject meth = __findattr__(name); 357 if (meth == null) 358 return null; 359 return meth.__call__(); 360 } 361 public PyObject invoke_ex(String name, PyObject arg1) { 362 PyObject meth = __findattr__(name); 363 if (meth == null) 364 return null; 365 return meth.__call__(arg1); 366 } 367 public PyObject invoke_ex(String name, PyObject arg1, PyObject arg2) { 368 PyObject meth = __findattr__(name); 369 if (meth == null) 370 return null; 371 return meth.__call__(arg1, arg2); 372 } 373 374 public PyObject __call__(PyObject args[], String keywords[]) { 375 ThreadState ts = Py.getThreadState(); 376 if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) 377 throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); 378 try { 379 return invoke("__call__", args, keywords); 380 } finally { 381 --ts.recursion_depth; 382 } 383 } 384 385 public PyString __repr__() { 386 PyObject ret = invoke_ex("__repr__"); 387 if (ret == null) { 388 PyObject mod = instclass.__dict__.__finditem__("__module__"); 389 String smod; 390 if (mod == Py.None) smod = ""; 391 else { 392 if (mod == null || !(mod instanceof PyString)) 393 smod = "<unknown>."; 394 else 395 smod = ((PyString)mod).toString()+'.'; 396 } 397 return new PyString("<"+smod+instclass.__name__+ 398 " instance "+Py.idstr(this)+">"); 399 } 400 401 if (!(ret instanceof PyString)) 402 throw Py.TypeError("__repr__ method must return a string"); 403 return (PyString)ret; 404 } 405 406 public PyString __str__() { 407 PyObject ret = invoke_ex("__str__"); 408 if (ret == null) 409 return __repr__(); 410 if (!(ret instanceof PyString)) 411 throw Py.TypeError("__str__ method must return a string"); 412 return (PyString)ret; 413 } 414 415 public int hashCode() { 416 PyObject ret; 417 ret = invoke_ex("__hash__"); 418 419 if (ret == null) { 420 if (__findattr__("__eq__") != null || 421 __findattr__("__cmp__") != null) 422 throw Py.TypeError("unhashable instance"); 423 return super.hashCode(); 424 } 425 if (ret instanceof PyInteger) { 426 return ((PyInteger)ret).getValue(); 427 } 428 throw Py.TypeError("__hash__() must return int"); 429 } 430 431 public int __cmp__(PyObject other) { 433 PyObject[] coerced = this._coerce(other); 434 PyObject v; 435 PyObject w; 436 PyObject ret = null; 437 if (coerced != null) { 438 v = coerced[0]; 439 w = coerced[1]; 440 if (!(v instanceof PyInstance) && 441 !(w instanceof PyInstance)) 442 return v._cmp(w); 443 } else { 444 v = this; 445 w = other; 446 } 447 if (v instanceof PyInstance) { 448 ret = ((PyInstance)v).invoke_ex("__cmp__",w); 449 if (ret != null) { 450 if (ret instanceof PyInteger) { 451 int result = ((PyInteger)ret).getValue(); 452 return result < 0 ? -1 : result > 0 ? 1 : 0; 453 } 454 throw Py.TypeError("__cmp__() must return int"); 455 } 456 } 457 if (w instanceof PyInstance) { 458 ret = ((PyInstance)w).invoke_ex("__cmp__",v); 459 if (ret != null) { 460 if (ret instanceof PyInteger) { 461 int result = ((PyInteger)ret).getValue(); 462 return -(result < 0 ? -1 : result > 0 ? 1 : 0); 463 } 464 throw Py.TypeError("__cmp__() must return int"); 465 } 466 467 } 468 return -2; 469 } 470 471 private PyObject invoke_ex_richcmp(String name, PyObject o) { 472 PyObject ret = invoke_ex(name, o); 473 if (ret == Py.NotImplemented) 474 return null; 475 return ret; 476 } 477 478 public PyObject __lt__(PyObject o) { 479 return invoke_ex_richcmp("__lt__", o); 480 } 481 482 public PyObject __le__(PyObject o) { 483 return invoke_ex_richcmp("__le__", o); 484 } 485 486 public PyObject __gt__(PyObject o) { 487 return invoke_ex_richcmp("__gt__", o); 488 } 489 490 public PyObject __ge__(PyObject o) { 491 return invoke_ex_richcmp("__ge__", o); 492 } 493 494 public PyObject __eq__(PyObject o) { 495 return invoke_ex_richcmp("__eq__", o); 496 } 497 498 public PyObject __ne__(PyObject o) { 499 return invoke_ex_richcmp("__ne__", o); 500 } 501 502 public boolean __nonzero__() { 503 PyObject meth = null; 504 try { 505 meth = __findattr__("__nonzero__"); 506 } catch (PyException exc) { } 507 508 if (meth == null) { 509 CollectionProxy proxy = getCollection(); 511 if (proxy != CollectionProxy.NoProxy) { 512 return proxy.__len__() != 0 ? true : false; 513 } 514 try { 515 meth = __findattr__("__len__"); 516 } catch (PyException exc) { } 517 if (meth == null) 518 return true; 519 } 520 521 PyObject ret = meth.__call__(); 522 return ret.__nonzero__(); 523 } 524 525 private CollectionProxy collectionProxy=null; 526 527 private CollectionProxy getCollection() { 528 if (collectionProxy == null) 529 collectionProxy = CollectionProxy.findCollection(javaProxy); 530 return collectionProxy; 531 } 532 533 public int __len__() { 534 CollectionProxy proxy = getCollection(); 535 if (proxy != CollectionProxy.NoProxy) { 536 return proxy.__len__(); 537 } 538 539 PyObject ret = invoke("__len__"); 540 if (ret instanceof PyInteger) 541 return ((PyInteger)ret).getValue(); 542 throw Py.TypeError("__len__() should return an int"); 543 } 544 545 public PyObject __finditem__(int key) { 546 CollectionProxy proxy = getCollection(); 547 if (proxy != CollectionProxy.NoProxy) { 548 return proxy.__finditem__(key); 549 } 550 return __finditem__(new PyInteger(key)); 551 } 552 553 private PyObject trySlice(PyObject key, String name, PyObject extraArg) { 554 if (!(key instanceof PySlice)) 555 return null; 556 557 PySlice slice = (PySlice)key; 558 559 if (slice.step != Py.None && slice.step != Py.One) { 560 if (slice.step instanceof PyInteger) { 561 if (((PyInteger)slice.step).getValue() != 1) { 562 return null; 563 } 564 } else { 565 return null; 566 } 567 } 568 569 PyObject func = __findattr__(name); 570 if (func == null) 571 return null; 572 573 PyObject start = slice.start; 574 PyObject stop = slice.stop; 575 576 if (start == Py.None) 577 start = Py.Zero; 578 if (stop == Py.None) 579 stop = new PyInteger(PySystemState.maxint); 580 581 if (extraArg == null) { 582 return func.__call__(start, stop); 583 } else { 584 return func.__call__(start, stop, extraArg); 585 } 586 } 587 588 public PyObject __finditem__(PyObject key) { 589 CollectionProxy proxy = getCollection(); 590 if (proxy != CollectionProxy.NoProxy) { 591 return proxy.__finditem__(key); 592 } 593 594 try { 595 PyObject ret = trySlice(key, "__getslice__", null); 596 if (ret != null) 597 return ret; 598 599 return invoke("__getitem__", key); 600 } catch (PyException e) { 601 if (Py.matchException(e, Py.IndexError)) 602 return null; 603 throw e; 604 } 605 } 606 607 public PyObject __getitem__(PyObject key) { 608 CollectionProxy proxy = getCollection(); 609 if (proxy != CollectionProxy.NoProxy) { 610 PyObject ret = proxy.__finditem__(key); 611 if (ret == null) { 612 throw Py.KeyError(key.toString()); 613 } 614 return ret; 615 } 616 617 PyObject ret = trySlice(key, "__getslice__", null); 618 if (ret != null) 619 return ret; 620 621 return invoke("__getitem__", key); 622 } 623 624 public void __setitem__(PyObject key, PyObject value) { 625 CollectionProxy proxy = getCollection(); 626 if (proxy != CollectionProxy.NoProxy) { 627 proxy.__setitem__(key, value); 628 return; 629 } 630 if (trySlice(key, "__setslice__", value) != null) 631 return; 632 633 invoke("__setitem__", key, value); 634 } 635 636 public void __delitem__(PyObject key) { 637 CollectionProxy proxy = getCollection(); 638 if (proxy != CollectionProxy.NoProxy) { 639 proxy.__delitem__(key); 640 return; 641 } 642 if (trySlice(key, "__delslice__", null) != null) 643 return; 644 invoke("__delitem__", key); 645 } 646 647 public PyObject __iter__() { 648 PyObject iter = getCollectionIter(); 649 if (iter != null) { 650 return iter; 651 } 652 PyObject func = __findattr__("__iter__"); 653 if (func != null) 654 return func.__call__(); 655 func = __findattr__("__getitem__"); 656 if (func == null) 657 return super.__iter__(); 658 return new PySequenceIter(this); 659 } 660 661 public PyObject __iternext__() { 662 PyObject func = __findattr__("next"); 663 if (func != null) { 664 try { 665 return func.__call__(); 666 } catch (PyException exc) { 667 if (Py.matchException(exc, Py.StopIteration)) 668 return null; 669 throw exc; 670 } 671 } 672 throw Py.TypeError("instance has no next() method"); 673 } 674 675 private static CollectionIter[] iterFactories = null; 676 677 private PyObject getCollectionIter() { 678 if (iterFactories == null) 679 initializeIterators(); 680 for (int i = 0; iterFactories[i] != null; i++) { 681 PyObject iter = iterFactories[i].findCollection(javaProxy); 682 if (iter != null) 683 return iter; 684 } 685 return null; 686 } 687 688 private static synchronized void initializeIterators() { 689 if (iterFactories != null) 690 return; 691 String factories = "org.python.core.CollectionIter," + 692 "org.python.core.CollectionIter2," + 693 Py.getSystemState().registry.getProperty( 694 "python.collections", ""); 695 int i = 0; 696 StringTokenizer st = new StringTokenizer (factories, ","); 697 iterFactories = new CollectionIter[st.countTokens() + 1]; 698 while (st.hasMoreTokens()) { 699 String s = st.nextToken(); 700 try { 701 Class factoryClass = Class.forName(s); 702 CollectionIter factory = 703 (CollectionIter)factoryClass.newInstance(); 704 iterFactories[i++] = factory; 705 } catch (Throwable t) { } 706 } 707 } 708 709 public boolean __contains__(PyObject o) { 710 PyObject func = __findattr__("__contains__"); 711 if (func == null) 712 return super.__contains__(o); 713 PyObject ret = func.__call__(o); 714 return ret.__nonzero__(); 715 } 716 717 public Object __coerce_ex__(PyObject o) { 719 PyObject ret = invoke_ex("__coerce__", o); 720 if (ret == null || ret == Py.None) 721 return ret; 722 if (!(ret instanceof PyTuple)) 723 throw Py.TypeError("coercion should return None or 2-tuple"); 724 return ((PyTuple)ret).getArray(); 725 } 726 727 728 730 732 736 public PyString __hex__() { 737 PyObject ret = invoke("__hex__"); 738 if (ret instanceof PyString) 739 return (PyString)ret; 740 throw Py.TypeError("__hex__() should return a string"); 741 } 742 743 747 public PyString __oct__() { 748 PyObject ret = invoke("__oct__"); 749 if (ret instanceof PyString) 750 return (PyString)ret; 751 throw Py.TypeError("__oct__() should return a string"); 752 } 753 754 758 public PyObject __int__() { 759 PyObject ret = invoke("__int__"); 760 if (ret instanceof PyInteger) 761 return (PyInteger)ret; 762 throw Py.TypeError("__int__() should return a int"); 763 } 764 765 769 public PyFloat __float__() { 770 PyObject ret = invoke("__float__"); 771 if (ret instanceof PyFloat) 772 return (PyFloat)ret; 773 throw Py.TypeError("__float__() should return a float"); 774 } 775 776 780 public PyLong __long__() { 781 PyObject ret = invoke("__long__"); 782 if (ret instanceof PyLong) 783 return (PyLong)ret; 784 throw Py.TypeError("__long__() should return a long"); 785 } 786 787 791 public PyComplex __complex__() { 792 PyObject ret = invoke("__complex__"); 793 if (ret instanceof PyComplex) 794 return (PyComplex)ret; 795 throw Py.TypeError("__complex__() should return a complex"); 796 } 797 798 802 public PyObject __pos__() { 803 return invoke("__pos__"); 804 } 805 806 810 public PyObject __neg__() { 811 return invoke("__neg__"); 812 } 813 814 818 public PyObject __abs__() { 819 return invoke("__abs__"); 820 } 821 822 826 public PyObject __invert__() { 827 return invoke("__invert__"); 828 } 829 830 832 836 public PyObject __add__(PyObject o) { 837 Object ctmp = __coerce_ex__(o); 838 if (ctmp == null || ctmp == Py.None) 839 return invoke_ex("__add__", o); 840 else { 841 PyObject o1 = ((PyObject[])ctmp)[0]; 842 PyObject o2 = ((PyObject[])ctmp)[1]; 843 if (this == o1) return invoke_ex("__add__", o2); 845 else 846 return o1._add(o2); 847 } 848 } 849 850 854 public PyObject __radd__(PyObject o) { 855 Object ctmp = __coerce_ex__(o); 856 if (ctmp == null || ctmp == Py.None) 857 return invoke_ex("__radd__", o); 858 else { 859 PyObject o1 = ((PyObject[])ctmp)[0]; 860 PyObject o2 = ((PyObject[])ctmp)[1]; 861 if (this == o1) return invoke_ex("__radd__", o2); 863 else 864 return o2._add(o1); 865 } 866 } 867 868 872 public PyObject __iadd__(PyObject o) { 873 PyObject ret = invoke_ex("__iadd__", o); 874 if (ret != null) 875 return ret; 876 return super.__iadd__(o); 877 } 878 879 883 public PyObject __sub__(PyObject o) { 884 Object ctmp = __coerce_ex__(o); 885 if (ctmp == null || ctmp == Py.None) 886 return invoke_ex("__sub__", o); 887 else { 888 PyObject o1 = ((PyObject[])ctmp)[0]; 889 PyObject o2 = ((PyObject[])ctmp)[1]; 890 if (this == o1) return invoke_ex("__sub__", o2); 892 else 893 return o1._sub(o2); 894 } 895 } 896 897 901 public PyObject __rsub__(PyObject o) { 902 Object ctmp = __coerce_ex__(o); 903 if (ctmp == null || ctmp == Py.None) 904 return invoke_ex("__rsub__", o); 905 else { 906 PyObject o1 = ((PyObject[])ctmp)[0]; 907 PyObject o2 = ((PyObject[])ctmp)[1]; 908 if (this == o1) return invoke_ex("__rsub__", o2); 910 else 911 return o2._sub(o1); 912 } 913 } 914 915 919 public PyObject __isub__(PyObject o) { 920 PyObject ret = invoke_ex("__isub__", o); 921 if (ret != null) 922 return ret; 923 return super.__isub__(o); 924 } 925 926 930 public PyObject __mul__(PyObject o) { 931 Object ctmp = __coerce_ex__(o); 932 if (ctmp == null || ctmp == Py.None) 933 return invoke_ex("__mul__", o); 934 else { 935 PyObject o1 = ((PyObject[])ctmp)[0]; 936 PyObject o2 = ((PyObject[])ctmp)[1]; 937 if (this == o1) return invoke_ex("__mul__", o2); 939 else 940 return o1._mul(o2); 941 } 942 } 943 944 948 public PyObject __rmul__(PyObject o) { 949 Object ctmp = __coerce_ex__(o); 950 if (ctmp == null || ctmp == Py.None) 951 return invoke_ex("__rmul__", o); 952 else { 953 PyObject o1 = ((PyObject[])ctmp)[0]; 954 PyObject o2 = ((PyObject[])ctmp)[1]; 955 if (this == o1) return invoke_ex("__rmul__", o2); 957 else 958 return o2._mul(o1); 959 } 960 } 961 962 966 public PyObject __imul__(PyObject o) { 967 PyObject ret = invoke_ex("__imul__", o); 968 if (ret != null) 969 return ret; 970 return super.__imul__(o); 971 } 972 973 977 public PyObject __div__(PyObject o) { 978 Object ctmp = __coerce_ex__(o); 979 if (ctmp == null || ctmp == Py.None) 980 return invoke_ex("__div__", o); 981 else { 982 PyObject o1 = ((PyObject[])ctmp)[0]; 983 PyObject o2 = ((PyObject[])ctmp)[1]; 984 if (this == o1) return invoke_ex("__div__", o2); 986 else 987 return o1._div(o2); 988 } 989 } 990 991 995 public PyObject __rdiv__(PyObject o) { 996 Object ctmp = __coerce_ex__(o); 997 if (ctmp == null || ctmp == Py.None) 998 return invoke_ex("__rdiv__", o); 999 else { 1000 PyObject o1 = ((PyObject[])ctmp)[0]; 1001 PyObject o2 = ((PyObject[])ctmp)[1]; 1002 if (this == o1) return invoke_ex("__rdiv__", o2); 1004 else 1005 return o2._div(o1); 1006 } 1007 } 1008 1009 1013 public PyObject __idiv__(PyObject o) { 1014 PyObject ret = invoke_ex("__idiv__", o); 1015 if (ret != null) 1016 return ret; 1017 return super.__idiv__(o); 1018 } 1019 1020 1024 public PyObject __floordiv__(PyObject o) { 1025 Object ctmp = __coerce_ex__(o); 1026 if (ctmp == null || ctmp == Py.None) 1027 return invoke_ex("__floordiv__", o); 1028 else { 1029 PyObject o1 = ((PyObject[])ctmp)[0]; 1030 PyObject o2 = ((PyObject[])ctmp)[1]; 1031 if (this == o1) return invoke_ex("__floordiv__", o2); 1033 else 1034 return o1._floordiv(o2); 1035 } 1036 } 1037 1038 1042 public PyObject __rfloordiv__(PyObject o) { 1043 Object ctmp = __coerce_ex__(o); 1044 if (ctmp == null || ctmp == Py.None) 1045 return invoke_ex("__rfloordiv__", o); 1046 else { 1047 PyObject o1 = ((PyObject[])ctmp)[0]; 1048 PyObject o2 = ((PyObject[])ctmp)[1]; 1049 if (this == o1) return invoke_ex("__rfloordiv__", o2); 1051 else 1052 return o2._floordiv(o1); 1053 } 1054 } 1055 1056 1060 public PyObject __ifloordiv__(PyObject o) { 1061 PyObject ret = invoke_ex("__ifloordiv__", o); 1062 if (ret != null) 1063 return ret; 1064 return super.__ifloordiv__(o); 1065 } 1066 1067 1071 public PyObject __truediv__(PyObject o) { 1072 Object ctmp = __coerce_ex__(o); 1073 if (ctmp == null || ctmp == Py.None) 1074 return invoke_ex("__truediv__", o); 1075 else { 1076 PyObject o1 = ((PyObject[])ctmp)[0]; 1077 PyObject o2 = ((PyObject[])ctmp)[1]; 1078 if (this == o1) return invoke_ex("__truediv__", o2); 1080 else 1081 return o1._truediv(o2); 1082 } 1083 } 1084 1085 1089 public PyObject __rtruediv__(PyObject o) { 1090 Object ctmp = __coerce_ex__(o); 1091 if (ctmp == null || ctmp == Py.None) 1092 return invoke_ex("__rtruediv__", o); 1093 else { 1094 PyObject o1 = ((PyObject[])ctmp)[0]; 1095 PyObject o2 = ((PyObject[])ctmp)[1]; 1096 if (this == o1) return invoke_ex("__rtruediv__", o2); 1098 else 1099 return o2._truediv(o1); 1100 } 1101 } 1102 1103 1107 public PyObject __itruediv__(PyObject o) { 1108 PyObject ret = invoke_ex("__itruediv__", o); 1109 if (ret != null) 1110 return ret; 1111 return super.__itruediv__(o); 1112 } 1113 1114 1118 public PyObject __mod__(PyObject o) { 1119 Object ctmp = __coerce_ex__(o); 1120 if (ctmp == null || ctmp == Py.None) 1121 return invoke_ex("__mod__", o); 1122 else { 1123 PyObject o1 = ((PyObject[])ctmp)[0]; 1124 PyObject o2 = ((PyObject[])ctmp)[1]; 1125 if (this == o1) return invoke_ex("__mod__", o2); 1127 else 1128 return o1._mod(o2); 1129 } 1130 } 1131 1132 1136 public PyObject __rmod__(PyObject o) { 1137 Object ctmp = __coerce_ex__(o); 1138 if (ctmp == null || ctmp == Py.None) 1139 return invoke_ex("__rmod__", o); 1140 else { 1141 PyObject o1 = ((PyObject[])ctmp)[0]; 1142 PyObject o2 = ((PyObject[])ctmp)[1]; 1143 if (this == o1) return invoke_ex("__rmod__", o2); 1145 else 1146 return o2._mod(o1); 1147 } 1148 } 1149 1150 1154 public PyObject __imod__(PyObject o) { 1155 PyObject ret = invoke_ex("__imod__", o); 1156 if (ret != null) 1157 return ret; 1158 return super.__imod__(o); 1159 } 1160 1161 1165 public PyObject __divmod__(PyObject o) { 1166 Object ctmp = __coerce_ex__(o); 1167 if (ctmp == null || ctmp == Py.None) 1168 return invoke_ex("__divmod__", o); 1169 else { 1170 PyObject o1 = ((PyObject[])ctmp)[0]; 1171 PyObject o2 = ((PyObject[])ctmp)[1]; 1172 if (this == o1) return invoke_ex("__divmod__", o2); 1174 else 1175 return o1._divmod(o2); 1176 } 1177 } 1178 1179 1183 public PyObject __rdivmod__(PyObject o) { 1184 Object ctmp = __coerce_ex__(o); 1185 if (ctmp == null || ctmp == Py.None) 1186 return invoke_ex("__rdivmod__", o); 1187 else { 1188 PyObject o1 = ((PyObject[])ctmp)[0]; 1189 PyObject o2 = ((PyObject[])ctmp)[1]; 1190 if (this == o1) return invoke_ex("__rdivmod__", o2); 1192 else 1193 return o2._divmod(o1); 1194 } 1195 } 1196 1197 1201 public PyObject __pow__(PyObject o) { 1202 Object ctmp = __coerce_ex__(o); 1203 if (ctmp == null || ctmp == Py.None) 1204 return invoke_ex("__pow__", o); 1205 else { 1206 PyObject o1 = ((PyObject[])ctmp)[0]; 1207 PyObject o2 = ((PyObject[])ctmp)[1]; 1208 if (this == o1) return invoke_ex("__pow__", o2); 1210 else 1211 return o1._pow(o2); 1212 } 1213 } 1214 1215 1219 public PyObject __rpow__(PyObject o) { 1220 Object ctmp = __coerce_ex__(o); 1221 if (ctmp == null || ctmp == Py.None) 1222 return invoke_ex("__rpow__", o); 1223 else { 1224 PyObject o1 = ((PyObject[])ctmp)[0]; 1225 PyObject o2 = ((PyObject[])ctmp)[1]; 1226 if (this == o1) return invoke_ex("__rpow__", o2); 1228 else 1229 return o2._pow(o1); 1230 } 1231 } 1232 1233 1237 public PyObject __ipow__(PyObject o) { 1238 PyObject ret = invoke_ex("__ipow__", o); 1239 if (ret != null) 1240 return ret; 1241 return super.__ipow__(o); 1242 } 1243 1244 1248 public PyObject __lshift__(PyObject o) { 1249 Object ctmp = __coerce_ex__(o); 1250 if (ctmp == null || ctmp == Py.None) 1251 return invoke_ex("__lshift__", o); 1252 else { 1253 PyObject o1 = ((PyObject[])ctmp)[0]; 1254 PyObject o2 = ((PyObject[])ctmp)[1]; 1255 if (this == o1) return invoke_ex("__lshift__", o2); 1257 else 1258 return o1._lshift(o2); 1259 } 1260 } 1261 1262 1266 public PyObject __rlshift__(PyObject o) { 1267 Object ctmp = __coerce_ex__(o); 1268 if (ctmp == null || ctmp == Py.None) 1269 return invoke_ex("__rlshift__", o); 1270 else { 1271 PyObject o1 = ((PyObject[])ctmp)[0]; 1272 PyObject o2 = ((PyObject[])ctmp)[1]; 1273 if (this == o1) return invoke_ex("__rlshift__", o2); 1275 else 1276 return o2._lshift(o1); 1277 } 1278 } 1279 1280 1284 public PyObject __ilshift__(PyObject o) { 1285 PyObject ret = invoke_ex("__ilshift__", o); 1286 if (ret != null) 1287 return ret; 1288 return super.__ilshift__(o); 1289 } 1290 1291 1295 public PyObject __rshift__(PyObject o) { 1296 Object ctmp = __coerce_ex__(o); 1297 if (ctmp == null || ctmp == Py.None) 1298 return invoke_ex("__rshift__", o); 1299 else { 1300 PyObject o1 = ((PyObject[])ctmp)[0]; 1301 PyObject o2 = ((PyObject[])ctmp)[1]; 1302 if (this == o1) return invoke_ex("__rshift__", o2); 1304 else 1305 return o1._rshift(o2); 1306 } 1307 } 1308 1309 1313 public PyObject __rrshift__(PyObject o) { 1314 Object ctmp = __coerce_ex__(o); 1315 if (ctmp == null || ctmp == Py.None) 1316 return invoke_ex("__rrshift__", o); 1317 else { 1318 PyObject o1 = ((PyObject[])ctmp)[0]; 1319 PyObject o2 = ((PyObject[])ctmp)[1]; 1320 if (this == o1) return invoke_ex("__rrshift__", o2); 1322 else 1323 return o2._rshift(o1); 1324 } 1325 } 1326 1327 1331 public PyObject __irshift__(PyObject o) { 1332 PyObject ret = invoke_ex("__irshift__", o); 1333 if (ret != null) 1334 return ret; 1335 return super.__irshift__(o); 1336 } 1337 1338 1342 public PyObject __and__(PyObject o) { 1343 Object ctmp = __coerce_ex__(o); 1344 if (ctmp == null || ctmp == Py.None) 1345 return invoke_ex("__and__", o); 1346 else { 1347 PyObject o1 = ((PyObject[])ctmp)[0]; 1348 PyObject o2 = ((PyObject[])ctmp)[1]; 1349 if (this == o1) return invoke_ex("__and__", o2); 1351 else 1352 return o1._and(o2); 1353 } 1354 } 1355 1356 1360 public PyObject __rand__(PyObject o) { 1361 Object ctmp = __coerce_ex__(o); 1362 if (ctmp == null || ctmp == Py.None) 1363 return invoke_ex("__rand__", o); 1364 else { 1365 PyObject o1 = ((PyObject[])ctmp)[0]; 1366 PyObject o2 = ((PyObject[])ctmp)[1]; 1367 if (this == o1) return invoke_ex("__rand__", o2); 1369 else 1370 return o2._and(o1); 1371 } 1372 } 1373 1374 1378 public PyObject __iand__(PyObject o) { 1379 PyObject ret = invoke_ex("__iand__", o); 1380 if (ret != null) 1381 return ret; 1382 return super.__iand__(o); 1383 } 1384 1385 1389 public PyObject __or__(PyObject o) { 1390 Object ctmp = __coerce_ex__(o); 1391 if (ctmp == null || ctmp == Py.None) 1392 return invoke_ex("__or__", o); 1393 else { 1394 PyObject o1 = ((PyObject[])ctmp)[0]; 1395 PyObject o2 = ((PyObject[])ctmp)[1]; 1396 if (this == o1) return invoke_ex("__or__", o2); 1398 else 1399 return o1._or(o2); 1400 } 1401 } 1402 1403 1407 public PyObject __ror__(PyObject o) { 1408 Object ctmp = __coerce_ex__(o); 1409 if (ctmp == null || ctmp == Py.None) 1410 return invoke_ex("__ror__", o); 1411 else { 1412 PyObject o1 = ((PyObject[])ctmp)[0]; 1413 PyObject o2 = ((PyObject[])ctmp)[1]; 1414 if (this == o1) return invoke_ex("__ror__", o2); 1416 else 1417 return o2._or(o1); 1418 } 1419 } 1420 1421 1425 public PyObject __ior__(PyObject o) { 1426 PyObject ret = invoke_ex("__ior__", o); 1427 if (ret != null) 1428 return ret; 1429 return super.__ior__(o); 1430 } 1431 1432 1436 public PyObject __xor__(PyObject o) { 1437 Object ctmp = __coerce_ex__(o); 1438 if (ctmp == null || ctmp == Py.None) 1439 return invoke_ex("__xor__", o); 1440 else { 1441 PyObject o1 = ((PyObject[])ctmp)[0]; 1442 PyObject o2 = ((PyObject[])ctmp)[1]; 1443 if (this == o1) return invoke_ex("__xor__", o2); 1445 else 1446 return o1._xor(o2); 1447 } 1448 } 1449 1450 1454 public PyObject __rxor__(PyObject o) { 1455 Object ctmp = __coerce_ex__(o); 1456 if (ctmp == null || ctmp == Py.None) 1457 return invoke_ex("__rxor__", o); 1458 else { 1459 PyObject o1 = ((PyObject[])ctmp)[0]; 1460 PyObject o2 = ((PyObject[])ctmp)[1]; 1461 if (this == o1) return invoke_ex("__rxor__", o2); 1463 else 1464 return o2._xor(o1); 1465 } 1466 } 1467 1468 1472 public PyObject __ixor__(PyObject o) { 1473 PyObject ret = invoke_ex("__ixor__", o); 1474 if (ret != null) 1475 return ret; 1476 return super.__ixor__(o); 1477 } 1478 1479} 1480 | Popular Tags |