From: <cg...@us...> - 2008-12-10 07:09:53
|
Revision: 5729 http://jython.svn.sourceforge.net/jython/?rev=5729&view=rev Author: cgroves Date: 2008-12-10 07:09:49 +0000 (Wed, 10 Dec 2008) Log Message: ----------- Allow setattr and delattr to access the dicts of PyJavaTypes. Fixes test_strptime as Time was expected to allow modification to its dict. Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyType.java Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-12-10 06:47:19 UTC (rev 5728) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-12-10 07:09:49 UTC (rev 5729) @@ -40,7 +40,15 @@ return PyObject.class.isAssignableFrom(underlying_class) ? null : underlying_class; } + // Java types are ok with things being added and removed from their dicts as long as there isn't + // something there, so let these checks through @Override + protected void checkDelattr() {} + + @Override + protected void checkSetattr() {} + + @Override protected void init() { name = underlying_class.getName(); // Strip the java fully qualified class name from Py classes in core Modified: branches/newstyle-java-types/src/org/python/core/PyType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyType.java 2008-12-10 06:47:19 UTC (rev 5728) +++ branches/newstyle-java-types/src/org/python/core/PyType.java 2008-12-10 07:09:49 UTC (rev 5729) @@ -1076,11 +1076,15 @@ type___setattr__(name, value); } - final void type___setattr__(String name, PyObject value) { + protected void checkSetattr() { if (builtin) { throw Py.TypeError(String.format("can't set attributes of built-in/extension type " - + "'%s'", this.name)); + + "'%s'", this.name)); } + } + + final void type___setattr__(String name, PyObject value) { + checkSetattr(); super.__setattr__(name, value); if (name == "__set__") { if (!has_set && lookup("__set__") != null) { @@ -1114,11 +1118,15 @@ type___delattr__(asName(name)); } - final void type___delattr__(String name) { + protected void checkDelattr() { if (builtin) { throw Py.TypeError(String.format("can't set attributes of built-in/extension type " - + "'%s'", this.name)); + + "'%s'", this.name)); } + } + + final void type___delattr__(String name) { + checkDelattr(); super.__delattr__(name); if (name == "__set__") { if (has_set && lookup("__set__") == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |