1 package org.python.core; 3 4 import java.util.Hashtable ; 5 import java.util.Enumeration ; 6 7 10 11 public class PyDictionary extends PyObject { 12 13 14 15 public static final String exposed_name="dict"; 16 17 public static void typeSetup(PyObject dict,PyType.Newstyle marker) { 18 class exposed___ne__ extends PyBuiltinFunctionNarrow { 19 20 private PyDictionary self; 21 22 public PyObject getSelf() { 23 return self; 24 } 25 26 exposed___ne__(PyDictionary self,PyBuiltinFunction.Info info) { 27 super(info); 28 this.self=self; 29 } 30 31 public PyBuiltinFunction makeBound(PyObject self) { 32 return new exposed___ne__((PyDictionary)self,info); 33 } 34 35 public PyObject __call__(PyObject arg0) { 36 PyObject ret=self.dict___ne__(arg0); 37 if (ret==null) 38 return Py.NotImplemented; 39 return ret; 40 } 41 42 public PyObject inst_call(PyObject gself,PyObject arg0) { 43 PyDictionary self=(PyDictionary)gself; 44 PyObject ret=self.dict___ne__(arg0); 45 if (ret==null) 46 return Py.NotImplemented; 47 return ret; 48 } 49 50 } 51 dict.__setitem__("__ne__",new PyMethodDescr("__ne__",PyDictionary.class,1,1,new exposed___ne__(null,null))); 52 class exposed___eq__ extends PyBuiltinFunctionNarrow { 53 54 private PyDictionary self; 55 56 public PyObject getSelf() { 57 return self; 58 } 59 60 exposed___eq__(PyDictionary self,PyBuiltinFunction.Info info) { 61 super(info); 62 this.self=self; 63 } 64 65 public PyBuiltinFunction makeBound(PyObject self) { 66 return new exposed___eq__((PyDictionary)self,info); 67 } 68 69 public PyObject __call__(PyObject arg0) { 70 PyObject ret=self.dict___eq__(arg0); 71 if (ret==null) 72 return Py.NotImplemented; 73 return ret; 74 } 75 76 public PyObject inst_call(PyObject gself,PyObject arg0) { 77 PyDictionary self=(PyDictionary)gself; 78 PyObject ret=self.dict___eq__(arg0); 79 if (ret==null) 80 return Py.NotImplemented; 81 return ret; 82 } 83 84 } 85 dict.__setitem__("__eq__",new PyMethodDescr("__eq__",PyDictionary.class,1,1,new exposed___eq__(null,null))); 86 class exposed___cmp__ extends PyBuiltinFunctionNarrow { 87 88 private PyDictionary self; 89 90 public PyObject getSelf() { 91 return self; 92 } 93 94 exposed___cmp__(PyDictionary self,PyBuiltinFunction.Info info) { 95 super(info); 96 this.self=self; 97 } 98 99 public PyBuiltinFunction makeBound(PyObject self) { 100 return new exposed___cmp__((PyDictionary)self,info); 101 } 102 103 public PyObject __call__(PyObject arg0) { 104 int ret=self.dict___cmp__(arg0); 105 if (ret==-2) { 106 throw Py.TypeError("dict"+".__cmp__(x,y) requires y to be '"+"dict"+"', not a '"+(arg0).getType().fastGetName()+"'"); 107 } 108 return Py.newInteger(ret); 109 } 110 111 public PyObject inst_call(PyObject gself,PyObject arg0) { 112 PyDictionary self=(PyDictionary)gself; 113 int ret=self.dict___cmp__(arg0); 114 if (ret==-2) { 115 throw Py.TypeError("dict"+".__cmp__(x,y) requires y to be '"+"dict"+"', not a '"+(arg0).getType().fastGetName()+"'"); 116 } 117 return Py.newInteger(ret); 118 } 119 120 } 121 dict.__setitem__("__cmp__",new PyMethodDescr("__cmp__",PyDictionary.class,1,1,new exposed___cmp__(null,null))); 122 class exposed_fromkeys extends PyBuiltinFunctionNarrow { 123 124 private PyDictionary self; 125 126 public PyObject getSelf() { 127 return self; 128 } 129 130 exposed_fromkeys(PyDictionary self,PyBuiltinFunction.Info info) { 131 super(info); 132 this.self=self; 133 } 134 135 public PyBuiltinFunction makeBound(PyObject self) { 136 return new exposed_fromkeys((PyDictionary)self,info); 137 } 138 139 public PyObject __call__(PyObject arg0,PyObject arg1) { 140 return self.dict_fromkeys(arg0,arg1); 141 } 142 143 public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { 144 PyDictionary self=(PyDictionary)gself; 145 return self.dict_fromkeys(arg0,arg1); 146 } 147 148 public PyObject __call__(PyObject arg0) { 149 return self.dict_fromkeys(arg0); 150 } 151 152 public PyObject inst_call(PyObject gself,PyObject arg0) { 153 PyDictionary self=(PyDictionary)gself; 154 return self.dict_fromkeys(arg0); 155 } 156 157 } 158 dict.__setitem__("fromkeys",new PyMethodDescr("fromkeys",PyDictionary.class,1,2,new exposed_fromkeys(null,null))); 159 160 161 class exposed___getitem__ extends PyBuiltinFunctionNarrow { 162 163 private PyDictionary self; 164 165 public PyObject getSelf() { 166 return self; 167 } 168 169 exposed___getitem__(PyDictionary self,PyBuiltinFunction.Info info) { 170 super(info); 171 this.self=self; 172 } 173 174 public PyBuiltinFunction makeBound(PyObject self) { 175 return new exposed___getitem__((PyDictionary)self,info); 176 } 177 178 public PyObject __call__(PyObject arg0) { 179 PyObject ret=self.dict___finditem__(arg0); 180 if (ret==null) 181 throw Py.KeyError(arg0.toString()); 182 return ret; 183 } 184 185 public PyObject inst_call(PyObject gself,PyObject arg0) { 186 PyDictionary self=(PyDictionary)gself; 187 PyObject ret=self.dict___finditem__(arg0); 188 if (ret==null) 189 throw Py.KeyError(arg0.toString()); 190 return ret; 191 } 192 193 } 194 dict.__setitem__("__getitem__",new PyMethodDescr("__getitem__",PyDictionary.class,1,1,new exposed___getitem__(null,null))); 195 class exposed_get extends PyBuiltinFunctionNarrow { 196 197 private PyDictionary self; 198 199 public PyObject getSelf() { 200 return self; 201 } 202 203 exposed_get(PyDictionary self,PyBuiltinFunction.Info info) { 204 super(info); 205 this.self=self; 206 } 207 208 public PyBuiltinFunction makeBound(PyObject self) { 209 return new exposed_get((PyDictionary)self,info); 210 } 211 212 public PyObject __call__(PyObject arg0,PyObject arg1) { 213 return self.dict_get(arg0,arg1); 214 } 215 216 public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { 217 PyDictionary self=(PyDictionary)gself; 218 return self.dict_get(arg0,arg1); 219 } 220 221 public PyObject __call__(PyObject arg0) { 222 return self.dict_get(arg0); 223 } 224 225 public PyObject inst_call(PyObject gself,PyObject arg0) { 226 PyDictionary self=(PyDictionary)gself; 227 return self.dict_get(arg0); 228 } 229 230 } 231 dict.__setitem__("get",new PyMethodDescr("get",PyDictionary.class,1,2,new exposed_get(null,null))); 232 class exposed_setdefault extends PyBuiltinFunctionNarrow { 233 234 private PyDictionary self; 235 236 public PyObject getSelf() { 237 return self; 238 } 239 240 exposed_setdefault(PyDictionary self,PyBuiltinFunction.Info info) { 241 super(info); 242 this.self=self; 243 } 244 245 public PyBuiltinFunction makeBound(PyObject self) { 246 return new exposed_setdefault((PyDictionary)self,info); 247 } 248 249 public PyObject __call__(PyObject arg0,PyObject arg1) { 250 return self.dict_setdefault(arg0,arg1); 251 } 252 253 public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { 254 PyDictionary self=(PyDictionary)gself; 255 return self.dict_setdefault(arg0,arg1); 256 } 257 258 public PyObject __call__(PyObject arg0) { 259 return self.dict_setdefault(arg0); 260 } 261 262 public PyObject inst_call(PyObject gself,PyObject arg0) { 263 PyDictionary self=(PyDictionary)gself; 264 return self.dict_setdefault(arg0); 265 } 266 267 } 268 dict.__setitem__("setdefault",new PyMethodDescr("setdefault",PyDictionary.class,1,2,new exposed_setdefault(null,null))); 269 class exposed_pop extends PyBuiltinFunctionNarrow { 270 271 private PyDictionary self; 272 273 public PyObject getSelf() { 274 return self; 275 } 276 277 exposed_pop(PyDictionary self,PyBuiltinFunction.Info info) { 278 super(info); 279 this.self=self; 280 } 281 282 public PyBuiltinFunction makeBound(PyObject self) { 283 return new exposed_pop((PyDictionary)self,info); 284 } 285 286 public PyObject __call__(PyObject arg0,PyObject arg1) { 287 return self.dict_pop(arg0,arg1); 288 } 289 290 public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { 291 PyDictionary self=(PyDictionary)gself; 292 return self.dict_pop(arg0,arg1); 293 } 294 295 public PyObject __call__(PyObject arg0) { 296 return self.dict_pop(arg0); 297 } 298 299 public PyObject inst_call(PyObject gself,PyObject arg0) { 300 PyDictionary self=(PyDictionary)gself; 301 return self.dict_pop(arg0); 302 } 303 304 } 305 dict.__setitem__("pop",new PyMethodDescr("pop",PyDictionary.class,1,2,new exposed_pop(null,null))); 306 307 class exposed_popitem extends PyBuiltinFunctionNarrow { 308 309 private PyDictionary self; 310 311 public PyObject getSelf() { 312 return self; 313 } 314 315 exposed_popitem(PyDictionary self,PyBuiltinFunction.Info info) { 316 super(info); 317 this.self=self; 318 } 319 320 public PyBuiltinFunction makeBound(PyObject self) { 321 return new exposed_popitem((PyDictionary)self,info); 322 } 323 324 public PyObject __call__() { 325 return self.dict_popitem(); 326 } 327 328 public PyObject inst_call(PyObject gself) { 329 PyDictionary self=(PyDictionary)gself; 330 return self.dict_popitem(); 331 } 332 333 } 334 dict.__setitem__("popitem",new PyMethodDescr("popitem",PyDictionary.class,0,0,new exposed_popitem(null,null))); 335 class exposed_has_key extends PyBuiltinFunctionNarrow { 336 337 private PyDictionary self; 338 339 public PyObject getSelf() { 340 return self; 341 } 342 343 exposed_has_key(PyDictionary self,PyBuiltinFunction.Info info) { 344 super(info); 345 this.self=self; 346 } 347 348 public PyBuiltinFunction makeBound(PyObject self) { 349 return new exposed_has_key((PyDictionary)self,info); 350 } 351 352 public PyObject __call__(PyObject arg0) { 353 return Py.newBoolean(self.dict_has_key(arg0)); 354 } 355 356 public PyObject inst_call(PyObject gself,PyObject arg0) { 357 PyDictionary self=(PyDictionary)gself; 358 return Py.newBoolean(self.dict_has_key(arg0)); 359 } 360 361 } 362 dict.__setitem__("has_key",new PyMethodDescr("has_key",PyDictionary.class,1,1,new exposed_has_key(null,null))); 363 class exposed___contains__ extends PyBuiltinFunctionNarrow { 364 365 private PyDictionary self; 366 367 public PyObject getSelf() { 368 return self; 369 } 370 371 exposed___contains__(PyDictionary self,PyBuiltinFunction.Info info) { 372 super(info); 373 this.self=self; 374 } 375 376 public PyBuiltinFunction makeBound(PyObject self) { 377 return new exposed___contains__((PyDictionary)self,info); 378 } 379 380 public PyObject __call__(PyObject arg0) { 381 return Py.newBoolean(self.dict___contains__(arg0)); 382 } 383 384 public PyObject inst_call(PyObject gself,PyObject arg0) { 385 PyDictionary self=(PyDictionary)gself; 386 return Py.newBoolean(self.dict___contains__(arg0)); 387 } 388 389 } 390 dict.__setitem__("__contains__",new PyMethodDescr("__contains__",PyDictionary.class,1,1,new exposed___contains__(null,null))); 391 class exposed___len__ extends PyBuiltinFunctionNarrow { 392 393 private PyDictionary self; 394 395 public PyObject getSelf() { 396 return self; 397 } 398 399 exposed___len__(PyDictionary self,PyBuiltinFunction.Info info) { 400 super(info); 401 this.self=self; 402 } 403 404 public PyBuiltinFunction makeBound(PyObject self) { 405 return new exposed___len__((PyDictionary)self,info); 406 } 407 408 public PyObject __call__() { 409 return Py.newInteger(self.dict___len__()); 410 } 411 412 public PyObject inst_call(PyObject gself) { 413 PyDictionary self=(PyDictionary)gself; 414 return Py.newInteger(self.dict___len__()); 415 } 416 417 } 418 dict.__setitem__("__len__",new PyMethodDescr("__len__",PyDictionary.class,0,0,new exposed___len__(null,null))); 419 class exposed___setitem__ extends PyBuiltinFunctionNarrow { 420 421 private PyDictionary self; 422 423 public PyObject getSelf() { 424 return self; 425 } 426 427 exposed___setitem__(PyDictionary self,PyBuiltinFunction.Info info) { 428 super(info); 429 this.self=self; 430 } 431 432 public PyBuiltinFunction makeBound(PyObject self) { 433 return new exposed___setitem__((PyDictionary)self,info); 434 } 435 436 public PyObject __call__(PyObject arg0,PyObject arg1) { 437 self.dict___setitem__(arg0,arg1); 438 return Py.None; 439 } 440 441 public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { 442 PyDictionary self=(PyDictionary)gself; 443 self.dict___setitem__(arg0,arg1); 444 return Py.None; 445 } 446 447 } 448 dict.__setitem__("__setitem__",new PyMethodDescr("__setitem__",PyDictionary.class,2,2,new exposed___setitem__(null,null))); 449 class exposed___delitem__ extends PyBuiltinFunctionNarrow { 450 451 private PyDictionary self; 452 453 public PyObject getSelf() { 454 return self; 455 } 456 457 exposed___delitem__(PyDictionary self,PyBuiltinFunction.Info info) { 458 super(info); 459 this.self=self; 460 } 461 462 public PyBuiltinFunction makeBound(PyObject self) { 463 return new exposed___delitem__((PyDictionary)self,info); 464 } 465 466 public PyObject __call__(PyObject arg0) { 467 self.dict___delitem__(arg0); 468 return Py.None; 469 } 470 471 public PyObject inst_call(PyObject gself,PyObject arg0) { 472 PyDictionary self=(PyDictionary)gself; 473 self.dict___delitem__(arg0); 474 return Py.None; 475 } 476 477 } 478 dict.__setitem__("__delitem__",new PyMethodDescr("__delitem__",PyDictionary.class,1,1,new exposed___delitem__(null,null))); 479 class exposed_keys extends PyBuiltinFunctionNarrow { 480 481 private PyDictionary self; 482 483 public PyObject getSelf() { 484 return self; 485 } 486 487 exposed_keys(PyDictionary self,PyBuiltinFunction.Info info) { 488 super(info); 489 this.self=self; 490 } 491 492 public PyBuiltinFunction makeBound(PyObject self) { 493 return new exposed_keys((PyDictionary)self,info); 494 } 495 496 public PyObject __call__() { 497 return self.dict_keys(); 498 } 499 500 public PyObject inst_call(PyObject gself) { 501 PyDictionary self=(PyDictionary)gself; 502 return self.dict_keys(); 503 } 504 505 } 506 dict.__setitem__("keys",new PyMethodDescr("keys",PyDictionary.class,0,0,new exposed_keys(null,null))); 507 class exposed_update extends PyBuiltinFunctionNarrow { 508 509 private PyDictionary self; 510 511 public PyObject getSelf() { 512 return self; 513 } 514 515 exposed_update(PyDictionary self,PyBuiltinFunction.Info info) { 516 super(info); 517 this.self=self; 518 } 519 520 public PyBuiltinFunction makeBound(PyObject self) { 521 return new exposed_update((PyDictionary)self,info); 522 } 523 524 public PyObject __call__(PyObject arg0) { 525 self.dict_update(arg0); 526 return Py.None; 527 } 528 529 public PyObject inst_call(PyObject gself,PyObject arg0) { 530 PyDictionary self=(PyDictionary)gself; 531 self.dict_update(arg0); 532 return Py.None; 533 } 534 535 } 536 dict.__setitem__("update",new PyMethodDescr("update",PyDictionary.class,1,1,new exposed_update(null,null))); 537 class exposed_itervalues extends PyBuiltinFunctionNarrow { 538 539 private PyDictionary self; 540 541 public PyObject getSelf() { 542 return self; 543 } 544 545 exposed_itervalues(PyDictionary self,PyBuiltinFunction.Info info) { 546 super(info); 547 this.self=self; 548 } 549 550 public PyBuiltinFunction makeBound(PyObject self) { 551 return new exposed_itervalues((PyDictionary)self,info); 552 } 553 554 public PyObject __call__() { 555 return self.dict_itervalues(); 556 } 557 558 public PyObject inst_call(PyObject gself) { 559 PyDictionary self=(PyDictionary)gself; 560 return self.dict_itervalues(); 561 } 562 563 } 564 dict.__setitem__("itervalues",new PyMethodDescr("itervalues",PyDictionary.class,0,0,new exposed_itervalues(null,null))); 565 class exposed_iteritems extends PyBuiltinFunctionNarrow { 566 567 private PyDictionary self; 568 569 public PyObject getSelf() { 570 return self; 571 } 572 573 exposed_iteritems(PyDictionary self,PyBuiltinFunction.Info info) { 574 super(info); 575 this.self=self; 576 } 577 578 public PyBuiltinFunction makeBound(PyObject self) { 579 return new exposed_iteritems((PyDictionary)self,info); 580 } 581 582 public PyObject __call__() { 583 return self.dict_iteritems(); 584 } 585 586 public PyObject inst_call(PyObject gself) { 587 PyDictionary self=(PyDictionary)gself; 588 return self.dict_iteritems(); 589 } 590 591 } 592 dict.__setitem__("iteritems",new PyMethodDescr("iteritems",PyDictionary.class,0,0,new exposed_iteritems(null,null))); 593 class exposed_iterkeys extends PyBuiltinFunctionNarrow { 594 595 private PyDictionary self; 596 597 public PyObject getSelf() { 598 return self; 599 } 600 601 exposed_iterkeys(PyDictionary self,PyBuiltinFunction.Info info) { 602 super(info); 603 this.self=self; 604 } 605 606 public PyBuiltinFunction makeBound(PyObject self) { 607 return new exposed_iterkeys((PyDictionary)self,info); 608 } 609 610 public PyObject __call__() { 611 return self.dict_iterkeys(); 612 } 613 614 public PyObject inst_call(PyObject gself) { 615 PyDictionary self=(PyDictionary)gself; 616 return self.dict_iterkeys(); 617 } 618 619 } 620 dict.__setitem__("iterkeys",new PyMethodDescr("iterkeys",PyDictionary.class,0,0,new exposed_iterkeys(null,null))); 621 class exposed_items extends PyBuiltinFunctionNarrow { 622 623 private PyDictionary self; 624 625 public PyObject getSelf() { 626 return self; 627 } 628 629 exposed_items(PyDictionary self,PyBuiltinFunction.Info info) { 630 super(info); 631 this.self=self; 632 } 633 634 public PyBuiltinFunction makeBound(PyObject self) { 635 return new exposed_items((PyDictionary)self,info); 636 } 637 638 public PyObject __call__() { 639 return self.dict_items(); 640 } 641 642 public PyObject inst_call(PyObject gself) { 643 PyDictionary self=(PyDictionary)gself; 644 return self.dict_items(); 645 } 646 647 } 648 dict.__setitem__("items",new PyMethodDescr("items",PyDictionary.class,0,0,new exposed_items(null,null))); 649 class exposed_values extends PyBuiltinFunctionNarrow { 650 651 private PyDictionary self; 652 653 public PyObject getSelf() { 654 return self; 655 } 656 657 exposed_values(PyDictionary self,PyBuiltinFunction.Info info) { 658 super(info); 659 this.self=self; 660 } 661 662 public PyBuiltinFunction makeBound(PyObject self) { 663 return new exposed_values((PyDictionary)self,info); 664 } 665 666 public PyObject __call__() { 667 return self.dict_values(); 668 } 669 670 public PyObject inst_call(PyObject gself) { 671 PyDictionary self=(PyDictionary)gself; 672 return self.dict_values(); 673 } 674 675 } 676 dict.__setitem__("values",new PyMethodDescr("values",PyDictionary.class,0,0,new exposed_values(null,null))); 677 class exposed_clear extends PyBuiltinFunctionNarrow { 678 679 private PyDictionary self; 680 681 public PyObject getSelf() { 682 return self; 683 } 684 685 exposed_clear(PyDictionary self,PyBuiltinFunction.Info info) { 686 super(info); 687 this.self=self; 688 } 689 690 public PyBuiltinFunction makeBound(PyObject self) { 691 return new exposed_clear((PyDictionary)self,info); 692 } 693 694 public PyObject __call__() { 695 self.dict_clear(); 696 return Py.None; 697 } 698 699 public PyObject inst_call(PyObject gself) { 700 PyDictionary self=(PyDictionary)gself; 701 self.dict_clear(); 702 return Py.None; 703 } 704 705 } 706 dict.__setitem__("clear",new PyMethodDescr("clear",PyDictionary.class,0,0,new exposed_clear(null,null))); 707 class exposed_copy extends PyBuiltinFunctionNarrow { 708 709 private PyDictionary self; 710 711 public PyObject getSelf() { 712 return self; 713 } 714 715 exposed_copy(PyDictionary self,PyBuiltinFunction.Info info) { 716 super(info); 717 this.self=self; 718 } 719 720 public PyBuiltinFunction makeBound(PyObject self) { 721 return new exposed_copy((PyDictionary)self,info); 722 } 723 724 public PyObject __call__() { 725 return self.dict_copy(); 726 } 727 728 public PyObject inst_call(PyObject gself) { 729 PyDictionary self=(PyDictionary)gself; 730 return self.dict_copy(); 731 } 732 733 } 734 dict.__setitem__("copy",new PyMethodDescr("copy",PyDictionary.class,0,0,new exposed_copy(null,null))); 735 class exposed___hash__ extends PyBuiltinFunctionNarrow { 736 737 private PyDictionary self; 738 739 public PyObject getSelf() { 740 return self; 741 } 742 743 exposed___hash__(PyDictionary self,PyBuiltinFunction.Info info) { 744 super(info); 745 this.self=self; 746 } 747 748 public PyBuiltinFunction makeBound(PyObject self) { 749 return new exposed___hash__((PyDictionary)self,info); 750 } 751 752 public PyObject __call__() { 753 return Py.newInteger(self.dict_hashCode()); 754 } 755 756 public PyObject inst_call(PyObject gself) { 757 PyDictionary self=(PyDictionary)gself; 758 return Py.newInteger(self.dict_hashCode()); 759 } 760 761 } 762 dict.__setitem__("__hash__",new PyMethodDescr("__hash__",PyDictionary.class,0,0,new exposed___hash__(null,null))); 763 class exposed___repr__ extends PyBuiltinFunctionNarrow { 764 765 private PyDictionary self; 766 767 public PyObject getSelf() { 768 return self; 769 } 770 771 exposed___repr__(PyDictionary self,PyBuiltinFunction.Info info) { 772 super(info); 773 this.self=self; 774 } 775 776 public PyBuiltinFunction makeBound(PyObject self) { 777 return new exposed___repr__((PyDictionary)self,info); 778 } 779 780 public PyObject __call__() { 781 return new PyString(self.dict_toString()); 782 } 783 784 public PyObject inst_call(PyObject gself) { 785 PyDictionary self=(PyDictionary)gself; 786 return new PyString(self.dict_toString()); 787 } 788 789 } 790 dict.__setitem__("__repr__",new PyMethodDescr("__repr__",PyDictionary.class,0,0,new exposed___repr__(null,null))); 791 class exposed___iter__ extends PyBuiltinFunctionNarrow { 792 793 private PyDictionary self; 794 795 public PyObject getSelf() { 796 return self; 797 } 798 799 exposed___iter__(PyDictionary self,PyBuiltinFunction.Info info) { 800 super(info); 801 this.self=self; 802 } 803 804 public PyBuiltinFunction makeBound(PyObject self) { 805 return new exposed___iter__((PyDictionary)self,info); 806 } 807 808 public PyObject __call__() { 809 return self.dict___iter__(); 810 } 811 812 public PyObject inst_call(PyObject gself) { 813 PyDictionary self=(PyDictionary)gself; 814 return self.dict___iter__(); 815 } 816 817 } 818 dict.__setitem__("__iter__",new PyMethodDescr("__iter__",PyDictionary.class,0,0,new exposed___iter__(null,null))); 819 class exposed___init__ extends PyBuiltinFunctionWide { 820 821 private PyDictionary self; 822 823 public PyObject getSelf() { 824 return self; 825 } 826 827 exposed___init__(PyDictionary self,PyBuiltinFunction.Info info) { 828 super(info); 829 this.self=self; 830 } 831 832 public PyBuiltinFunction makeBound(PyObject self) { 833 return new exposed___init__((PyDictionary)self,info); 834 } 835 836 public PyObject inst_call(PyObject self,PyObject[]args) { 837 return inst_call(self,args,Py.NoKeywords); 838 } 839 840 public PyObject __call__(PyObject[]args) { 841 return __call__(args,Py.NoKeywords); 842 } 843 844 public PyObject __call__(PyObject[]args,String []keywords) { 845 self.dict_init(args,keywords); 846 return Py.None; 847 } 848 849 public PyObject inst_call(PyObject gself,PyObject[]args,String []keywords) { 850 PyDictionary self=(PyDictionary)gself; 851 self.dict_init(args,keywords); 852 return Py.None; 853 } 854 855 } 856 dict.__setitem__("__init__",new PyMethodDescr("__init__",PyDictionary.class,-1,-1,new exposed___init__(null,null))); 857 dict.__setitem__("__new__",new PyNewWrapper(PyDictionary.class,"__new__",-1,-1) { 858 859 public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String []keywords) { 860 PyDictionary newobj; 861 if (for_type==subtype) { 862 newobj=new PyDictionary(); 863 if (init) 864 newobj.dict_init(args,keywords); 865 } else { 866 newobj=new PyDictionaryDerived(subtype); 867 } 868 return newobj; 869 } 870 }); 871 } 872 873 protected Hashtable table; 874 875 878 public PyDictionary() { 879 this(new Hashtable ()); 880 } 881 882 886 public PyDictionary(PyType subtype) { 887 super(subtype); 888 table = new Hashtable (); 889 } 890 891 896 public PyDictionary(Hashtable t) { 897 table = t; 898 } 899 900 906 public PyDictionary(PyObject elements[]) { 907 this(); 908 for (int i = 0; i < elements.length; i+=2) { 909 table.put(elements[i], elements[i+1]); 910 } 911 } 912 913 final void dict_init(PyObject[] args,String [] kwds) { 914 int nargs = args.length - kwds.length; 915 if (nargs > 1) 916 throw PyBuiltinFunction.DefaultInfo.unexpectedCall( 917 nargs, 918 false, 919 exposed_name, 920 0, 921 1); 922 if (nargs == 1) { 923 PyObject src = args[0]; 924 if (src.__findattr__("keys") != null) 925 this.update(src); 926 else { 927 PyObject pairs = Py.iter(src, "iteration over non-sequence"); 928 PyObject pair; 929 int cnt = 0; 930 for (; (pair = pairs.__iternext__()) != null; cnt++) { 931 try { 932 pair = PySequence.fastSequence(pair, ""); 933 } catch(PyException e) { 934 if (Py.matchException(e, Py.TypeError)) 935 throw Py.TypeError("cannot convert dictionary update "+ 936 "sequence element #"+cnt+" to a sequence"); 937 throw e; 938 } 939 int n; 940 if ((n = pair.__len__()) != 2) { 941 throw Py.TypeError("dictionary update sequence element #"+cnt+ 942 " has length "+n+"; 2 is required"); 943 } 944 this.__setitem__(pair.__getitem__(0),pair.__getitem__(1)); 945 } 946 } 947 for (int i=0; i < kwds.length; i++) { 948 this.__setitem__(kwds[i],args[nargs+i]); 949 } 950 } 951 } 952 public PyObject fromkeys(PyObject keys) { 953 return dict_fromkeys(keys, null); 954 } 955 956 public PyObject fromkeys(PyObject keys, PyObject value) { 957 return dict_fromkeys(keys, value); 958 } 959 960 final PyObject dict_fromkeys(PyObject keys) { 961 return dict_fromkeys(keys, null); 962 } 963 964 final PyObject dict_fromkeys(PyObject keys, PyObject value) { 965 if (value == null) { 966 value = Py.None; 967 } 968 PyDictionary d = new PyDictionary(); 969 PyIterator iter = (PyIterator)keys.__iter__(); 970 for (PyObject o = iter.__iternext__();o != null;o = iter.__iternext__()) { 971 d.__setitem__(o, value); 972 } 973 return d; 974 } 975 976 977 978 public String safeRepr() throws PyIgnoreMethodTag { 979 return "'dict' object"; 980 } 981 982 public int __len__() { 983 return dict___len__(); 984 } 985 986 final int dict___len__() { 987 return table.size(); 988 } 989 990 public boolean __nonzero__() { 991 return dict___nonzero__(); 992 } 993 994 final boolean dict___nonzero__() { 995 return table.size() != 0; 996 } 997 998 public PyObject __finditem__(int index) { 999 throw Py.TypeError("loop over non-sequence"); 1000 } 1001 1002 public PyObject __finditem__(PyObject key) { 1003 return dict___finditem__(key); 1004 } 1005 1006 final PyObject dict___finditem__(PyObject key) { 1007 return (PyObject)table.get(key); 1008 } 1009 1010 public void __setitem__(PyObject key, PyObject value) { 1011 dict___setitem__(key,value); 1012 } 1013 1014 final void dict___setitem__(PyObject key, PyObject value) { 1015 table.put(key, value); 1016 } 1017 1018 public void __delitem__(PyObject key) { 1019 dict___delitem__(key); 1020 } 1021 1022 final void dict___delitem__(PyObject key) { 1023 Object ret = table.remove(key); 1024 if (ret == null) 1025 throw Py.KeyError(key.toString()); 1026 } 1027 1028 public PyObject __iter__() { 1029 return dict___iter__(); 1030 } 1031 1032 final PyObject dict___iter__() { 1033 return new PyDictionaryIter(this, table.keys(), PyDictionaryIter.KEYS); 1034 } 1035 1036 public String toString() { 1037 return dict_toString(); 1038 } 1039 1040 final String dict_toString() { 1041 ThreadState ts = Py.getThreadState(); 1042 if (!ts.enterRepr(this)) { 1043 return "{...}"; 1044 } 1045 1046 java.util.Enumeration ek = table.keys(); 1047 java.util.Enumeration ev = table.elements(); 1048 int n = table.size(); 1049 StringBuffer buf = new StringBuffer ("{"); 1050 1051 for(int i=0; i<n; i++) { 1052 buf.append(((PyObject)ek.nextElement()).__repr__().toString()); 1053 buf.append(": "); 1054 buf.append(((PyObject)ev.nextElement()).__repr__().toString()); 1055 if (i < n-1) 1056 buf.append(", "); 1057 } 1058 buf.append("}"); 1059 1060 ts.exitRepr(this); 1061 return buf.toString(); 1062 } 1063 1064 public PyObject __eq__(PyObject ob_other) { 1065 return dict___eq__(ob_other); 1066 } 1067 1068 final PyObject dict___eq__(PyObject ob_other) { 1069 if (ob_other.getType() != getType()) 1070 return null; 1071 1072 PyDictionary other = (PyDictionary)ob_other; 1073 int an = table.size(); 1074 int bn = other.table.size(); 1075 if (an != bn) 1076 return Py.Zero; 1077 1078 PyList akeys = keys(); 1079 for (int i=0; i<an; i++) { 1080 PyObject akey = akeys.pyget(i); 1081 PyObject bvalue = other.__finditem__(akey); 1082 if (bvalue == null) 1083 return Py.Zero; 1084 PyObject avalue = __finditem__(akey); 1085 if (!avalue._eq(bvalue).__nonzero__()) 1086 return Py.Zero; 1087 } 1088 return Py.One; 1089 } 1090 1091 public PyObject __ne__(PyObject ob_other) { 1092 return dict___ne__(ob_other); 1093 } 1094 1095 final PyObject dict___ne__(PyObject ob_other) { 1096 PyObject eq_result = __eq__(ob_other); 1097 if (eq_result == null) return null; 1098 return eq_result == Py.One?Py.Zero:Py.One; 1099 } 1100 1101 public int __cmp__(PyObject ob_other) { 1102 return dict___cmp__(ob_other); 1103 } 1104 1105 final int dict___cmp__(PyObject ob_other) { 1106 if (ob_other.getType() != getType()) 1107 return -2; 1108 1109 PyDictionary other = (PyDictionary)ob_other; 1110 int an = table.size(); 1111 int bn = other.table.size(); 1112 if (an < bn) return -1; 1113 if (an > bn) return 1; 1114 1115 PyList akeys = keys(); 1116 PyList bkeys = other.keys(); 1117 1118 akeys.sort(); 1119 bkeys.sort(); 1120 1121 for (int i=0; i<bn; i++) { 1122 PyObject akey = akeys.pyget(i); 1123 PyObject bkey = bkeys.pyget(i); 1124 int c = akey._cmp(bkey); 1125 if (c != 0) 1126 return c; 1127 1128 PyObject avalue = __finditem__(akey); 1129 PyObject bvalue = other.__finditem__(bkey); 1130 c = avalue._cmp(bvalue); 1131 if (c != 0) 1132 return c; 1133 } 1134 return 0; 1135 } 1136 1137 1140 public boolean has_key(PyObject key) { 1141 return dict_has_key(key); 1142 } 1143 1144 final boolean dict_has_key(PyObject key) { 1145 return table.containsKey(key); 1146 } 1147 1148 final boolean dict___contains__(PyObject o) { 1149 return dict_has_key(o); 1150 } 1151 1152 1160 public PyObject get(PyObject key, PyObject default_object) { 1161 return dict_get(key,default_object); 1162 } 1163 1164 final PyObject dict_get(PyObject key, PyObject default_object) { 1165 PyObject o = __finditem__(key); 1166 if (o == null) 1167 return default_object; 1168 else 1169 return o; 1170 } 1171 1172 1178 public PyObject get(PyObject key) { 1179 return dict_get(key); 1180 } 1181 1182 final PyObject dict_get(PyObject key) { 1183 return get(key, Py.None); 1184 } 1185 1186 1189 public PyDictionary copy() { 1190 return dict_copy(); 1191 } 1192 1193 final PyDictionary dict_copy() { 1194 return new PyDictionary((Hashtable )table.clone()); 1195 } 1196 1197 1200 public void clear() { 1201 dict_clear(); 1202 } 1203 1204 final void dict_clear() { 1205 table.clear(); 1206 } 1207 1208 1212 public void update(PyObject d) { 1213 dict_update(d); 1214 } 1215 1216 final void dict_update(PyObject d) { 1217 if (d instanceof PyDictionary) { 1218 do_update((PyDictionary)d); 1219 } else if (d instanceof PyStringMap) { 1220 do_update(d,((PyStringMap)d).keys()); 1221 } else { 1222 do_update(d,d.invoke("keys")); 1223 } 1224 1225 } 1226 1227 private void do_update(PyDictionary d) { 1228 Hashtable otable = d.table; 1229 1230 java.util.Enumeration ek = otable.keys(); 1231 java.util.Enumeration ev = otable.elements(); 1232 int n = otable.size(); 1233 1234 for (int i=0; i<n; i++) 1235 table.put(ek.nextElement(), ev.nextElement()); 1236 } 1237 1238 private void do_update(PyObject d,PyObject keys) { 1239 PyObject iter = keys.__iter__(); 1240 for (PyObject key; (key = iter.__iternext__()) != null; ) 1241 __setitem__(key, d.__getitem__(key)); 1242 } 1243 1244 1250 public PyObject setdefault(PyObject key) { 1251 return dict_setdefault(key); 1252 } 1253 1254 final PyObject dict_setdefault(PyObject key) { 1255 return setdefault(key, Py.None); 1256 } 1257 1258 1266 public PyObject setdefault(PyObject key, PyObject failobj) { 1267 return dict_setdefault(key,failobj); 1268 } 1269 1270 final PyObject dict_setdefault(PyObject key, PyObject failobj) { 1271 PyObject o = __finditem__(key); 1272 if (o == null) 1273 __setitem__(key, o = failobj); 1274 return o; 1275 } 1276 1277 1281 public PyObject pop(PyObject key) { 1282 return dict_pop(key); 1283 } 1284 1285 final PyObject dict_pop(PyObject key) { 1286 if (!table.containsKey(key)) 1287 throw Py.KeyError("popitem(): dictionary is empty"); 1288 PyObject val = (PyObject) table.get(key); 1289 table.remove(key); 1290 return val; 1291 } 1292 1293 1297 public PyObject pop(PyObject key, PyObject defaultValue) { 1298 return dict_pop(key, defaultValue); 1299 } 1300 1301 final PyObject dict_pop(PyObject key, PyObject defaultValue) { 1302 if (!table.containsKey(key)) 1303 return defaultValue; 1304 PyObject val = (PyObject) table.get(key); 1305 table.remove(key); 1306 return val; 1307 } 1308 1309 1310 1314 public PyObject popitem() { 1315 return dict_popitem(); 1316 } 1317 1318 final PyObject dict_popitem() { 1319 java.util.Enumeration keys = table.keys(); 1320 if (!keys.hasMoreElements()) 1321 throw Py.KeyError("popitem(): dictionary is empty"); 1322 PyObject key = (PyObject) keys.nextElement(); 1323 PyObject val = (PyObject) table.get(key); 1324 table.remove(key); 1325 return new PyTuple(new PyObject[] { key, val }); 1326 } 1327 1328 1332 public PyList items() { 1333 return dict_items(); 1334 } 1335 1336 final PyList dict_items() { 1337 java.util.Enumeration ek = table.keys(); 1338 java.util.Enumeration ev = table.elements(); 1339 int n = table.size(); 1340 java.util.Vector l = new java.util.Vector (n); 1341 1342 for (int i=0; i<n; i++) 1343 l.addElement(new PyTuple(new PyObject[] { 1344 (PyObject)ek.nextElement(), (PyObject)ev.nextElement() 1345 })); 1346 return new PyList(l); 1347 } 1348 1349 1352 public PyList keys() { 1353 return dict_keys(); 1354 } 1355 1356 final PyList dict_keys() { 1357 java.util.Enumeration e = table.keys(); 1358 int n = table.size(); 1359 java.util.Vector l = new java.util.Vector (n); 1360 1361 for (int i=0; i<n; i++) 1362 l.addElement(e.nextElement()); 1363 return new PyList(l); 1364 } 1365 1366 1369 public PyList values() { 1370 return dict_values(); 1371 } 1372 1373 final PyList dict_values() { 1374 java.util.Enumeration e = table.elements(); 1375 int n = table.size(); 1376 java.util.Vector l = new java.util.Vector (n); 1377 1378 for (int i=0; i<n; i++) 1379 l.addElement(e.nextElement()); 1380 return new PyList(l); 1381 } 1382 1383 1386 public PyObject iteritems() { 1387 return dict_iteritems(); 1388 } 1389 1390 final PyObject dict_iteritems() { 1391 return new PyDictionaryIter(this, table.keys(), 1392 PyDictionaryIter.ITEMS); 1393 } 1394 1395 1398 public PyObject iterkeys() { 1399 return dict_iterkeys(); 1400 } 1401 1402 final PyObject dict_iterkeys() { 1403 return new PyDictionaryIter(this, table.keys(), 1404 PyDictionaryIter.KEYS); 1405 } 1406 1407 1410 public PyObject itervalues() { 1411 return dict_itervalues(); 1412 } 1413 1414 final PyObject dict_itervalues() { 1415 return new PyDictionaryIter(this, table.keys(), 1416 PyDictionaryIter.VALUES); 1417 } 1418 1419 public int hashCode() { 1420 return dict_hashCode(); 1421 } 1422 1423 final int dict_hashCode() { 1424 throw Py.TypeError("unhashable type"); 1425 } 1426 1427} 1428 1429class PyDictionaryIter extends PyIterator { 1430 public static final int KEYS = 0; 1431 public static final int VALUES = 1; 1432 public static final int ITEMS = 2; 1433 1434 private PyObject dict; 1435 private Enumeration enumeration; 1436 private int type; 1437 1438 public PyDictionaryIter(PyObject dict, Enumeration e, int type) { 1439 this.dict = dict; 1440 this.enumeration = e; 1441 this.type = type; 1442 } 1443 1444 public PyObject __iternext__() { 1445 if (!enumeration.hasMoreElements()) 1446 return null; 1447 PyObject key = (PyObject) enumeration.nextElement(); 1448 switch (type) { 1449 case VALUES: 1450 return dict.__finditem__(key); 1451 case ITEMS: 1452 return new PyTuple(new PyObject[] { key, dict.__finditem__(key) }); 1453 default: return key; 1455 } 1456 } 1457} 1458 1459 | Popular Tags |