From: <fwi...@us...> - 2008-11-26 05:19:44
|
Revision: 5642 http://jython.svn.sourceforge.net/jython/?rev=5642&view=rev Author: fwierzbicki Date: 2008-11-26 05:19:41 +0000 (Wed, 26 Nov 2008) Log Message: ----------- Applied Geoffrey French's collection fixes as this gets me further along in my experiments and I expect Geoffrey's fixes will make it into trunk via the java-newsytle branch. I'm not planning to do a direct merge from this branch back to trunk anyway. Thanks Geoffrey for the patch! Modified Paths: -------------- branches/astwrite/Lib/test/test_ast.py branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java branches/astwrite/src/org/python/core/AbstractArray.java branches/astwrite/src/org/python/core/CollectionProxy.java branches/astwrite/src/org/python/core/PyInstance.java branches/astwrite/src/org/python/core/PyList.java Modified: branches/astwrite/Lib/test/test_ast.py =================================================================== --- branches/astwrite/Lib/test/test_ast.py 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/Lib/test/test_ast.py 2008-11-26 05:19:41 UTC (rev 5642) @@ -34,7 +34,7 @@ return t elif isinstance(t, ast_list): return [to_tuple(e) for e in t] - result = [t.__class__.__name__] + result = [get_class_name(t)] if hasattr(t, 'lineno') and hasattr(t, 'col_offset'): result.append((t.lineno, t.col_offset)) if t._fields is None: @@ -219,17 +219,17 @@ def test_dump(self): node = ast.parse('spam(eggs, "and cheese")') self.assertEqual(ast.dump(node), - "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load()), " - "args=[Name(id='eggs', ctx=Load()), Str(s='and cheese')], " + u"Module(body=[Expr(value=Call(func=Name(id=u'spam', ctx=Load()), " + "args=[Name(id=u'eggs', ctx=Load()), Str(s='and cheese')], " "keywords=[], starargs=None, kwargs=None))])" ) self.assertEqual(ast.dump(node, annotate_fields=False), - "Module([Expr(Call(Name('spam', Load()), [Name('eggs', Load()), " + "Module([Expr(Call(Name(u'spam', Load()), [Name(u'eggs', Load()), " "Str('and cheese')], [], None, None))])" ) self.assertEqual(ast.dump(node, include_attributes=True), - "Module(body=[Expr(value=Call(func=Name(id='spam', ctx=Load(), " - "lineno=1, col_offset=0), args=[Name(id='eggs', ctx=Load(), " + "Module(body=[Expr(value=Call(func=Name(id=u'spam', ctx=Load(), " + "lineno=1, col_offset=0), args=[Name(id=u'eggs', ctx=Load(), " "lineno=1, col_offset=5), Str(s='and cheese', lineno=1, " "col_offset=11)], keywords=[], starargs=None, kwargs=None, " "lineno=1, col_offset=0), lineno=1, col_offset=0)])" Modified: branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/antlr/adapter/ExprAdapter.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -2,10 +2,12 @@ import org.python.core.Py; import org.python.core.PyInteger; +import org.python.core.PyString; import org.python.core.PyJavaInstance; import org.python.antlr.ast.exprType; import org.python.antlr.ast.Num; +import org.python.antlr.ast.Str; import java.util.ArrayList; import java.util.List; @@ -23,6 +25,8 @@ return o; } else if (o instanceof Integer) { return new Num(new PyInteger((Integer)o)); + } else if (o instanceof String) { + return new Str(new PyString((String)o)); } //FIXME: investigate the right exception Modified: branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java =================================================================== --- branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/antlr/adapter/ListWrapper.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -8,6 +8,7 @@ import org.python.core.Py; import org.python.core.PyObject; +import org.python.core.PySequence; public class ListWrapper implements List { @@ -15,15 +16,15 @@ private AstAdapter adapter; public ListWrapper(List list) { + this(list, null); + } + + public ListWrapper(List list, AstAdapter adapter) { if (list == null) { throw Py.TypeError("AST list can't be None"); } this.list = list; - } - - public ListWrapper(List list, AstAdapter adapter) { this.adapter = adapter; - this.list = list; } public boolean containsAll(Collection c) { @@ -118,6 +119,7 @@ return list.subList(fromIndex, toIndex); } + /* public ListWrapper __add__(Object o) { List newList = new ArrayList(); newList.addAll(list); @@ -125,10 +127,6 @@ return new ListWrapper(newList); } - public void __iadd__(PyObject o) { - extend(o); - } - public int __len__() { return list.size(); } @@ -138,87 +136,91 @@ } public PyObject __imul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("1 Not supported yet."); } public PyObject __iter__() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("2 Not supported yet."); } public PyObject __mul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("3 Not supported yet."); } public PyObject __radd__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("4 Not supported yet."); } public PyObject __rmul__(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("5 Not supported yet."); } + */ public void append(PyObject o) { list.add(adapter.adapt(o)); } public int count(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("6 Not supported yet."); } protected void del(int i) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("7 Not supported yet."); } protected void delRange(int start, int stop, int step) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("8 Not supported yet."); } public void extend(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("9 Not supported yet."); } public int index(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("10 Not supported yet."); } public int index(PyObject o, int start) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("11 Not supported yet."); } public int index(PyObject o, int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("12 Not supported yet."); } public void insert(int index, PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("13 Not supported yet."); } public PyObject pop() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("14 Not supported yet."); } public PyObject pop(int n) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("15 Not supported yet."); } public void remove(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("16 Not supported yet."); } public void reverse() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("17 Not supported yet."); } public void sort(PyObject compare) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("18 Not supported yet."); } public void sort() { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("19 Not supported yet."); } public void sort(PyObject cmp, PyObject key, PyObject reverse) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException("20 Not supported yet."); } - + + public String toString() { + return list.toString(); + } } Modified: branches/astwrite/src/org/python/core/AbstractArray.java =================================================================== --- branches/astwrite/src/org/python/core/AbstractArray.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/AbstractArray.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -383,7 +383,7 @@ } throw new IndexOutOfBoundsException("start and stop must follow: 0 <= start <= stop <= " + - (this.size - 1) + ", but found start= " + start + " and stop=" + stop); + this.size + ", but found start= " + start + " and stop=" + stop); } /** Modified: branches/astwrite/src/org/python/core/CollectionProxy.java =================================================================== --- branches/astwrite/src/org/python/core/CollectionProxy.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/CollectionProxy.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -2,6 +2,7 @@ package org.python.core; +import java.util.Arrays; import java.util.Collection; import java.util.Dictionary; import java.util.Enumeration; @@ -17,6 +18,9 @@ if (object == null) return NoProxy; + if (object instanceof Vector) { + return new VectorProxy(((Vector) object)); + } if (object instanceof List) { return new ListProxy(((List) object)); } @@ -31,9 +35,6 @@ } - if (object instanceof Vector) { - return new VectorProxy(((Vector) object)); - } if (object instanceof Enumeration) { return new EnumerationProxy(((Enumeration) object)); } @@ -112,10 +113,13 @@ } } -class VectorProxy extends CollectionProxy { - Vector proxy; - public VectorProxy(Vector proxy) { + + +class ListProxy extends CollectionProxy { + List proxy; + + public ListProxy(List proxy) { this.proxy = proxy; } @@ -124,71 +128,222 @@ } public PyObject __finditem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; try { - return Py.java2py(this.proxy.elementAt(key)); - } catch (ArrayIndexOutOfBoundsException exc) { - return null; + return Py.java2py(this.proxy.get(k)); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("index out of range: " + String.valueOf(key)); } } + protected PyObject __finditem__(int start, int stop, int step, int n) { + if(step > 0 && stop < start) { + stop = start; + } + PyObject[] newList = new PyObject[n]; + if(step == 1) { + for (int i = start; i < stop; i++) + { + newList[i-start] = Py.java2py(this.proxy.get(i)); + } + return new PyList(newList); + } + int j = 0; + for(int i = start; j < n; i += step) { + newList[j] = Py.java2py(this.proxy.get(i)); + j++; + } + return new PyList(newList); + } + public PyObject __finditem__(PyObject key) { if (key instanceof PyInteger) { return __finditem__(((PyInteger) key).getValue()); + } else if (key instanceof PySlice) { + PySlice slice = (PySlice)key; + int indices[] = slice.indicesEx(this.proxy.size()); + return __finditem__(indices[0], indices[1], indices[2], indices[3]); } else { - throw Py.TypeError("only integer keys accepted"); + throw Py.TypeError("only integer or slice keys accepted"); } } + public void __setitem__(int key, PyObject value) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + this.proxy.set(k, Py.tojava(value, Object.class)); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } + public void __setitem__(PyObject key, PyObject value) { if (key instanceof PyInteger) { - this.proxy.setElementAt(Py.tojava(value, Object.class), - ((PyInteger) key).getValue()); + __setitem__(((PyInteger) key).getValue(), value); + } else if (key instanceof PySlice) { + PySlice slice = (PySlice)key; + int indices[] = slice.indicesEx(this.proxy.size()); + __setitem__(slice, indices[0], indices[1], indices[2], indices[3], value); } else { throw Py.TypeError("only integer keys accepted"); } } + public void __delitem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + this.proxy.remove(k); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } + + protected void __delitem__(int start, int stop, int step, int n) { + if(step == 1) { + for (int i = stop - 1; i >= start; i--) { + this.proxy.remove(i); + } + } else if(step > 1) { + for(int i = start; i < stop; i += step) { + this.proxy.remove(i); + i--; + stop--; + } + } else if(step < 0) { + for(int i = start; i >= 0 && i >= stop; i += step) { + this.proxy.remove(i); + } + } + } + public void __delitem__(PyObject key) { if (key instanceof PyInteger) { - this.proxy.removeElementAt(((PyInteger) key).getValue()); + __delitem__(((PyInteger) key).getValue()); + } else if (key instanceof PySlice) { + PySlice slice = (PySlice)key; + int indices[] = slice.indicesEx(this.proxy.size()); + __delitem__(indices[0], indices[1], indices[2], indices[3]); } else { throw Py.TypeError("only integer keys accepted"); } } -} -class DictionaryProxy extends CollectionProxy { - Dictionary proxy; - public DictionaryProxy(Dictionary proxy) { - this.proxy = proxy; + + + protected void __setitem__(PySlice slice, int start, int stop, int step, int n, PyObject value) { + if(stop < start) { + stop = start; + } + if(value instanceof PySequence) { + PySequence sequence = (PySequence) value; + setslicePySequence(slice, start, stop, step, n, sequence); + } else if(value instanceof List) { + List list = (List)value.__tojava__(List.class); + if(list != null && list != Py.NoConversion) { + setsliceList(slice, start, stop, step, list); + } + } else { + setsliceIterable(slice, start, stop, step, n, value); + } } - public int __len__() { - return this.proxy.size(); + protected void setslicePySequence(PySlice slice, int start, int stop, int step, int n, PySequence value) { + if(slice.step != Py.None) { + if(n != value.__len__()) { + throw Py.ValueError("attempt to assign sequence of size " + value.__len__() + " to extended slice of size " + n); + } + } + if(step == 1) { + PyObject[] srcArray; + Object[] jArray; + + if(value instanceof PySequenceList) { + srcArray = ((PySequenceList)value).getArray(); + } else { + srcArray = Py.unpackSequence(value, value.__len__()); + } + jArray = new Object[srcArray.length]; + for (int i = 0; i < srcArray.length; i++) { + jArray[i] = Py.tojava(srcArray[i], Object.class); + } + List sub = this.proxy.subList(start, stop); + sub.clear(); + this.proxy.addAll( start, Arrays.asList(jArray) ); + } else if(step != 0) { + for (int i = 0, j = start; i < n; i++, j += step) { + this.proxy.set(j, Py.tojava(value.pyget(i), Object.class)); + } + } } - public PyObject __finditem__(int key) { - throw Py.TypeError("loop over non-sequence"); + protected void setsliceList(PySlice slice, int start, int stop, int step, List value) { + if(step != 1) { + throw Py.TypeError("setslice with java.util.List and step != 1 not supported yet"); + } + int n = value.size(); + for(int i = 0; i < n; i++) { + this.proxy.add(i + start, value.get(i)); + } } - public PyObject __finditem__(PyObject key) { - return Py.java2py(this.proxy.get(Py.tojava(key, Object.class))); + protected void setsliceIterable(PySlice slice, int start, int stop, int step, int n, PyObject value) { + PyObject[] seq; + try { + seq = Py.make_array(value); + } catch (PyException pye) { + if (Py.matchException(pye, Py.TypeError)) { + throw Py.TypeError("can only assign an iterable"); + } + throw pye; + } + setslicePySequence(slice, start, stop, step, n, new PyList(seq)); } +} - public void __setitem__(PyObject key, PyObject value) { - this.proxy.put(Py.tojava(key, Object.class), Py.tojava(value, - Object.class)); + + + +class VectorProxy extends ListProxy { + public VectorProxy(Vector proxy) { + super(proxy); } - public void __delitem__(PyObject key) { - this.proxy.remove(Py.tojava(key, Object.class)); + public PyObject __finditem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + return Py.java2py(((Vector)this.proxy).elementAt(k)); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("index out of range: " + String.valueOf(key)); + } } + + public void __setitem__(int key, PyObject value) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + ((Vector)this.proxy).setElementAt(Py.tojava(value, Object.class), k); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } + + public void __delitem__(int key) { + int k = key < 0 ? key + this.proxy.size() : key; + try { + ((Vector)this.proxy).removeElementAt(k); + } catch (IndexOutOfBoundsException exc) { + throw Py.IndexError("assignment index out of range: " + String.valueOf(key)); + } + } } -class ListProxy extends CollectionProxy { - List proxy; - public ListProxy(List proxy) { + + + +class DictionaryProxy extends CollectionProxy { + Dictionary proxy; + + public DictionaryProxy(Dictionary proxy) { this.proxy = proxy; } @@ -197,46 +352,22 @@ } public PyObject __finditem__(int key) { - try { - return Py.java2py(this.proxy.get(key)); - } catch (IndexOutOfBoundsException exc) { - return null; - } + throw Py.TypeError("loop over non-sequence"); } public PyObject __finditem__(PyObject key) { - if (key instanceof PyInteger) { - return __finditem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } + return Py.java2py(this.proxy.get(Py.tojava(key, Object.class))); } - public void __setitem__(int key, PyObject value) { - this.proxy.set(key, Py.tojava(value, Object.class)); - } - public void __setitem__(PyObject key, PyObject value) { - if (key instanceof PyInteger) { - __setitem__(((PyInteger) key).getValue(), value); - } else { - throw Py.TypeError("only integer keys accepted"); - } + this.proxy.put(Py.tojava(key, Object.class), Py.tojava(value, + Object.class)); } - public void __delitem__(int key) { - this.proxy.remove(key); - } - public void __delitem__(PyObject key) { - if (key instanceof PyInteger) { - __delitem__(((PyInteger) key).getValue()); - } else { - throw Py.TypeError("only integer keys accepted"); - } + this.proxy.remove(Py.tojava(key, Object.class)); } } - class MapProxy extends CollectionProxy { Map proxy; Modified: branches/astwrite/src/org/python/core/PyInstance.java =================================================================== --- branches/astwrite/src/org/python/core/PyInstance.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/PyInstance.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -10,6 +10,10 @@ public class PyInstance extends PyObject { + // Collection proxy invoke no method found error code - return an error + // code instead of using slower exceptions + public static PyObject collectionProxyNoMethodError = new PyObject(); + // xxx doc, final name public transient PyClass instclass; @@ -251,6 +255,61 @@ return __findattr__("__index__") != null; } + + public PyObject iinvoke_collectionProxy(String name) { + PyObject f = ifindlocal(name); + if (f == null) { + f = ifindclass(name, false); + if (f != null) { + if (f instanceof PyFunction) { + return f.__call__(this); + } else { + f = f.__get__(this, instclass); + } + } + } + if (f == null) f = ifindfunction(name); + if (f == null) return collectionProxyNoMethodError; + return f.__call__(); + } + + public PyObject iinvoke_collectionProxy(String name, PyObject arg1) { + PyObject f = ifindlocal(name); + if (f == null) { + f = ifindclass(name, false); + if (f != null) { + if (f instanceof PyFunction) { + return f.__call__(this, arg1); + } else { + f = f.__get__(this, instclass); + } + } + } + if (f == null) f = ifindfunction(name); + if (f == null) return collectionProxyNoMethodError; + return f.__call__(arg1); + } + + public PyObject iinvoke_collectionProxy(String name, PyObject arg1, PyObject arg2) { + PyObject f = ifindlocal(name); + if (f == null) { + f = ifindclass(name, false); + if (f != null) { + if (f instanceof PyFunction) { + return f.__call__(this, arg1, arg2); + } else { + f = f.__get__(this, instclass); + } + } + } + if (f == null) f = ifindfunction(name); + if (f == null) return collectionProxyNoMethodError; + return f.__call__(arg1, arg2); + } + + + + public PyObject invoke(String name) { PyObject f = ifindlocal(name); if (f == null) { @@ -548,16 +607,18 @@ } catch (PyException exc) { } if (meth == null) { - // Copied form __len__() - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__len__() != 0 ? true : false; - } try { meth = __findattr__("__len__"); } catch (PyException exc) { } - if (meth == null) - return true; + if (meth == null) { + // Copied form __len__() + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__len__() != 0 ? true : false; + } else { + return true; + } + } } PyObject ret = meth.__call__(); @@ -573,22 +634,21 @@ } public int __len__() { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__len__(); + PyObject ret = iinvoke_collectionProxy("__len__"); + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__len__(); + } else { + noAttributeError("__len__"); + } } - - PyObject ret = invoke("__len__"); if (ret instanceof PyInteger) return ((PyInteger)ret).getValue(); throw Py.TypeError("__len__() should return an int"); } public PyObject __finditem__(int key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__finditem__(key); - } return __finditem__(new PyInteger(key)); } @@ -614,13 +674,9 @@ } public PyObject __finditem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - return proxy.__finditem__(key); - } - + PyObject ret = null; try { - return invoke("__getitem__", key); + ret = iinvoke_collectionProxy("__getitem__", key); } catch (PyException e) { if (Py.matchException(e, Py.IndexError)) return null; @@ -628,36 +684,64 @@ return null; throw e; } + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__finditem__(key); + } else { + noAttributeError("__getitem__"); + } + } + + return ret; } public PyObject __getitem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - PyObject ret = proxy.__finditem__(key); - if (ret == null) { - throw Py.KeyError(key.toString()); + PyObject ret = iinvoke_collectionProxy("__getitem__", key); + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + ret = proxy.__finditem__(key); + if (ret == null) { + throw Py.KeyError(key.toString()); + } + return ret; + } else { + noAttributeError("__getitem__"); } - return ret; } - return invoke("__getitem__", key); + + return ret; } public void __setitem__(PyObject key, PyObject value) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - proxy.__setitem__(key, value); - return; + PyObject ret = iinvoke_collectionProxy("__setitem__", key, value); + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + proxy.__setitem__(key, value); + return; + } else { + noAttributeError("__setitem__"); + } } - invoke("__setitem__", key, value); } public void __delitem__(PyObject key) { - CollectionProxy proxy = getCollection(); - if (proxy != CollectionProxy.NoProxy) { - proxy.__delitem__(key); - return; + PyObject ret = iinvoke_collectionProxy("__delitem__", key); + + if (ret == collectionProxyNoMethodError) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + proxy.__delitem__(key); + return; + } else { + noAttributeError("__delitem__"); + } } - invoke("__delitem__", key); } public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) { @@ -688,16 +772,18 @@ } public PyObject __iter__() { - PyObject iter = getCollectionIter(); - if (iter != null) { - return iter; - } PyObject func = __findattr__("__iter__"); if (func != null) return func.__call__(); func = __findattr__("__getitem__"); - if (func == null) - return super.__iter__(); + if (func == null) { + PyObject iter = getCollectionIter(); + if (iter != null) { + return iter; + } else { + return super.__iter__(); + } + } return new PySequenceIter(this); } Modified: branches/astwrite/src/org/python/core/PyList.java =================================================================== --- branches/astwrite/src/org/python/core/PyList.java 2008-11-26 03:42:02 UTC (rev 5641) +++ branches/astwrite/src/org/python/core/PyList.java 2008-11-26 05:19:41 UTC (rev 5642) @@ -114,7 +114,9 @@ protected void delRange(int start, int stop, int step) { if(step == 1) { - remove(start, stop); + if ( stop > start ) { + remove(start, stop); + } } else if(step > 1) { for(int i = start; i < stop; i += step) { remove(i); @@ -164,13 +166,7 @@ otherArray = otherArray.clone(); } list.replaceSubArray(start, stop, otherArray, 0, n); - } else if(step > 1) { - int n = value.__len__(); - for(int i = 0, j = 0; i < n; i++, j += step) { - list.pyset(j + start, value.pyget(i)); - } - } else if(step < 0) { - int n = value.__len__(); + } else if(step != 0) { if(value == this) { PyList newseq = new PyList(); PyObject iter = value.__iter__(); @@ -179,7 +175,8 @@ } value = newseq; } - for(int i = 0, j = list.size() - 1; i < n; i++, j += step) { + int n = value.__len__(); + for (int i = 0, j = start; i < n; i++, j += step) { list.pyset(j, value.pyget(i)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |