From: <otm...@us...> - 2010-09-28 05:35:28
|
Revision: 7127 http://jython.svn.sourceforge.net/jython/?rev=7127&view=rev Author: otmarhumbel Date: 2010-09-28 05:35:21 +0000 (Tue, 28 Sep 2010) Log Message: ----------- handle more SQL types in zxJDBC DataHandler (fixes issue #1647) thanks to Stephen Layland for the first patch thanks to Patrick Reinhart for discovering the missing types Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/com/ziclix/python/sql/DataHandler.java trunk/jython/src/com/ziclix/python/sql/Jython22DataHandler.java trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java trunk/jython/src/com/ziclix/python/sql/resource/zxJDBCMessages.properties Added Paths: ----------- trunk/jython/tests/java/com/ trunk/jython/tests/java/com/ziclix/ trunk/jython/tests/java/com/ziclix/python/ trunk/jython/tests/java/com/ziclix/python/sql/ trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-09-27 13:14:22 UTC (rev 7126) +++ trunk/jython/NEWS 2010-09-28 05:35:21 UTC (rev 7127) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.2rc1 + Bugs Fixed + - [ 1647 ] zxJDBC does not handle NVARCHAR + Jython 2.5.2b2 Bugs Fixed - [ 1327 ] Classloaders cannot GC, which exhausts permgen (partial bug fix) Modified: trunk/jython/src/com/ziclix/python/sql/DataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2010-09-27 13:14:22 UTC (rev 7126) +++ trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2010-09-28 05:35:21 UTC (rev 7127) @@ -8,11 +8,6 @@ */ package com.ziclix.python.sql; -import org.python.core.Py; -import org.python.core.PyFile; -import org.python.core.PyObject; -import org.python.core.PyList; - import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -20,9 +15,11 @@ import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Constructor; +import java.math.BigDecimal; import java.math.BigInteger; -import java.math.BigDecimal; +import java.sql.Blob; import java.sql.CallableStatement; +import java.sql.Clob; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -32,6 +29,11 @@ import java.sql.Timestamp; import java.sql.Types; +import org.python.core.Py; +import org.python.core.PyFile; +import org.python.core.PyList; +import org.python.core.PyObject; + /** * The DataHandler is responsible mapping the JDBC data type to * a Jython object. Depending on the version of the JDBC @@ -250,6 +252,7 @@ break; case Types.BIT: + case Types.BOOLEAN: obj = set.getBoolean(col) ? Py.True : Py.False; break; @@ -291,6 +294,7 @@ break; case Types.OTHER: + case Types.JAVA_OBJECT: obj = Py.java2py(set.getObject(col)); break; @@ -300,16 +304,41 @@ obj = Py.java2py(set.getBytes(col)); break; + case Types.BLOB: + Blob blob = set.getBlob(col); + obj = blob == null ? Py.None : Py.java2py(read(blob.getBinaryStream())); + break; + + case Types.CLOB: + Clob clob = set.getClob(col); + obj = clob == null ? Py.None : Py.java2py(read(clob.getCharacterStream())); + break; + + // TODO can we support these? + case Types.ARRAY: + throw createUnsupportedTypeSQLException("ARRAY", col); + case Types.DATALINK: + throw createUnsupportedTypeSQLException("DATALINK", col); + case Types.DISTINCT: + throw createUnsupportedTypeSQLException("DISTINCT", col); + case Types.REF: + throw createUnsupportedTypeSQLException("REF", col); + case Types.STRUCT: + throw createUnsupportedTypeSQLException("STRUCT", col); + default : - Integer[] vals = {new Integer(col), new Integer(type)}; - String msg = zxJDBC.getString("errorGettingIndex", vals); - - throw new SQLException(msg); + throw createUnsupportedTypeSQLException(new Integer(type), col); } return set.wasNull() || obj == null ? Py.None : obj; } + protected final SQLException createUnsupportedTypeSQLException(Object type, int col) { + Object[] vals = {type, new Integer(col)}; + String msg = zxJDBC.getString("unsupportedTypeForColumn", vals); + return new SQLException(msg); + } + /** * Given a CallableStatement, column and type, return the appropriate * Jython object. @@ -387,10 +416,7 @@ break; default : - Integer[] vals = {new Integer(col), new Integer(type)}; - String msg = zxJDBC.getString("errorGettingIndex", vals); - - throw new SQLException(msg); + createUnsupportedTypeSQLException(type, col); } return stmt.wasNull() || obj == null ? Py.None : obj; Modified: trunk/jython/src/com/ziclix/python/sql/Jython22DataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/Jython22DataHandler.java 2010-09-27 13:14:22 UTC (rev 7126) +++ trunk/jython/src/com/ziclix/python/sql/Jython22DataHandler.java 2010-09-28 05:35:21 UTC (rev 7127) @@ -51,6 +51,7 @@ * most notably Oracle. This callback allows a DataHandler to affect the * name. */ + @Override public String getMetaDataName(PyObject name) { return ((name == Py.None) ? null : name.__str__().toString()); } @@ -63,6 +64,7 @@ * @return an instance of a Procedure * @throws SQLException */ + @Override public Procedure getProcedure(PyCursor cursor, PyObject name) throws SQLException { return new Procedure(cursor, name); } @@ -75,6 +77,7 @@ * @throws SQLException thrown if an exception occurs * */ + @Override public PyObject getRowId(Statement stmt) throws SQLException { return Py.None; } @@ -83,6 +86,7 @@ * A callback prior to each execution of the statement. If the statement is * a PreparedStatement, all the parameters will have been set. */ + @Override public void preExecute(Statement stmt) throws SQLException { return; } @@ -90,6 +94,7 @@ /** * A callback after successfully executing the statement. */ + @Override public void postExecute(Statement stmt) throws SQLException { return; } @@ -103,6 +108,7 @@ * @param object the PyObject in question * @throws SQLException */ + @Override public void setJDBCObject(PreparedStatement stmt, int index, PyObject object) throws SQLException { try { @@ -133,6 +139,7 @@ * @param type the <i>java.sql.Types</i> for which this PyObject should be bound * @throws SQLException */ + @Override public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { try { @@ -209,6 +216,7 @@ * @param type the column type * @throws SQLException if the type is unmappable */ + @Override @SuppressWarnings("deprecation") public PyObject getPyObject(ResultSet set, int col, int type) throws SQLException { @@ -308,10 +316,7 @@ break; default : - Integer[] vals = {new Integer(col), new Integer(type)}; - String msg = zxJDBC.getString("errorGettingIndex", vals); - - throw new SQLException(msg); + throw createUnsupportedTypeSQLException(new Integer(type), col); } return (set.wasNull() || (obj == null)) ? Py.None : obj; @@ -326,6 +331,7 @@ * @param type the column type * @throws SQLException if the type is unmappable */ + @Override @SuppressWarnings("deprecation") public PyObject getPyObject(CallableStatement stmt, int col, int type) throws SQLException { @@ -398,10 +404,7 @@ break; default : - Integer[] vals = {new Integer(col), new Integer(type)}; - String msg = zxJDBC.getString("errorGettingIndex", vals); - - throw new SQLException(msg); + throw createUnsupportedTypeSQLException(new Integer(type), col); } return (stmt.wasNull() || (obj == null)) ? Py.None : obj; @@ -420,6 +423,7 @@ * @throws SQLException * */ + @Override public void registerOut(CallableStatement statement, int index, int colType, int dataType, String dataTypeName) throws SQLException { try { @@ -445,6 +449,7 @@ * * @return a list of datahandlers */ + @Override public PyObject __chain__() { return new PyList(Py.javas2pys(this)); } Modified: trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java 2010-09-27 13:14:22 UTC (rev 7126) +++ trunk/jython/src/com/ziclix/python/sql/handler/OracleDataHandler.java 2010-09-28 05:35:21 UTC (rev 7127) @@ -8,26 +8,25 @@ */ package com.ziclix.python.sql.handler; -import com.ziclix.python.sql.DataHandler; -import com.ziclix.python.sql.FilterDataHandler; -import com.ziclix.python.sql.zxJDBC; +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.sql.Types; + import oracle.jdbc.OracleResultSet; import oracle.jdbc.OracleTypes; import oracle.sql.BLOB; import oracle.sql.ROWID; + import org.python.core.Py; import org.python.core.PyInteger; import org.python.core.PyObject; -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.sql.Types; +import com.ziclix.python.sql.DataHandler; +import com.ziclix.python.sql.FilterDataHandler; /** * Oracle specific data handling. @@ -96,13 +95,6 @@ super.setJDBCObject(stmt, index, object, Types.DOUBLE); break; - case Types.BLOB: - case Types.CLOB: - Integer[] vals = {new Integer(index), new Integer(type)}; - String msg = zxJDBC.getString("errorSettingIndex", vals); - - throw new SQLException(msg); - case OracleTypes.ROWID: stmt.setString(index, (String) object.__tojava__(String.class)); break; Modified: trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java 2010-09-27 13:14:22 UTC (rev 7126) +++ trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java 2010-09-28 05:35:21 UTC (rev 7127) @@ -38,6 +38,7 @@ super(datahandler); } + @Override protected String getRowIdMethodName() { return "getLastOID"; } @@ -51,6 +52,7 @@ * @return the mapped Python object * @throws SQLException thrown for a sql exception */ + @Override public PyObject getPyObject(ResultSet set, int col, int type) throws SQLException { PyObject obj = Py.None; @@ -90,6 +92,7 @@ * @param type * @throws SQLException */ + @Override public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { if (DataHandler.checkNull(stmt, index, object, type)) { @@ -115,6 +118,8 @@ super.setJDBCObject(stmt, index, object, type); } } + + @Override public void setJDBCObject(PreparedStatement stmt, int index, PyObject object) throws SQLException { // PostgreSQL doesn't support BigIntegers without explicitely setting the // type. Modified: trunk/jython/src/com/ziclix/python/sql/resource/zxJDBCMessages.properties =================================================================== --- trunk/jython/src/com/ziclix/python/sql/resource/zxJDBCMessages.properties 2010-09-27 13:14:22 UTC (rev 7126) +++ trunk/jython/src/com/ziclix/python/sql/resource/zxJDBCMessages.properties 2010-09-28 05:35:21 UTC (rev 7127) @@ -94,8 +94,7 @@ noColInfo=unable to obtain column info excludedAllCols=excluded all columns invalidTableName=invalid table name [None] -errorSettingIndex=error setting index [{0}], type [{1}] -errorGettingIndex=error getting index [{0}], type [{1}] +unsupportedTypeForColumn=type [{0}] is not supported for column index: {1} maybeCallproc=use .callproc() for stored procedures nodynamiccursors=this version of jdbc does not support dynamic cursors nocallprocsupport=dynamic cursor does not support .callproc; use static cursors instead Added: trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java =================================================================== --- trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java (rev 0) +++ trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java 2010-09-28 05:35:21 UTC (rev 7127) @@ -0,0 +1,95 @@ +package com.ziclix.python.sql; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Arrays; +import java.util.List; + +import org.python.core.PySystemState; + +import junit.framework.TestCase; + +public class DataHandlerTest extends TestCase { + + private DataHandler _handler; + + @Override + protected void setUp() throws Exception { + PySystemState.initialize(); + _handler = new DataHandler(); + } + + /** + * make sure we handle every {@link java.sql.Types} somehow + * + * @throws Exception + */ + public void testGetPyObjectResultSetIntInt() throws Exception { + ResultSet rs = (ResultSet)Proxy.newProxyInstance(getClass().getClassLoader(), + new Class<?>[] {ResultSet.class}, + new DefaultReturnHandler()); + List<String> unsupportedTypes = Arrays.asList("ARRAY", + "DATALINK", + "DISTINCT", + "REF", + "STRUCT"); + for (Field field : Types.class.getDeclaredFields()) { + String typeName = field.getName(); + int type = field.getInt(null); + if (unsupportedTypes.contains(typeName)) { + try { + _handler.getPyObject(rs, 1, type); + fail("SQLException expected"); + } catch (SQLException sqle) { + // expected + } + } else { + assertNotNull(typeName + " should return None", _handler.getPyObject(rs, 1, type)); + } + } + } + + /** + * This is a poor man's mock - i cannot introduce a mock framework at this point in time + */ + static class DefaultReturnHandler implements InvocationHandler { + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Class<?> returnType = method.getReturnType(); + if (returnType.equals(Boolean.class) || returnType.equals(Boolean.TYPE)) { + return Boolean.FALSE; + } else if (Character.TYPE.equals(returnType)) { + return Character.valueOf('0'); + } else if (Byte.TYPE.equals(returnType)) { + return Byte.valueOf((byte)0); + } else if (Short.TYPE.equals(returnType)) { + return Short.valueOf((short)0); + } else if (Integer.TYPE.equals(returnType)) { + return Integer.valueOf(0); + } else if (Long.TYPE.equals(returnType)) { + return Long.valueOf(0L); + } else if (Float.TYPE.equals(returnType)) { + return Float.valueOf(0); + } else if (Double.TYPE.equals(returnType)) { + return Double.valueOf(0); + } else if (returnType.isPrimitive()) { + throw new RuntimeException("unhandled primitve type " + returnType); + } else if (returnType.isAssignableFrom(BigInteger.class)) { + return BigInteger.ZERO; + } else if (returnType.isAssignableFrom(BigDecimal.class)) { + return BigDecimal.ZERO; + } else if (returnType.isAssignableFrom(Number.class)) { + return 0; + } else { + return null; + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-09-29 06:30:05
|
Revision: 7128 http://jython.svn.sourceforge.net/jython/?rev=7128&view=rev Author: otmarhumbel Date: 2010-09-29 06:29:59 +0000 (Wed, 29 Sep 2010) Log Message: ----------- try to get the console encoding from java.io.Console using reflection fixes issue #1568 (given that Jython runs on Java 6) thanks to Regis Desgroppes for the hints Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-09-28 05:35:21 UTC (rev 7127) +++ trunk/jython/NEWS 2010-09-29 06:29:59 UTC (rev 7128) @@ -2,6 +2,7 @@ Jython 2.5.2rc1 Bugs Fixed + - [ 1568 ] sys.stdout.encoding returns wrong value in Windows with Jython 2.5.1 (fixed on Java 6 only) - [ 1647 ] zxJDBC does not handle NVARCHAR Jython 2.5.2b2 Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2010-09-28 05:35:21 UTC (rev 7127) +++ trunk/jython/src/org/python/core/PySystemState.java 2010-09-29 06:29:59 UTC (rev 7128) @@ -10,6 +10,7 @@ import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; +import java.lang.reflect.Method; import java.net.URL; import java.net.URLDecoder; import java.nio.charset.Charset; @@ -652,12 +653,7 @@ } } if (!registry.containsKey(PYTHON_CONSOLE_ENCODING)) { - String encoding; - try { - encoding = System.getProperty("file.encoding"); - } catch (SecurityException se) { - encoding = null; - } + String encoding = getPlatformEncoding(); if (encoding != null) { registry.put(PYTHON_CONSOLE_ENCODING, encoding); } @@ -665,7 +661,40 @@ // Set up options from registry Options.setFromRegistry(); } + + /** + * @return the encoding of the underlying platform; can be <code>null</code> + */ + private static String getPlatformEncoding() { + // first try to grab the Console encoding + String encoding = getConsoleEncoding(); + if (encoding == null) { + try { + encoding = System.getProperty("file.encoding"); + } catch (SecurityException se) { + // ignore, can't do anything about it + } + } + return encoding; + } + /** + * @return the console encoding; can be <code>null</code> + */ + private static String getConsoleEncoding() { + String encoding = null; + try { + // the Console class is only present in java 6 - have to use reflection + Class<?> consoleClass = Class.forName("java.io.Console"); + Method encodingMethod = consoleClass.getDeclaredMethod("encoding"); + encodingMethod.setAccessible(true); // private static method + encoding = (String)encodingMethod.invoke(consoleClass); + } catch (Exception e) { + // ignore any exception + } + return encoding; + } + private static void addRegistryFile(File file) { if (file.exists()) { if (!file.isDirectory()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-10-03 21:14:35
|
Revision: 7132 http://jython.svn.sourceforge.net/jython/?rev=7132&view=rev Author: otmarhumbel Date: 2010-10-03 21:14:29 +0000 (Sun, 03 Oct 2010) Log Message: ----------- handle the new JDBC 4.0 java.sql.Types as well (this hopefully really fixes issue 1647) Modified Paths: -------------- trunk/jython/src/com/ziclix/python/sql/DataHandler.java trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java Modified: trunk/jython/src/com/ziclix/python/sql/DataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2010-10-03 19:47:13 UTC (rev 7131) +++ trunk/jython/src/com/ziclix/python/sql/DataHandler.java 2010-10-03 21:14:29 UTC (rev 7132) @@ -236,11 +236,14 @@ case Types.CHAR: case Types.VARCHAR: + case Java6Types.NCHAR: + case Java6Types.NVARCHAR: String string = set.getString(col); obj = string == null ? Py.None : Py.newUnicode(string); break; case Types.LONGVARCHAR: + case Java6Types.LONGNVARCHAR: Reader reader = set.getCharacterStream(col); obj = reader == null ? Py.None : Py.newUnicode(read(reader)); break; @@ -310,6 +313,8 @@ break; case Types.CLOB: + case Java6Types.NCLOB: + case Java6Types.SQLXML: Clob clob = set.getClob(col); obj = clob == null ? Py.None : Py.java2py(read(clob.getCharacterStream())); break; @@ -323,6 +328,8 @@ throw createUnsupportedTypeSQLException("DISTINCT", col); case Types.REF: throw createUnsupportedTypeSQLException("REF", col); + case Java6Types.ROWID: + throw createUnsupportedTypeSQLException("STRUCT", col); case Types.STRUCT: throw createUnsupportedTypeSQLException("STRUCT", col); @@ -560,5 +567,60 @@ public String toString() { return getClass().getName(); } + + /** + * This interface can be removed as soon as we target java 6 + */ + private static interface Java6Types{ + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type <code>ROWID</code> + * + * @since 1.6 + * + */ + public final static int ROWID = -8; + + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type <code>NCHAR</code> + * + * @since 1.6 + */ + public static final int NCHAR = -15; + + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type <code>NVARCHAR</code>. + * + * @since 1.6 + */ + public static final int NVARCHAR = -9; + + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type <code>LONGNVARCHAR</code>. + * + * @since 1.6 + */ + public static final int LONGNVARCHAR = -16; + + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type <code>NCLOB</code>. + * + * @since 1.6 + */ + public static final int NCLOB = 2011; + + /** + * The constant in the Java programming language, sometimes referred to + * as a type code, that identifies the generic SQL type <code>XML</code>. + * + * @since 1.6 + */ + public static final int SQLXML = 2009; + } + } Modified: trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java =================================================================== --- trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java 2010-10-03 19:47:13 UTC (rev 7131) +++ trunk/jython/tests/java/com/ziclix/python/sql/DataHandlerTest.java 2010-10-03 21:14:29 UTC (rev 7132) @@ -39,6 +39,7 @@ "DATALINK", "DISTINCT", "REF", + "ROWID", // java 6 "STRUCT"); for (Field field : Types.class.getDeclaredFields()) { String typeName = field.getName(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-10-04 19:53:01
|
Revision: 7134 http://jython.svn.sourceforge.net/jython/?rev=7134&view=rev Author: otmarhumbel Date: 2010-10-04 19:52:55 +0000 (Mon, 04 Oct 2010) Log Message: ----------- enable help() in standalone mode fixes issue #1452 thanks to David Handy for the patch! Modified Paths: -------------- trunk/jython/Lib/pydoc.py trunk/jython/NEWS Modified: trunk/jython/Lib/pydoc.py =================================================================== --- trunk/jython/Lib/pydoc.py 2010-10-04 17:28:05 UTC (rev 7133) +++ trunk/jython/Lib/pydoc.py 2010-10-04 19:52:55 UTC (rev 7134) @@ -1623,7 +1623,11 @@ self.input = input self.output = output self.docdir = None - execdir = os.path.dirname(sys.executable) + if sys.executable is None: + execdir = os.getcwd() + else: + execdir = os.path.dirname(sys.executable) + homedir = os.environ.get('PYTHONHOME') for dir in [os.environ.get('PYTHONDOCS'), homedir and os.path.join(homedir, 'doc'), Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-04 17:28:05 UTC (rev 7133) +++ trunk/jython/NEWS 2010-10-04 19:52:55 UTC (rev 7134) @@ -2,6 +2,7 @@ Jython 2.5.2rc1 Bugs Fixed + - [ 1452 ] pydoc help() function fails because sys.executable is None in stand-alone Jython - [ 1568 ] sys.stdout.encoding returns wrong value in Windows with Jython 2.5.1 (fixed on Java 6 only) - [ 1647 ] zxJDBC does not handle NVARCHAR This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-05 22:26:40
|
Revision: 7136 http://jython.svn.sourceforge.net/jython/?rev=7136&view=rev Author: zyasoft Date: 2010-10-05 22:26:34 +0000 (Tue, 05 Oct 2010) Log Message: ----------- Upgraded Guava Google collections to 0.7. Modified Paths: -------------- trunk/jython/build.xml Added Paths: ----------- trunk/jython/extlibs/guava-r07.jar Removed Paths: ------------- trunk/jython/extlibs/guava-r05.jar Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2010-10-05 20:19:43 UTC (rev 7135) +++ trunk/jython/build.xml 2010-10-05 22:26:34 UTC (rev 7136) @@ -189,7 +189,7 @@ <pathelement path="${extlibs.dir}/asm-3.1.jar" /> <pathelement path="${extlibs.dir}/asm-commons-3.1.jar" /> <pathelement path="${extlibs.dir}/constantine.jar" /> - <pathelement path="${extlibs.dir}/guava-r05.jar" /> + <pathelement path="${extlibs.dir}/guava-r07.jar" /> <pathelement path="${extlibs.dir}/jaffl.jar"/> <pathelement path="${extlibs.dir}/jffi-Darwin.jar"/> <pathelement path="${extlibs.dir}/jffi-i386-FreeBSD.jar"/> @@ -588,7 +588,7 @@ <zipfileset src="extlibs/asm-commons-3.1.jar"/> <zipfileset src="extlibs/asm-util-3.1.jar"/> <rule pattern="org.objectweb.asm.**" result="org.python.objectweb.asm.@1"/> - <zipfileset src="extlibs/guava-r05.jar"/> + <zipfileset src="extlibs/guava-r07.jar"/> <rule pattern="com.google.**" result="org.python.google.@1"/> <zipfileset src="extlibs/jaffl.jar"/> <zipfileset src="extlibs/jffi-Darwin.jar"/> Deleted: trunk/jython/extlibs/guava-r05.jar =================================================================== (Binary files differ) Added: trunk/jython/extlibs/guava-r07.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/guava-r07.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-10-09 07:53:48
|
Revision: 7141 http://jython.svn.sourceforge.net/jython/?rev=7141&view=rev Author: otmarhumbel Date: 2010-10-09 07:53:42 +0000 (Sat, 09 Oct 2010) Log Message: ----------- handle standalone recognition in the JBoss 5 virtual file system fixes issue #1639 many thanks to Eric Lentz! Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/PySystemState.java Added Paths: ----------- trunk/jython/tests/java/org/python/core/PySystemStateTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-07 20:46:21 UTC (rev 7140) +++ trunk/jython/NEWS 2010-10-09 07:53:42 UTC (rev 7141) @@ -2,6 +2,7 @@ Jython 2.5.2rc1 Bugs Fixed + - [ 1639 ] JBoss 5, vfszip protocol in use for jarFileName in PySystemState - [ 1660 ] threading module memory leak - [ 1452 ] pydoc help() function fails because sys.executable is None in stand-alone Jython - [ 1568 ] sys.stdout.encoding returns wrong value in Windows with Jython 2.5.1 (fixed on Java 6 only) Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2010-10-07 20:46:21 UTC (rev 7140) +++ trunk/jython/src/org/python/core/PySystemState.java 2010-10-09 07:53:42 UTC (rev 7141) @@ -16,19 +16,17 @@ import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import java.security.AccessControlException; -import java.util.concurrent.Callable; -import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.Map; -import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; +import java.util.Map.Entry; +import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentMap; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import com.google.common.collect.MapMaker; import org.jruby.ext.posix.util.Platform; import org.python.Version; import org.python.core.adapter.ClassicPyObjectAdapter; @@ -55,6 +53,7 @@ private static final String JAR_URL_PREFIX = "jar:file:"; private static final String JAR_SEPARATOR = "!"; + private static final String VFSZIP_PREFIX = "vfszip:"; public static final PyString version = new PyString(Version.getVersion()); public static final int hexversion = ((Version.PY_MAJOR_VERSION << 24) | @@ -1112,12 +1111,15 @@ * @return the full name of the jar file containing this class, <code>null</code> if not available. */ private static String getJarFileName() { - String jarFileName = null; - Class thisClass = PySystemState.class; + Class<PySystemState> thisClass = PySystemState.class; String fullClassName = thisClass.getName(); String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1); URL url = thisClass.getResource(className + ".class"); - // we expect an URL like jar:file:/install_dir/jython.jar!/org/python/core/PySystemState.class + return getJarFileNameFromURL(url); + } + + protected static String getJarFileNameFromURL(URL url) { + String jarFileName = null; if (url != null) { try { // escape plus signs, since the URLDecoder would turn them into spaces @@ -1129,7 +1131,21 @@ urlString = urlString.replaceAll(escapedPlus, plus); int jarSeparatorIndex = urlString.lastIndexOf(JAR_SEPARATOR); if (urlString.startsWith(JAR_URL_PREFIX) && jarSeparatorIndex > 0) { + // jar:file:/install_dir/jython.jar!/org/python/core/PySystemState.class jarFileName = urlString.substring(JAR_URL_PREFIX.length(), jarSeparatorIndex); + } else if (urlString.startsWith(VFSZIP_PREFIX)) { + // vfszip:/some/path/jython.jar/org/python/core/PySystemState.class + final String path = PySystemState.class.getName().replace('.', '/'); + int jarIndex = urlString.indexOf(".jar/".concat(path)); + if (jarIndex > 0) { + jarIndex += 4; + int start = VFSZIP_PREFIX.length(); + if (Platform.IS_WINDOWS) { + // vfszip:/C:/some/path/jython.jar/org/python/core/PySystemState.class + start++; + } + jarFileName = urlString.substring(start, jarIndex); + } } } catch (Exception e) {} } Added: trunk/jython/tests/java/org/python/core/PySystemStateTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/PySystemStateTest.java (rev 0) +++ trunk/jython/tests/java/org/python/core/PySystemStateTest.java 2010-10-09 07:53:42 UTC (rev 7141) @@ -0,0 +1,81 @@ +package org.python.core; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +import junit.framework.TestCase; + +import org.jruby.ext.posix.util.Platform; + +public class PySystemStateTest extends TestCase { + + public void testGetJarFileNameFromURL() throws Exception { + // null + assertNull(PySystemState.getJarFileNameFromURL(null)); + // plain jar url + String urlString = "jar:file:/some_dir/some.jar!/a/package/with/A.class"; + URL url = new URL(urlString); + assertEquals("/some_dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + // jar url to decode + urlString = "jar:file:/some%20dir/some.jar!/a/package/with/A.class"; + url = new URL(urlString); + assertEquals("/some dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + // jar url with + signs to escape + urlString = "jar:file:/some+dir/some.jar!/a/package/with/A.class"; + url = new URL(urlString); + assertEquals("/some+dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + } + + public void testGetJarFileNameFromURL_jboss() throws Exception { + final String protocol = "vfszip"; + final String host = ""; + final int port = -1; + final URLStreamHandler handler = new TestJBossURLStreamHandler(); + String file; + URL url; + if (Platform.IS_WINDOWS) { + // plain jboss url + file = "/C:/some_dir/some.jar/org/python/core/PySystemState.class"; + url = new URL(protocol, host, port, file, handler); + // tests with jboss on windows gave URL's like this: + assertEquals("vfszip:/C:/some_dir/some.jar/org/python/core/PySystemState.class", url.toString()); + assertEquals("C:/some_dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + // jboss url to decode + file = "/C:/some%20dir/some.jar/org/python/core/PySystemState.class"; + url = new URL(protocol, host, port, file, handler); + assertEquals("vfszip:/C:/some%20dir/some.jar/org/python/core/PySystemState.class", url.toString()); + assertEquals("C:/some dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + // jboss url with + to escape + file = "/C:/some+dir/some.jar/org/python/core/PySystemState.class"; + url = new URL(protocol, host, port, file, handler); + assertEquals("vfszip:/C:/some+dir/some.jar/org/python/core/PySystemState.class", url.toString()); + assertEquals("C:/some+dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + } else { + // plain jboss url + file = "/some_dir/some.jar/org/python/core/PySystemState.class"; + url = new URL(protocol, host, port, file, handler); + assertEquals("vfszip:/some_dir/some.jar/org/python/core/PySystemState.class", url.toString()); + assertEquals("/some_dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + // jboss url to decode + file = "/some%20dir/some.jar/org/python/core/PySystemState.class"; + url = new URL(protocol, host, port, file, handler); + assertEquals("vfszip:/some%20dir/some.jar/org/python/core/PySystemState.class", url.toString()); + assertEquals("/some dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + // jboss url with + to escape + file = "/some+dir/some.jar/org/python/core/PySystemState.class"; + url = new URL(protocol, host, port, file, handler); + assertEquals("vfszip:/some+dir/some.jar/org/python/core/PySystemState.class", url.toString()); + assertEquals("/some+dir/some.jar", PySystemState.getJarFileNameFromURL(url)); + } + } + + protected static class TestJBossURLStreamHandler extends URLStreamHandler { + + @Override + protected URLConnection openConnection(URL u) throws IOException { + throw new RuntimeException("unexpected call to openConnection " + u.toString()); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-10-10 10:29:22
|
Revision: 7142 http://jython.svn.sourceforge.net/jython/?rev=7142&view=rev Author: otmarhumbel Date: 2010-10-10 10:29:15 +0000 (Sun, 10 Oct 2010) Log Message: ----------- properly quote COMSPEC on exit fixes issue #1661 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/shell/jython.bat Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-09 07:53:42 UTC (rev 7141) +++ trunk/jython/NEWS 2010-10-10 10:29:15 UTC (rev 7142) @@ -2,6 +2,7 @@ Jython 2.5.2rc1 Bugs Fixed + - [ 1661 ] Error at on exit in TCC/LE - [ 1639 ] JBoss 5, vfszip protocol in use for jarFileName in PySystemState - [ 1660 ] threading module memory leak - [ 1452 ] pydoc help() function fails because sys.executable is None in stand-alone Jython Modified: trunk/jython/src/shell/jython.bat =================================================================== --- trunk/jython/src/shell/jython.bat 2010-10-09 07:53:42 UTC (rev 7141) +++ trunk/jython/src/shell/jython.bat 2010-10-10 10:29:15 UTC (rev 7142) @@ -295,4 +295,5 @@ :finish -%COMSPEC% /c exit /b %E% +set _UNQUOTED_COMSPEC=%COMSPEC:"=% +"%_UNQUOTED_COMSPEC%" /c exit /b %E% This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-16 02:55:38
|
Revision: 7147 http://jython.svn.sourceforge.net/jython/?rev=7147&view=rev Author: zyasoft Date: 2010-10-16 02:55:32 +0000 (Sat, 16 Oct 2010) Log Message: ----------- The underlying array used by PyArray allocates extra space when extended, in case there will be future extension, much like the support in list. (AbstractArray in fact used to be used by list.) However, PyArray.__tojava__ needed to shrink the array when unboxing as a regular Java array. Resolved by simply copying when size != capacity. Fixes 1543. Modified Paths: -------------- trunk/jython/Lib/test/test_array_jy.py trunk/jython/NEWS trunk/jython/src/org/python/core/PyArray.java Modified: trunk/jython/Lib/test/test_array_jy.py =================================================================== --- trunk/jython/Lib/test/test_array_jy.py 2010-10-14 12:46:59 UTC (rev 7146) +++ trunk/jython/Lib/test/test_array_jy.py 2010-10-16 02:55:32 UTC (rev 7147) @@ -47,7 +47,15 @@ Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") + def test_java_roundtrip(self): + # bug 1543 + from java.lang import Object + x = array(Object, [0,1,2]) + x.append(3) + y = array(Object, [x]) # forces an implicit __tojava__ + self.assertEqual(x, y[0], "Did not shrink to fit") + class ToFromfileTestCase(unittest.TestCase): def tearDown(self): Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-14 12:46:59 UTC (rev 7146) +++ trunk/jython/NEWS 2010-10-16 02:55:32 UTC (rev 7147) @@ -2,6 +2,7 @@ Jython 2.5.2rc1 Bugs Fixed + - [ 1543 ] PyArray fails to clean up pre-allocated space - [ 1661 ] Error at on exit in TCC/LE - [ 1639 ] JBoss 5, vfszip protocol in use for jarFileName in PySystemState - [ 1660 ] threading module memory leak Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2010-10-14 12:46:59 UTC (rev 7146) +++ trunk/jython/src/org/python/core/PyArray.java 2010-10-16 02:55:32 UTC (rev 7147) @@ -412,7 +412,13 @@ public Object __tojava__(Class<?> c) { if(c == Object.class || (c.isArray() && c.getComponentType().isAssignableFrom(type))) { - return data; + if (delegate.capacity != delegate.size) { + // when unboxing, need to shrink the array first, otherwise incorrect + // results to Java + return delegate.copyArray(); + } else { + return data; + } } if(c.isInstance(this)) return this; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-16 03:04:27
|
Revision: 7148 http://jython.svn.sourceforge.net/jython/?rev=7148&view=rev Author: zyasoft Date: 2010-10-16 03:04:21 +0000 (Sat, 16 Oct 2010) Log Message: ----------- Added test for #1662 re strptime properly quoting ending literals. Modified Paths: -------------- trunk/jython/NEWS Added Paths: ----------- trunk/jython/Lib/test/test_strptime_jy.py Added: trunk/jython/Lib/test/test_strptime_jy.py =================================================================== --- trunk/jython/Lib/test/test_strptime_jy.py (rev 0) +++ trunk/jython/Lib/test/test_strptime_jy.py 2010-10-16 03:04:21 UTC (rev 7148) @@ -0,0 +1,23 @@ +# merge into upstream test_strptime.py at some point + +import unittest +from datetime import datetime +from test import test_support + + +class ParsingTests(unittest.TestCase): + + def test_iso8601(self): + now = datetime.utcnow().replace(microsecond=0) + self.assertEqual(now, datetime.strptime(now.isoformat('T'), "%Y-%m-%dT%H:%M:%S")) + # tests bug 1662 + self.assertEqual(now, datetime.strptime(now.isoformat('T') + 'Z', "%Y-%m-%dT%H:%M:%SZ")) + +def test_main(): + test_support.run_unittest( + ParsingTests + ) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-16 02:55:32 UTC (rev 7147) +++ trunk/jython/NEWS 2010-10-16 03:04:21 UTC (rev 7148) @@ -2,6 +2,7 @@ Jython 2.5.2rc1 Bugs Fixed + - [ 1662 ] time.strptime does not use Java date format strings properly - [ 1543 ] PyArray fails to clean up pre-allocated space - [ 1661 ] Error at on exit in TCC/LE - [ 1639 ] JBoss 5, vfszip protocol in use for jarFileName in PySystemState This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-17 04:51:22
|
Revision: 7153 http://jython.svn.sourceforge.net/jython/?rev=7153&view=rev Author: zyasoft Date: 2010-10-17 04:51:15 +0000 (Sun, 17 Oct 2010) Log Message: ----------- Modified readline, specifically completion support and various hooks, so that it supports ipython 0.10.1 (with a minor patch on os.name in that codebase). Still requires user to provide an alternative properties file, that should be fixed before RC1. Fixes #1133. Modified Paths: -------------- trunk/jython/Lib/readline.py trunk/jython/src/org/python/util/JLineConsole.java Modified: trunk/jython/Lib/readline.py =================================================================== --- trunk/jython/Lib/readline.py 2010-10-16 16:15:33 UTC (rev 7152) +++ trunk/jython/Lib/readline.py 2010-10-17 04:51:15 UTC (rev 7153) @@ -7,6 +7,24 @@ except AttributeError: raise ImportError("Cannot access JLineConsole") +history_list = None + +def _setup_history(): + # This is obviously not desirable, but avoids O(n) workarounds to + # modify the history (ipython uses the function + # remove_history_item to mutate the history relatively frequently) + global history_list + + history = reader.history + try: + history_list_field = history.class.getDeclaredField("history") + history_list_field.setAccessible(True) + history_list = history_list_field.get(history) + except: + pass + +_setup_history() + def parse_and_bind(string): # TODO this should probably reinitialize the reader, if possible # with any desired settings; this will require some more work to implement @@ -14,24 +32,28 @@ # most importantly, need to support at least # readline.parse_and_bind("tab: complete") # but it's possible we can readily support other aspects of a readline file + + # XXX first time through, print a warning message about the required setup + # with jline properties (or potentially test...) pass def get_line_buffer(): - return str(reader.cursorBuffer.buffer) # or use toString to get unicode? + return str(reader.cursorBuffer.buffer) def insert_text(string): reader.putString(string) def read_init_file(filename=None): - pass + print "Not implemented: read_init_file", filename def read_history_file(filename="~/.history"): expanded = os.path.expanduser(filename) new_history = reader.getHistory().getClass()() with open(expanded) as f: for line in f: - new_history.addToHistory(line) + new_history.addToHistory(line.rstrip()) reader.history = new_history + _setup_history() def write_history_file(filename="~/.history"): expanded = os.path.expanduser(filename) @@ -42,6 +64,9 @@ def clear_history(): reader.history.clear() +def add_history(line): + reader.addToHistory(line) + def get_history_length(): return reader.history.maxSize @@ -55,23 +80,22 @@ return reader.history.historyList[index] def remove_history_item(pos): - # TODO possible? - raise Exception("not implemented") + if history_list: + history_list.remove(pos) + else: + print "Cannot remove history item at position:", pos def redisplay(): reader.redrawLine() def set_startup_hook(function=None): - # TODO add - pass - + sys._jy_interpreter.startupHook = function + def set_pre_input_hook(function=None): - # TODO add - pass + print "Not implemented: set_pre_input_hook", function +_completer_function = None -_completion_function = None - def set_completer(function=None): """set_completer([function]) -> None Set or remove the completer function. @@ -79,42 +103,50 @@ for state in 0, 1, 2, ..., until it returns a non-string. It should return the next possible completion starting with 'text'.""" - _completion_function = function + global _completer_function + _completer_function = function def complete_handler(buffer, cursor, candidates): + start = _get_delimited(buffer, cursor)[0] + delimited = buffer[start:cursor] for state in xrange(100): # TODO arbitrary, what's the number used by gnu readline? completion = None try: - completion = function(buffer[:cursor], state) + completion = function(delimited, state) except: pass if completion: candidates.add(completion) else: break - return 0 + return start reader.addCompletor(complete_handler) def get_completer(): - return _completion_function + return _completer_function +def _get_delimited(buffer, cursor): + start = cursor + for i in xrange(cursor-1, -1, -1): + if buffer[i] in _completer_delims: + break + start = i + return start, cursor + def get_begidx(): - # TODO add - pass + return _get_delimited(str(reader.cursorBuffer.buffer), reader.cursorBuffer.cursor)[0] def get_endidx(): - # TODO add - pass + return _get_delimited(str(reader.cursorBuffer.buffer), reader.cursorBuffer.cursor)[1] def set_completer_delims(string): - pass + global _completer_delims, _completer_delims_set + _completer_delims = string + _completer_delims_set = set(string) def get_completer_delims(): - pass + return _completer_delims -def add_history(line): - reader.addToHistory(line) - - +set_completer_delims(' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?') Modified: trunk/jython/src/org/python/util/JLineConsole.java =================================================================== --- trunk/jython/src/org/python/util/JLineConsole.java 2010-10-16 16:15:33 UTC (rev 7152) +++ trunk/jython/src/org/python/util/JLineConsole.java 2010-10-17 04:51:15 UTC (rev 7153) @@ -32,6 +32,11 @@ /** Main interface to JLine. */ protected ConsoleReader reader; + /** Set by readline.set_startup_hook */ + protected PyObject startup_hook; + + protected PyObject pre_input_hook; + /** Whether reader is a WindowsTerminal. */ private boolean windows; @@ -116,6 +121,13 @@ while (true) { try { + if (startup_hook != null) { + try { + startup_hook.__call__(); + } catch (Exception ex) { + System.err.println(ex); + } + } line = reader.readLine(promptString); break; } catch (IOException ioe) { @@ -163,4 +175,19 @@ public ConsoleReader getReader() { return reader; } + + + /** + * @return the startup hook (called prior to each readline) + */ + public PyObject getStartupHook() { + return startup_hook; + } + + /** + * Sets the startup hook (called prior to each readline) + */ + public void setStartupHook(PyObject hook) { + startup_hook = hook; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-10-17 22:52:16
|
Revision: 7157 http://jython.svn.sourceforge.net/jython/?rev=7157&view=rev Author: otmarhumbel Date: 2010-10-17 22:52:09 +0000 (Sun, 17 Oct 2010) Log Message: ----------- prepare for 2.5.2rc1 Modified Paths: -------------- trunk/jython/README.txt trunk/jython/build.xml Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2010-10-17 22:26:38 UTC (rev 7156) +++ trunk/jython/README.txt 2010-10-17 22:52:09 UTC (rev 7157) @@ -1,8 +1,8 @@ -Welcome to Jython 2.5.2 Beta2 -============================= +Welcome to Jython 2.5.2 rc1 +=========================== -This is the second beta release of the 2.5.2 version of Jython. Our -current plans is that this will be the last beta of 2.5.2, but this +This is the first release candidate of the 2.5.2 version of Jython. +We hope that this is the only release candidate of 2.5.2, but this will depend on bug reports. This release fixes bugs related to resource leaks, Java integration, Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2010-10-17 22:26:38 UTC (rev 7156) +++ trunk/jython/build.xml 2010-10-17 22:52:09 UTC (rev 7157) @@ -123,13 +123,13 @@ <property name="PY_RELEASE_LEVEL_SNAPSHOT" value="170"/> <!-- 0xAA --> <!-- The current version info --> - <property name="jython.version" value="2.5.2b2"/> - <property name="jython.version.noplus" value="2.5.2b2"/> + <property name="jython.version" value="2.5.2rc1"/> + <property name="jython.version.noplus" value="2.5.2rc1"/> <property name="jython.major_version" value="2"/> <property name="jython.minor_version" value="5"/> <property name="jython.micro_version" value="2"/> - <property name="jython.release_level" value="${PY_RELEASE_LEVEL_BETA}"/> - <property name="jython.release_serial" value="2"/> + <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> + <property name="jython.release_serial" value="1"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-22 01:13:54
|
Revision: 7162 http://jython.svn.sourceforge.net/jython/?rev=7162&view=rev Author: zyasoft Date: 2010-10-22 01:13:48 +0000 (Fri, 22 Oct 2010) Log Message: ----------- Uses JLine support, when available, to turn off echoing in getpass.getpass. Fixes #1628. Modified Paths: -------------- trunk/jython/Lib/getpass.py trunk/jython/NEWS Modified: trunk/jython/Lib/getpass.py =================================================================== --- trunk/jython/Lib/getpass.py 2010-10-19 03:02:51 UTC (rev 7161) +++ trunk/jython/Lib/getpass.py 2010-10-22 01:13:48 UTC (rev 7162) @@ -14,10 +14,37 @@ # Authors: Piers Lauder (original) # Guido van Rossum (Windows support and cleanup) +import os import sys __all__ = ["getpass","getuser"] +def jython_getpass(prompt='Password: ', stream=None): + """Prompt for a password, with echo turned off. + The prompt is written on stream, by default stdout. + + Restore terminal settings at end. + """ + if stream is None: + stream = sys.stdout + + try: + terminal = sys._jy_interpreter.reader.terminal + except: + return default_getpass(prompt) + + echoed = terminal.getEcho() + terminal.disableEcho() + try: + passwd = _raw_input(prompt, stream) + finally: + if echoed: + terminal.enableEcho() + + stream.write('\n') + return passwd + + def unix_getpass(prompt='Password: ', stream=None): """Prompt for a password, with echo turned off. The prompt is written on stream, by default stdout. @@ -99,8 +126,6 @@ """ - import os - for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'): user = os.environ.get(name) if user: @@ -123,7 +148,10 @@ try: from EasyDialogs import AskPassword except ImportError: - getpass = default_getpass + if os.name == 'java': + getpass = jython_getpass + else: + getpass = default_getpass else: getpass = AskPassword else: Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-19 03:02:51 UTC (rev 7161) +++ trunk/jython/NEWS 2010-10-22 01:13:48 UTC (rev 7162) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.2rc2 + Bugs Fixed + - [ 1628 ] getpass.getpass echoes input + Jython 2.5.2rc1 Bugs Fixed - [ 1133 ] Support ipython and other completers with readline emulation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2010-10-22 01:40:41
|
Revision: 7163 http://jython.svn.sourceforge.net/jython/?rev=7163&view=rev Author: zyasoft Date: 2010-10-22 01:40:30 +0000 (Fri, 22 Oct 2010) Log Message: ----------- cPickle did not properly call import from Java, using null instead of Py.None for globals and locals. Thanks Anselm Kruis for the patch! Fixes #1648. Modified Paths: -------------- trunk/jython/Lib/test/test_cpickle_jy.py trunk/jython/NEWS trunk/jython/src/org/python/modules/cPickle.java Modified: trunk/jython/Lib/test/test_cpickle_jy.py =================================================================== --- trunk/jython/Lib/test/test_cpickle_jy.py 2010-10-22 01:13:48 UTC (rev 7162) +++ trunk/jython/Lib/test/test_cpickle_jy.py 2010-10-22 01:40:30 UTC (rev 7163) @@ -2,6 +2,8 @@ Made for Jython. """ +import __builtin__ +import sys import cPickle import pickle import unittest @@ -70,6 +72,25 @@ self.assertRaises(pickle.UnpicklingError, b_unpickler.load) + def testWithUserDefinedImport(self): + """test cPickle calling a user defined import function.""" + # This tests the fix for http://bugs.jython.org/issue1665 + # setup + original_import = __builtin__.__import__ + def import_hook(name, _globals=None, locals=None, fromlist=None, level= -1): + return original_import(name, _globals, locals, fromlist, level) + + # test + __builtin__.__import__ = import_hook + try: + if "no_such_module" in sys.modules: + del sys.modules["no_such_module"] # force cPickle to call __import__ + self.assertRaises(ImportError, cPickle.loads, pickle.GLOBAL + "no_such_module\n" + "no_such_class\n") + finally: + __builtin__.__import__ = original_import + + + def test_main(): test_support.run_unittest(CPickleTestCase) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-22 01:13:48 UTC (rev 7162) +++ trunk/jython/NEWS 2010-10-22 01:40:30 UTC (rev 7163) @@ -2,7 +2,9 @@ Jython 2.5.2rc2 Bugs Fixed + - [ 1665 ] cPickle calls __import__ with illegal parameters - [ 1628 ] getpass.getpass echoes input + - Fix logic to detect that a console is interactive (related to #1133) Jython 2.5.2rc1 Bugs Fixed @@ -16,9 +18,8 @@ - [ 1452 ] pydoc help() function fails because sys.executable is None in stand-alone Jython - [ 1568 ] sys.stdout.encoding returns wrong value in Windows with Jython 2.5.1 (fixed on Java 6 only) - [ 1647 ] zxJDBC does not handle NVARCHAR + - SocketServer module now supports ephemeral server ports (by using port 0); see discussion for #1660 - SocketServer module now supports ephemeral server ports (by using port 0); see discussion for #1660 - Jython 2.5.2b2 Bugs Fixed - [ 1327 ] Classloaders cannot GC, which exhausts permgen (partial bug fix) Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2010-10-22 01:13:48 UTC (rev 7162) +++ trunk/jython/src/org/python/modules/cPickle.java 2010-10-22 01:40:30 UTC (rev 7163) @@ -2245,7 +2245,7 @@ private static PyObject importModule(String name) { PyObject fromlist = new PyTuple(Py.newString("__doc__")); - return __builtin__.__import__(name, null, null, fromlist); + return __builtin__.__import__(name, Py.None, Py.None, fromlist); } private static PyObject getJavaFunc(String name, String methodName) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-10-24 20:10:39
|
Revision: 7165 http://jython.svn.sourceforge.net/jython/?rev=7165&view=rev Author: otmarhumbel Date: 2010-10-24 20:10:31 +0000 (Sun, 24 Oct 2010) Log Message: ----------- prepare for 2.5.2rc2 Modified Paths: -------------- trunk/jython/README.txt trunk/jython/build.xml Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2010-10-22 03:01:56 UTC (rev 7164) +++ trunk/jython/README.txt 2010-10-24 20:10:31 UTC (rev 7165) @@ -1,8 +1,9 @@ Welcome to Jython 2.5.2 rc1 =========================== -This is the first release candidate of the 2.5.2 version of Jython. -We hope that this is the only release candidate of 2.5.2, but this +This is the second release candidate of the 2.5.2 version of Jython. +The major difference to rc1 is a fix for better IPython support. +We still hope that there won't be many more release candidates, but this will depend on bug reports. This release fixes bugs related to resource leaks, Java integration, Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2010-10-22 03:01:56 UTC (rev 7164) +++ trunk/jython/build.xml 2010-10-24 20:10:31 UTC (rev 7165) @@ -123,13 +123,13 @@ <property name="PY_RELEASE_LEVEL_SNAPSHOT" value="170"/> <!-- 0xAA --> <!-- The current version info --> - <property name="jython.version" value="2.5.2rc1"/> - <property name="jython.version.noplus" value="2.5.2rc1"/> + <property name="jython.version" value="2.5.2rc2"/> + <property name="jython.version.noplus" value="2.5.2rc2"/> <property name="jython.major_version" value="2"/> <property name="jython.minor_version" value="5"/> <property name="jython.micro_version" value="2"/> <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> - <property name="jython.release_serial" value="1"/> + <property name="jython.release_serial" value="2"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2010-11-06 00:15:39
|
Revision: 7169 http://jython.svn.sourceforge.net/jython/?rev=7169&view=rev Author: otmarhumbel Date: 2010-11-06 00:15:33 +0000 (Sat, 06 Nov 2010) Log Message: ----------- let the engine scope behave more like locals and globals; fixes issue #1674 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-10-24 21:44:54 UTC (rev 7168) +++ trunk/jython/NEWS 2010-11-06 00:15:33 UTC (rev 7169) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.2rc3 + Bugs Fixed + - [ 1674 ] PDB crashes under the JSR-223 scripting engine + Jython 2.5.2rc2 Bugs Fixed - [ 1665 ] cPickle calls __import__ with illegal parameters Modified: trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java =================================================================== --- trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2010-10-24 21:44:54 UTC (rev 7168) +++ trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2010-11-06 00:15:33 UTC (rev 7169) @@ -1,10 +1,15 @@ package org.python.jsr223; +import java.util.HashMap; import java.util.List; +import java.util.Map; + import javax.script.Bindings; import javax.script.ScriptContext; import javax.script.ScriptEngine; import org.python.core.Py; +import org.python.core.PyDictionary; +import org.python.core.PyIterator; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; @@ -56,16 +61,31 @@ return members; } - // Not necessary for functionality; present to satisfy __builtin__.PyMapping_check + // satisfy mapping and lookup @ExposedMethod + @Override public PyObject __getitem__(PyObject key) { - return super.__getitem__(key); + return __finditem__(key); } + // satisfy iterable + @ExposedMethod + @Override + public PyObject __iter__() { + return new ScopeIterator(this); + } + + @Override + public String toString() { + return getDictionary().toString(); + } + + @Override public PyObject __finditem__(PyObject key) { return __finditem__(key.asString()); } + @Override public PyObject __finditem__(String key) { int scope = context.getAttributesScope(key); if (scope == -1) @@ -74,10 +94,12 @@ } @ExposedMethod + @Override public void __setitem__(PyObject key, PyObject value) { __setitem__(key.asString(), value); } + @Override public void __setitem__(String key, PyObject value) { int scope = context.getAttributesScope(key); if (scope == -1) @@ -86,14 +108,57 @@ } @ExposedMethod + @Override public void __delitem__(PyObject key) { __delitem__(key.asString()); } + @Override public void __delitem__(String key) { int scope = context.getAttributesScope(key); if (scope == -1) throw Py.KeyError(key); context.removeAttribute(key, scope); } + + private Map<PyObject, PyObject> getMap() { + ScopeIterator iterator = new ScopeIterator(this); + Map<PyObject, PyObject> map = new HashMap<PyObject, PyObject>(iterator.size()); + PyObject key = iterator.__iternext__(); + while (key != null) { + map.put(key, __finditem__(key)); + key = iterator.__iternext__(); + } + return map; + } + + private PyDictionary getDictionary() { + return new PyDictionary(getMap()); + } + + public class ScopeIterator extends PyIterator { + private int _index; + private int _size; + private PyObject _keys; + + ScopeIterator(PyScriptEngineScope scope) { + _keys = scope.scope_keys(); + _size = _keys.__len__(); + _index = -1; + } + + public int size() { + return _size; + } + + @Override + public PyObject __iternext__() { + PyObject result = null; + _index++; + if (_index < size()) { + result = _keys.__getitem__(_index); + } + return result; + } + } } Modified: trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java =================================================================== --- trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2010-10-24 21:44:54 UTC (rev 7168) +++ trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2010-11-06 00:15:33 UTC (rev 7169) @@ -206,4 +206,48 @@ Object newStringCapitalize = invocableEngine.invokeMethod("test", "capitalize"); assertEquals(newStringCapitalize, "Test"); } + + public void testPdb() { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + // String from issue 1674 + String pdbString = "from pdb import set_trace; set_trace()"; + try { + pythonEngine.eval(pdbString); + fail("bdb.BdbQuit expected"); + } catch (ScriptException e) { + assertTrue(e.getMessage().startsWith("bdb.BdbQuit")); + } + } + + public void testScope_repr() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + pythonEngine.eval("a = 4"); + pythonEngine.eval("b = 'hi'"); + pythonEngine.eval("localrepr = `locals()`"); + assertEquals("{'b': u'hi', 'a': 4}", pythonEngine.get("localrepr")); + } + + public void testScope_iter() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + pythonEngine.eval("a = 4"); + pythonEngine.eval("b = 'hi'"); + pythonEngine.eval("list = []"); + pythonEngine.eval("for loc in locals(): list.append(loc)"); + pythonEngine.eval("listrepr = `list`"); + assertEquals("[u'a', u'b', u'list']", pythonEngine.get("listrepr")); + } + + public void testScope_lookup() throws ScriptException{ + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + pythonEngine.eval("a = 4"); + pythonEngine.eval("b = 'hi'"); + pythonEngine.eval("var_a = locals()['a']"); + pythonEngine.eval("arepr = `var_a`"); + assertEquals("4", pythonEngine.get("arepr")); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-12-24 00:34:38
|
Revision: 7174 http://jython.svn.sourceforge.net/jython/?rev=7174&view=rev Author: pjenvey Date: 2010-12-24 00:34:31 +0000 (Fri, 24 Dec 2010) Log Message: ----------- allow -c/-w options without a space separator fixes #1680 thanks Zemian Deng Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-11-23 06:51:27 UTC (rev 7173) +++ trunk/jython/NEWS 2010-12-24 00:34:31 UTC (rev 7174) @@ -2,7 +2,8 @@ Jython 2.5.2rc3 Bugs Fixed - - [ 1674 ] PDB crashes under the JSR-223 scripting engine + - [ 1674 ] PDB crashes under the JSR-223 scripting engine + - [ 1680 ] jython -c option is not parsed right Jython 2.5.2rc2 Bugs Fixed Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2010-11-23 06:51:27 UTC (rev 7173) +++ trunk/jython/src/org/python/util/jython.java 2010-12-24 00:34:31 UTC (rev 7174) @@ -436,7 +436,7 @@ Options.verbose +=3 ; } else if (arg.equals("-S")) { Options.importSite = false; - } else if (arg.equals("-c")) { + } else if (arg.startsWith("-c")) { runCommand = true; if (arg.length() > 2) { command = arg.substring(2); @@ -453,7 +453,7 @@ } index++; break; - } else if (arg.equals("-W")) { + } else if (arg.startsWith("-W")) { warnoptions.add(args[++index]); } else if (arg.equals("-C")) { encoding = args[++index]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-12-24 01:37:08
|
Revision: 7175 http://jython.svn.sourceforge.net/jython/?rev=7175&view=rev Author: pjenvey Date: 2010-12-24 01:37:01 +0000 (Fri, 24 Dec 2010) Log Message: ----------- special case type objects in the jsr223 Scope assignment as we don't want their proxy objects fixes #1681 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-12-24 00:34:31 UTC (rev 7174) +++ trunk/jython/NEWS 2010-12-24 01:37:01 UTC (rev 7175) @@ -4,6 +4,7 @@ Bugs Fixed - [ 1674 ] PDB crashes under the JSR-223 scripting engine - [ 1680 ] jython -c option is not parsed right + - [ 1681 ] JSR-223, Jython 2.5.2 and implementing Java Interfaces from Python Jython 2.5.2rc2 Bugs Fixed Modified: trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java =================================================================== --- trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2010-12-24 00:34:31 UTC (rev 7174) +++ trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2010-12-24 01:37:01 UTC (rev 7175) @@ -104,7 +104,9 @@ int scope = context.getAttributesScope(key); if (scope == -1) scope = ScriptContext.ENGINE_SCOPE; - context.setAttribute(key, value.__tojava__(Object.class), scope); + context.setAttribute(key, + value instanceof PyType ? value : value.__tojava__(Object.class), + scope); } @ExposedMethod Modified: trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java =================================================================== --- trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2010-12-24 00:34:31 UTC (rev 7174) +++ trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2010-12-24 01:37:01 UTC (rev 7175) @@ -249,5 +249,18 @@ pythonEngine.eval("arepr = `var_a`"); assertEquals("4", pythonEngine.get("arepr")); } + + public void testIssue1681() throws ScriptException{ + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + pythonEngine.eval("import PythonCallable\n" + + "class MyPythonCallable(PythonCallable):\n" + + " def getAString(self): return 'a string'\n\n" + + "result = MyPythonCallable().getAString()\n" + + "test = MyPythonCallable()\n" + + "result2 = test.getAString()"); + assertEquals("a string", pythonEngine.get("result")); + assertEquals("a string", pythonEngine.get("result2")); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-12-24 23:23:11
|
Revision: 7178 http://jython.svn.sourceforge.net/jython/?rev=7178&view=rev Author: pjenvey Date: 2010-12-24 23:23:05 +0000 (Fri, 24 Dec 2010) Log Message: ----------- fix exit code of 0 on unhandled exceptions in non-interactive mode fixes #1682 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-12-24 23:17:07 UTC (rev 7177) +++ trunk/jython/NEWS 2010-12-24 23:23:05 UTC (rev 7178) @@ -5,6 +5,8 @@ - [ 1674 ] PDB crashes under the JSR-223 scripting engine - [ 1680 ] jython -c option is not parsed right - [ 1681 ] JSR-223, Jython 2.5.2 and implementing Java Interfaces from Python + - [ 1675 ] Jython exits prematurely when executing a file, thus killing Swing windows + - [ 1682 ] exit code of 0 on unhandled exception Jython 2.5.2rc2 Bugs Fixed Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2010-12-24 23:17:07 UTC (rev 7177) +++ trunk/jython/src/org/python/util/jython.java 2010-12-24 23:23:05 UTC (rev 7178) @@ -262,10 +262,8 @@ return; } else { Py.printException(t); - if (!opts.interactive) { - interp.cleanup(); - System.exit(-1); - } + interp.cleanup(); + System.exit(-1); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2010-12-29 01:59:27
|
Revision: 7181 http://jython.svn.sourceforge.net/jython/?rev=7181&view=rev Author: pjenvey Date: 2010-12-29 01:59:20 +0000 (Wed, 29 Dec 2010) Log Message: ----------- fix strptime('','') fixes #1668 patch from Israel Tsadok Modified Paths: -------------- trunk/jython/Lib/test/test_time.py trunk/jython/NEWS trunk/jython/src/org/python/modules/time/Time.java Modified: trunk/jython/Lib/test/test_time.py =================================================================== --- trunk/jython/Lib/test/test_time.py 2010-12-27 15:50:19 UTC (rev 7180) +++ trunk/jython/Lib/test/test_time.py 2010-12-29 01:59:20 UTC (rev 7181) @@ -120,6 +120,12 @@ except ValueError: self.fail('conversion specifier: %r failed.' % format) + def test_strptime_empty(self): + try: + time.strptime('', '') + except ValueError: + self.fail('strptime failed on empty args.') + def test_asctime(self): time.asctime(time.gmtime(self.t)) self.assertRaises(TypeError, time.asctime, 0) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-12-27 15:50:19 UTC (rev 7180) +++ trunk/jython/NEWS 2010-12-29 01:59:20 UTC (rev 7181) @@ -7,6 +7,7 @@ - [ 1681 ] JSR-223, Jython 2.5.2 and implementing Java Interfaces from Python - [ 1675 ] Jython exits prematurely when executing a file, thus killing Swing windows - [ 1682 ] exit code of 0 on unhandled exception + - [ 1668 ] strptime('','') works on cpython but not on jython Jython 2.5.2rc2 Bugs Fixed Modified: trunk/jython/src/org/python/modules/time/Time.java =================================================================== --- trunk/jython/src/org/python/modules/time/Time.java 2010-12-27 15:50:19 UTC (rev 7180) +++ trunk/jython/src/org/python/modules/time/Time.java 2010-12-29 01:59:20 UTC (rev 7181) @@ -759,6 +759,10 @@ boolean directive = false; boolean inQuote = false; + if (format.length() == 0) { + return null; + } + for (int i = 0; i < format.length(); i++) { char charAt = format.charAt(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2011-01-07 01:15:58
|
Revision: 7182 http://jython.svn.sourceforge.net/jython/?rev=7182&view=rev Author: pjenvey Date: 2011-01-07 01:15:51 +0000 (Fri, 07 Jan 2011) Log Message: ----------- special case handling of unicode sys.path items, basically pass them through fixes #1693 test case from Oti Modified Paths: -------------- trunk/jython/Lib/test/test_sys_jy.py trunk/jython/NEWS trunk/jython/src/org/python/core/SyspathJavaLoader.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/core/packagecache/PathPackageManager.java Modified: trunk/jython/Lib/test/test_sys_jy.py =================================================================== --- trunk/jython/Lib/test/test_sys_jy.py 2010-12-29 01:59:20 UTC (rev 7181) +++ trunk/jython/Lib/test/test_sys_jy.py 2011-01-07 01:15:51 UTC (rev 7182) @@ -1,7 +1,10 @@ +from __future__ import with_statement +import os +import re import sys -import re +import tempfile import unittest -import test.test_support +from test import test_support class SysTest(unittest.TestCase): @@ -132,7 +135,7 @@ class SyspathResourceTest(unittest.TestCase): def setUp(self): self.orig_path = sys.path - sys.path.insert(0, test.test_support.findfile("bug1373.jar")) + sys.path.insert(0, test_support.findfile("bug1373.jar")) def tearDown(self): sys.path = self.orig_path @@ -146,8 +149,43 @@ self.assert_(Main.getResource('Main.txt')) +class SyspathUnicodeTest(unittest.TestCase): + """bug 1693: importing from a unicode path threw a unicode encoding + error""" + + def test_nonexisting_import_from_unicodepath(self): + # \xf6 = german o umlaut + sys.path.append(u'/home/tr\xf6\xf6t') + self.assertRaises(ImportError, __import__, 'non_existing_module') + + def test_import_from_unicodepath(self): + # \xf6 = german o umlaut + moduleDir = tempfile.mkdtemp(suffix=u'tr\xf6\xf6t') + try: + self.assertTrue(os.path.exists(moduleDir)) + module = 'unicodetempmodule' + moduleFile = '%s/%s.py' % (moduleDir, module) + try: + with open(moduleFile, 'w') as f: + f.write('# empty module') + self.assertTrue(os.path.exists(moduleFile)) + sys.path.append(moduleDir) + __import__(module) + moduleClassFile = '%s/%s$py.class' % (moduleDir, module) + self.assertTrue(os.path.exists(moduleClassFile)) + os.remove(moduleClassFile) + finally: + os.remove(moduleFile) + finally: + os.rmdir(moduleDir) + self.assertFalse(os.path.exists(moduleDir)) + + def test_main(): - test.test_support.run_unittest(SysTest, ShadowingTest, SyspathResourceTest) + test_support.run_unittest(SysTest, + ShadowingTest, + SyspathResourceTest, + SyspathUnicodeTest) if __name__ == "__main__": test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2010-12-29 01:59:20 UTC (rev 7181) +++ trunk/jython/NEWS 2011-01-07 01:15:51 UTC (rev 7182) @@ -8,6 +8,7 @@ - [ 1675 ] Jython exits prematurely when executing a file, thus killing Swing windows - [ 1682 ] exit code of 0 on unhandled exception - [ 1668 ] strptime('','') works on cpython but not on jython + - [ 1693 ] Unicode sys.path elements cause UnicodeErrors on import Jython 2.5.2rc2 Bugs Fixed Modified: trunk/jython/src/org/python/core/SyspathJavaLoader.java =================================================================== --- trunk/jython/src/org/python/core/SyspathJavaLoader.java 2010-12-29 01:59:20 UTC (rev 7181) +++ trunk/jython/src/org/python/core/SyspathJavaLoader.java 2011-01-07 01:15:51 UTC (rev 7182) @@ -3,7 +3,6 @@ package org.python.core; -import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -14,8 +13,6 @@ import java.util.StringTokenizer; import java.util.zip.ZipEntry; -import javax.management.RuntimeErrorException; - import org.python.core.util.RelativeFile; public class SyspathJavaLoader extends ClassLoader { @@ -115,7 +112,10 @@ SyspathArchive archive = (SyspathArchive)entry; buffer = getBytesFromArchive(archive, name); } else { - String dir = entry.__str__().toString(); + if (!(entry instanceof PyUnicode)) { + entry = entry.__str__(); + } + String dir = entry.toString(); buffer = getBytesFromDir(dir, name); } if (buffer != null) { @@ -155,7 +155,10 @@ } continue; } - String dir = sys.getPath(entry.__str__().toString()); + if (!(entry instanceof PyUnicode)) { + entry = entry.__str__(); + } + String dir = sys.getPath(entry.toString()); try { File resource = new File(dir, res); if (!resource.exists()) { Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2010-12-29 01:59:20 UTC (rev 7181) +++ trunk/jython/src/org/python/core/imp.java 2011-01-07 01:15:51 UTC (rev 7182) @@ -436,7 +436,6 @@ } static PyObject find_module(String name, String moduleName, PyList path) { - PyObject loader = Py.None; PySystemState sys = Py.getSystemState(); PyObject metaPath = sys.meta_path; @@ -468,7 +467,10 @@ return loadFromLoader(loader, moduleName); } } - ret = loadFromSource(sys, name, moduleName, p.__str__().toString()); + if (!(p instanceof PyUnicode)) { + p = p.__str__(); + } + ret = loadFromSource(sys, name, moduleName, p.toString()); if (ret != null) { return ret; } Modified: trunk/jython/src/org/python/core/packagecache/PathPackageManager.java =================================================================== --- trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2010-12-29 01:59:20 UTC (rev 7181) +++ trunk/jython/src/org/python/core/packagecache/PathPackageManager.java 2011-01-07 01:15:51 UTC (rev 7182) @@ -7,7 +7,9 @@ import org.python.core.Py; import org.python.core.PyJavaPackage; import org.python.core.PyList; +import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyUnicode; import org.python.core.util.RelativeFile; import java.io.BufferedInputStream; @@ -38,7 +40,11 @@ + name; for (int i = 0; i < path.__len__(); i++) { - String dir = path.pyget(i).__str__().toString(); + PyObject entry = path.pyget(i); + if (!(entry instanceof PyUnicode)) { + entry = entry.__str__(); + } + String dir = entry.toString(); File f = new RelativeFile(dir, child); try { @@ -96,7 +102,12 @@ String child = jpkg.__name__.replace('.', File.separatorChar); for (int i = 0; i < path.__len__(); i++) { - String dir = path.pyget(i).__str__().toString(); + PyObject entry = path.pyget(i); + if (!(entry instanceof PyUnicode)) { + entry = entry.__str__(); + } + String dir = entry.toString(); + if (dir.length() == 0) { dir = null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2011-01-10 21:42:52
|
Revision: 7183 http://jython.svn.sourceforge.net/jython/?rev=7183&view=rev Author: otmarhumbel Date: 2011-01-10 21:42:46 +0000 (Mon, 10 Jan 2011) Log Message: ----------- prepare for 2.5.2rc3 Modified Paths: -------------- trunk/jython/README.txt trunk/jython/build.xml Modified: trunk/jython/README.txt =================================================================== --- trunk/jython/README.txt 2011-01-07 01:15:51 UTC (rev 7182) +++ trunk/jython/README.txt 2011-01-10 21:42:46 UTC (rev 7183) @@ -1,10 +1,9 @@ -Welcome to Jython 2.5.2 rc2 +Welcome to Jython 2.5.2 rc3 =========================== -This is the second release candidate of the 2.5.2 version of Jython. -The major difference to rc1 is a fix for better IPython support. -We still hope that there won't be many more release candidates, but this -will depend on bug reports. +This is the third release candidate of the 2.5.2 version of Jython. +It contains the most important bug fixes since 2.5.2 rc2. +We believe that this is the last release candidate before the final 2.5.2 release! This release fixes bugs related to resource leaks, Java integration, and a number of other issues. See the NEWS file for more details. In Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2011-01-07 01:15:51 UTC (rev 7182) +++ trunk/jython/build.xml 2011-01-10 21:42:46 UTC (rev 7183) @@ -123,13 +123,13 @@ <property name="PY_RELEASE_LEVEL_SNAPSHOT" value="170"/> <!-- 0xAA --> <!-- The current version info --> - <property name="jython.version" value="2.5.2rc2"/> - <property name="jython.version.noplus" value="2.5.2rc2"/> + <property name="jython.version" value="2.5.2rc3"/> + <property name="jython.version.noplus" value="2.5.2rc3"/> <property name="jython.major_version" value="2"/> <property name="jython.minor_version" value="5"/> <property name="jython.micro_version" value="2"/> <property name="jython.release_level" value="${PY_RELEASE_LEVEL_GAMMA}"/> - <property name="jython.release_serial" value="2"/> + <property name="jython.release_serial" value="3"/> <condition property="do.snapshot.build"> <isset property="snapshot.revision" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2011-01-21 01:18:41
|
Revision: 7186 http://jython.svn.sourceforge.net/jython/?rev=7186&view=rev Author: pjenvey Date: 2011-01-21 01:18:35 +0000 (Fri, 21 Jan 2011) Log Message: ----------- o fix threading.local subclassing problems with __init__ arguments o fastGetDict doesn't need to synchronize around a ThreadLocal initialization fixes #1667 thanks Kelly Campbell Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/modules/thread/PyLocal.java Added Paths: ----------- trunk/jython/Lib/test/test_threading_local_jy.py Added: trunk/jython/Lib/test/test_threading_local_jy.py =================================================================== --- trunk/jython/Lib/test/test_threading_local_jy.py (rev 0) +++ trunk/jython/Lib/test/test_threading_local_jy.py 2011-01-21 01:18:35 UTC (rev 7186) @@ -0,0 +1,61 @@ +"""Test for thread locals""" +import random +import sys +import threading +import time +import unittest +from test import test_support +from threading import local + +class LocalStuff(local): + def __init__(self, stuff, foo=1): + local.__init__(self) + self.stuff = stuff + self.foo = foo + +class TestThread(threading.Thread): + def __init__(self, stuff, name): + threading.Thread.__init__(self) + self.stuff = stuff + self.name = name + self.errors = [] + + def run(self): + for i in xrange(10): + try: + self.stuff.stuff = self.name + myStuff = self.stuff.stuff + time.sleep(random.random() * 2) + if myStuff != self.stuff.stuff: + self.errors.append("myStuff should equal self.stuff.stuff") + if self.stuff.foo != 1: + self.errors.append("foo should be 1") + except TypeError, te: + self.errors.append("TypeError: %s" % te) + except: + self.errors.append("unexpected error: %s" % sys.exc_info()[0] ) + + def getErrors(self): + return self.errors + +class ThreadLocalConstructorTestCase(unittest.TestCase): + + def test_construct_locals(self): + """Ensures that constructing a local can have arguments""" + stuff = LocalStuff("main stuff") + threads = [] + for i in xrange(20): + threads.append(TestThread(stuff, name=("thread-%d" % i))) + threads[i].start() + for i in xrange(20): + threads[i].join() + errors = threads[i].getErrors() + self.assertEquals(0, len(errors), errors) + + +def test_main(): + test_support.run_unittest(ThreadLocalConstructorTestCase) + + +if __name__ == "__main__": + test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2011-01-10 23:29:19 UTC (rev 7185) +++ trunk/jython/NEWS 2011-01-21 01:18:35 UTC (rev 7186) @@ -1,5 +1,9 @@ Jython NEWS +Jython 2.5.2 + Bugs Fixed + - [ 1667 ] thread.local subclasses with constructor params fail + Jython 2.5.2rc3 Bugs Fixed - [ 1674 ] PDB crashes under the JSR-223 scripting engine Modified: trunk/jython/src/org/python/modules/thread/PyLocal.java =================================================================== --- trunk/jython/src/org/python/modules/thread/PyLocal.java 2011-01-10 23:29:19 UTC (rev 7185) +++ trunk/jython/src/org/python/modules/thread/PyLocal.java 2011-01-21 01:18:35 UTC (rev 7186) @@ -1,3 +1,4 @@ +/* Copyright (c) Jython Developers */ package org.python.modules.thread; import org.python.core.Py; @@ -6,7 +7,6 @@ import org.python.core.PyObject; import org.python.core.PyType; import org.python.expose.ExposedGet; -import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedSet; import org.python.expose.ExposedType; @@ -28,9 +28,8 @@ public PyLocal(PyType subType) { super(subType); - // Because the instantiation of a type instance in PyType.invoke_new_ - // calls dispatch__init__, we call tdict.set here so dispatch__init__ - // doesn't get called a second time for a thread in fastGetDict + // Don't lazy load the underlying dict in the insantiating thread; that would call + // __init__ a the second time tdict.set(new PyDictionary()); } @@ -40,29 +39,24 @@ PyType subtype, PyObject[] args, String[] keywords) { + PyObject[] where = new PyObject[1]; + subtype.lookup_where("__init__", where); + if (where[0] == PyObject.TYPE && args.length > 0) { + throw Py.TypeError("Initialization arguments are not supported"); + } + PyLocal newobj; if (new_.getWrappedType() == subtype) { newobj = new PyLocal(); } else { newobj = new PyLocalDerived(subtype); } - if (init) { - newobj._local___init__(args, keywords); - } + newobj.args = args; + newobj.keywords = keywords; + return newobj; } - @ExposedMethod - final void _local___init__(PyObject[] args, String[] keywords) { - PyObject[] where = new PyObject[1]; - getType().lookup_where("__init__", where); - if (where[0] == TYPE && args.length > 0) { - throw Py.TypeError("Initialization arguments are not supported"); - } - this.args = args; - this.keywords = keywords; - } - @Override @ExposedGet(name = "__dict__") public PyObject getDict() { @@ -76,7 +70,7 @@ } @Override - public synchronized PyObject fastGetDict() { + public PyObject fastGetDict() { PyDictionary ldict = tdict.get(); if (ldict == null) { ldict = new PyDictionary(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2011-01-22 21:25:04
|
Revision: 7188 http://jython.svn.sourceforge.net/jython/?rev=7188&view=rev Author: pjenvey Date: 2011-01-22 21:24:58 +0000 (Sat, 22 Jan 2011) Log Message: ----------- add more missing dict-like methods to the jsr223 scope. fixes the warning module under jsr223 fixes #1698 Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2011-01-21 01:23:32 UTC (rev 7187) +++ trunk/jython/NEWS 2011-01-22 21:24:58 UTC (rev 7188) @@ -3,6 +3,7 @@ Jython 2.5.2 Bugs Fixed - [ 1667 ] thread.local subclasses with constructor params fail + - [ 1698 ] warnings module fails under JSR-223 Jython 2.5.2rc3 Bugs Fixed Modified: trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java =================================================================== --- trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2011-01-21 01:23:32 UTC (rev 7187) +++ trunk/jython/src/org/python/jsr223/PyScriptEngineScope.java 2011-01-22 21:24:58 UTC (rev 7188) @@ -75,7 +75,47 @@ return new ScopeIterator(this); } + @ExposedMethod(defaults = "Py.None") + final PyObject scope_get(PyObject keyObj, PyObject defaultObj) { + String key = keyObj.asString(); + int scope = context.getAttributesScope(key); + return scope == -1 ? defaultObj : Py.java2py(context.getAttribute(key, scope)); + } + + @ExposedMethod + final boolean scope_has_key(PyObject key) { + return context.getAttributesScope(key.asString()) != -1; + } + @Override + public boolean __contains__(PyObject obj) { + return scope___contains__(obj); + } + + @ExposedMethod + final boolean scope___contains__(PyObject obj) { + return scope_has_key(obj); + } + + @ExposedMethod(defaults = "Py.None") + final PyObject scope_setdefault(PyObject keyObj, PyObject failObj) { + PyObject result; + String key = keyObj.asString(); + int scope = context.getAttributesScope(key); + if (scope == -1) { + scope = ScriptContext.ENGINE_SCOPE; + context.setAttribute(key, + failObj instanceof PyType + ? failObj : failObj.__tojava__(Object.class), + scope); + result = failObj; + } else { + result = Py.java2py(context.getAttribute(key, scope)); + } + return result; + } + + @Override public String toString() { return getDictionary().toString(); } Modified: trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java =================================================================== --- trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2011-01-21 01:23:32 UTC (rev 7187) +++ trunk/jython/tests/java/org/python/jsr223/ScriptEngineTest.java 2011-01-22 21:24:58 UTC (rev 7188) @@ -263,5 +263,13 @@ assertEquals("a string", pythonEngine.get("result")); assertEquals("a string", pythonEngine.get("result2")); } + + public void testIssue1698() throws ScriptException{ + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + pythonEngine.eval("import warnings"); + // Would previously fail + pythonEngine.eval("warnings.warn('test')"); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2011-02-02 10:37:05
|
Revision: 7192 http://jython.svn.sourceforge.net/jython/?rev=7192&view=rev Author: otmarhumbel Date: 2011-02-02 10:36:55 +0000 (Wed, 02 Feb 2011) Log Message: ----------- prevent internal variables from being reused in subrocess calls fixes issue #1700 thanks agronholm for the analysis Modified Paths: -------------- trunk/jython/Lib/test/test_bat_jy.py trunk/jython/NEWS trunk/jython/src/shell/jython.bat Modified: trunk/jython/Lib/test/test_bat_jy.py =================================================================== --- trunk/jython/Lib/test/test_bat_jy.py 2011-01-25 23:46:27 UTC (rev 7191) +++ trunk/jython/Lib/test/test_bat_jy.py 2011-02-02 10:36:55 UTC (rev 7192) @@ -48,7 +48,7 @@ return self.process.getErrorStream() class StarterProcess: - def writeStarter(self, args, javaHome, jythonHome, jythonOpts): + def writeStarter(self, args, javaHome, jythonHome, jythonOpts, internals=False): (starter, starterPath) = tempfile.mkstemp(suffix='.bat', prefix='starter', text=True) starter.close() outfilePath = starterPath[:-4] + '.out' @@ -60,6 +60,9 @@ starter.write('set JYTHON_HOME=%s\n' % jythonHome) if jythonOpts: starter.write('set JYTHON_OPTS=%s\n' % jythonOpts) + if internals: + starter.write('set _JYTHON_OPTS=leaking_internals\n') + starter.write('set _JYTHON_HOME=c:/leaking/internals\n') starter.write(self.buildCommand(args, outfilePath)) return (starterPath, outfilePath) finally: @@ -92,9 +95,9 @@ except IllegalThreadStateException: return True - def run(self, args, javaHome, jythonHome, jythonOpts): + def run(self, args, javaHome, jythonHome, jythonOpts, internals=False): ''' creates a start script, executes it and captures the output ''' - (starterPath, outfilePath) = self.writeStarter(args, javaHome, jythonHome, jythonOpts) + (starterPath, outfilePath) = self.writeStarter(args, javaHome, jythonHome, jythonOpts, internals) try: process = Runtime.getRuntime().exec(starterPath) stdoutMonitor = StdoutMonitor(process) @@ -130,7 +133,7 @@ home = ex[:-11] # \jython.bat return home - def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None): + def assertOutput(self, flags=None, javaHome=None, jythonHome=None, jythonOpts=None, internals=False): args = [self.quote(sys.executable), '--print'] memory = None stack = None @@ -161,7 +164,7 @@ jythonArgs = jythonArgs.replace('%%', '%') # workaround two .bat files args.append(flag) process = StarterProcess() - out = process.run(args, javaHome, jythonHome, jythonOpts) + out = process.run(args, javaHome, jythonHome, jythonOpts, internals) self.assertNotEquals('', out) homeIdx = out.find('-Dpython.home=') java = 'java' @@ -256,7 +259,11 @@ def test_multiple(self): self.assertOutput(jythonOpts='some arbitrary options') - + +class InternalsTest(BaseTest): + def test_no_leaks(self): + self.assertOutput(internals=True) + class JavaOptsTest(BaseTest): def test_memory(self): self.assertOutput(['-J-Xmx321m']) @@ -387,6 +394,7 @@ JavaHomeTest, JythonHomeTest, JythonOptsTest, + InternalsTest, JavaOptsTest, ArgsTest, DoubleDashTest, Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2011-01-25 23:46:27 UTC (rev 7191) +++ trunk/jython/NEWS 2011-02-02 10:36:55 UTC (rev 7192) @@ -5,6 +5,7 @@ - [ 1667 ] thread.local subclasses with constructor params fail - [ 1698 ] warnings module fails under JSR-223 - [ 1697 ] Wrong error message when http connection can not be established + - [ 1700 ] "virtualenv is not compatible" to 2.5.2rc3 Jython 2.5.2rc3 Bugs Fixed Modified: trunk/jython/src/shell/jython.bat =================================================================== --- trunk/jython/src/shell/jython.bat 2011-01-25 23:46:27 UTC (rev 7191) +++ trunk/jython/src/shell/jython.bat 2011-02-02 10:36:55 UTC (rev 7192) @@ -24,9 +24,12 @@ rem ----- Verify and set required environment variables ----------------------- +rem make sure to clear the internal variables, to prevent leaking into subprocess calls set _JAVA_CMD=java if defined JAVA_HOME set _JAVA_CMD="%JAVA_HOME:"=%\bin\java" -if defined JYTHON_OPTS set _JYTHON_OPTS="%JYTHON_OPTS:"=%" +set _JYTHON_OPTS= +if defined JYTHON_OPTS set _JYTHON_OPTS="%JYTHON_OPTS:"=%" +set _JYTHON_HOME= if defined JYTHON_HOME set _JYTHON_HOME="%JYTHON_HOME:"=%" if defined _JYTHON_HOME goto gotHome This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2011-02-03 21:56:30
|
Revision: 7193 http://jython.svn.sourceforge.net/jython/?rev=7193&view=rev Author: amak Date: 2011-02-03 21:56:23 +0000 (Thu, 03 Feb 2011) Log Message: ----------- Checking in more support for IPV6, including support for 4-tuples including scope, etc. Modified Paths: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py trunk/jython/NEWS Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2011-02-02 10:36:55 UTC (rev 7192) +++ trunk/jython/Lib/socket.py 2011-02-03 21:56:23 UTC (rev 7193) @@ -314,26 +314,20 @@ def __init__(self, socket=None): if socket: self.jchannel = socket.getChannel() - self.host = socket.getInetAddress().getHostAddress() - self.port = socket.getPort() else: self.jchannel = java.nio.channels.SocketChannel.open() - self.host = None - self.port = None self.jsocket = self.jchannel.socket() self.socketio = org.python.core.io.SocketIO(self.jchannel, 'rw') - def bind(self, host, port, reuse_addr): + def bind(self, jsockaddr, reuse_addr): self.jsocket.setReuseAddress(reuse_addr) - self.jsocket.bind(java.net.InetSocketAddress(host, port)) + self.jsocket.bind(jsockaddr) - def connect(self, host, port): - self.host = host - self.port = port + def connect(self, jsockaddr): if self.mode == MODE_TIMEOUT: - self.jsocket.connect(java.net.InetSocketAddress(self.host, self.port), self._timeout_millis) + self.jsocket.connect (jsockaddr, self._timeout_millis) else: - self.jchannel.connect(java.net.InetSocketAddress(self.host, self.port)) + self.jchannel.connect(jsockaddr) def finish_connect(self): return self.jchannel.finishConnect() @@ -382,15 +376,11 @@ (SOL_SOCKET, SO_TIMEOUT): 'SoTimeout', } - def __init__(self, host, port, backlog, reuse_addr): + def __init__(self, jsockaddr, backlog, reuse_addr): self.jchannel = java.nio.channels.ServerSocketChannel.open() self.jsocket = self.jchannel.socket() - if host: - bindaddr = java.net.InetSocketAddress(host, port) - else: - bindaddr = java.net.InetSocketAddress(port) self.jsocket.setReuseAddress(reuse_addr) - self.jsocket.bind(bindaddr, backlog) + self.jsocket.bind(jsockaddr, backlog) self.socketio = org.python.core.io.ServerSocketIO(self.jchannel, 'rw') def accept(self): @@ -422,20 +412,16 @@ (SOL_SOCKET, SO_TIMEOUT): 'SoTimeout', } - def __init__(self, port=None, address=None, reuse_addr=0): + def __init__(self, jsockaddr=None, reuse_addr=0): self.jchannel = java.nio.channels.DatagramChannel.open() self.jsocket = self.jchannel.socket() - if port is not None: - if address is not None: - local_address = java.net.InetSocketAddress(address, port) - else: - local_address = java.net.InetSocketAddress(port) + if jsockaddr is not None: self.jsocket.setReuseAddress(reuse_addr) - self.jsocket.bind(local_address) + self.jsocket.bind(jsockaddr) self.socketio = org.python.core.io.DatagramSocketIO(self.jchannel, 'rw') - def connect(self, host, port): - self.jchannel.connect(java.net.InetSocketAddress(host, port)) + def connect(self, jsockaddr): + self.jchannel.connect(jsockaddr) def disconnect(self): """ @@ -469,12 +455,11 @@ bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent - def sendto(self, byte_array, host, port, flags): - socket_address = java.net.InetSocketAddress(host, port) + def sendto(self, byte_array, jsockaddr, flags): if self.mode == MODE_TIMEOUT: - return self._do_send_net(byte_array, socket_address, flags) + return self._do_send_net(byte_array, jsockaddr, flags) else: - return self._do_send_nio(byte_array, socket_address, flags) + return self._do_send_nio(byte_array, jsockaddr, flags) def send(self, byte_array, flags): if self.mode == MODE_TIMEOUT: @@ -526,8 +511,7 @@ else: return self._do_receive_nio(0, num_bytes, flags) -# For now, we DO NOT have complete IPV6 support. -has_ipv6 = False +has_ipv6 = True # IPV6 FTW! # Name and address functions @@ -607,6 +591,88 @@ assert protocol == IPPROTO_UDP, "Only IPPROTO_UDP supported on SOCK_DGRAM sockets" return _udpsocket() +class _ip_address_t: + + def __str__(self): + return "('%s', %d)" % (self.sockaddr, self.port) + +class _ipv4_address_t(_ip_address_t): + + def __init__(self, sockaddr, port, jaddress): + self.sockaddr = sockaddr + self.port = port + self.jaddress = jaddress + + def __getitem__(self, index): + if 0 == index: + return self.sockaddr + elif 1 == index: + return self.port + else: + raise IndexError() + + def __len__(self): + return 2 + +class _ipv6_address_t(_ip_address_t): + + def __init__(self, sockaddr, port, jaddress): + self.sockaddr = sockaddr + self.port = port + self.jaddress = jaddress + + def __getitem__(self, index): + if 0 == index: + return self.sockaddr + elif 1 == index: + return self.port + elif 2 == index: + return 0 + elif 3 == index: + return self.jaddress.scopeId + else: + raise IndexError() + + def __len__(self): + return 4 + +def _get_jsockaddr(address_object, for_udp=False): + if address_object is None: + return java.net.InetSocketAddress(0) # Let the system pick an ephemeral port + if isinstance(address_object, _ip_address_t): + return java.net.InetSocketAddress(address_object.jaddress, address_object[1]) + error_message = "Address must be a 2-tuple (ipv4: (host, port)) or a 4-tuple (ipv6: (host, port, flow, scope))" + if not isinstance(address_object, tuple) or \ + len(address_object) not in [2,4] or \ + not isinstance(address_object[0], basestring) or \ + not isinstance(address_object[1], (int, long)): + raise TypeError(error_message) + if len(address_object) == 4 and not isinstance(address_object[3], (int, long)): + raise TypeError(error_message) + hostname, port = address_object[0].strip(), address_object[1] + if for_udp: + if hostname == "": + hostname = INADDR_ANY + elif hostname == "<broadcast>": + hostname = INADDR_BROADCAST + else: + if hostname == "": + hostname = None + if hostname is None: + return java.net.InetSocketAddress(port) + if isinstance(hostname, unicode): + # XXX: Should be encode('idna') (See CPython + # socketmodule::getsockaddrarg), but Jython's idna support is + # currently broken + hostname = hostname.encode() + if len(address_object) == 4: + # There is no way to get a Inet6Address: Inet6Address.getByName() simply calls + # InetAddress.getByName,() which also returns Inet4Address objects + # If users want to use IPv6 address, scoped or not, + # they should use getaddrinfo(family=AF_INET6) + pass + return java.net.InetSocketAddress(java.net.InetAddress.getByName(hostname), port) + _ipv4_addresses_only = False def _use_ipv4_addresses_only(value): @@ -639,11 +705,12 @@ else: canonname = asPyString(a.getCanonicalHostName()) if host is None and passive_mode and not canonname_mode: - sockname = INADDR_ANY + sockaddr = INADDR_ANY else: - sockname = asPyString(a.getHostAddress()) + sockaddr = asPyString(a.getHostAddress()) # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses - results.append((family, socktype, proto, canonname, (sockname, port))) + sock_tuple = {AF_INET : _ipv4_address_t, AF_INET6 : _ipv6_address_t}[family](sockaddr, port, a) + results.append((family, socktype, proto, canonname, sock_tuple)) return results except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -800,24 +867,6 @@ def _get_jsocket(self): return self.sock_impl.jsocket -def _unpack_address_tuple(address_tuple): - # TODO: Upgrade to support the 4-tuples used for IPv6 addresses - # which include flowinfo and scope_id. - # To be upgraded in synch with getaddrinfo - error_message = "Address must be a tuple of (hostname, port)" - if not isinstance(address_tuple, tuple) or \ - not isinstance(address_tuple[0], basestring) or \ - not isinstance(address_tuple[1], (int, long)): - raise TypeError(error_message) - hostname = address_tuple[0] - if isinstance(hostname, unicode): - # XXX: Should be encode('idna') (See CPython - # socketmodule::getsockaddrarg), but Jython's idna support is - # currently broken - hostname = hostname.encode() - hostname = hostname.strip() - return hostname, address_tuple[1] - class _tcpsocket(_nonblocking_api_mixin): sock_impl = None @@ -833,7 +882,7 @@ assert not self.sock_impl assert not self.local_addr # Do the address format check - _unpack_address_tuple(addr) + _get_jsockaddr(addr) self.local_addr = addr def listen(self, backlog): @@ -841,11 +890,7 @@ try: assert not self.sock_impl self.server = 1 - if self.local_addr: - host, port = _unpack_address_tuple(self.local_addr) - else: - host, port = "", 0 - self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) + self.sock_impl = _server_socket_impl(_get_jsockaddr(self.local_addr), backlog, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) self._config() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -867,22 +912,14 @@ except java.lang.Exception, jlx: raise _map_exception(jlx) - def _get_host_port(self, addr): - host, port = _unpack_address_tuple(addr) - if host == "": - host = java.net.InetAddress.getLocalHost() - return host, port - def _do_connect(self, addr): try: assert not self.sock_impl - host, port = self._get_host_port(addr) self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = _unpack_address_tuple(self.local_addr) - self.sock_impl.bind(bind_host, bind_port, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) + self.sock_impl.bind(_get_jsockaddr(self.local_addr), self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) self._config() # Configure timeouts, etc, now that the socket exists - self.sock_impl.connect(host, port) + self.sock_impl.connect(_get_jsockaddr(addr)) except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -983,7 +1020,7 @@ class _udpsocket(_nonblocking_api_mixin): sock_impl = None - addr = None + connected = False def __init__(self): _nonblocking_api_mixin.__init__(self) @@ -991,24 +1028,19 @@ def bind(self, addr): try: assert not self.sock_impl - host, port = _unpack_address_tuple(addr) - if host == "": - host = INADDR_ANY - host_address = java.net.InetAddress.getByName(host) - self.sock_impl = _datagram_socket_impl(port, host_address, self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) + self.sock_impl = _datagram_socket_impl(_get_jsockaddr(addr, True), self.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ]) self._config() except java.lang.Exception, jlx: raise _map_exception(jlx) def _do_connect(self, addr): try: - host, port = _unpack_address_tuple(addr) - assert not self.addr - self.addr = addr + assert not self.connected, "Datagram Socket is already connected" if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() - self.sock_impl.connect(host, port) + self.sock_impl.connect(_get_jsockaddr(addr)) + self.connected = True except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -1029,17 +1061,14 @@ if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() - host, port = _unpack_address_tuple(addr) - if host == "<broadcast>": - host = INADDR_BROADCAST byte_array = java.lang.String(data).getBytes('iso-8859-1') - result = self.sock_impl.sendto(byte_array, host, port, flags) + result = self.sock_impl.sendto(byte_array, _get_jsockaddr(addr, True), flags) return result except java.lang.Exception, jlx: raise _map_exception(jlx) def send(self, data, flags=None): - if not self.addr: raise error(errno.ENOTCONN, "Socket is not connected") + if not self.connected: raise error(errno.ENOTCONN, "Socket is not connected") byte_array = java.lang.String(data).getBytes('iso-8859-1') return self.sock_impl.send(byte_array, flags) Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2011-02-02 10:36:55 UTC (rev 7192) +++ trunk/jython/Lib/test/test_socket.py 2011-02-03 21:56:23 UTC (rev 7193) @@ -1502,6 +1502,73 @@ doAddressTest(socket.getaddrinfo("localhost", 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, 0)) socket._use_ipv4_addresses_only(False) + def testAddrTupleTypes(self): + ipv4_address_tuple = socket.getaddrinfo("localhost", 80, socket.AF_INET, socket.SOCK_STREAM, 0, 0)[0][4] + self.failUnlessEqual(ipv4_address_tuple[0], "127.0.0.1") + self.failUnlessEqual(ipv4_address_tuple[1], 80) + self.failUnlessRaises(IndexError, lambda: ipv4_address_tuple[2]) + self.failUnlessEqual(str(ipv4_address_tuple), "('127.0.0.1', 80)") + + ipv6_address_tuple = socket.getaddrinfo("localhost", 80, socket.AF_INET6, socket.SOCK_STREAM, 0, 0)[0][4] + self.failUnless (ipv6_address_tuple[0] in ["::1", "0:0:0:0:0:0:0:1"]) + self.failUnlessEqual(ipv6_address_tuple[1], 80) + self.failUnlessEqual(ipv6_address_tuple[2], 0) + # Can't have an expectation for scope + try: + ipv6_address_tuple[3] + except IndexError: + self.fail("Failed to retrieve third element of ipv6 4-tuple") + self.failUnlessRaises(IndexError, lambda: ipv6_address_tuple[4]) + self.failUnless(str(ipv6_address_tuple) in ["('::1', 80)", "('0:0:0:0:0:0:0:1', 80)"]) + +class TestJython_get_jsockaddr(unittest.TestCase): + "These tests are specific to jython: they test a key internal routine" + + def testIPV4AddressesFromGetAddrInfo(self): + local_addr = socket.getaddrinfo("localhost", 80, socket.AF_INET, socket.SOCK_STREAM, 0, 0)[0][4] + sockaddr = socket._get_jsockaddr(local_addr) + self.failUnless(isinstance(sockaddr, java.net.InetSocketAddress), "_get_jsockaddr returned wrong type: '%s'" % str(type(sockaddr))) + self.failUnlessEqual(sockaddr.address.hostAddress, "127.0.0.1") + self.failUnlessEqual(sockaddr.port, 80) + + def testIPV6AddressesFromGetAddrInfo(self): + local_addr = socket.getaddrinfo("localhost", 80, socket.AF_INET6, socket.SOCK_STREAM, 0, 0)[0][4] + sockaddr = socket._get_jsockaddr(local_addr) + self.failUnless(isinstance(sockaddr, java.net.InetSocketAddress), "_get_jsockaddr returned wrong type: '%s'" % str(type(sockaddr))) + self.failUnless(sockaddr.address.hostAddress in ["::1", "0:0:0:0:0:0:0:1"]) + self.failUnlessEqual(sockaddr.port, 80) + + def testAddressesFrom2Tuple(self): + for addr_tuple in [ + ("localhost", 80), + ]: + sockaddr = socket._get_jsockaddr(addr_tuple) + self.failUnless(isinstance(sockaddr, java.net.InetSocketAddress), "_get_jsockaddr returned wrong type: '%s'" % str(type(sockaddr))) + self.failUnless(sockaddr.address.hostAddress in ["127.0.0.1", "::1", "0:0:0:0:0:0:0:1"]) + self.failUnlessEqual(sockaddr.port, 80) + + def testAddressesFrom4Tuple(self): + # This test disabled: cannot construct IPV6 addresses from 4-tuple + return + for addr_tuple in [ + ("localhost", 80, 0, 0), + ]: + sockaddr = socket._get_jsockaddr(addr_tuple) + self.failUnless(isinstance(sockaddr, java.net.InetSocketAddress), "_get_jsockaddr returned wrong type: '%s'" % str(type(sockaddr))) + self.failUnless(isinstance(sockaddr.address, java.net.Inet6Address), "_get_jsockaddr returned wrong address type: '%s'" % str(type(sockaddr.address))) + self.failUnless(sockaddr.address.hostAddress in ["::1", "0:0:0:0:0:0:0:1"]) + self.failUnlessEqual(sockaddr.address.scopeId, 0) + self.failUnlessEqual(sockaddr.port, 80) + + def testSpecialHostnames(self): + for addr_tuple, for_udp, expected_hostname in [ + ( ("", 80), False, socket.INADDR_ANY), + ( ("", 80), True, socket.INADDR_ANY), + ( ("<broadcast>", 80), True, socket.INADDR_BROADCAST), + ]: + sockaddr = socket._get_jsockaddr(addr_tuple, for_udp) + self.failUnlessEqual(sockaddr.hostName, expected_hostname, "_get_jsockaddr returned wrong hostname '%s' for special hostname '%s'" % (sockaddr.hostName, expected_hostname)) + class TestExceptions(unittest.TestCase): def testExceptionTree(self): @@ -1728,10 +1795,12 @@ if sys.platform[:4] == 'java': tests.append(TestJythonTCPExceptions) tests.append(TestJythonUDPExceptions) + tests.append(TestJython_get_jsockaddr) # TODO: Broadcast requires permission, and is blocked by some firewalls # Need some way to discover the network setup on the test machine if False: tests.append(UDPBroadcastTest) +# tests = [TestJython_get_jsockaddr] suites = [unittest.makeSuite(klass, 'test') for klass in tests] test_support.run_suite(unittest.TestSuite(suites)) Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2011-02-02 10:36:55 UTC (rev 7192) +++ trunk/jython/NEWS 2011-02-03 21:56:23 UTC (rev 7193) @@ -5,6 +5,7 @@ - [ 1667 ] thread.local subclasses with constructor params fail - [ 1698 ] warnings module fails under JSR-223 - [ 1697 ] Wrong error message when http connection can not be established + - [ 1210 ] Lib/socket.py doesn't allow IPv6 sockets and fails with an AssertionError - [ 1700 ] "virtualenv is not compatible" to 2.5.2rc3 Jython 2.5.2rc3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |