| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Jython
Revision: 5274
Author: zyasoft
Date: 30 Aug 2008 14:39:59
Changes:Exposed unicode_toString, str_toString so that Jython code can
directly access the underlying java.lang.String backing our unicode
and str types. This enables writing code like this:
return Normalizer.normalize(unistr.toString(), normalizer_form)
without Jython automatically encoding the string on our behalf. That's
often what we want for CPython compatibility, but not when we are
calling methods like this. (Too bad we need to know.)
Added unicodedata.py and supporting data files UnicodeData.txt and
EastAsianWidth.txt, both from 4.10. (We may wish to update to be more
compliant with Java than Python 2.5.) Because the time it takes to
import, serious refactoring should be considered, including possibly
doing a codegen to Java approach. Currently does not pass MD5 hash
tests in test_unicodedata, which by their nature are highly sensitive.
Added collections.namedtuple. First 2.6 feature. (We should have a few
in Jython 2.5.) This was originally added to support Python version of
unicodedata.py, but is now just included.
| ... | ...@@ -0,0 +1,19 @@ | |
| 1 | package org.python.modules._collections; | |
| 2 | ||
| 3 | import org.python.core.ClassDictInit; | |
| 4 | import org.python.core.PyType; | |
| 5 | import org.python.core.PyObject; | |
| 6 | ||
| 7 | /** | |
| 8 | * Collections - This module adds the ability to use high performance data | |
| 9 | * structures. | |
| 10 | * - deque: ordered collection accessible from endpoints only | |
| 11 | * - defaultdict: dict subclass with a default value factory | |
| 12 | */ | |
| 13 | public class Collections implements ClassDictInit { | |
| 14 | ||
| 15 | public static void classDictInit(PyObject dict) { | |
| 16 | dict.__setitem__("deque", PyDeque.TYPE); | |
| 17 | dict.__setitem__("defaultdict", PyDefaultDict.TYPE); | |
| 18 | } | |
| 19 | } |
| ... | ...@@ -0,0 +1,1156 @@ | |
| 1 | /* Generated file, do not modify. See jython/src/templates/gderived.py. */ | |
| 2 | package org.python.modules._collections; | |
| 3 | ||
| 4 | import org.python.core.*; | |
| 5 | ||
| 6 | public class PyDequeDerived extends PyDeque implements Slotted { | |
| 7 | ||
| 8 | public PyObject getSlot(int index) { | |
| 9 | return slots[index]; | |
| 10 | } | |
| 11 | ||
| 12 | public void setSlot(int index,PyObject value) { | |
| 13 | slots[index]=value; | |
| 14 | } | |
| 15 | ||
| 16 | private PyObject[]slots; | |
| 17 | ||
| 18 | private PyObject dict; | |
| 19 | ||
| 20 | public PyObject fastGetDict() { | |
| 21 | return dict; | |
| 22 | } | |
| 23 | ||
| 24 | public PyObject getDict() { | |
| 25 | return dict; | |
| 26 | } | |
| 27 | ||
| 28 | public void setDict(PyObject newDict) { | |
| 29 | if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { | |
| 30 | dict=newDict; | |
| 31 | } else { | |
| 32 | throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); | |
| 33 | } | |
| 34 | } | |
| 35 | ||
| 36 | public void delDict() { | |
| 37 | // deleting an object's instance dict makes it grow a new one | |
| 38 | dict=new PyStringMap(); | |
| 39 | } | |
| 40 | ||
| 41 | public PyDequeDerived(PyType subtype) { | |
| 42 | super(subtype); | |
| 43 | slots=new PyObject[subtype.getNumSlots()]; | |
| 44 | dict=subtype.instDict(); | |
| 45 | } | |
| 46 | ||
| 47 | public PyString __str__() { | |
| 48 | PyType self_type=getType(); | |
| 49 | PyObject impl=self_type.lookup("__str__"); | |
| 50 | if (impl!=null) { | |
| 51 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 52 | if (res instanceof PyString) | |
| 53 | return(PyString)res; | |
| 54 | throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); | |
| 55 | } | |
| 56 | return super.__str__(); | |
| 57 | } | |
| 58 | ||
| 59 | public PyString __repr__() { | |
| 60 | PyType self_type=getType(); | |
| 61 | PyObject impl=self_type.lookup("__repr__"); | |
| 62 | if (impl!=null) { | |
| 63 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 64 | if (res instanceof PyString) | |
| 65 | return(PyString)res; | |
| 66 | throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); | |
| 67 | } | |
| 68 | return super.__repr__(); | |
| 69 | } | |
| 70 | ||
| 71 | public PyString __hex__() { | |
| 72 | PyType self_type=getType(); | |
| 73 | PyObject impl=self_type.lookup("__hex__"); | |
| 74 | if (impl!=null) { | |
| 75 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 76 | if (res instanceof PyString) | |
| 77 | return(PyString)res; | |
| 78 | throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); | |
| 79 | } | |
| 80 | return super.__hex__(); | |
| 81 | } | |
| 82 | ||
| 83 | public PyString __oct__() { | |
| 84 | PyType self_type=getType(); | |
| 85 | PyObject impl=self_type.lookup("__oct__"); | |
| 86 | if (impl!=null) { | |
| 87 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 88 | if (res instanceof PyString) | |
| 89 | return(PyString)res; | |
| 90 | throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); | |
| 91 | } | |
| 92 | return super.__oct__(); | |
| 93 | } | |
| 94 | ||
| 95 | public PyFloat __float__() { | |
| 96 | PyType self_type=getType(); | |
| 97 | PyObject impl=self_type.lookup("__float__"); | |
| 98 | if (impl!=null) { | |
| 99 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 100 | if (res instanceof PyFloat) | |
| 101 | return(PyFloat)res; | |
| 102 | throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); | |
| 103 | } | |
| 104 | return super.__float__(); | |
| 105 | } | |
| 106 | ||
| 107 | public PyComplex __complex__() { | |
| 108 | PyType self_type=getType(); | |
| 109 | PyObject impl=self_type.lookup("__complex__"); | |
| 110 | if (impl!=null) { | |
| 111 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 112 | if (res instanceof PyComplex) | |
| 113 | return(PyComplex)res; | |
| 114 | throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); | |
| 115 | } | |
| 116 | return super.__complex__(); | |
| 117 | } | |
| 118 | ||
| 119 | public PyObject __pos__() { | |
| 120 | PyType self_type=getType(); | |
| 121 | PyObject impl=self_type.lookup("__pos__"); | |
| 122 | if (impl!=null) | |
| 123 | return impl.__get__(this,self_type).__call__(); | |
| 124 | return super.__pos__(); | |
| 125 | } | |
| 126 | ||
| 127 | public PyObject __neg__() { | |
| 128 | PyType self_type=getType(); | |
| 129 | PyObject impl=self_type.lookup("__neg__"); | |
| 130 | if (impl!=null) | |
| 131 | return impl.__get__(this,self_type).__call__(); | |
| 132 | return super.__neg__(); | |
| 133 | } | |
| 134 | ||
| 135 | public PyObject __abs__() { | |
| 136 | PyType self_type=getType(); | |
| 137 | PyObject impl=self_type.lookup("__abs__"); | |
| 138 | if (impl!=null) | |
| 139 | return impl.__get__(this,self_type).__call__(); | |
| 140 | return super.__abs__(); | |
| 141 | } | |
| 142 | ||
| 143 | public PyObject __invert__() { | |
| 144 | PyType self_type=getType(); | |
| 145 | PyObject impl=self_type.lookup("__invert__"); | |
| 146 | if (impl!=null) | |
| 147 | return impl.__get__(this,self_type).__call__(); | |
| 148 | return super.__invert__(); | |
| 149 | } | |
| 150 | ||
| 151 | public PyObject __reduce__() { | |
| 152 | PyType self_type=getType(); | |
| 153 | PyObject impl=self_type.lookup("__reduce__"); | |
| 154 | if (impl!=null) | |
| 155 | return impl.__get__(this,self_type).__call__(); | |
| 156 | return super.__reduce__(); | |
| 157 | } | |
| 158 | ||
| 159 | public PyObject __add__(PyObject other) { | |
| 160 | PyType self_type=getType(); | |
| 161 | PyObject impl=self_type.lookup("__add__"); | |
| 162 | if (impl!=null) { | |
| 163 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 164 | if (res==Py.NotImplemented) | |
| 165 | return null; | |
| 166 | return res; | |
| 167 | } | |
| 168 | return super.__add__(other); | |
| 169 | } | |
| 170 | ||
| 171 | public PyObject __radd__(PyObject other) { | |
| 172 | PyType self_type=getType(); | |
| 173 | PyObject impl=self_type.lookup("__radd__"); | |
| 174 | if (impl!=null) { | |
| 175 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 176 | if (res==Py.NotImplemented) | |
| 177 | return null; | |
| 178 | return res; | |
| 179 | } | |
| 180 | return super.__radd__(other); | |
| 181 | } | |
| 182 | ||
| 183 | public PyObject __sub__(PyObject other) { | |
| 184 | PyType self_type=getType(); | |
| 185 | PyObject impl=self_type.lookup("__sub__"); | |
| 186 | if (impl!=null) { | |
| 187 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 188 | if (res==Py.NotImplemented) | |
| 189 | return null; | |
| 190 | return res; | |
| 191 | } | |
| 192 | return super.__sub__(other); | |
| 193 | } | |
| 194 | ||
| 195 | public PyObject __rsub__(PyObject other) { | |
| 196 | PyType self_type=getType(); | |
| 197 | PyObject impl=self_type.lookup("__rsub__"); | |
| 198 | if (impl!=null) { | |
| 199 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 200 | if (res==Py.NotImplemented) | |
| 201 | return null; | |
| 202 | return res; | |
| 203 | } | |
| 204 | return super.__rsub__(other); | |
| 205 | } | |
| 206 | ||
| 207 | public PyObject __mul__(PyObject other) { | |
| 208 | PyType self_type=getType(); | |
| 209 | PyObject impl=self_type.lookup("__mul__"); | |
| 210 | if (impl!=null) { | |
| 211 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 212 | if (res==Py.NotImplemented) | |
| 213 | return null; | |
| 214 | return res; | |
| 215 | } | |
| 216 | return super.__mul__(other); | |
| 217 | } | |
| 218 | ||
| 219 | public PyObject __rmul__(PyObject other) { | |
| 220 | PyType self_type=getType(); | |
| 221 | PyObject impl=self_type.lookup("__rmul__"); | |
| 222 | if (impl!=null) { | |
| 223 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 224 | if (res==Py.NotImplemented) | |
| 225 | return null; | |
| 226 | return res; | |
| 227 | } | |
| 228 | return super.__rmul__(other); | |
| 229 | } | |
| 230 | ||
| 231 | public PyObject __div__(PyObject other) { | |
| 232 | PyType self_type=getType(); | |
| 233 | PyObject impl=self_type.lookup("__div__"); | |
| 234 | if (impl!=null) { | |
| 235 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 236 | if (res==Py.NotImplemented) | |
| 237 | return null; | |
| 238 | return res; | |
| 239 | } | |
| 240 | return super.__div__(other); | |
| 241 | } | |
| 242 | ||
| 243 | public PyObject __rdiv__(PyObject other) { | |
| 244 | PyType self_type=getType(); | |
| 245 | PyObject impl=self_type.lookup("__rdiv__"); | |
| 246 | if (impl!=null) { | |
| 247 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 248 | if (res==Py.NotImplemented) | |
| 249 | return null; | |
| 250 | return res; | |
| 251 | } | |
| 252 | return super.__rdiv__(other); | |
| 253 | } | |
| 254 | ||
| 255 | public PyObject __floordiv__(PyObject other) { | |
| 256 | PyType self_type=getType(); | |
| 257 | PyObject impl=self_type.lookup("__floordiv__"); | |
| 258 | if (impl!=null) { | |
| 259 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 260 | if (res==Py.NotImplemented) | |
| 261 | return null; | |
| 262 | return res; | |
| 263 | } | |
| 264 | return super.__floordiv__(other); | |
| 265 | } | |
| 266 | ||
| 267 | public PyObject __rfloordiv__(PyObject other) { | |
| 268 | PyType self_type=getType(); | |
| 269 | PyObject impl=self_type.lookup("__rfloordiv__"); | |
| 270 | if (impl!=null) { | |
| 271 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 272 | if (res==Py.NotImplemented) | |
| 273 | return null; | |
| 274 | return res; | |
| 275 | } | |
| 276 | return super.__rfloordiv__(other); | |
| 277 | } | |
| 278 | ||
| 279 | public PyObject __truediv__(PyObject other) { | |
| 280 | PyType self_type=getType(); | |
| 281 | PyObject impl=self_type.lookup("__truediv__"); | |
| 282 | if (impl!=null) { | |
| 283 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 284 | if (res==Py.NotImplemented) | |
| 285 | return null; | |
| 286 | return res; | |
| 287 | } | |
| 288 | return super.__truediv__(other); | |
| 289 | } | |
| 290 | ||
| 291 | public PyObject __rtruediv__(PyObject other) { | |
| 292 | PyType self_type=getType(); | |
| 293 | PyObject impl=self_type.lookup("__rtruediv__"); | |
| 294 | if (impl!=null) { | |
| 295 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 296 | if (res==Py.NotImplemented) | |
| 297 | return null; | |
| 298 | return res; | |
| 299 | } | |
| 300 | return super.__rtruediv__(other); | |
| 301 | } | |
| 302 | ||
| 303 | public PyObject __mod__(PyObject other) { | |
| 304 | PyType self_type=getType(); | |
| 305 | PyObject impl=self_type.lookup("__mod__"); | |
| 306 | if (impl!=null) { | |
| 307 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 308 | if (res==Py.NotImplemented) | |
| 309 | return null; | |
| 310 | return res; | |
| 311 | } | |
| 312 | return super.__mod__(other); | |
| 313 | } | |
| 314 | ||
| 315 | public PyObject __rmod__(PyObject other) { | |
| 316 | PyType self_type=getType(); | |
| 317 | PyObject impl=self_type.lookup("__rmod__"); | |
| 318 | if (impl!=null) { | |
| 319 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 320 | if (res==Py.NotImplemented) | |
| 321 | return null; | |
| 322 | return res; | |
| 323 | } | |
| 324 | return super.__rmod__(other); | |
| 325 | } | |
| 326 | ||
| 327 | public PyObject __divmod__(PyObject other) { | |
| 328 | PyType self_type=getType(); | |
| 329 | PyObject impl=self_type.lookup("__divmod__"); | |
| 330 | if (impl!=null) { | |
| 331 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 332 | if (res==Py.NotImplemented) | |
| 333 | return null; | |
| 334 | return res; | |
| 335 | } | |
| 336 | return super.__divmod__(other); | |
| 337 | } | |
| 338 | ||
| 339 | public PyObject __rdivmod__(PyObject other) { | |
| 340 | PyType self_type=getType(); | |
| 341 | PyObject impl=self_type.lookup("__rdivmod__"); | |
| 342 | if (impl!=null) { | |
| 343 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 344 | if (res==Py.NotImplemented) | |
| 345 | return null; | |
| 346 | return res; | |
| 347 | } | |
| 348 | return super.__rdivmod__(other); | |
| 349 | } | |
| 350 | ||
| 351 | public PyObject __rpow__(PyObject other) { | |
| 352 | PyType self_type=getType(); | |
| 353 | PyObject impl=self_type.lookup("__rpow__"); | |
| 354 | if (impl!=null) { | |
| 355 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 356 | if (res==Py.NotImplemented) | |
| 357 | return null; | |
| 358 | return res; | |
| 359 | } | |
| 360 | return super.__rpow__(other); | |
| 361 | } | |
| 362 | ||
| 363 | public PyObject __lshift__(PyObject other) { | |
| 364 | PyType self_type=getType(); | |
| 365 | PyObject impl=self_type.lookup("__lshift__"); | |
| 366 | if (impl!=null) { | |
| 367 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 368 | if (res==Py.NotImplemented) | |
| 369 | return null; | |
| 370 | return res; | |
| 371 | } | |
| 372 | return super.__lshift__(other); | |
| 373 | } | |
| 374 | ||
| 375 | public PyObject __rlshift__(PyObject other) { | |
| 376 | PyType self_type=getType(); | |
| 377 | PyObject impl=self_type.lookup("__rlshift__"); | |
| 378 | if (impl!=null) { | |
| 379 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 380 | if (res==Py.NotImplemented) | |
| 381 | return null; | |
| 382 | return res; | |
| 383 | } | |
| 384 | return super.__rlshift__(other); | |
| 385 | } | |
| 386 | ||
| 387 | public PyObject __rshift__(PyObject other) { | |
| 388 | PyType self_type=getType(); | |
| 389 | PyObject impl=self_type.lookup("__rshift__"); | |
| 390 | if (impl!=null) { | |
| 391 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 392 | if (res==Py.NotImplemented) | |
| 393 | return null; | |
| 394 | return res; | |
| 395 | } | |
| 396 | return super.__rshift__(other); | |
| 397 | } | |
| 398 | ||
| 399 | public PyObject __rrshift__(PyObject other) { | |
| 400 | PyType self_type=getType(); | |
| 401 | PyObject impl=self_type.lookup("__rrshift__"); | |
| 402 | if (impl!=null) { | |
| 403 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 404 | if (res==Py.NotImplemented) | |
| 405 | return null; | |
| 406 | return res; | |
| 407 | } | |
| 408 | return super.__rrshift__(other); | |
| 409 | } | |
| 410 | ||
| 411 | public PyObject __and__(PyObject other) { | |
| 412 | PyType self_type=getType(); | |
| 413 | PyObject impl=self_type.lookup("__and__"); | |
| 414 | if (impl!=null) { | |
| 415 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 416 | if (res==Py.NotImplemented) | |
| 417 | return null; | |
| 418 | return res; | |
| 419 | } | |
| 420 | return super.__and__(other); | |
| 421 | } | |
| 422 | ||
| 423 | public PyObject __rand__(PyObject other) { | |
| 424 | PyType self_type=getType(); | |
| 425 | PyObject impl=self_type.lookup("__rand__"); | |
| 426 | if (impl!=null) { | |
| 427 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 428 | if (res==Py.NotImplemented) | |
| 429 | return null; | |
| 430 | return res; | |
| 431 | } | |
| 432 | return super.__rand__(other); | |
| 433 | } | |
| 434 | ||
| 435 | public PyObject __or__(PyObject other) { | |
| 436 | PyType self_type=getType(); | |
| 437 | PyObject impl=self_type.lookup("__or__"); | |
| 438 | if (impl!=null) { | |
| 439 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 440 | if (res==Py.NotImplemented) | |
| 441 | return null; | |
| 442 | return res; | |
| 443 | } | |
| 444 | return super.__or__(other); | |
| 445 | } | |
| 446 | ||
| 447 | public PyObject __ror__(PyObject other) { | |
| 448 | PyType self_type=getType(); | |
| 449 | PyObject impl=self_type.lookup("__ror__"); | |
| 450 | if (impl!=null) { | |
| 451 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 452 | if (res==Py.NotImplemented) | |
| 453 | return null; | |
| 454 | return res; | |
| 455 | } | |
| 456 | return super.__ror__(other); | |
| 457 | } | |
| 458 | ||
| 459 | public PyObject __xor__(PyObject other) { | |
| 460 | PyType self_type=getType(); | |
| 461 | PyObject impl=self_type.lookup("__xor__"); | |
| 462 | if (impl!=null) { | |
| 463 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 464 | if (res==Py.NotImplemented) | |
| 465 | return null; | |
| 466 | return res; | |
| 467 | } | |
| 468 | return super.__xor__(other); | |
| 469 | } | |
| 470 | ||
| 471 | public PyObject __rxor__(PyObject other) { | |
| 472 | PyType self_type=getType(); | |
| 473 | PyObject impl=self_type.lookup("__rxor__"); | |
| 474 | if (impl!=null) { | |
| 475 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 476 | if (res==Py.NotImplemented) | |
| 477 | return null; | |
| 478 | return res; | |
| 479 | } | |
| 480 | return super.__rxor__(other); | |
| 481 | } | |
| 482 | ||
| 483 | public PyObject __lt__(PyObject other) { | |
| 484 | PyType self_type=getType(); | |
| 485 | PyObject impl=self_type.lookup("__lt__"); | |
| 486 | if (impl!=null) { | |
| 487 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 488 | if (res==Py.NotImplemented) | |
| 489 | return null; | |
| 490 | return res; | |
| 491 | } | |
| 492 | return super.__lt__(other); | |
| 493 | } | |
| 494 | ||
| 495 | public PyObject __le__(PyObject other) { | |
| 496 | PyType self_type=getType(); | |
| 497 | PyObject impl=self_type.lookup("__le__"); | |
| 498 | if (impl!=null) { | |
| 499 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 500 | if (res==Py.NotImplemented) | |
| 501 | return null; | |
| 502 | return res; | |
| 503 | } | |
| 504 | return super.__le__(other); | |
| 505 | } | |
| 506 | ||
| 507 | public PyObject __gt__(PyObject other) { | |
| 508 | PyType self_type=getType(); | |
| 509 | PyObject impl=self_type.lookup("__gt__"); | |
| 510 | if (impl!=null) { | |
| 511 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 512 | if (res==Py.NotImplemented) | |
| 513 | return null; | |
| 514 | return res; | |
| 515 | } | |
| 516 | return super.__gt__(other); | |
| 517 | } | |
| 518 | ||
| 519 | public PyObject __ge__(PyObject other) { | |
| 520 | PyType self_type=getType(); | |
| 521 | PyObject impl=self_type.lookup("__ge__"); | |
| 522 | if (impl!=null) { | |
| 523 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 524 | if (res==Py.NotImplemented) | |
| 525 | return null; | |
| 526 | return res; | |
| 527 | } | |
| 528 | return super.__ge__(other); | |
| 529 | } | |
| 530 | ||
| 531 | public PyObject __eq__(PyObject other) { | |
| 532 | PyType self_type=getType(); | |
| 533 | PyObject impl=self_type.lookup("__eq__"); | |
| 534 | if (impl!=null) { | |
| 535 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 536 | if (res==Py.NotImplemented) | |
| 537 | return null; | |
| 538 | return res; | |
| 539 | } | |
| 540 | return super.__eq__(other); | |
| 541 | } | |
| 542 | ||
| 543 | public PyObject __ne__(PyObject other) { | |
| 544 | PyType self_type=getType(); | |
| 545 | PyObject impl=self_type.lookup("__ne__"); | |
| 546 | if (impl!=null) { | |
| 547 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 548 | if (res==Py.NotImplemented) | |
| 549 | return null; | |
| 550 | return res; | |
| 551 | } | |
| 552 | return super.__ne__(other); | |
| 553 | } | |
| 554 | ||
| 555 | public PyObject __iadd__(PyObject other) { | |
| 556 | PyType self_type=getType(); | |
| 557 | PyObject impl=self_type.lookup("__iadd__"); | |
| 558 | if (impl!=null) { | |
| 559 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 560 | if (res==Py.NotImplemented) | |
| 561 | return null; | |
| 562 | return res; | |
| 563 | } | |
| 564 | return super.__iadd__(other); | |
| 565 | } | |
| 566 | ||
| 567 | public PyObject __isub__(PyObject other) { | |
| 568 | PyType self_type=getType(); | |
| 569 | PyObject impl=self_type.lookup("__isub__"); | |
| 570 | if (impl!=null) { | |
| 571 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 572 | if (res==Py.NotImplemented) | |
| 573 | return null; | |
| 574 | return res; | |
| 575 | } | |
| 576 | return super.__isub__(other); | |
| 577 | } | |
| 578 | ||
| 579 | public PyObject __imul__(PyObject other) { | |
| 580 | PyType self_type=getType(); | |
| 581 | PyObject impl=self_type.lookup("__imul__"); | |
| 582 | if (impl!=null) { | |
| 583 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 584 | if (res==Py.NotImplemented) | |
| 585 | return null; | |
| 586 | return res; | |
| 587 | } | |
| 588 | return super.__imul__(other); | |
| 589 | } | |
| 590 | ||
| 591 | public PyObject __idiv__(PyObject other) { | |
| 592 | PyType self_type=getType(); | |
| 593 | PyObject impl=self_type.lookup("__idiv__"); | |
| 594 | if (impl!=null) { | |
| 595 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 596 | if (res==Py.NotImplemented) | |
| 597 | return null; | |
| 598 | return res; | |
| 599 | } | |
| 600 | return super.__idiv__(other); | |
| 601 | } | |
| 602 | ||
| 603 | public PyObject __ifloordiv__(PyObject other) { | |
| 604 | PyType self_type=getType(); | |
| 605 | PyObject impl=self_type.lookup("__ifloordiv__"); | |
| 606 | if (impl!=null) { | |
| 607 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 608 | if (res==Py.NotImplemented) | |
| 609 | return null; | |
| 610 | return res; | |
| 611 | } | |
| 612 | return super.__ifloordiv__(other); | |
| 613 | } | |
| 614 | ||
| 615 | public PyObject __itruediv__(PyObject other) { | |
| 616 | PyType self_type=getType(); | |
| 617 | PyObject impl=self_type.lookup("__itruediv__"); | |
| 618 | if (impl!=null) { | |
| 619 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 620 | if (res==Py.NotImplemented) | |
| 621 | return null; | |
| 622 | return res; | |
| 623 | } | |
| 624 | return super.__itruediv__(other); | |
| 625 | } | |
| 626 | ||
| 627 | public PyObject __imod__(PyObject other) { | |
| 628 | PyType self_type=getType(); | |
| 629 | PyObject impl=self_type.lookup("__imod__"); | |
| 630 | if (impl!=null) { | |
| 631 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 632 | if (res==Py.NotImplemented) | |
| 633 | return null; | |
| 634 | return res; | |
| 635 | } | |
| 636 | return super.__imod__(other); | |
| 637 | } | |
| 638 | ||
| 639 | public PyObject __ipow__(PyObject other) { | |
| 640 | PyType self_type=getType(); | |
| 641 | PyObject impl=self_type.lookup("__ipow__"); | |
| 642 | if (impl!=null) { | |
| 643 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 644 | if (res==Py.NotImplemented) | |
| 645 | return null; | |
| 646 | return res; | |
| 647 | } | |
| 648 | return super.__ipow__(other); | |
| 649 | } | |
| 650 | ||
| 651 | public PyObject __ilshift__(PyObject other) { | |
| 652 | PyType self_type=getType(); | |
| 653 | PyObject impl=self_type.lookup("__ilshift__"); | |
| 654 | if (impl!=null) { | |
| 655 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 656 | if (res==Py.NotImplemented) | |
| 657 | return null; | |
| 658 | return res; | |
| 659 | } | |
| 660 | return super.__ilshift__(other); | |
| 661 | } | |
| 662 | ||
| 663 | public PyObject __irshift__(PyObject other) { | |
| 664 | PyType self_type=getType(); | |
| 665 | PyObject impl=self_type.lookup("__irshift__"); | |
| 666 | if (impl!=null) { | |
| 667 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 668 | if (res==Py.NotImplemented) | |
| 669 | return null; | |
| 670 | return res; | |
| 671 | } | |
| 672 | return super.__irshift__(other); | |
| 673 | } | |
| 674 | ||
| 675 | public PyObject __iand__(PyObject other) { | |
| 676 | PyType self_type=getType(); | |
| 677 | PyObject impl=self_type.lookup("__iand__"); | |
| 678 | if (impl!=null) { | |
| 679 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 680 | if (res==Py.NotImplemented) | |
| 681 | return null; | |
| 682 | return res; | |
| 683 | } | |
| 684 | return super.__iand__(other); | |
| 685 | } | |
| 686 | ||
| 687 | public PyObject __ior__(PyObject other) { | |
| 688 | PyType self_type=getType(); | |
| 689 | PyObject impl=self_type.lookup("__ior__"); | |
| 690 | if (impl!=null) { | |
| 691 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 692 | if (res==Py.NotImplemented) | |
| 693 | return null; | |
| 694 | return res; | |
| 695 | } | |
| 696 | return super.__ior__(other); | |
| 697 | } | |
| 698 | ||
| 699 | public PyObject __ixor__(PyObject other) { | |
| 700 | PyType self_type=getType(); | |
| 701 | PyObject impl=self_type.lookup("__ixor__"); | |
| 702 | if (impl!=null) { | |
| 703 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 704 | if (res==Py.NotImplemented) | |
| 705 | return null; | |
| 706 | return res; | |
| 707 | } | |
| 708 | return super.__ixor__(other); | |
| 709 | } | |
| 710 | ||
| 711 | public PyObject __int__() { | |
| 712 | PyType self_type=getType(); | |
| 713 | PyObject impl=self_type.lookup("__int__"); | |
| 714 | if (impl!=null) { | |
| 715 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 716 | if (res instanceof PyInteger||res instanceof PyLong) | |
| 717 | return(PyObject)res; | |
| 718 | throw Py.TypeError("__int__"+" should return an integer"); | |
| 719 | } | |
| 720 | return super.__int__(); | |
| 721 | } | |
| 722 | ||
| 723 | public PyObject __long__() { | |
| 724 | PyType self_type=getType(); | |
| 725 | PyObject impl=self_type.lookup("__long__"); | |
| 726 | if (impl!=null) { | |
| 727 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 728 | if (res instanceof PyLong||res instanceof PyInteger) | |
| 729 | return res; | |
| 730 | throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); | |
| 731 | } | |
| 732 | return super.__long__(); | |
| 733 | } | |
| 734 | ||
| 735 | public int hashCode() { | |
| 736 | PyType self_type=getType(); | |
| 737 | PyObject impl=self_type.lookup("__hash__"); | |
| 738 | if (impl!=null) { | |
| 739 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 740 | if (res instanceof PyInteger) { | |
| 741 | return((PyInteger)res).getValue(); | |
| 742 | } else | |
| 743 | if (res instanceof PyLong) { | |
| 744 | return((PyLong)res).getValue().intValue(); | |
| 745 | } | |
| 746 | throw Py.TypeError("__hash__ should return a int"); | |
| 747 | } | |
| 748 | if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { | |
| 749 | throw Py.TypeError("unhashable type"); | |
| 750 | } | |
| 751 | return super.hashCode(); | |
| 752 | } | |
| 753 | ||
| 754 | public PyUnicode __unicode__() { | |
| 755 | PyType self_type=getType(); | |
| 756 | PyObject impl=self_type.lookup("__unicode__"); | |
| 757 | if (impl!=null) { | |
| 758 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 759 | if (res instanceof PyUnicode) | |
| 760 | return(PyUnicode)res; | |
| 761 | if (res instanceof PyString) | |
| 762 | return new PyUnicode((PyString)res); | |
| 763 | throw Py.TypeError("__unicode__"+" should return a "+"unicode"); | |
| 764 | } | |
| 765 | return super.__unicode__(); | |
| 766 | } | |
| 767 | ||
| 768 | public int __cmp__(PyObject other) { | |
| 769 | PyType self_type=getType(); | |
| 770 | PyType[]where_type=new PyType[1]; | |
| 771 | PyObject impl=self_type.lookup_where("__cmp__",where_type); | |
| 772 | // Full Compatibility with CPython __cmp__: | |
| 773 | // If the derived type don't override __cmp__, the | |
| 774 | // *internal* super().__cmp__ should be called, not the | |
| 775 | // exposed one. The difference is that the exposed __cmp__ | |
| 776 | // throws a TypeError if the argument is an instance of the same type. | |
| 777 | if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { | |
| 778 | return super.__cmp__(other); | |
| 779 | } | |
| 780 | PyObject res=impl.__get__(this,self_type).__call__(other); | |
| 781 | if (res instanceof PyInteger) { | |
| 782 | int v=((PyInteger)res).getValue(); | |
| 783 | return v<0?-1:v>0?1:0; | |
| 784 | } | |
| 785 | throw Py.TypeError("__cmp__ should return a int"); | |
| 786 | } | |
| 787 | ||
| 788 | public boolean __nonzero__() { | |
| 789 | PyType self_type=getType(); | |
| 790 | PyObject impl=self_type.lookup("__nonzero__"); | |
| 791 | if (impl==null) { | |
| 792 | impl=self_type.lookup("__len__"); | |
| 793 | if (impl==null) | |
| 794 | return super.__nonzero__(); | |
| 795 | } | |
| 796 | return impl.__get__(this,self_type).__call__().__nonzero__(); | |
| 797 | } | |
| 798 | ||
| 799 | public boolean __contains__(PyObject o) { | |
| 800 | PyType self_type=getType(); | |
| 801 | PyObject impl=self_type.lookup("__contains__"); | |
| 802 | if (impl==null) | |
| 803 | return super.__contains__(o); | |
| 804 | return impl.__get__(this,self_type).__call__(o).__nonzero__(); | |
| 805 | } | |
| 806 | ||
| 807 | public int __len__() { | |
| 808 | PyType self_type=getType(); | |
| 809 | PyObject impl=self_type.lookup("__len__"); | |
| 810 | if (impl!=null) { | |
| 811 | PyObject res=impl.__get__(this,self_type).__call__(); | |
| 812 | if (res instanceof PyInteger) | |
| 813 | return((PyInteger)res).getValue(); | |
| 814 | throw Py.TypeError("__len__ should return a int"); | |
| 815 | } | |
| 816 | return super.__len__(); | |
| 817 | } | |
| 818 | ||
| 819 | public PyObject __iter__() { | |
| 820 | PyType self_type=getType(); | |
| 821 | PyObject impl=self_type.lookup("__iter__"); | |
| 822 | if (impl!=null) | |
| 823 | return impl.__get__(this,self_type).__call__(); | |
| 824 | impl=self_type.lookup("__getitem__"); | |
| 825 | if (impl==null) | |
| 826 | return super.__iter__(); | |
| 827 | return new PySequenceIter(this); | |
| 828 | } | |
| 829 | ||
| 830 | public PyObject __iternext__() { | |
| 831 | PyType self_type=getType(); | |
| 832 | PyObject impl=self_type.lookup("next"); | |
| 833 | if (impl!=null) { | |
| 834 | try { | |
| 835 | return impl.__get__(this,self_type).__call__(); | |
| 836 | } catch (PyException exc) { | |
| 837 | if (Py.matchException(exc,Py.StopIteration)) | |
| 838 |