From: <pj...@us...> - 2008-07-21 04:59:19
|
Revision: 4979 http://jython.svn.sourceforge.net/jython/?rev=4979&view=rev Author: pjenvey Date: 2008-07-21 04:59:03 +0000 (Mon, 21 Jul 2008) Log Message: ----------- Merged revisions 4962-4978 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r4966 | pjenvey | 2008-07-17 14:25:44 -0700 (Thu, 17 Jul 2008) | 3 lines fix loading of 0L in cPickle proto 2 and match cPickle's dumps(0L, 2) to pickle's ........ r4975 | pjenvey | 2008-07-19 16:23:25 -0700 (Sat, 19 Jul 2008) | 1 line reintegrate r3069: don't abspath __classpath__ in sys.path ........ r4976 | pjenvey | 2008-07-20 18:38:17 -0700 (Sun, 20 Jul 2008) | 1 line small cleanup ........ r4977 | pjenvey | 2008-07-20 18:43:14 -0700 (Sun, 20 Jul 2008) | 4 lines add PyFastSequenceIter (for list and tuple) which calls final seq___finditem__. whereas PySequenceIter calls __finditem__ which may be overridden by subclasses ........ r4978 | pjenvey | 2008-07-20 18:59:47 -0700 (Sun, 20 Jul 2008) | 3 lines fix __finditem__(int) not trying subclasses' __getitem__ if the parent overrode it (like PySequence does) ........ Modified Paths: -------------- branches/asm/Lib/site.py branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBooleanDerived.java branches/asm/src/org/python/core/PyClassMethodDerived.java branches/asm/src/org/python/core/PyComplexDerived.java branches/asm/src/org/python/core/PyDictionaryDerived.java branches/asm/src/org/python/core/PyEnumerateDerived.java branches/asm/src/org/python/core/PyFileDerived.java branches/asm/src/org/python/core/PyFloatDerived.java branches/asm/src/org/python/core/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyModuleDerived.java branches/asm/src/org/python/core/PyObjectDerived.java branches/asm/src/org/python/core/PyPropertyDerived.java branches/asm/src/org/python/core/PySequence.java branches/asm/src/org/python/core/PySequenceIter.java branches/asm/src/org/python/core/PySetDerived.java branches/asm/src/org/python/core/PySliceDerived.java branches/asm/src/org/python/core/PyStringDerived.java branches/asm/src/org/python/core/PySuperDerived.java branches/asm/src/org/python/core/PyTuple.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.java branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/asm/src/org/python/modules/cPickle.java branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java branches/asm/src/org/python/modules/collections/PyDequeDerived.java branches/asm/src/org/python/modules/random/PyRandomDerived.java branches/asm/src/org/python/modules/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java branches/asm/src/templates/object.derived Added Paths: ----------- branches/asm/Lib/test/test_cpickle_jy.py branches/asm/Lib/test/test_iter_jy.py branches/asm/src/org/python/core/PyFastSequenceIter.java Property Changed: ---------------- branches/asm/ Property changes on: branches/asm ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-4961 + /trunk/jython:1-4978 Modified: branches/asm/Lib/site.py =================================================================== --- branches/asm/Lib/site.py 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/Lib/site.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -64,7 +64,10 @@ def makepath(*paths): - dir = os.path.abspath(os.path.join(*paths)) + dir = os.path.join(*paths) + if dir == '__classpath__': + return dir, dir + dir = os.path.abspath(dir) return dir, os.path.normcase(dir) def abs__file__(): Copied: branches/asm/Lib/test/test_cpickle_jy.py (from rev 4978, trunk/jython/Lib/test/test_cpickle_jy.py) =================================================================== --- branches/asm/Lib/test/test_cpickle_jy.py (rev 0) +++ branches/asm/Lib/test/test_cpickle_jy.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,22 @@ +"""Misc cPickle tests. + +Made for Jython. +""" +import cPickle +import pickle +import unittest +from test import test_support + +class CPickleTestCase(unittest.TestCase): + + def test_zero_long(self): + self.assertEqual(cPickle.loads(cPickle.dumps(0L, 2)), 0L) + self.assertEqual(cPickle.dumps(0L, 2), pickle.dumps(0L, 2)) + + +def test_main(): + test_support.run_unittest(CPickleTestCase) + + +if __name__ == '__main__': + test_main() Copied: branches/asm/Lib/test/test_iter_jy.py (from rev 4978, trunk/jython/Lib/test/test_iter_jy.py) =================================================================== --- branches/asm/Lib/test/test_iter_jy.py (rev 0) +++ branches/asm/Lib/test/test_iter_jy.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,32 @@ +"""Misc iterator tests. + +Made for Jython. +""" +import test_support +import unittest + +class IterTestCase(unittest.TestCase): + + def test_fastiter(self): + class MyList(list): + def __getitem__(self, index): + return str(index) + '!' + class MyTuple(tuple): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyList(['a', 'b'])).next(), 'a') + self.assertEqual(iter(MyTuple(['a', 'b'])).next(), 'a') + + def test_slowiter(self): + class MyStr(str): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyStr('ab')).next(), '0!') + + +def test_main(): + test_support.run_unittest(IterTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Copied: branches/asm/src/org/python/core/PyFastSequenceIter.java (from rev 4978, trunk/jython/src/org/python/core/PyFastSequenceIter.java) =================================================================== --- branches/asm/src/org/python/core/PyFastSequenceIter.java (rev 0) +++ branches/asm/src/org/python/core/PyFastSequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,27 @@ +/* Copyright (c) Jython Developers */ +package org.python.core; + +/** + * Sequence iterator specialized for accessing the underlying sequence directly. + */ +public class PyFastSequenceIter extends PyIterator { + + private PySequence seq; + + private int index = 0; + + public PyFastSequenceIter(PySequence seq) { + this.seq = seq; + } + + public PyObject __iternext__() { + try { + return seq.seq___finditem__(index++); + } catch (PyException exc) { + if (Py.matchException(exc, Py.StopIteration)) { + return null; + } + throw exc; + } + } +} Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyList.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -380,9 +380,13 @@ return seq___nonzero__(); } + public PyObject __iter__() { + return list___iter__(); + } + @ExposedMethod public PyObject list___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySequence.java =================================================================== --- branches/asm/src/org/python/core/PySequence.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySequence.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -256,7 +256,11 @@ } } - public synchronized PyObject __finditem__(int index) { + public PyObject __finditem__(int index) { + return seq___finditem__(index); + } + + final synchronized PyObject seq___finditem__(int index) { index = fixindex(index); if(index == -1) { return null; @@ -271,7 +275,7 @@ final PyObject seq___finditem__(PyObject index) { if(index instanceof PyInteger || index instanceof PyLong) { - return __finditem__(index.asInt()); + return seq___finditem__(index.asInt()); } else if(index instanceof PySlice) { PySlice s = (PySlice)index; return __getslice__(s.start, s.stop, s.step); Modified: branches/asm/src/org/python/core/PySequenceIter.java =================================================================== --- branches/asm/src/org/python/core/PySequenceIter.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -1,12 +1,17 @@ +/* Copyright (c) Jython Developers */ package org.python.core; +/** + * General sequence iterator. + */ public class PySequenceIter extends PyIterator { + private PyObject seq; - private int idx; + private int index = 0; + public PySequenceIter(PyObject seq) { this.seq = seq; - this.idx = 0; } public PyObject __iternext__() { @@ -16,7 +21,7 @@ PyObject result; try { - result = seq.__finditem__(idx++); + result = seq.__finditem__(index++); } catch (PyException exc) { if (Py.matchException(exc, Py.StopIteration)) { seq = null; @@ -30,4 +35,3 @@ return result; } } - Modified: branches/asm/src/org/python/core/PySetDerived.java =================================================================== --- branches/asm/src/org/python/core/PySetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySetDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySliceDerived.java =================================================================== --- branches/asm/src/org/python/core/PySliceDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySliceDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyStringDerived.java =================================================================== --- branches/asm/src/org/python/core/PyStringDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyStringDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySuperDerived.java =================================================================== --- branches/asm/src/org/python/core/PySuperDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySuperDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyTuple.java =================================================================== --- branches/asm/src/org/python/core/PyTuple.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTuple.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -191,9 +191,13 @@ return repeat(count); } + public PyObject __iter__() { + return tuple___iter__(); + } + @ExposedMethod public PyObject tuple___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/cPickle.java =================================================================== --- branches/asm/src/org/python/modules/cPickle.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/cPickle.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -1130,9 +1130,17 @@ private void save_long(PyObject object) { if(protocol >= 2) { BigInteger integer = ((PyLong)object).getValue(); + + if (integer.compareTo(BigInteger.ZERO) == 0) { + // It's 0 -- an empty bytestring. + file.write(LONG1); + file.write((char)0); + return; + } + byte[] bytes = integer.toByteArray(); int l = bytes.length; - if(l < 256) { + if (l < 256) { file.write(LONG1); file.write((char)l); } else { @@ -1905,6 +1913,10 @@ private void load_bin_long(int length) { int longLength = read_binint(length); + if (longLength == 0) { + push(new PyLong(BigInteger.ZERO)); + return; + } String s = file.read(longLength); byte[] bytes = new byte[s.length()]; // Write to the byte array in reverse order: pickle orders Modified: branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/collections/PyDequeDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -832,6 +832,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -832,6 +832,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/templates/object.derived =================================================================== --- branches/asm/src/templates/object.derived 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/templates/object.derived 2008-07-21 04:59:03 UTC (rev 4979) @@ -188,6 +188,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type = getType(); + PyObject impl = self_type.lookup("__getitem__"); + if (impl != null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc, Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |