You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <otm...@us...> - 2009-01-18 13:46:22
|
Revision: 5946 http://jython.svn.sourceforge.net/jython/?rev=5946&view=rev Author: otmarhumbel Date: 2009-01-18 13:46:12 +0000 (Sun, 18 Jan 2009) Log Message: ----------- enable running jython from a directory with an exclamation mark in it's name due to jdk limitations this is only possible for + jdk 1.6 and higher + directory names not ending with an exclamation mark due to the special treatment of exclamation marks in enabledelayedexpansion, this is currently not possible for jython.bat on windows installer autotests now use an exclamation mark if possible Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/Installation.java trunk/installer/src/java/org/python/util/install/JavaVersionTester.java trunk/installer/src/java/org/python/util/install/driver/Autotest.java trunk/installer/test/java/org/python/util/install/InstallationTest.java trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/installer/src/java/org/python/util/install/Installation.java =================================================================== --- trunk/installer/src/java/org/python/util/install/Installation.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/src/java/org/python/util/install/Installation.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -17,6 +17,9 @@ import org.python.util.install.driver.Tunnel; public class Installation { + public final static int NORMAL_RETURN = 0; + public final static int ERROR_RETURN = 1; + protected static final String ALL = "1"; protected static final String STANDARD = "2"; protected static final String MINIMUM = "3"; @@ -29,9 +32,6 @@ protected static final String HEADLESS_PROPERTY_NAME = "java.awt.headless"; - protected final static int NORMAL_RETURN = 0; - protected final static int ERROR_RETURN = 1; - private static final String RESOURCE_CLASS = "org.python.util.install.TextConstants"; private static ResourceBundle _textConstants = ResourceBundle.getBundle(RESOURCE_CLASS, Locale.getDefault()); @@ -92,24 +92,31 @@ protected static boolean isValidJava(JavaVersionInfo javaVersionInfo) { String specificationVersion = javaVersionInfo.getSpecificationVersion(); verboseOutput("specification version: '" + specificationVersion + "'"); + boolean valid = true; + if (getJavaSpecificationVersion(specificationVersion) < 15) { + valid = false; + } + return valid; + } + + /** + * @return specification version as an int, e.g. 15 or 16 (the micro part is ignored) + * @param specificationVersion + * as system property + */ + public static int getJavaSpecificationVersion(String specificationVersion) { // major.minor.micro // according to http://java.sun.com/j2se/1.5.0/docs/guide/versioning/spec/versioning2.html - int major = 0; - int minor = 0; + String major = "1"; + String minor = "0"; StringTokenizer tokenizer = new StringTokenizer(specificationVersion, "."); if (tokenizer.hasMoreTokens()) { - major = Integer.valueOf(tokenizer.nextToken()).intValue(); + major = tokenizer.nextToken(); } if (tokenizer.hasMoreTokens()) { - minor = Integer.valueOf(tokenizer.nextToken()).intValue(); + minor = tokenizer.nextToken(); } - boolean valid = true; - if (major == 1) { - if (minor < 5) { - valid = false; - } - } - return valid; + return Integer.valueOf(major.concat(minor)).intValue(); } public static boolean isWindows() { @@ -201,6 +208,46 @@ return versionInfo; } + + /** + * @return The system default java version + */ + public static JavaVersionInfo getDefaultJavaVersion() { + JavaVersionInfo versionInfo = new JavaVersionInfo(); + String executableName = "java"; + try { + // launch the java command - temporary file will be written by the child process + File tempFile = File.createTempFile("jython_installation", ".properties"); + if (tempFile.exists() && tempFile.canWrite()) { + String command[] = new String[5]; + command[0] = executableName; + command[1] = "-cp"; + // our own class path should be ok here + command[2] = System.getProperty("java.class.path"); + command[3] = JavaVersionTester.class.getName(); + command[4] = tempFile.getAbsolutePath(); + ChildProcess childProcess = new ChildProcess(command, 10000); // 10 seconds + childProcess.setDebug(false); + int errorCode = childProcess.run(); + if (errorCode != NORMAL_RETURN) { + versionInfo.setErrorCode(errorCode); + versionInfo.setReason(getText(TextKeys.C_NO_VALID_JAVA, executableName)); + } else { + Properties tempProperties = new Properties(); + tempProperties.load(new FileInputStream(tempFile)); + fillJavaVersionInfo(versionInfo, tempProperties); + } + } else { + versionInfo.setErrorCode(ERROR_RETURN); + versionInfo.setReason(getText(TextKeys.C_UNABLE_CREATE_TMPFILE, + tempFile.getAbsolutePath())); + } + } catch (IOException e) { + versionInfo.setErrorCode(ERROR_RETURN); + versionInfo.setReason(getText(TextKeys.C_NO_VALID_JAVA, executableName)); + } + return versionInfo; + } protected static void fillJavaVersionInfo(JavaVersionInfo versionInfo, Properties properties) { versionInfo.setVersion(properties.getProperty(JavaVersionTester.JAVA_VERSION)); @@ -208,7 +255,7 @@ versionInfo.setVendor(properties.getProperty(JavaVersionTester.JAVA_VENDOR)); } - protected static class JavaVersionInfo { + public static class JavaVersionInfo { private String _version; private String _specificationVersion; private String _vendor; @@ -246,7 +293,7 @@ return _version; } - protected String getSpecificationVersion() { + public String getSpecificationVersion() { return _specificationVersion; } @@ -254,7 +301,7 @@ return _vendor; } - protected int getErrorCode() { + public int getErrorCode() { return _errorCode; } Modified: trunk/installer/src/java/org/python/util/install/JavaVersionTester.java =================================================================== --- trunk/installer/src/java/org/python/util/install/JavaVersionTester.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/src/java/org/python/util/install/JavaVersionTester.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -9,7 +9,7 @@ public static final String JAVA_HOME = "java.home"; protected static final String JAVA_VERSION = "java.version"; - protected static final String JAVA_SPECIFICATION_VERSION = "java.specification.version"; + public static final String JAVA_SPECIFICATION_VERSION = "java.specification.version"; protected static final String JAVA_VENDOR = "java.vendor"; private static final String NEWLINE = "\n"; Modified: trunk/installer/src/java/org/python/util/install/driver/Autotest.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/Autotest.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/src/java/org/python/util/install/driver/Autotest.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -4,9 +4,12 @@ import java.io.IOException; import org.python.util.install.FileHelper; +import org.python.util.install.Installation; import org.python.util.install.InstallationListener; import org.python.util.install.InstallerCommandLine; import org.python.util.install.JavaHomeHandler; +import org.python.util.install.JavaVersionTester; +import org.python.util.install.Installation.JavaVersionInfo; public abstract class Autotest implements InstallationListener { @@ -14,6 +17,7 @@ private static int _count = 0; // unique test number private static File _rootDirectory = null; + private static JavaVersionInfo _systemDefaultJavaVersion; private String _name; private File _targetDir; @@ -176,6 +180,10 @@ b.append(_count); // explicitly use a blank, to nail down some platform specific problems b.append(' '); + // add an exclamation mark if possible (see issue #1208) + if(canHandleExclamationMarks()) { + b.append('!'); + } b.append(getNameSuffix()); b.append('_'); _name = b.toString(); @@ -230,4 +238,37 @@ } } + /** + * Determine if the target directory may contain an exclamation mark (see also issue #1208). + * <p> + * Autotests can handle exclamation marks, if both the running and the system default java + * specification versions are 1.6 or higher. Class.getResource() was fixed for JDK 1.6, but only if the directory name does not end with '!'... + * <p> + * Currently there is no way on windows, because the enabledelayedexpansion in jython.bat cannot + * handle exclamation marks in variable names. + * + * @return <code>true</code> if we can handle exclamation marks, <code>false</code> otherwise + */ + private boolean canHandleExclamationMarks() { + boolean exclamation = false; + if (!Installation.isWindows()) { + // get the running java specification version + String specificationVersion = System.getProperty(JavaVersionTester.JAVA_SPECIFICATION_VERSION, + ""); + if (Installation.getJavaSpecificationVersion(specificationVersion) > 15) { + // get the system default java version + if (_systemDefaultJavaVersion == null) { + _systemDefaultJavaVersion = Installation.getDefaultJavaVersion(); + } + if (_systemDefaultJavaVersion.getErrorCode() == Installation.NORMAL_RETURN) { + specificationVersion = _systemDefaultJavaVersion.getSpecificationVersion(); + if (Installation.getJavaSpecificationVersion(specificationVersion) > 15) { + exclamation = true; + } + } + } + } + return exclamation; + } + } Modified: trunk/installer/test/java/org/python/util/install/InstallationTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/InstallationTest.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/installer/test/java/org/python/util/install/InstallationTest.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -73,6 +73,15 @@ assertTrue(Installation.isValidJava(javaVersionInfo)); } + public void testGetJavaSpecificationVersion() { + String specificationVersion = "1.4.2"; + assertEquals(14, Installation.getJavaSpecificationVersion(specificationVersion)); + specificationVersion = "1.5.0"; + assertEquals(15, Installation.getJavaSpecificationVersion(specificationVersion)); + specificationVersion = "1.6.0"; + assertEquals(16, Installation.getJavaSpecificationVersion(specificationVersion)); + } + public void testIsGNUJava() { assertFalse(Installation.isGNUJava()); String originalVmName = System.getProperty(Installation.JAVA_VM_NAME); @@ -85,5 +94,14 @@ assertFalse(Installation.isGNUJava()); } } + + public void testGetDefaultJavaVersion() { + JavaVersionInfo info = Installation.getDefaultJavaVersion(); + assertNotNull(info); + assertEquals(Installation.NORMAL_RETURN, info.getErrorCode()); + String specVersion = info.getSpecificationVersion(); + assertNotNull(specVersion); + assertTrue(specVersion.length() >= 3); + } } Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-01-18 10:04:29 UTC (rev 5945) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-01-18 13:46:12 UTC (rev 5946) @@ -889,7 +889,7 @@ if (url != null) { try { String urlString = URLDecoder.decode(url.toString()); - int jarSeparatorIndex = urlString.indexOf(JAR_SEPARATOR); + int jarSeparatorIndex = urlString.lastIndexOf(JAR_SEPARATOR); if (urlString.startsWith(JAR_URL_PREFIX) && jarSeparatorIndex > 0) { jarFileName = urlString.substring(JAR_URL_PREFIX.length(), jarSeparatorIndex); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-18 10:04:32
|
Revision: 5945 http://jython.svn.sourceforge.net/jython/?rev=5945&view=rev Author: cgroves Date: 2009-01-18 10:04:29 +0000 (Sun, 18 Jan 2009) Log Message: ----------- Add an Ant task to compile .py files to $py.class. It runs on Lib as part of developer-build to exercise it a little bit. Also, only rename the xerces parts of org.apache. Otherwise our ant imports get renamed when jarjaring. Modified Paths: -------------- trunk/jython/build.xml trunk/jython/src/org/python/compiler/Future.java trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/compiler/ScopesCompiler.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/expose/generate/ExposeTask.java trunk/jython/src/org/python/modules/_py_compile.java Added Paths: ----------- trunk/jython/src/org/python/util/GlobMatchingTask.java trunk/jython/src/org/python/util/JycompileAntTask.java Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/build.xml 2009-01-18 10:04:29 UTC (rev 5945) @@ -101,9 +101,9 @@ </echo> </target> - <target name="jarless" depends="compile, copy-lib"/> + <target name="jarless" depends="compile, pycompile"/> - <target name="developer-build" depends="prepare-output, jar, copy-lib" description="a local build for developers" /> + <target name="developer-build" depends="prepare-output, pycompile" description="a local build for developers" /> <target name="full-build" depends="full-check, install" description="a full build with svn checkout" /> @@ -364,7 +364,7 @@ <!-- skip-brand can be set in ant.properties or as a system property to keep from updating the version.properties file and making the jar on every developer build. --> - <target name="brand-version" depends="version-init, svnversion" unless="skip-brand"> + <target name="brand-version" depends="init, svnversion" unless="skip-brand"> <condition property="build.svn.revision" value=""> <not> <isset property="build.svn.revision"/> @@ -522,8 +522,10 @@ <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> <zipfileset src="extlibs/constantine-0.4.jar"/> <rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/> - <zipfileset src="extlibs/xercesImpl-2.9.1.jar"/> - <rule pattern="org.apache.**" result="org.python.apache.@1"/> + <rule pattern="org.apache.xml.**" result="org.python.apache.xml.@1"/> + <rule pattern="org.apache.xerces.**" result="org.python.apache.xerces.@1"/> + <rule pattern="org.apache.wml.**" result="org.python.apache.wml.@1"/> + <rule pattern="org.apache.html.**" result="org.python.apache.html.@1"/> <manifest> <attribute name="Main-Class" value="org.python.util.jython" /> <attribute name="Built-By" value="${user.name}" /> @@ -637,6 +639,15 @@ </copy> </target> + <target name="pycompile" depends="jar,copy-lib"> + <taskdef name="jycompile" classname="org.python.util.JycompileAntTask"> + <classpath path="${dist.dir}/Lib"/> + <classpath path="${dist.dir}/${jython.dev.jar}" /> + <classpath refid="main.classpath" /> + </taskdef> + <jycompile srcdir="${dist.dir}/Lib" destdir="${dist.dir}/Lib" excludes="test/**"/> + </target> + <target name="copy-lib" depends="init, copy-javalib, copy-cpythonlib"> <!-- XXX untested and most likely broken in 2.5 <copy todir="${dist.dir}" preservelastmodified="true"> Modified: trunk/jython/src/org/python/compiler/Future.java =================================================================== --- trunk/jython/src/org/python/compiler/Future.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/compiler/Future.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -26,8 +26,7 @@ return false; int n = cand.getInternalNames().size(); if (n == 0) { - throw new ParseException( - "future statement does not support import *",cand); + throw new ParseException("future statement does not support import *", cand); } for (int i = 0; i < n; i++) { String feature = cand.getInternalNames().get(i).getInternalName(); @@ -56,8 +55,7 @@ if (feature.equals("GIL") || feature.equals("global_interpreter_lock")) { throw new ParseException("Never going to happen!", cand); } - throw new ParseException("future feature "+feature+ - " is not defined",cand); + throw new ParseException("future feature " + feature + " is not defined", cand); } return true; } @@ -90,7 +88,7 @@ if (!(s instanceof ImportFrom)) break; s.from_future_checked = true; - if (!check((ImportFrom) s)) + if (!check((ImportFrom)s)) break; } @@ -119,7 +117,7 @@ public boolean areDivisionOn() { return division; } - + public boolean withStatementSupported() { return with_statement; } Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/compiler/Module.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -435,12 +435,12 @@ c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); c.dup(); c.ifnonnull(label_got_name); - + c.pop(); c.aload(1); c.ldc("__name__"); c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); - + c.label(label_got_name); c.astore(module_tmp); c.aload(1); @@ -448,7 +448,7 @@ c.aload(module_tmp); c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); } - + Label genswitch = new Label(); if (scope.generator) { c.goto_(genswitch); @@ -476,13 +476,13 @@ compiler.parse(tree, c, fast_locals, className, classBody, scope, cflags); - + // similar to visitResume code in pyasm.py if (scope.generator) { c.label(genswitch); - + c.aload(1); - c.getfield("org/python/core/PyFrame", "f_lasti", "I"); + c.getfield("org/python/core/PyFrame", "f_lasti", "I"); Label[] yields = new Label[compiler.yields.size()+1]; yields[0] = start; @@ -637,7 +637,7 @@ public static void compile(mod node, OutputStream ostream, String name, String filename, boolean linenumbers, boolean printResults, - org.python.core.CompilerFlags cflags) + CompilerFlags cflags) throws Exception { Module module = new Module(name, filename, linenumbers); Modified: trunk/jython/src/org/python/compiler/ScopesCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopesCompiler.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/compiler/ScopesCompiler.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -19,11 +19,11 @@ import org.python.antlr.ast.Return; import org.python.antlr.ast.With; import org.python.antlr.ast.Yield; -import org.python.antlr.ast.comprehension; import org.python.antlr.ast.arguments; import org.python.antlr.ast.expr_contextType; import org.python.antlr.base.expr; import org.python.antlr.base.stmt; +import org.python.core.ParserFacade; import java.util.ArrayList; import java.util.Hashtable; @@ -85,8 +85,7 @@ try { visit(node); } catch (Throwable t) { - throw org.python.core.ParserFacade.fixParseError(null, t, - code_compiler.getFilename()); + throw ParserFacade.fixParseError(null, t, code_compiler.getFilename()); } } @@ -138,10 +137,10 @@ beginScope(node.getInternalName(), FUNCSCOPE, node, ac); int n = ac.names.size(); for (int i = 0; i < n; i++) { - cur.addParam((String) ac.names.get(i)); + cur.addParam(ac.names.get(i)); } for (int i = 0; i < ac.init_code.size(); i++) { - visit((stmt) ac.init_code.get(i)); + visit(ac.init_code.get(i)); } cur.markFromParam(); suite(node.getInternalBody()); @@ -291,7 +290,7 @@ traverse(node); return null; } - + @Override public Object visitReturn(Return node) throws Exception { if (node.getInternalValue() != null) { Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -495,23 +495,23 @@ jarIndex = lowerCaseClasspath.indexOf(JYTHON_DEV_JAR); } if (jarIndex >= 0) { - int start = classpath.lastIndexOf(java.io.File.pathSeparator, jarIndex) + 1; + int start = classpath.lastIndexOf(File.pathSeparator, jarIndex) + 1; root = classpath.substring(start, jarIndex); } else { // in case JYTHON_JAR is referenced from a MANIFEST inside another jar on the classpath - root = jarFileName; + root = new File(jarFileName).getParent(); } } } - if (root != null) { - File rootFile = new File(root); - try { - root = rootFile.getCanonicalPath(); - } catch (IOException ioe) { - root = rootFile.getAbsolutePath(); - } + if (root == null) { + return null; } - return root; + File rootFile = new File(root); + try { + return rootFile.getCanonicalPath(); + } catch (IOException ioe) { + return rootFile.getAbsolutePath(); + } } public static void determinePlatform(Properties props) { @@ -554,8 +554,7 @@ } try { addRegistryFile(new File(prefix, "registry")); - File homeFile = new File(registry.getProperty("user.home"), - ".jython"); + File homeFile = new File(registry.getProperty("user.home"), ".jython"); addRegistryFile(homeFile); } catch (Exception exc) { } @@ -615,21 +614,23 @@ } public static synchronized void initialize() { - initialize(null, null, new String[] {""}); + initialize(null, null); } + public static synchronized void initialize(Properties preProperties, Properties postProperties) { + initialize(preProperties, postProperties, new String[] {""}); + } + public static synchronized void initialize(Properties preProperties, Properties postProperties, - String[] argv) - { + String[] argv) { initialize(preProperties, postProperties, argv, null); } public static synchronized void initialize(Properties preProperties, Properties postProperties, String[] argv, - ClassLoader classLoader) - { + ClassLoader classLoader) { initialize(preProperties, postProperties, argv, classLoader, new ClassicPyObjectAdapter()); } Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/core/imp.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -133,6 +133,14 @@ return data; } + public static byte[] compileSource(String name, File file) { + return compileSource(name, file, null); + } + + public static byte[] compileSource(String name, File file, String sourceFilename) { + return compileSource(name, file, sourceFilename, null); + } + public static byte[] compileSource(String name, File file, String sourceFilename, String compiledFilename) { if (sourceFilename == null) { @@ -209,8 +217,7 @@ } } - public static PyObject createFromSource(String name, InputStream fp, - String filename) { + public static PyObject createFromSource(String name, InputStream fp, String filename) { return createFromSource(name, fp, filename, null); } Modified: trunk/jython/src/org/python/expose/generate/ExposeTask.java =================================================================== --- trunk/jython/src/org/python/expose/generate/ExposeTask.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/expose/generate/ExposeTask.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -7,93 +7,44 @@ import java.util.Set; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.MatchingTask; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.util.GlobPatternMapper; -import org.apache.tools.ant.util.SourceFileScanner; import org.objectweb.asm.ClassWriter; -import org.python.util.Generic; +import org.python.util.GlobMatchingTask; -public class ExposeTask extends MatchingTask { +public class ExposeTask extends GlobMatchingTask { - private Path src; - - private File destDir; - - private Set<File> toExpose = Generic.set(); - - /** - * Set the source directories to find the class files to be exposed. - */ - public void setSrcdir(Path srcDir) { - if(src == null) { - src = srcDir; - } else { - src.append(srcDir); - } + @Override + protected String getFrom() { + return "*.class"; } - /** - * Gets the source dirs to find the class files to be exposed. - */ - public Path getSrcdir() { - return src; + @Override + protected String getTo() { + return "*.class"; } - /** - * Set the destination directory into which the Java source files should be compiled. - * - * @param destDir - * the destination director - */ - public void setDestdir(File destDir) { - this.destDir = destDir; - } - - /** - * Gets the destination directory into which the java source files should be compiled. - * - * @return the destination directory - */ - public File getDestdir() { - return destDir; - } - @Override - // documentation inherited - public void execute() throws BuildException { - checkParameters(); - toExpose.clear(); - for(String srcEntry : src.list()) { - File srcDir = getProject().resolveFile(srcEntry); - if(!srcDir.exists()) { - throw new BuildException("srcdir '" + srcDir.getPath() + "' does not exist!", - getLocation()); - } - String[] files = getDirectoryScanner(srcDir).getIncludedFiles(); - scanDir(srcDir, destDir != null ? destDir : srcDir, files); - } - if(toExpose.size() > 1) { + public void process(Set<File> toExpose) throws BuildException { + if (toExpose.size() > 1) { log("Exposing " + toExpose.size() + " classes"); - } else if(toExpose.size() == 1) { + } else if (toExpose.size() == 1) { log("Exposing 1 class"); } - for(File f : toExpose) { + for (File f : toExpose) { ExposedTypeProcessor etp; try { etp = new ExposedTypeProcessor(new FileInputStream(f)); - } catch(IOException e) { + } catch (IOException e) { throw new BuildException("Unable to read '" + f + "' to expose it", e); - } catch(InvalidExposingException iee) { + } catch (InvalidExposingException iee) { throw new BuildException(iee.getMessage()); } - for(MethodExposer exposer : etp.getMethodExposers()) { + for (MethodExposer exposer : etp.getMethodExposers()) { generate(exposer); } - for(DescriptorExposer exposer : etp.getDescriptorExposers()) { + for (DescriptorExposer exposer : etp.getDescriptorExposers()) { generate(exposer); } - if(etp.getNewExposer() != null) { + if (etp.getNewExposer() != null) { generate(etp.getNewExposer()); } generate(etp.getTypeExposer()); @@ -114,39 +65,16 @@ try { out = new FileOutputStream(dest); out.write(newClassfile); - } catch(IOException e) { + } catch (IOException e) { throw new BuildException("Unable to write to '" + dest + "'", e); } finally { - if(out != null) { + if (out != null) { try { out.close(); - } catch(IOException e) { + } catch (IOException e) { // Le sigh... } } } } - - protected void scanDir(File srcDir, File destDir, String[] files) { - GlobPatternMapper m = new GlobPatternMapper(); - m.setFrom("*.class"); - m.setTo("*.class"); - SourceFileScanner sfs = new SourceFileScanner(this); - for(File file : sfs.restrictAsFiles(files, srcDir, destDir, m)) { - toExpose.add(file); - } - } - - /** - * Check that all required attributes have been set and nothing silly has been entered. - */ - protected void checkParameters() throws BuildException { - if(src == null || src.size() == 0) { - throw new BuildException("srcdir attribute must be set!", getLocation()); - } - if(destDir != null && !destDir.isDirectory()) { - throw new BuildException("destination directory '" + destDir + "' does not exist " - + "or is not a directory", getLocation()); - } - } } Modified: trunk/jython/src/org/python/modules/_py_compile.java =================================================================== --- trunk/jython/src/org/python/modules/_py_compile.java 2009-01-18 00:53:10 UTC (rev 5944) +++ trunk/jython/src/org/python/modules/_py_compile.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -13,41 +13,46 @@ public static PyList __all__ = new PyList(new PyString[] { new PyString("compile") }); public static boolean compile(String filename, String cfile, String dfile) { - // Resolve relative path names. dfile is only used for error - // messages and should not be resolved + // Resolve relative path names. dfile is only used for error messages and should not be + // resolved PySystemState sys = Py.getSystemState(); filename = sys.getPath(filename); cfile = sys.getPath(cfile); - + File file = new File(filename); if (!file.exists()) { throw Py.IOError(Errno.ENOENT, filename); } - String name = file.getName(); + String name = getModuleName(file); + + byte[] bytes = org.python.core.imp.compileSource(name, file, dfile, cfile); + org.python.core.imp.cacheCompiledSource(filename, cfile, bytes); + + return bytes.length > 0; + } + + public static final String getModuleName(File f) { + String name = f.getName(); int dot = name.lastIndexOf('.'); if (dot != -1) { name = name.substring(0, dot); } // name the __init__ module after its package - File dir = file.getParentFile(); - if (dir != null && name.equals("__init__")) { + File dir = f.getParentFile(); + if (name.equals("__init__")) { name = dir.getName(); dir = dir.getParentFile(); } - // Make the compiled classfile's name the fully qualified with a package by - // walking up the directory tree looking for __init__.py files. Don't - // check for __init__$py.class since we're compiling source here and the - // existence of a class file without corresponding source probably doesn't - // indicate a package. + // Make the compiled classfile's name fully qualified with a package by walking up the + // directory tree looking for __init__.py files. Don't check for __init__$py.class since + // we're compiling source here and the existence of a class file without corresponding + // source probably doesn't indicate a package. while (dir != null && (new File(dir, "__init__.py").exists())) { name = dir.getName() + "." + name; dir = dir.getParentFile(); } - byte[] bytes = org.python.core.imp.compileSource(name, file, dfile, cfile); - org.python.core.imp.cacheCompiledSource(filename, cfile, bytes); - - return bytes.length > 0; + return name; } } Added: trunk/jython/src/org/python/util/GlobMatchingTask.java =================================================================== --- trunk/jython/src/org/python/util/GlobMatchingTask.java (rev 0) +++ trunk/jython/src/org/python/util/GlobMatchingTask.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -0,0 +1,101 @@ +package org.python.util; + +import java.io.File; +import java.util.Set; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.MatchingTask; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.GlobPatternMapper; +import org.apache.tools.ant.util.SourceFileScanner; + +public abstract class GlobMatchingTask extends MatchingTask { + + private Path src; + + protected File destDir; + + private Set<File> toExpose = Generic.set(); + + /** + * Set the source directories to find the class files to be exposed. + */ + public void setSrcdir(Path srcDir) { + if (src == null) { + src = srcDir; + } else { + src.append(srcDir); + } + } + + /** + * Gets the source dirs to find the class files to be exposed. + */ + public Path getSrcdir() { + return src; + } + + /** + * Set the destination directory into which the Java source files should be compiled. + * + * @param destDir + * the destination director + */ + public void setDestdir(File destDir) { + this.destDir = destDir; + } + + /** + * Gets the destination directory into which the java source files should be compiled. + * + * @return the destination directory + */ + public File getDestdir() { + return destDir; + } + + @Override + public void execute() throws BuildException { + checkParameters(); + toExpose.clear(); + for (String srcEntry : src.list()) { + File srcDir = getProject().resolveFile(srcEntry); + if (!srcDir.exists()) { + throw new BuildException("srcdir '" + srcDir.getPath() + "' does not exist!", + getLocation()); + } + String[] files = getDirectoryScanner(srcDir).getIncludedFiles(); + scanDir(srcDir, destDir != null ? destDir : srcDir, files); + } + process(toExpose); + } + + protected abstract void process(Set<File> matches); + + protected abstract String getFrom(); + + protected abstract String getTo(); + + protected void scanDir(File srcDir, File destDir, String[] files) { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom(getFrom()); + m.setTo(getTo()); + SourceFileScanner sfs = new SourceFileScanner(this); + for (File file : sfs.restrictAsFiles(files, srcDir, destDir, m)) { + toExpose.add(file); + } + } + + /** + * Check that all required attributes have been set and nothing silly has been entered. + */ + protected void checkParameters() throws BuildException { + if (src == null || src.size() == 0) { + throw new BuildException("srcdir attribute must be set!", getLocation()); + } + if (destDir != null && !destDir.isDirectory()) { + throw new BuildException("destination directory '" + destDir + "' does not exist " + + "or is not a directory", getLocation()); + } + } +} \ No newline at end of file Added: trunk/jython/src/org/python/util/JycompileAntTask.java =================================================================== --- trunk/jython/src/org/python/util/JycompileAntTask.java (rev 0) +++ trunk/jython/src/org/python/util/JycompileAntTask.java 2009-01-18 10:04:29 UTC (rev 5945) @@ -0,0 +1,56 @@ +package org.python.util; + +import java.io.File; +import java.util.Properties; +import java.util.Set; + +import org.apache.tools.ant.BuildException; +import org.python.core.PyException; +import org.python.core.PySystemState; +import org.python.core.imp; +import org.python.modules._py_compile; + +public class JycompileAntTask extends GlobMatchingTask { + + @Override + public void process(Set<File> toCompile) throws BuildException { + if (toCompile.size() == 0) { + return; + } else if (toCompile.size() > 1) { + log("Compiling " + toCompile.size() + " files"); + } else if (toCompile.size() == 1) { + log("Compiling 1 file"); + } + Properties props = new Properties(); + props.setProperty(PySystemState.PYTHON_CACHEDIR_SKIP, "true"); + PySystemState.initialize(System.getProperties(), props); + for (File src : toCompile) { + String name = _py_compile.getModuleName(src); + String compiledFilePath = name.replace('.', '/'); + if (src.getName().endsWith("__init__.py")) { + compiledFilePath += "/__init__"; + } + File compiled = new File(destDir, compiledFilePath + "$py.class"); + byte[] bytes; + try { + bytes = imp.compileSource(name, src); + } catch (PyException pye) { + pye.printStackTrace(); + throw new BuildException("Compile failed; see the compiler error output for details."); + } + File dir = compiled.getParentFile(); + if (!dir.exists() && !compiled.getParentFile().mkdirs()) { + throw new BuildException("Unable to make directory for compiled file: " + compiled); + } + imp.cacheCompiledSource(src.getAbsolutePath(), compiled.getAbsolutePath(), bytes); + } + } + + protected String getFrom() { + return "*.py"; + } + + protected String getTo() { + return "*$py.class"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-18 00:53:16
|
Revision: 5944 http://jython.svn.sourceforge.net/jython/?rev=5944&view=rev Author: cgroves Date: 2009-01-18 00:53:10 +0000 (Sun, 18 Jan 2009) Log Message: ----------- ecj likes this, but javac disputes that it's compilable, so go back to the old way Modified Paths: -------------- trunk/jython/src/org/python/core/Py.java Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-01-17 23:57:54 UTC (rev 5943) +++ trunk/jython/src/org/python/core/Py.java 2009-01-18 00:53:10 UTC (rev 5944) @@ -84,10 +84,13 @@ public static long TPFLAGS_BASETYPE = 1L << 10; /** Builtin types that are used to setup PyObject. */ - static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(PyObject.class, - PyType.class, - PyBuiltinCallable.class, - PyDataDescr.class); + static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(); + static { + BOOTSTRAP_TYPES.add(PyObject.class); + BOOTSTRAP_TYPES.add(PyType.class); + BOOTSTRAP_TYPES.add(PyBuiltinCallable.class); + BOOTSTRAP_TYPES.add(PyDataDescr.class); + } /** A unique object to indicate no conversion is possible in __tojava__ methods **/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-17 23:58:01
|
Revision: 5943 http://jython.svn.sourceforge.net/jython/?rev=5943&view=rev Author: cgroves Date: 2009-01-17 23:57:54 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Match the statuses from CPython Modified Paths: -------------- trunk/jython/Lib/threading.py Modified: trunk/jython/Lib/threading.py =================================================================== --- trunk/jython/Lib/threading.py 2009-01-17 22:36:27 UTC (rev 5942) +++ trunk/jython/Lib/threading.py 2009-01-17 23:57:54 UTC (rev 5943) @@ -153,10 +153,10 @@ ThreadStates = { java.lang.Thread.State.NEW : 'initial', - java.lang.Thread.State.RUNNABLE: 'runnable', - java.lang.Thread.State.BLOCKED: 'blocked', - java.lang.Thread.State.WAITING: 'waiting', - java.lang.Thread.State.TIMED_WAITING: 'timed_waiting', + java.lang.Thread.State.RUNNABLE: 'started', + java.lang.Thread.State.BLOCKED: 'started', + java.lang.Thread.State.WAITING: 'started', + java.lang.Thread.State.TIMED_WAITING: 'started', java.lang.Thread.State.TERMINATED: 'stopped', } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-17 22:48:48
|
Revision: 5942 http://jython.svn.sourceforge.net/jython/?rev=5942&view=rev Author: cgroves Date: 2009-01-17 22:36:27 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Resurrect some PyJavaClass code to fix bug #1235. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/util/Generic.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-17 22:36:27 UTC (rev 5942) @@ -72,6 +72,12 @@ c.id = 16 self.assertEquals(16, c.id) + def test_awt_hack(self): + # We ignore several deprecated methods in java.awt.* in favor of bean properties that were + # addded in Java 1.1. This tests that one of those bean properties is visible. + c = Container() + c.size = 400, 300 + self.assertEquals(Dimension(400, 300), c.size) class SysIntegrationTest(unittest.TestCase): def setUp(self): Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/src/org/python/core/Py.java 2009-01-17 22:36:27 UTC (rev 5942) @@ -84,13 +84,10 @@ public static long TPFLAGS_BASETYPE = 1L << 10; /** Builtin types that are used to setup PyObject. */ - static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(); - static { - BOOTSTRAP_TYPES.add(PyObject.class); - BOOTSTRAP_TYPES.add(PyType.class); - BOOTSTRAP_TYPES.add(PyBuiltinCallable.class); - BOOTSTRAP_TYPES.add(PyDataDescr.class); - } + static final Set<Class<?>> BOOTSTRAP_TYPES = Generic.set(PyObject.class, + PyType.class, + PyBuiltinCallable.class, + PyDataDescr.class); /** A unique object to indicate no conversion is possible in __tojava__ methods **/ Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-17 22:36:27 UTC (rev 5942) @@ -23,6 +23,16 @@ private final static Class<?>[] OO = {PyObject.class, PyObject.class}; + /** Deprecated methods in java.awt.* that have bean property equivalents we prefer. */ + private final static Set<String> BAD_AWT_METHODS = Generic.set("layout", + "insets", + "size", + "minimumSize", + "preferredSize", + "maximumSize", + "bounds", + "enable"); + private static Map<Class<?>, PyBuiltinMethod[]> collectionProxies; public static PyObject wrapJavaObject(Object o) { @@ -121,11 +131,22 @@ method.setAccessible(true); } } + + boolean isInAwt = name.startsWith("java.awt.") && name.indexOf('.', 9) == -1; for (Method meth : methods) { if (!declaredOnMember(baseClass, meth) || ignore(meth)) { continue; } + String methname = meth.getName(); + + // Special case a few troublesome methods in java.awt.*. These methods are all + // deprecated and interfere too badly with bean properties to be tolerated. This is + // totally a hack but a lot of code that uses java.awt will break without it. + if (isInAwt && BAD_AWT_METHODS.contains(methname)) { + continue; + } + String nmethname = normalize(methname); PyReflectedFunction reflfunc = (PyReflectedFunction)dict.__finditem__(nmethname); if (reflfunc == null) { Modified: trunk/jython/src/org/python/util/Generic.java =================================================================== --- trunk/jython/src/org/python/util/Generic.java 2009-01-17 20:56:28 UTC (rev 5941) +++ trunk/jython/src/org/python/util/Generic.java 2009-01-17 22:36:27 UTC (rev 5942) @@ -45,4 +45,16 @@ public static <T> Set<T> set() { return new HashSet<T>(); } + + /** + * Makes a Set using the generic type inferred from whatever this is being assigned to filled + * with the items in <code>contents</code>. + */ + public static <T, U extends T> Set<T> set(U...contents) { + Set<T> s = new HashSet<T>(contents.length); + for (U u : contents) { + s.add(u); + } + return s; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-17 20:56:34
|
Revision: 5941 http://jython.svn.sourceforge.net/jython/?rev=5941&view=rev Author: cgroves Date: 2009-01-17 20:56:28 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Implement Iterable in PyIterator. This means generators are usable in foreach loops. The implementation could be moved up to PyObject, but I feel like implementing the interface says that the object will be iterable, and not all PyObjects provide an __iter__. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/BytecodeLoader.java trunk/jython/src/org/python/core/PyIterator.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PySequence.java trunk/jython/src/org/python/core/codecs.java trunk/jython/src/org/python/core/imp.java trunk/jython/tests/java/org/python/tests/Coercions.java Added Paths: ----------- trunk/jython/src/org/python/core/WrappedIterIterator.java Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-17 20:56:28 UTC (rev 5941) @@ -193,9 +193,7 @@ yield 2 yield 3 self.assertEquals(6, Coercions.takeIterable(simple_gen())) - self.assertEquals(True, Coercions.takeBoolIterable(simple_gen())) - def test_class_coercion(self): c = Coercions() from java.util import Hashtable, HashMap Modified: trunk/jython/src/org/python/core/BytecodeLoader.java =================================================================== --- trunk/jython/src/org/python/core/BytecodeLoader.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/BytecodeLoader.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -8,7 +8,7 @@ import org.python.util.Generic; /** - * Utility class for loading of compiled python modules and java classes defined in python modules. + * Utility class for loading compiled python modules and java classes defined in python modules. */ public class BytecodeLoader { Modified: trunk/jython/src/org/python/core/PyIterator.java =================================================================== --- trunk/jython/src/org/python/core/PyIterator.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/PyIterator.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -1,6 +1,8 @@ // Copyright 2000 Finn Bock package org.python.core; +import java.util.Iterator; + /** * An abstract helper class useful when implementing an iterator object. This implementation supply * a correct __iter__() and a next() method based on the __iternext__() implementation. The @@ -9,7 +11,7 @@ * If the implementation raises a StopIteration exception, it should be stored in stopException so * the correct exception can be thrown to preserve the line numbers in the traceback. */ -public abstract class PyIterator extends PyObject { +public abstract class PyIterator extends PyObject implements Iterable<Object> { protected PyException stopException; @@ -51,4 +53,13 @@ } return ret; } + + public Iterator<Object> iterator() { + return new WrappedIterIterator<Object>(this) { + @Override + public Object next() { + return getNext().__tojava__(Object.class); + } + }; + } } Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/PyList.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -3,13 +3,13 @@ import java.util.Collection; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; import org.python.expose.MethodType; +import org.python.util.Generic; /** * A builtin python list. @@ -51,7 +51,7 @@ } private static List<PyObject> listify(Iterator<PyObject> iter) { - final List<PyObject> list = new LinkedList<PyObject>(); + List<PyObject> list = Generic.list(); while (iter.hasNext()) { list.add(iter.next()); } Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/PyObject.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -7,8 +7,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; - import org.python.expose.ExposedDelete; import org.python.expose.ExposedGet; import org.python.expose.ExposedMethod; @@ -765,37 +763,11 @@ */ public Iterable<PyObject> asIterable() { return new Iterable<PyObject>() { - public Iterator<PyObject> iterator() { - return new Iterator<PyObject>() { - - private PyObject iter = __iter__(); - - private PyObject next; - - private boolean checkedForNext; - - public boolean hasNext() { - if (!checkedForNext) { - next = iter.__iternext__(); - checkedForNext = true; - } - return next != null; - } - + return new WrappedIterIterator<PyObject>(__iter__()) { public PyObject next() { - if (!hasNext()) { - throw new NoSuchElementException("End of the line, bub"); - } - PyObject toReturn = next; - checkedForNext = false; - next = null; - return toReturn; + return getNext(); } - - public void remove() { - throw new UnsupportedOperationException("Can't remove from a Python iterator"); - } }; } }; @@ -1894,8 +1866,8 @@ where1 = where[0]; PyObject impl2 = t2.lookup_where(right, where); where2 = where[0]; - if (impl2 != null && impl1 != null && where1 != where2 && - (t2.isSubType(t1) && !Py.isSubClass(where1, where2) + if (impl2 != null && impl1 != null && where1 != where2 && + (t2.isSubType(t1) && !Py.isSubClass(where1, where2) && !Py.isSubClass(t1, where2) || isStrUnicodeSpecialCase(t1, t2, op))) { PyObject tmp = o1; Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/PySequence.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -14,9 +14,6 @@ */ public abstract class PySequence extends PyObject { - /** - * This constructor is used by PyJavaClass.init() - */ public PySequence() {} public int gListAllocatedStatus = -1; Added: trunk/jython/src/org/python/core/WrappedIterIterator.java =================================================================== --- trunk/jython/src/org/python/core/WrappedIterIterator.java (rev 0) +++ trunk/jython/src/org/python/core/WrappedIterIterator.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -0,0 +1,48 @@ +package org.python.core; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Exposes a Python iter as a Java Iterator. + */ +public abstract class WrappedIterIterator<E> implements Iterator<E> { + + private final PyObject iter; + + private PyObject next; + + private boolean checkedForNext; + + public WrappedIterIterator(PyObject iter) { + this.iter = iter; + } + + public boolean hasNext() { + if (!checkedForNext) { + next = iter.__iternext__(); + checkedForNext = true; + } + return next != null; + } + + /** + * Subclasses must implement this to turn the type returned by the iter to the type expected by + * Java. + */ + public abstract E next(); + + public PyObject getNext() { + if (!hasNext()) { + throw new NoSuchElementException("End of the line, bub"); + } + PyObject toReturn = next; + checkedForNext = false; + next = null; + return toReturn; + } + + public void remove() { + throw new UnsupportedOperationException("Can't remove from a Python iterator"); + } +} Modified: trunk/jython/src/org/python/core/codecs.java =================================================================== --- trunk/jython/src/org/python/core/codecs.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/codecs.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -245,14 +245,14 @@ if (Py.isInstance(exc, Py.UnicodeDecodeError)) { PyObject object = exc.__getattr__("object"); if (!Py.isInstance(object, PyString.TYPE) || Py.isInstance(object, PyUnicode.TYPE)) { - throw Py.TypeError("object attribute must be str"); + throw Py.TypeError("object attribute must be str"); } PyObject end = exc.__getattr__("end"); return new PyTuple(new PyUnicode(Py_UNICODE_REPLACEMENT_CHARACTER), end); } else if (Py.isInstance(exc, Py.UnicodeEncodeError)) { PyObject object = exc.__getattr__("object"); if (!Py.isInstance(object, PyUnicode.TYPE)) { - throw Py.TypeError("object attribute must be unicode"); + throw Py.TypeError("object attribute must be unicode"); } PyObject end = exc.__getattr__("end"); return new PyTuple(Py.java2py("?"), end); @@ -388,9 +388,9 @@ XMLCHARREFREPLACE, BACKSLASHREPLACE }; - for (int i = 0; i < builtinErrorHandlers.length; i++) { - register_error(builtinErrorHandlers[i], Py.newJavaFunc(codecs.class, - builtinErrorHandlers[i] + "_errors")); + for (String builtinErrorHandler : builtinErrorHandlers) { + register_error(builtinErrorHandler, Py.newJavaFunc(codecs.class, + builtinErrorHandler + "_errors")); } import_encodings(); } @@ -414,9 +414,9 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1 , - + }; - + private static boolean SPECIAL(char c, boolean encodeO, boolean encodeWS){ return (c>127 || utf7_special[(c)] == 1) || (encodeWS && (utf7_special[(c)] == 2)) || @@ -447,7 +447,6 @@ int bitsInCharsleft = 0; long charsleft = 0; boolean surrogate = false; - char highOrderSurrogate = 0; StringBuilder unicode = new StringBuilder(e); while (s < e) { // restart: @@ -470,7 +469,6 @@ surrogate = false; } else if (0xDC00 <= outCh && outCh <= 0xDFFF) { surrogate = true; - highOrderSurrogate = outCh; } else { unicode.append(outCh); } @@ -537,7 +535,6 @@ "code pairs are not supported"); } else if (0xDC00 <= outCh && outCh <= 0xDFFF) { surrogate = true; - highOrderSurrogate = outCh; } else { unicode.append(outCh); } @@ -631,7 +628,7 @@ bitsleft -= 6; } /* If the next character is special then we dont' need to terminate - the shift sequence. If the next character is not a BASE64 character + the shift sequence. If the next character is not a BASE64 character or '-' then the shift sequence will be terminated implicitly and we don't have to insert a '-'. */ @@ -1280,7 +1277,7 @@ this.start = start; this.stop = stop; this.step = step; - + // this bounds checking is necessary to convert between use of code units elsewhere, and codepoints here // it would be nice if it were unnecessary! int count = getCodePointCount(s); @@ -1290,7 +1287,7 @@ else if (stop >= count) { this.stop = count; } - + for (int i = 0; i < start; i++) { nextCodePoint(); } @@ -1303,7 +1300,7 @@ private static int getCodePointCount(String s) { return s.codePointCount(0, s.length()); } - + public boolean hasNext() { return current < stop; } Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/src/org/python/core/imp.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -9,6 +9,7 @@ import java.io.InputStream; import java.util.concurrent.locks.ReentrantLock; +import org.python.compiler.Module; import org.python.core.util.FileUtil; /** @@ -189,9 +190,7 @@ } } - public static byte[] compileSource(String name, - InputStream fp, - String filename) { + public static byte[] compileSource(String name, InputStream fp, String filename) { ByteArrayOutputStream ofp = new ByteArrayOutputStream(); try { if(filename == null) { @@ -203,13 +202,7 @@ } finally { fp.close(); } - org.python.compiler.Module.compile(node, - ofp, - name + "$py", - filename, - true, - false, - null); + Module.compile(node, ofp, name + "$py", filename, true, false, null); return ofp.toByteArray(); } catch(Throwable t) { throw ParserFacade.fixParseError(null, t, filename); Modified: trunk/jython/tests/java/org/python/tests/Coercions.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-17 20:35:09 UTC (rev 5940) +++ trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-17 20:56:28 UTC (rev 5941) @@ -83,4 +83,21 @@ public static String take(byte bt) { return "take with byte arg: " + bt; } + + public static int takeIterable(Iterable<Integer> it) { + int sum = 0; + for (Integer integer : it) { + sum += integer; + } + return sum; + } + + public static boolean takeBoolIterable(Iterable<Boolean> it) { + for (Boolean integer : it) { + if (!integer) { + return false; + } + } + return true; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-17 20:35:14
|
Revision: 5940 http://jython.svn.sourceforge.net/jython/?rev=5940&view=rev Author: cgroves Date: 2009-01-17 20:35:09 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Add some tests for overriding attribute lookup and adding mapping methods to wrapped Java types. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/CustomizableMapHolder.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-17 18:42:14 UTC (rev 5939) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-17 20:35:09 UTC (rev 5940) @@ -1,3 +1,4 @@ +import operator import os import unittest import subprocess @@ -17,7 +18,7 @@ from javax.swing.tree import TreePath from org.python.core.util import FileUtil -from org.python.tests import BeanImplementation, Listenable +from org.python.tests import BeanImplementation, Child, Listenable, CustomizableMapHolder class InstantiationTest(unittest.TestCase): def test_cant_instantiate_abstract(self): @@ -62,7 +63,16 @@ self.assertEquals("name", bself.getName()) SubBean() + def test_inheriting_half_bean(self): + c = Child() + self.assertEquals("blah", c.value) + c.value = "bleh" + self.assertEquals("bleh", c.value) + self.assertEquals(7, c.id) + c.id = 16 + self.assertEquals(16, c.id) + class SysIntegrationTest(unittest.TestCase): def setUp(self): self.orig_stdout = sys.stdout @@ -338,6 +348,31 @@ "-J-Djava.security.manager", "-J-Djava.security.policy=%s" % policy, script]), 0) +class JavaWrapperCustomizationTest(unittest.TestCase): + def tearDown(self): + CustomizableMapHolder.clearAdditions() + + def test_adding_item_access(self): + m = CustomizableMapHolder() + self.assertRaises(TypeError, operator.getitem, m, "initial") + CustomizableMapHolder.addGetitem() + self.assertEquals(m.held["initial"], m["initial"]) + # dict would throw a KeyError here, but Map returns null for a missing key + self.assertEquals(None, m["nonexistent"]) + self.assertRaises(TypeError, operator.setitem, m, "initial") + CustomizableMapHolder.addSetitem() + m["initial"] = 12 + self.assertEquals(12, m["initial"]) + + def test_adding_attributes(self): + m = CustomizableMapHolder() + self.assertRaises(AttributeError, getattr, m, "initial") + CustomizableMapHolder.addGetattribute() + self.assertEquals(7, m.held["initial"], "Existing fields should still be accessible") + self.assertEquals(7, m.initial) + self.assertEquals(None, m.nonexistent, "Nonexistent fields should be passed on to the Map") + + def test_main(): test_support.run_unittest(InstantiationTest, BeanTest, @@ -351,7 +386,8 @@ BigNumberTest, JavaStringTest, JavaDelegationTest, - SecurityManagerTest) + SecurityManagerTest, + JavaWrapperCustomizationTest) if __name__ == "__main__": test_main() Modified: trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java =================================================================== --- trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java 2009-01-17 18:42:14 UTC (rev 5939) +++ trunk/jython/src/org/python/core/PyBuiltinMethodNarrow.java 2009-01-17 20:35:09 UTC (rev 5940) @@ -1,7 +1,25 @@ package org.python.core; public abstract class PyBuiltinMethodNarrow extends PyBuiltinMethod { + /** + * Creates a method for the given name that takes no arguments. + */ + protected PyBuiltinMethodNarrow(String name) { + this(name, 0); + } + /** + * Creates a method for the <code>name<code> that takes exactly <code>numArgs</code> arguments. + */ + protected PyBuiltinMethodNarrow(String name, int numArgs) { + this(name, numArgs, numArgs); + } + + + /** + * Creates a method for the given name that takes at least <code>minArgs</code> and at most + * <code>maxArgs</code> arguments. + */ protected PyBuiltinMethodNarrow(String name, int minArgs, int maxArgs) { super(null, new DefaultInfo(name, minArgs, maxArgs)); } Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-17 18:42:14 UTC (rev 5939) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-17 20:35:09 UTC (rev 5940) @@ -349,7 +349,7 @@ for (Map.Entry<Class<?>, PyBuiltinMethod[]> entry : getCollectionProxies().entrySet()) { if (entry.getKey() == forClass) { for (PyBuiltinMethod meth : entry.getValue()) { - dict.__setitem__(meth.info.getName(), new PyMethodDescr(this, meth)); + addMethod(meth); } } } @@ -373,29 +373,26 @@ || getDescrMethod(forClass, "_dodel", PyObject.class) != null; } else { // Pass __eq__ and __repr__ through to subclasses of Object - PyBuiltinCallable equals = new PyBuiltinMethodNarrow("__eq__", 1, 1) { + addMethod(new PyBuiltinMethodNarrow("__eq__", 1) { @Override public PyObject __call__(PyObject o) { Object proxy = self.getJavaProxy(); Object oAsJava = o.__tojava__(proxy.getClass()); return proxy.equals(oAsJava) ? Py.True : Py.False; } - }; - dict.__setitem__("__eq__", new PyMethodDescr(this, equals)); - PyBuiltinCallable hash = new PyBuiltinMethodNarrow("__hash__", 0, 0) { + }); + addMethod(new PyBuiltinMethodNarrow("__hash__") { @Override public PyObject __call__() { return Py.newInteger(self.getJavaProxy().hashCode()); } - }; - dict.__setitem__("__hash__", new PyMethodDescr(this, hash)); - PyBuiltinCallable repr = new PyBuiltinMethodNarrow("__repr__", 0, 0) { + }); + addMethod(new PyBuiltinMethodNarrow("__repr__") { @Override public PyObject __call__() { return Py.newString(self.getJavaProxy().toString()); } - }; - dict.__setitem__("__repr__", new PyMethodDescr(this, repr)); + }); } } @@ -522,8 +519,8 @@ } private static class ListMethod extends PyBuiltinMethodNarrow { - protected ListMethod(String name, int minArgs, int maxArgs) { - super(name, minArgs, maxArgs); + protected ListMethod(String name, int numArgs) { + super(name, numArgs); } protected List<Object> asList(){ @@ -532,8 +529,8 @@ } private static class MapMethod extends PyBuiltinMethodNarrow { - protected MapMethod(String name, int minArgs, int maxArgs) { - super(name, minArgs, maxArgs); + protected MapMethod(String name, int numArgs) { + super(name, numArgs); } protected Map<Object, Object> asMap(){ @@ -545,21 +542,21 @@ if (collectionProxies == null) { collectionProxies = Generic.map(); - PyBuiltinMethodNarrow iterableProxy = new PyBuiltinMethodNarrow("__iter__", 0, 0) { + PyBuiltinMethodNarrow iterableProxy = new PyBuiltinMethodNarrow("__iter__") { public PyObject __call__() { return new IteratorIter(((Iterable)self.getJavaProxy())); } }; collectionProxies.put(Iterable.class, new PyBuiltinMethod[] {iterableProxy}); - PyBuiltinMethodNarrow lenProxy = new PyBuiltinMethodNarrow("__len__", 0, 0) { + PyBuiltinMethodNarrow lenProxy = new PyBuiltinMethodNarrow("__len__") { @Override public PyObject __call__() { return Py.newInteger(((Collection<?>)self.getJavaProxy()).size()); } }; - PyBuiltinMethodNarrow containsProxy = new PyBuiltinMethodNarrow("__contains__", 1, 1) { + PyBuiltinMethodNarrow containsProxy = new PyBuiltinMethodNarrow("__contains__") { @Override public PyObject __call__(PyObject obj) { Object other = obj.__tojava__(Object.class); @@ -570,14 +567,14 @@ collectionProxies.put(Collection.class, new PyBuiltinMethod[] {lenProxy, containsProxy}); - PyBuiltinMethodNarrow iteratorProxy = new PyBuiltinMethodNarrow("__iter__", 0, 0) { + PyBuiltinMethodNarrow iteratorProxy = new PyBuiltinMethodNarrow("__iter__") { public PyObject __call__() { return new IteratorIter(((Iterator)self.getJavaProxy())); } }; collectionProxies.put(Iterator.class, new PyBuiltinMethod[] {iteratorProxy}); - PyBuiltinMethodNarrow enumerationProxy = new PyBuiltinMethodNarrow("__iter__", 0, 0) { + PyBuiltinMethodNarrow enumerationProxy = new PyBuiltinMethodNarrow("__iter__") { public PyObject __call__() { return new EnumerationIter(((Enumeration)self.getJavaProxy())); } @@ -585,38 +582,38 @@ collectionProxies.put(Enumeration.class, new PyBuiltinMethod[] {enumerationProxy}); // Map doesn't extend Collection, so it needs its own version of len, iter and contains - PyBuiltinMethodNarrow mapLenProxy = new MapMethod("__len__", 0, 0) { + PyBuiltinMethodNarrow mapLenProxy = new MapMethod("__len__", 0) { @Override public PyObject __call__() { return Py.java2py(asMap().size()); } }; - PyBuiltinMethodNarrow mapIterProxy = new MapMethod("__iter__", 0, 0) { + PyBuiltinMethodNarrow mapIterProxy = new MapMethod("__iter__", 0) { @Override public PyObject __call__() { return new IteratorIter(asMap().keySet()); } }; - PyBuiltinMethodNarrow mapContainsProxy = new MapMethod("__contains__", 1, 1) { + PyBuiltinMethodNarrow mapContainsProxy = new MapMethod("__contains__", 1) { public PyObject __call__(PyObject obj) { Object other = obj.__tojava__(Object.class); return asMap().containsKey(other) ? Py.True : Py.False; } }; - PyBuiltinMethodNarrow mapGetProxy = new MapMethod("__getitem__", 1, 1) { + PyBuiltinMethodNarrow mapGetProxy = new MapMethod("__getitem__", 1) { @Override public PyObject __call__(PyObject key) { return Py.java2py(asMap().get(Py.tojava(key, Object.class))); } }; - PyBuiltinMethodNarrow mapPutProxy = new MapMethod("__setitem__", 2, 2) { + PyBuiltinMethodNarrow mapPutProxy = new MapMethod("__setitem__", 2) { @Override public PyObject __call__(PyObject key, PyObject value) { return Py.java2py(asMap().put(Py.tojava(key, Object.class), Py.tojava(value, Object.class))); } }; - PyBuiltinMethodNarrow mapRemoveProxy = new MapMethod("__delitem__", 1, 1) { + PyBuiltinMethodNarrow mapRemoveProxy = new MapMethod("__delitem__", 1) { @Override public PyObject __call__(PyObject key) { return Py.java2py(asMap().remove(Py.tojava(key, Object.class))); @@ -629,20 +626,20 @@ mapPutProxy, mapRemoveProxy}); - PyBuiltinMethodNarrow listGetProxy = new ListMethod("__getitem__", 1, 1) { + PyBuiltinMethodNarrow listGetProxy = new ListMethod("__getitem__", 1) { @Override public PyObject __call__(PyObject key) { return new ListIndexDelegate(asList()).checkIdxAndGetItem(key); } }; - PyBuiltinMethodNarrow listSetProxy = new ListMethod("__setitem__", 2, 2) { + PyBuiltinMethodNarrow listSetProxy = new ListMethod("__setitem__", 2) { @Override public PyObject __call__(PyObject key, PyObject value) { new ListIndexDelegate(asList()).checkIdxAndSetItem(key, value); return Py.None; } }; - PyBuiltinMethodNarrow listRemoveProxy = new ListMethod("__delitem__", 1, 1) { + PyBuiltinMethodNarrow listRemoveProxy = new ListMethod("__delitem__", 1) { @Override public PyObject __call__(PyObject key) { new ListIndexDelegate(asList()).checkIdxAndDelItem(key); Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-17 18:42:14 UTC (rev 5939) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-17 20:35:09 UTC (rev 5940) @@ -1067,6 +1067,15 @@ type___setattr__(name, value); } + /** + * Adds the given method to this type's dict under its name in its descriptor. If there's an + * existing item in the dict, it's replaced. + */ + public void addMethod(PyBuiltinMethod meth) { + PyMethodDescr pmd = meth.makeDescriptor(this); + dict.__setitem__(pmd.getName(), pmd); + } + protected void checkSetattr() { if (builtin) { throw Py.TypeError(String.format("can't set attributes of built-in/extension type " Added: trunk/jython/tests/java/org/python/tests/CustomizableMapHolder.java =================================================================== --- trunk/jython/tests/java/org/python/tests/CustomizableMapHolder.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/CustomizableMapHolder.java 2009-01-17 20:35:09 UTC (rev 5940) @@ -0,0 +1,75 @@ +package org.python.tests; + +import java.util.Map; + +import org.python.core.Py; +import org.python.core.PyBuiltinMethod; +import org.python.core.PyBuiltinMethodNarrow; +import org.python.core.PyException; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.util.Generic; + + +public class CustomizableMapHolder { + + public Map<String, Integer> held = Generic.map(); + + { + held.put("initial", 7); + } + + public static void clearAdditions() { + PyObject dict = PyType.fromClass(CustomizableMapHolder.class).fastGetDict(); + for (String name : new String[] {"__getitem__", "__setitem__", "__getattribute__"}) { + if (dict.__finditem__(name) != null) { + dict.__delitem__(name); + } + } + } + + public static void addGetitem() { + PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getitem__", 1) { + @Override + public PyObject __call__(PyObject arg) { + CustomizableMapHolder inst = Py.tojava(self, CustomizableMapHolder.class); + String key = Py.tojava(arg, String.class); + return Py.java2py(inst.held.get(key)); + } + }; + PyType.fromClass(CustomizableMapHolder.class).addMethod(meth); + } + + public static void addSetitem() { + PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__setitem__", 2) { + @Override + public PyObject __call__(PyObject arg1, PyObject arg2) { + CustomizableMapHolder inst = Py.tojava(self, CustomizableMapHolder.class); + String key = Py.tojava(arg1, String.class); + Integer val = Py.tojava(arg2, Integer.class); + inst.held.put(key, val); + return Py.None; + } + }; + PyType.fromClass(CustomizableMapHolder.class).addMethod(meth); + } + + public static void addGetattribute() { + final PyObject objectGetattribute = PyObject.TYPE.__getattr__("__getattribute__"); + PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getattribute__", 1) { + @Override + public PyObject __call__(PyObject name) { + try { + return objectGetattribute.__call__(self, name); + } catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) { + throw pye; + } + } + CustomizableMapHolder inst = Py.tojava(self, CustomizableMapHolder.class); + return Py.java2py(inst.held.get(Py.tojava(name, String.class))); + } + }; + PyType.fromClass(CustomizableMapHolder.class).addMethod(meth); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-17 18:42:18
|
Revision: 5939 http://jython.svn.sourceforge.net/jython/?rev=5939&view=rev Author: cgroves Date: 2009-01-17 18:42:14 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Shoulda gone out with r5607. Modified Paths: -------------- trunk/jython/Lib/test/test_builtin_jy.py trunk/jython/src/org/python/modules/Setup.java Modified: trunk/jython/Lib/test/test_builtin_jy.py =================================================================== --- trunk/jython/Lib/test/test_builtin_jy.py 2009-01-17 18:31:06 UTC (rev 5938) +++ trunk/jython/Lib/test/test_builtin_jy.py 2009-01-17 18:42:14 UTC (rev 5939) @@ -162,7 +162,7 @@ def test_names(self): for name in sys.builtin_module_names: - if name != '_jython' and name not in ('time', '_random', 'array', '_collections', '_ast'): + if name not in ('time', '_random', 'array', '_collections', '_ast'): module = __import__(name) self.assertEqual(name, module.__name__) Modified: trunk/jython/src/org/python/modules/Setup.java =================================================================== --- trunk/jython/src/org/python/modules/Setup.java 2009-01-17 18:31:06 UTC (rev 5938) +++ trunk/jython/src/org/python/modules/Setup.java 2009-01-17 18:42:14 UTC (rev 5939) @@ -41,7 +41,6 @@ "_codecs", "imp", "ucnhash", - "_jython", "_new:org.python.modules._newmodule", "_weakref:org.python.modules._weakref.WeakrefModule", "errno", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-17 18:31:10
|
Revision: 5938 http://jython.svn.sourceforge.net/jython/?rev=5938&view=rev Author: zyasoft Date: 2009-01-17 18:31:06 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Fixes #1217 where we report the underlying Java error (java.util.zip.DataFormatException) instead of the standard Python one (zlib.error). This also helps support PyAMF on Jython. Thanks Nick Joyce for the patch. Modified Paths: -------------- trunk/jython/Lib/test/test_zlib.py trunk/jython/Lib/zlib.py Modified: trunk/jython/Lib/test/test_zlib.py =================================================================== --- trunk/jython/Lib/test/test_zlib.py 2009-01-17 18:12:57 UTC (rev 5937) +++ trunk/jython/Lib/test/test_zlib.py 2009-01-17 18:31:06 UTC (rev 5938) @@ -81,6 +81,8 @@ self.assertRaises(ValueError, zlib.decompressobj().flush, 0) self.assertRaises(ValueError, zlib.decompressobj().flush, -1) + def test_decompress_badinput(self): + self.assertRaises(zlib.error, zlib.decompress, 'foo') class CompressTestCase(unittest.TestCase): Modified: trunk/jython/Lib/zlib.py =================================================================== --- trunk/jython/Lib/zlib.py 2009-01-17 18:12:57 UTC (rev 5937) +++ trunk/jython/Lib/zlib.py 2009-01-17 18:31:06 UTC (rev 5938) @@ -15,7 +15,7 @@ """ import jarray, binascii -from java.util.zip import Adler32, Deflater, Inflater +from java.util.zip import Adler32, Deflater, Inflater, DataFormatException from java.lang import Long, String from cStringIO import StringIO @@ -66,8 +66,8 @@ def decompress(string, wbits=0, bufsize=16384): inflater = Inflater(wbits < 0) inflater.setInput(string) + return _get_inflate_data(inflater) - class compressobj: # all jython uses wbits for is deciding whether to skip the header if it's negative @@ -152,22 +152,26 @@ s = StringIO() while not deflater.finished(): l = deflater.deflate(buf) + if l == 0: break s.write(String(buf, 0, 0, l)) s.seek(0) return s.read() - def _get_inflate_data(inflater, max_length=0): buf = jarray.zeros(1024, 'b') s = StringIO() total = 0 while not inflater.finished(): - if max_length: - l = inflater.inflate(buf, 0, min(1024, max_length - total)) - else: - l = inflater.inflate(buf) + try: + if max_length: + l = inflater.inflate(buf, 0, min(1024, max_length - total)) + else: + l = inflater.inflate(buf) + except DataFormatException, e: + raise error(str(e)) + if l == 0: break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-17 18:13:00
|
Revision: 5937 http://jython.svn.sourceforge.net/jython/?rev=5937&view=rev Author: zyasoft Date: 2009-01-17 18:12:57 +0000 (Sat, 17 Jan 2009) Log Message: ----------- Fixes #1227 where for cStringIO.StringIO, orderings of method calls like write-seek-write did not properly work. This also addresses a problem for PyAMF support. Thanks go to Nick Joyce for the patch! Modified Paths: -------------- trunk/jython/Lib/test/test_StringIO_jy.py trunk/jython/src/org/python/modules/cStringIO.java Modified: trunk/jython/Lib/test/test_StringIO_jy.py =================================================================== --- trunk/jython/Lib/test/test_StringIO_jy.py 2009-01-16 09:17:19 UTC (rev 5936) +++ trunk/jython/Lib/test/test_StringIO_jy.py 2009-01-17 18:12:57 UTC (rev 5937) @@ -12,9 +12,17 @@ self.assertEqual(u'foo', cStringIO.StringIO(u'foo').read()) self.assertEqual('foo', cStringIO.StringIO(u'foo').read()) +class TestWrite(unittest.TestCase): + def test_write_seek_write(self): + f = cStringIO.StringIO() + f.write('hello') + f.seek(2) + f.write('hi') + self.assertEquals(f.getvalue(), 'hehio') def test_main(): test_support.run_unittest(TestUnicodeInput) + test_support.run_unittest(TestWrite) if __name__ == '__main__': test_main() Modified: trunk/jython/src/org/python/modules/cStringIO.java =================================================================== --- trunk/jython/src/org/python/modules/cStringIO.java 2009-01-16 09:17:19 UTC (rev 5936) +++ trunk/jython/src/org/python/modules/cStringIO.java 2009-01-17 18:12:57 UTC (rev 5937) @@ -325,9 +325,40 @@ public synchronized void write(String s) { _complain_ifclosed(); - buf.setLength(pos); - int newpos = pos + s.length(); - buf.replace(pos, newpos, s); + + int spos = pos; + int slen = buf.length(); + + if (spos == slen) { + buf.append(s); + buf.setLength(slen + s.length()); + pos = spos + s.length(); + + return; + } + + if (spos > slen) { + int l = spos - slen; + char[] bytes = new char[l]; + + for (int i = 0; i < l - 1; i++) + bytes[i] = '\0'; + + buf.append(bytes); + slen = spos; + } + + int newpos = spos + s.length(); + + if (newpos > slen) { + buf.replace(spos, slen - spos, s); + buf.append(s.substring(slen)); + slen = newpos; + } else { + buf.replace(spos, spos + s.length(), s); + } + + buf.setLength(slen); pos = newpos; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-16 09:17:43
|
Revision: 5936 http://jython.svn.sourceforge.net/jython/?rev=5936&view=rev Author: cgroves Date: 2009-01-16 09:17:19 +0000 (Fri, 16 Jan 2009) Log Message: ----------- Check for parent beans of the same name to fill in missing getters or setters when adding beans for a type. Fixes bug #1132. Thanks to garyh for tracking it down and supplying a test case. Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/Child.java trunk/jython/tests/java/org/python/tests/Parent.java Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-16 08:11:48 UTC (rev 5935) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-16 09:17:19 UTC (rev 5936) @@ -187,6 +187,15 @@ self.assertEquals("OtherSubVisible[]", c.takeArray([OtherSubVisible()])) self.assertEquals("SubVisible[]", c.takeArray([SubVisible()])) + def test_iterable_coercion(self): + def simple_gen(): + yield 1 + yield 2 + yield 3 + self.assertEquals(6, Coercions.takeIterable(simple_gen())) + self.assertEquals(True, Coercions.takeBoolIterable(simple_gen())) + + def test_class_coercion(self): c = Coercions() from java.util import Hashtable, HashMap Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-16 08:11:48 UTC (rev 5935) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-16 09:17:19 UTC (rev 5936) @@ -269,8 +269,31 @@ prop.field = ((PyReflectedField)prev).field; } } + + // If one of our superclasses has something defined for this name, check if its a bean + // property, and if so, try to fill in any gaps in our property from there + PyObject superForName = lookup(prop.__name__); + if (superForName instanceof PyBeanProperty) { + PyBeanProperty superProp = ((PyBeanProperty)superForName); + // If it has a set method and we don't, take it regardless. If the types don't line + // up, it'll be rejected below + if (prop.setMethod == null) { + prop.setMethod = superProp.setMethod; + } else if (superProp.myType == prop.setMethod.getParameterTypes()[0]) { + // Otherwise, we must not have a get method. Only take a get method if the type + // on it agrees with the set method we already have. The bean on this type + // overrides a conflicting one o the parent + prop.getMethod = superProp.getMethod; + prop.myType = superProp.myType; + } + + if (prop.field == null) { + // If the parent bean is hiding a static field, we need it as well. + prop.field = superProp.field; + } + } // If the return types on the set and get methods for a property don't agree, the get - // get method takes precedence + // method takes precedence if (prop.getMethod != null && prop.setMethod != null && prop.myType != prop.setMethod.getParameterTypes()[0]) { prop.setMethod = null; Added: trunk/jython/tests/java/org/python/tests/Child.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Child.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Child.java 2009-01-16 09:17:19 UTC (rev 5936) @@ -0,0 +1,12 @@ +package org.python.tests; + +public class Child extends Parent { + + public void setId(int newId) { + this.id = newId; + } + + public String getValue() { + return value; + } +} Added: trunk/jython/tests/java/org/python/tests/Parent.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Parent.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Parent.java 2009-01-16 09:17:19 UTC (rev 5936) @@ -0,0 +1,16 @@ +package org.python.tests; + +public class Parent { + + protected String value = "blah"; + + protected int id = 7; + + public int getId() { + return id; + } + + public void setValue(String value) { + this.value = value; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-16 08:11:53
|
Revision: 5935 http://jython.svn.sourceforge.net/jython/?rev=5935&view=rev Author: cgroves Date: 2009-01-16 08:11:48 +0000 (Fri, 16 Jan 2009) Log Message: ----------- underlying_class is the class of instances of this type, so PyJavaType shouldn't store the class it's wrapping in it. Instead, it should use the general javaProxy field on PyObject and leave underlying_class up to its bases. Without this, Python classes can't subclass a Java interface and a Python class subclassing a Java class or interface. Modified Paths: -------------- trunk/jython/Lib/test/test_java_subclasses.py trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py 2009-01-15 03:36:09 UTC (rev 5934) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-01-16 08:11:48 UTC (rev 5935) @@ -5,8 +5,8 @@ from test import test_support -from java.lang import (Boolean, Class, ClassLoader, Integer, Object, Runnable, String, Thread, - ThreadGroup) +from java.lang import (Boolean, Class, ClassLoader, Comparable,Integer, Object, Runnable, String, + Thread, ThreadGroup) from java.util import Date, Hashtable, Vector from java.awt import Color, Component, Dimension, Rectangle @@ -29,6 +29,22 @@ self.fail("Shouldn't be callable with a no args") self.assertRaises(TypeError, Callbacker.callNoArg, PyBadCallback()) + def test_inheriting_from_python_and_java_interface(self): + calls = [] + class Runner(Runnable): + def run(self): + calls.append("Runner.run") + + class ComparableRunner(Comparable, Runner): + def compareTo(self, other): + calls.append("ComparableRunner.compareTo") + return 0 + + c = ComparableRunner() + c.compareTo(None) + c.run() + self.assertEquals(calls, ["ComparableRunner.compareTo", "Runner.run"]) + class TableModelTest(unittest.TestCase): def test_class_coercion(self): '''Python type instances coerce to a corresponding Java wrapper type in Object.getClass''' @@ -89,6 +105,17 @@ except TypeError: pass + class PyDim(Dimension): + pass + class PyDimRun(PyDim, Runnable): + pass + try: + class PyDimRunCol(PyDimRun, Color): + pass + self.fail("Shouldn't be able to subclass more than one concrete java class") + except TypeError: + pass + def test_multilevel_override(self): class SubDate(Date): def toString(self): Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2009-01-15 03:36:09 UTC (rev 5934) +++ trunk/jython/src/org/python/core/PyArray.java 2009-01-16 08:11:48 UTC (rev 5935) @@ -96,7 +96,7 @@ typecode = obj.toString(); type = char2class(typecode.charAt(0)); } else if (obj instanceof PyJavaType) { - type = ((PyJavaType)obj).underlying_class; + type = ((PyJavaType)obj).getProxyType(); typecode = type.getName(); } else { throw Py.TypeError("array() argument 1 must be char, not " + obj.getType().fastGetName()); Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-15 03:36:09 UTC (rev 5934) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-16 08:11:48 UTC (rev 5935) @@ -37,7 +37,7 @@ @Override public Class<?> getProxyType() { - return PyObject.class.isAssignableFrom(underlying_class) ? null : underlying_class; + return (Class<?>)javaProxy; } // Java types are ok with things being added and removed from their dicts as long as there isn't @@ -57,34 +57,35 @@ } @Override - protected void init() { - name = underlying_class.getName(); + protected void init(Class<?> forClass) { + name = forClass.getName(); // Strip the java fully qualified class name from Py classes in core if (name.startsWith("org.python.core.Py")) { name = name.substring("org.python.core.Py".length()).toLowerCase(); } dict = new PyStringMap(); - Class<?> baseClass = underlying_class.getSuperclass(); - if (PyObject.class.isAssignableFrom(underlying_class)) { + Class<?> baseClass = forClass.getSuperclass(); + if (PyObject.class.isAssignableFrom(forClass)) { // Non-exposed subclasses of PyObject use a simple linear mro to PyObject that ignores // their interfaces + underlying_class = forClass; computeLinearMro(baseClass); } else { - javaProxy = underlying_class; + javaProxy = forClass; objtype = PyType.fromClass(Class.class); // Wrapped Java types fill in their mro first using their base class and then all of // their interfaces. if (baseClass == null) { base = PyType.fromClass(PyObject.class); - } else if(underlying_class == Class.class) { + } else if (javaProxy == Class.class) { base = PyType.fromClass(PyType.class); } else { base = PyType.fromClass(baseClass); } - bases = new PyObject[1 + underlying_class.getInterfaces().length]; + bases = new PyObject[1 + forClass.getInterfaces().length]; bases[0] = base; for (int i = 1; i < bases.length; i++) { - bases[i] = PyType.fromClass(underlying_class.getInterfaces()[i - 1]); + bases[i] = PyType.fromClass(forClass.getInterfaces()[i - 1]); } Set<PyObject> seen = Generic.set(); List<PyObject> mros = Generic.list(); @@ -101,9 +102,9 @@ // PyReflected* can't call or access anything from non-public classes that aren't in // org.python.core - if (!Modifier.isPublic(underlying_class.getModifiers()) && + if (!Modifier.isPublic(forClass.getModifiers()) && !name.startsWith("org.python.core") && Options.respectJavaAccessibility) { - handleSuperMethodArgCollisions(); + handleSuperMethodArgCollisions(forClass); return; } @@ -113,9 +114,9 @@ Method[] methods; if (Options.respectJavaAccessibility) { // returns just the public methods - methods = underlying_class.getMethods(); + methods = forClass.getMethods(); } else { - methods = underlying_class.getDeclaredMethods(); + methods = forClass.getDeclaredMethods(); for (Method method : methods) { method.setAccessible(true); } @@ -205,9 +206,9 @@ Field[] fields; if (Options.respectJavaAccessibility) { // returns just the public fields - fields = underlying_class.getFields(); + fields = forClass.getFields(); } else { - fields = underlying_class.getDeclaredFields(); + fields = forClass.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); } @@ -281,11 +282,11 @@ Constructor<?>[] constructors; // No matter the security manager, trying to set the constructor on class to accessible // blows up - if (Options.respectJavaAccessibility || Class.class == underlying_class) { + if (Options.respectJavaAccessibility || Class.class == forClass) { // returns just the public constructors - constructors = underlying_class.getConstructors(); + constructors = forClass.getConstructors(); } else { - constructors = underlying_class.getDeclaredConstructors(); + constructors = forClass.getDeclaredConstructors(); for (Constructor<?> ctr : constructors) { ctr.setAccessible(true); } @@ -293,8 +294,8 @@ for (Constructor<?> ctr : constructors) { reflctr.addConstructor(ctr); } - if (PyObject.class.isAssignableFrom(underlying_class)) { - PyObject new_ = new PyNewWrapper(underlying_class, "__new__", -1, -1) { + if (PyObject.class.isAssignableFrom(forClass)) { + PyObject new_ = new PyNewWrapper(forClass, "__new__", -1, -1) { public PyObject new_impl(boolean init, PyType subtype, @@ -307,10 +308,10 @@ } else { dict.__setitem__("__init__", reflctr); } - for (Class<?> inner : underlying_class.getClasses()) { + for (Class<?> inner : forClass.getClasses()) { // Only add the class if there isn't something else with that name and it came from this // class - if (inner.getDeclaringClass() == underlying_class && + if (inner.getDeclaringClass() == forClass && dict.__finditem__(inner.getSimpleName()) == null) { // If this class is currently being loaded, any exposed types it contains won't have // set their builder in PyType yet, so add them to BOOTSTRAP_TYPES so they're @@ -323,16 +324,15 @@ } } for (Map.Entry<Class<?>, PyBuiltinMethod[]> entry : getCollectionProxies().entrySet()) { - if (entry.getKey() == underlying_class) { + if (entry.getKey() == forClass) { for (PyBuiltinMethod meth : entry.getValue()) { dict.__setitem__(meth.info.getName(), new PyMethodDescr(this, meth)); } } } - if (ClassDictInit.class.isAssignableFrom(underlying_class) - && underlying_class != ClassDictInit.class) { + if (ClassDictInit.class.isAssignableFrom(forClass) && forClass != ClassDictInit.class) { try { - Method m = underlying_class.getMethod("classDictInit", PyObject.class); + Method m = forClass.getMethod("classDictInit", PyObject.class); m.invoke(null, dict); // allow the class to override its name after it is loaded PyObject nameSpecified = dict.__finditem__("__name__"); @@ -344,10 +344,10 @@ } } if (baseClass != Object.class) { - has_set = getDescrMethod(underlying_class, "__set__", OO) != null - || getDescrMethod(underlying_class, "_doset", OO) != null; - has_delete = getDescrMethod(underlying_class, "__delete__", PyObject.class) != null - || getDescrMethod(underlying_class, "_dodel", PyObject.class) != null; + has_set = getDescrMethod(forClass, "__set__", OO) != null + || getDescrMethod(forClass, "_doset", OO) != null; + has_delete = getDescrMethod(forClass, "__delete__", PyObject.class) != null + || getDescrMethod(forClass, "_dodel", PyObject.class) != null; } else { // Pass __eq__ and __repr__ through to subclasses of Object PyBuiltinCallable equals = new PyBuiltinMethodNarrow("__eq__", 1, 1) { @@ -391,8 +391,8 @@ * drawback of failing when running in a security environment that didn't allow setting * accessibility, so this method replaced it. */ - private void handleSuperMethodArgCollisions() { - for (Class iface : underlying_class.getInterfaces()) { + private void handleSuperMethodArgCollisions(Class<?> forClass) { + for (Class<?> iface : forClass.getInterfaces()) { for (Method meth : iface.getMethods()) { if (!Modifier.isPublic(meth.getDeclaringClass().getModifiers())) { // Ignore methods from non-public interfaces as they're similarly bugged Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-15 03:36:09 UTC (rev 5934) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-16 08:11:48 UTC (rev 5935) @@ -45,7 +45,10 @@ /** __flags__, the type's options. */ private long tp_flags; - /** The underlying java class or null. */ + /** + * The Java Class instances of this type will be represented as, or null if it's determined by a + * base type. + */ protected Class<?> underlying_class; /** Whether it's a builtin type. */ @@ -202,12 +205,12 @@ PyType newtype; if (new_.for_type == metatype || metatype == PyType.fromClass(Class.class)) { newtype = new PyType(); // XXX set metatype - if(proxyClass != null) { - newtype.underlying_class = proxyClass; - } } else { newtype = new PyTypeDerived(metatype); } + if (proxyClass != null) { + newtype.javaProxy = proxyClass; + } if (dict instanceof PyStringMap) { dict = ((PyStringMap)dict).copy(); } else { @@ -340,10 +343,11 @@ } /** - * Called on builtin types after underlying_class has been set on them. Should fill in dict, - * name, mro, base and bases from the class. + * Called on builtin types for a particular class. Should fill in dict, name, mro, base and + * bases from the class. */ - protected void init() { + protected void init(Class<?> forClass) { + underlying_class = forClass; if (underlying_class == PyObject.class) { mro = new PyType[] {this}; } else { @@ -950,7 +954,7 @@ } // The types in Py.BOOTSTRAP_TYPES are initialized before their builders are assigned, // so do the work of addFromClass & fillFromClass after the fact - fromClass(builder.getTypeClass()).init(); + fromClass(builder.getTypeClass()).init(builder.getTypeClass()); } } @@ -985,9 +989,8 @@ } class_to_type.put(c, newtype); - newtype.underlying_class = c; newtype.builtin = true; - newtype.init(); + newtype.init(c); return newtype; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-15 03:36:13
|
Revision: 5934 http://jython.svn.sourceforge.net/jython/?rev=5934&view=rev Author: fwierzbicki Date: 2009-01-15 03:36:09 +0000 (Thu, 15 Jan 2009) Log Message: ----------- Change negate so that -0 and -0.0 behave as CPython behaves (no USub node, just negate zero). Modified Paths: -------------- trunk/jython/src/org/python/antlr/GrammarActions.java Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2009-01-15 03:14:36 UTC (rev 5933) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2009-01-15 03:36:09 UTC (rev 5934) @@ -483,7 +483,7 @@ Num num = (Num)o; if (num.getInternalN() instanceof PyInteger) { int v = ((PyInteger)num.getInternalN()).getValue(); - if (v > 0) { + if (v >= 0) { num.setN(new PyInteger(-v)); return num; } @@ -495,13 +495,13 @@ } } else if (num.getInternalN() instanceof PyFloat) { double v = ((PyFloat)num.getInternalN()).getValue(); - if (v > 0) { + if (v >= 0) { num.setN(new PyFloat(-v)); return num; } } else if (num.getInternalN() instanceof PyComplex) { double v = ((PyComplex)num.getInternalN()).imag; - if (v > 0) { + if (v >= 0) { num.setN(new PyComplex(0,-v)); return num; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-15 03:22:26
|
Revision: 5932 http://jython.svn.sourceforge.net/jython/?rev=5932&view=rev Author: fwierzbicki Date: 2009-01-15 02:04:31 +0000 (Thu, 15 Jan 2009) Log Message: ----------- Small change to obsessively match CPython AST. Modified Paths: -------------- trunk/jython/grammar/Python.g Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-01-14 23:56:22 UTC (rev 5931) +++ trunk/jython/grammar/Python.g 2009-01-15 02:04:31 UTC (rev 5932) @@ -1412,9 +1412,9 @@ //sliceop: ':' [test] sliceop : COLON - (test[expr_contextType.Load] - -> test - )? + (test[expr_contextType.Load] -> test + |-> ^(COLON<Name>[$COLON, "None", expr_contextType.Load]) + ) ; //exprlist: expr (',' expr)* [','] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-15 03:14:39
|
Revision: 5933 http://jython.svn.sourceforge.net/jython/?rev=5933&view=rev Author: fwierzbicki Date: 2009-01-15 03:14:36 +0000 (Thu, 15 Jan 2009) Log Message: ----------- Merged revisions 5925,5927,5930-5932 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5925 | cgroves | 2009-01-13 17:10:24 -0500 (Tue, 13 Jan 2009) | 1 line Allow importation from bytecode in a zip file even if the source isn't present ........ r5927 | fwierzbicki | 2009-01-13 22:42:42 -0500 (Tue, 13 Jan 2009) | 4 lines Small fix to grammar -- a "print" by itself should have it's NL attribute set to true as CPython does. Because "false" doesn't make sense in this context (it would be a no-op), the compiler doesn't check, so it passed unnoticed. ........ r5930 | fwierzbicki | 2009-01-14 09:09:58 -0500 (Wed, 14 Jan 2009) | 3 lines oops, move back to _ast since I want to compare with Python 2.5 which does not yet have ast.py. ........ r5931 | fwierzbicki | 2009-01-14 18:56:22 -0500 (Wed, 14 Jan 2009) | 2 lines DEDENT problem with comments in single mode fixed. ........ r5932 | fwierzbicki | 2009-01-14 21:04:31 -0500 (Wed, 14 Jan 2009) | 2 lines Small change to obsessively match CPython AST. ........ Modified Paths: -------------- trunk/sandbox/wierzbicki/grammar26/Lib/test/test_codeop_jy.py trunk/sandbox/wierzbicki/grammar26/ast/astview.py trunk/sandbox/wierzbicki/grammar26/grammar/Python.g trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/PythonTokenSource.java trunk/sandbox/wierzbicki/grammar26/src/org/python/modules/zipimport/zipimporter.java Property Changed: ---------------- trunk/sandbox/wierzbicki/grammar26/ Property changes on: trunk/sandbox/wierzbicki/grammar26 ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5923 + /trunk/jython:1-5932 Modified: trunk/sandbox/wierzbicki/grammar26/Lib/test/test_codeop_jy.py =================================================================== --- trunk/sandbox/wierzbicki/grammar26/Lib/test/test_codeop_jy.py 2009-01-15 02:04:31 UTC (rev 5932) +++ trunk/sandbox/wierzbicki/grammar26/Lib/test/test_codeop_jy.py 2009-01-15 03:14:36 UTC (rev 5933) @@ -102,6 +102,8 @@ # Failed for Jython 2.5a2. See http://bugs.jython.org/issue1116. av("@a.b.c\ndef f():\n pass") + av("def f():\n pass\n#foo") + def test_incomplete(self): ai = self.assertIncomplete Modified: trunk/sandbox/wierzbicki/grammar26/ast/astview.py =================================================================== --- trunk/sandbox/wierzbicki/grammar26/ast/astview.py 2009-01-15 02:04:31 UTC (rev 5932) +++ trunk/sandbox/wierzbicki/grammar26/ast/astview.py 2009-01-15 03:14:36 UTC (rev 5933) @@ -10,7 +10,7 @@ """ -import ast +import _ast import sys if sys.platform.startswith('java'): @@ -49,7 +49,7 @@ children = [child] for node in children: - if isinstance(node, ast.AST): + if isinstance(node, _ast.AST): yield lispify_ast(node) else: if isinstance(node, float): @@ -64,7 +64,7 @@ def tree(pyfile): try: - node = compile(open(pyfile).read(), pyfile, "exec", ast.PyCF_ONLY_AST) + node = compile(open(pyfile).read(), pyfile, "exec", _ast.PyCF_ONLY_AST) except SyntaxError: return "SyntaxError", return lispify_ast(node) Modified: trunk/sandbox/wierzbicki/grammar26/grammar/Python.g =================================================================== --- trunk/sandbox/wierzbicki/grammar26/grammar/Python.g 2009-01-15 02:04:31 UTC (rev 5932) +++ trunk/sandbox/wierzbicki/grammar26/grammar/Python.g 2009-01-15 03:14:36 UTC (rev 5933) @@ -624,7 +624,7 @@ | RIGHTSHIFT t2=printlist2 -> ^(PRINT<Print>[$PRINT, actions.castExpr($t2.elts.get(0)), actions.castExprs($t2.elts, 1), $t2.newline]) | - -> ^(PRINT<Print>[$PRINT, null, new ArrayList<expr>(), false]) + -> ^(PRINT<Print>[$PRINT, null, new ArrayList<expr>(), true]) ) ; @@ -1412,9 +1412,9 @@ //sliceop: ':' [test] sliceop : COLON - (test[expr_contextType.Load] - -> test - )? + (test[expr_contextType.Load] -> test + |-> ^(COLON<Name>[$COLON, "None", expr_contextType.Load]) + ) ; //exprlist: expr (',' expr)* [','] Modified: trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/PythonTokenSource.java =================================================================== --- trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/PythonTokenSource.java 2009-01-15 02:04:31 UTC (rev 5932) +++ trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/PythonTokenSource.java 2009-01-15 03:14:36 UTC (rev 5933) @@ -195,7 +195,7 @@ t = stream.LT(1); stream.consume(); - enqueueHiddens(t); + List<Token> commentedNewlines = enqueueHiddens(t); // compute cpos as the char pos of next non-WS token in line int cpos = t.getCharPositionInLine(); // column dictates indent/dedent @@ -230,6 +230,9 @@ for(int i=1;i<newlines.length();i++) { generateNewline(newline); } + for (Token c : commentedNewlines) { + generateNewline(c); + } } if (t.getType() != PythonLexer.LEADING_WS) { // discard WS @@ -246,7 +249,8 @@ tokens.addElement(t); } - private void enqueueHiddens(Token t) { + private List<Token> enqueueHiddens(Token t) { + List<Token> newlines = new ArrayList<Token>(); if (inSingle && t.getType() == Token.EOF) { if (stream.size() > lastTokenAddedIndex + 1) { Token hidden = stream.get(lastTokenAddedIndex + 1); @@ -254,7 +258,7 @@ String text = hidden.getText(); int i = text.indexOf("\n"); while(i != -1) { - generateNewline(hidden); + newlines.add(hidden); i = text.indexOf("\n", i + 1); } } @@ -265,6 +269,7 @@ tokens.addAll(hiddenTokens); } lastTokenAddedIndex = t.getTokenIndex(); + return newlines; } private void handleIndents(int cpos, CommonToken t) { Modified: trunk/sandbox/wierzbicki/grammar26/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/sandbox/wierzbicki/grammar26/src/org/python/modules/zipimport/zipimporter.java 2009-01-15 02:04:31 UTC (rev 5932) +++ trunk/sandbox/wierzbicki/grammar26/src/org/python/modules/zipimport/zipimporter.java 2009-01-15 03:14:36 UTC (rev 5933) @@ -315,7 +315,7 @@ String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); if (sourceTocEntry == null) { - return false; + return true;// If there is no source, assume the bytecode is ok } try { long bytecodeTime = dosTimeToEpoch(tocEntry.__finditem__(5).asInt(0), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-14 23:56:26
|
Revision: 5931 http://jython.svn.sourceforge.net/jython/?rev=5931&view=rev Author: fwierzbicki Date: 2009-01-14 23:56:22 +0000 (Wed, 14 Jan 2009) Log Message: ----------- DEDENT problem with comments in single mode fixed. Modified Paths: -------------- trunk/jython/Lib/test/test_codeop_jy.py trunk/jython/src/org/python/antlr/PythonTokenSource.java Modified: trunk/jython/Lib/test/test_codeop_jy.py =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py 2009-01-14 14:09:58 UTC (rev 5930) +++ trunk/jython/Lib/test/test_codeop_jy.py 2009-01-14 23:56:22 UTC (rev 5931) @@ -102,6 +102,8 @@ # Failed for Jython 2.5a2. See http://bugs.jython.org/issue1116. av("@a.b.c\ndef f():\n pass") + av("def f():\n pass\n#foo") + def test_incomplete(self): ai = self.assertIncomplete Modified: trunk/jython/src/org/python/antlr/PythonTokenSource.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTokenSource.java 2009-01-14 14:09:58 UTC (rev 5930) +++ trunk/jython/src/org/python/antlr/PythonTokenSource.java 2009-01-14 23:56:22 UTC (rev 5931) @@ -195,7 +195,7 @@ t = stream.LT(1); stream.consume(); - enqueueHiddens(t); + List<Token> commentedNewlines = enqueueHiddens(t); // compute cpos as the char pos of next non-WS token in line int cpos = t.getCharPositionInLine(); // column dictates indent/dedent @@ -230,6 +230,9 @@ for(int i=1;i<newlines.length();i++) { generateNewline(newline); } + for (Token c : commentedNewlines) { + generateNewline(c); + } } if (t.getType() != PythonLexer.LEADING_WS) { // discard WS @@ -246,7 +249,8 @@ tokens.addElement(t); } - private void enqueueHiddens(Token t) { + private List<Token> enqueueHiddens(Token t) { + List<Token> newlines = new ArrayList<Token>(); if (inSingle && t.getType() == Token.EOF) { if (stream.size() > lastTokenAddedIndex + 1) { Token hidden = stream.get(lastTokenAddedIndex + 1); @@ -254,7 +258,7 @@ String text = hidden.getText(); int i = text.indexOf("\n"); while(i != -1) { - generateNewline(hidden); + newlines.add(hidden); i = text.indexOf("\n", i + 1); } } @@ -265,6 +269,7 @@ tokens.addAll(hiddenTokens); } lastTokenAddedIndex = t.getTokenIndex(); + return newlines; } private void handleIndents(int cpos, CommonToken t) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-14 14:10:07
|
Revision: 5930 http://jython.svn.sourceforge.net/jython/?rev=5930&view=rev Author: fwierzbicki Date: 2009-01-14 14:09:58 +0000 (Wed, 14 Jan 2009) Log Message: ----------- oops, move back to _ast since I want to compare with Python 2.5 which does not yet have ast.py. Modified Paths: -------------- trunk/jython/ast/astview.py Modified: trunk/jython/ast/astview.py =================================================================== --- trunk/jython/ast/astview.py 2009-01-14 04:35:22 UTC (rev 5929) +++ trunk/jython/ast/astview.py 2009-01-14 14:09:58 UTC (rev 5930) @@ -10,7 +10,7 @@ """ -import ast +import _ast import sys if sys.platform.startswith('java'): @@ -49,7 +49,7 @@ children = [child] for node in children: - if isinstance(node, ast.AST): + if isinstance(node, _ast.AST): yield lispify_ast(node) else: if isinstance(node, float): @@ -64,7 +64,7 @@ def tree(pyfile): try: - node = compile(open(pyfile).read(), pyfile, "exec", ast.PyCF_ONLY_AST) + node = compile(open(pyfile).read(), pyfile, "exec", _ast.PyCF_ONLY_AST) except SyntaxError: return "SyntaxError", return lispify_ast(node) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-14 04:35:35
|
Revision: 5929 http://jython.svn.sourceforge.net/jython/?rev=5929&view=rev Author: fwierzbicki Date: 2009-01-14 04:35:22 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Initialized merge tracking via "svnmerge" with revisions "1-5923" from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython Property Changed: ---------------- trunk/sandbox/wierzbicki/grammar26/ Property changes on: trunk/sandbox/wierzbicki/grammar26 ___________________________________________________________________ Added: svnmerge-integrated + /trunk/jython:1-5923 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-14 03:59:03
|
Revision: 5928 http://jython.svn.sourceforge.net/jython/?rev=5928&view=rev Author: fwierzbicki Date: 2009-01-14 03:58:51 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Merged revisions 5900-5901,5903-5906,5908,5912-5918,5920,5923,5925,5927 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5900 | fwierzbicki | 2009-01-09 10:16:08 -0500 (Fri, 09 Jan 2009) | 2 lines Fix for wrong error line number when file ends with open paren. ........ r5901 | otmarhumbel | 2009-01-09 12:31:07 -0500 (Fri, 09 Jan 2009) | 1 line reduce the size of the installer .jar by excluding external libraries we do not want to distribute ........ r5903 | fwierzbicki | 2009-01-09 15:40:11 -0500 (Fri, 09 Jan 2009) | 2 lines Change release numbers in build. ........ r5904 | fwierzbicki | 2009-01-09 15:43:55 -0500 (Fri, 09 Jan 2009) | 2 lines locked CPython to revision 68460. ........ r5905 | fwierzbicki | 2009-01-09 15:53:52 -0500 (Fri, 09 Jan 2009) | 2 lines Update README ........ r5906 | pjenvey | 2009-01-09 19:49:02 -0500 (Fri, 09 Jan 2009) | 2 lines fix broken import ........ r5908 | pedronis | 2009-01-10 07:39:15 -0500 (Sat, 10 Jan 2009) | 5 lines yet another try at binop rule, with more exhaustive tests (verified against cpython) that now pass see also PyPy issue 412 ........ r5912 | cgroves | 2009-01-10 19:53:55 -0500 (Sat, 10 Jan 2009) | 6 lines * Add xerces' version number to its file name for future explorers. * Add a skip-brand property to build.xml that allows version branding to be skipped, which keeps jython-dev.jar from being built even if no other files change and shaves a couple seconds off a dev build. ........ r5913 | cgroves | 2009-01-10 20:03:33 -0500 (Sat, 10 Jan 2009) | 1 line Compile Syspath.java for 1.5 instead of 1.6 ........ r5914 | cgroves | 2009-01-10 20:12:16 -0500 (Sat, 10 Jan 2009) | 5 lines Creating the empty.py file after the bytecode just meant that it had a more recent modtime and would be preferred for importing, so it wasn't testing anything. ........ r5915 | cgroves | 2009-01-10 22:21:25 -0500 (Sat, 10 Jan 2009) | 1 line Cleanup ........ r5916 | cgroves | 2009-01-11 01:04:11 -0500 (Sun, 11 Jan 2009) | 6 lines Convert to PyObject going into and Object coming out of java.util.Set methods on PySet like PyDictionary does for Map methods and PyList does for List methods. Without this, Java code can add non-PyObjects to the underlying set causing the Python access to it to throw ClassCastExceptions. ........ r5917 | cgroves | 2009-01-11 01:24:45 -0500 (Sun, 11 Jan 2009) | 3 lines Huh, I guess ECJ can handle inferring these generics, but javac sure can't. ........ r5918 | cgroves | 2009-01-11 05:35:10 -0500 (Sun, 11 Jan 2009) | 6 lines In String compilation contexts, we can assume the bytes have already been decoded and just pass them through when parsing instead of using ascii. This gets test_doctest back to passing as it was before and keeps the pep 263 checks. ........ r5920 | cgroves | 2009-01-11 17:26:38 -0500 (Sun, 11 Jan 2009) | 6 lines test320 - Moved to test_traceback_jy test366,373 - Moved to test_java_integration test391 - Moved to test_java_visibility test395 - Tested by test_java_visibility test396 - Tested by test_java_subclasses ........ r5923 | pjenvey | 2009-01-11 20:31:59 -0500 (Sun, 11 Jan 2009) | 1 line bump copyright year ........ r5925 | cgroves | 2009-01-13 17:10:24 -0500 (Tue, 13 Jan 2009) | 1 line Allow importation from bytecode in a zip file even if the source isn't present ........ r5927 | fwierzbicki | 2009-01-13 22:42:42 -0500 (Tue, 13 Jan 2009) | 4 lines Small fix to grammar -- a "print" by itself should have it's NL attribute set to true as CPython does. Because "false" doesn't make sense in this context (it would be a no-op), the compiler doesn't check, so it passed unnoticed. ........ Revision Links: -------------- http://jython.svn.sourceforge.net/jython/?rev=68460&view=rev Modified Paths: -------------- branches/jy3k/LICENSE.txt branches/jy3k/Lib/os.py branches/jy3k/Lib/test/syspath_import.jar branches/jy3k/Lib/test/test_descr_jy.py branches/jy3k/Lib/test/test_doctest.py branches/jy3k/Lib/test/test_eof_jy.py branches/jy3k/Lib/test/test_import_jy.py branches/jy3k/Lib/test/test_java_integration.py branches/jy3k/Lib/test/test_java_visibility.py branches/jy3k/Lib/test/test_traceback_jy.py branches/jy3k/README.txt branches/jy3k/build.xml branches/jy3k/src/org/python/antlr/PythonTokenSource.java branches/jy3k/src/org/python/compiler/ProxyMaker.java branches/jy3k/src/org/python/core/BaseSet.java branches/jy3k/src/org/python/core/CompilerFlags.java branches/jy3k/src/org/python/core/ParserFacade.java branches/jy3k/src/org/python/core/PyDictionary.java branches/jy3k/src/org/python/core/PyFrozenSet.java branches/jy3k/src/org/python/core/PyIterator.java branches/jy3k/src/org/python/core/PyLong.java branches/jy3k/src/org/python/core/PyObject.java branches/jy3k/src/org/python/core/PyObjectList.java branches/jy3k/src/org/python/core/PySequenceList.java branches/jy3k/src/org/python/core/PySet.java branches/jy3k/src/org/python/core/PySystemState.java branches/jy3k/src/org/python/core/PyType.java branches/jy3k/src/org/python/modules/zipimport/zipimporter.java branches/jy3k/src/org/python/util/Generic.java branches/jy3k/src/org/python/util/NameUnionAntType.java branches/jy3k/tests/java/javatests/ListTest.java branches/jy3k/tests/java/javatests/TestSupport.java Added Paths: ----------- branches/jy3k/Lib/test/eof_fodder7.py branches/jy3k/Lib/test/except_in_raising_code.py branches/jy3k/Lib/test/test_set_jy.py branches/jy3k/extlibs/xercesImpl-2.9.1.jar branches/jy3k/tests/java/javatests/PySetInJavaTest.java Removed Paths: ------------- branches/jy3k/bugtests/classes/test395j1.java branches/jy3k/bugtests/classes/test395j2.java branches/jy3k/bugtests/classes/test396j.java branches/jy3k/bugtests/test320.py branches/jy3k/bugtests/test366.py branches/jy3k/bugtests/test373.py branches/jy3k/bugtests/test391.py branches/jy3k/bugtests/test395.py branches/jy3k/bugtests/test396.py branches/jy3k/extlibs/xercesImpl.jar branches/jy3k/src/org/python/core/PySetIterator.java Modified: branches/jy3k/LICENSE.txt =================================================================== --- branches/jy3k/LICENSE.txt 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/LICENSE.txt 2009-01-14 03:58:51 UTC (rev 5928) @@ -53,7 +53,7 @@ Jython 2.0, 2.1 License ================================ -Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Jython Developers +Copyright (c) 2000-2009 Jython Developers. All rights reserved. Redistribution and use in source and binary forms, with or without Modified: branches/jy3k/Lib/os.py =================================================================== --- branches/jy3k/Lib/os.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/os.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -569,7 +569,7 @@ if _time_t is None: from java.lang import Integer, Long try: - from org.python.posix import Platform + from org.python.posix.util import Platform except ImportError: from org.jruby.ext.posix.util import Platform _time_t = Integer if Platform.IS_32_BIT else Long Copied: branches/jy3k/Lib/test/eof_fodder7.py (from rev 5927, trunk/jython/Lib/test/eof_fodder7.py) =================================================================== --- branches/jy3k/Lib/test/eof_fodder7.py (rev 0) +++ branches/jy3k/Lib/test/eof_fodder7.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,5 @@ +def hi(): + pass + +def bye(): + hi( Copied: branches/jy3k/Lib/test/except_in_raising_code.py (from rev 5927, trunk/jython/Lib/test/except_in_raising_code.py) =================================================================== --- branches/jy3k/Lib/test/except_in_raising_code.py (rev 0) +++ branches/jy3k/Lib/test/except_in_raising_code.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,8 @@ +def test(): + print noname + +def foo(): + try: + test() + except ValueError: + raise RuntimeError("Accessing a undefined name should raise a NameError") Modified: branches/jy3k/Lib/test/syspath_import.jar =================================================================== (Binary files differ) Modified: branches/jy3k/Lib/test/test_descr_jy.py =================================================================== --- branches/jy3k/Lib/test/test_descr_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_descr_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -368,13 +368,148 @@ except AttributeError, e: self.assertEquals("Custom message", str(e)) +# try to test more exhaustively binop overriding combination cases +class Base(object): + def __init__(self, name): + self.name = name + +def lookup_where(obj, name): + mro = type(obj).__mro__ + for t in mro: + if name in t.__dict__: + return t.__dict__[name], t + return None, None + +def refop(x, y, opname, ropname): + # this has been validated by running the tests on top of cpython + # so for the space of possibilities that the tests touch it is known + # to behave like cpython as long as the latter doesn't change its own + # algorithm + t1 = type(x) + t2 = type(y) + op, where1 = lookup_where(x, opname) + rop, where2 = lookup_where(y, ropname) + if op is None and rop is not None: + return rop(y, x) + if rop and where1 is not where2: + if (issubclass(t2, t1) and not issubclass(where1, where2) + and not issubclass(t1, where2) + ): + return rop(y, x) + if op is None: + return "TypeError" + return op(x,y) + +def do_test(X, Y, name, impl): + x = X('x') + y = Y('y') + opname = '__%s__' % name + ropname = '__r%s__' % name + + count = [0] + fail = [] + + def check(z1, z2): + ref = refop(z1, z2, opname, ropname) + try: + v = impl(z1, z2) + except TypeError: + v = "TypeError" + if v != ref: + fail.append(count[0]) + + def override_in_hier(n=6): + if n == 0: + count[0] += 1 + check(x, y) + check(y, x) + return + + f = lambda self, other: (n, self.name, other.name) + if n%2 == 0: + name = opname + else: + name = ropname + + for C in Y.__mro__: + if name in C.__dict__: + continue + if C is not object: + setattr(C, name, f) + override_in_hier(n-1) + if C is not object: + delattr(C, name) + + override_in_hier() + #print count[0] + return fail + +class BinopCombinationsTestCase(unittest.TestCase): + + def test_binop_combinations_mul(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'mul', lambda x,y: x*y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_sub(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'sub', lambda x,y: x-y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_pow(self): + class X(Base): + pass + class Y(X): + pass + + fail = do_test(X, Y, 'pow', lambda x,y: x**y) + #print len(fail) + self.assert_(not fail) + + def test_binop_combinations_more_exhaustive(self): + class X(Base): + pass + + class B1(object): + pass + + class B2(object): + pass + + class X1(B1, X, B2): + pass + + class C1(object): + pass + + class C2(object): + pass + + class Y(C1, X1, C2): + pass + + fail = do_test(X, Y, 'sub', lambda x,y: x-y) + #print len(fail) + self.assert_(not fail) + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, InPlaceTestCase, DescrExceptionsTestCase, - GetAttrTestCase) + GetAttrTestCase, + BinopCombinationsTestCase) if __name__ == '__main__': test_main() Modified: branches/jy3k/Lib/test/test_doctest.py =================================================================== --- branches/jy3k/Lib/test/test_doctest.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_doctest.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -2265,18 +2265,17 @@ File "...", line 7, in test_doctest4.txt Failed example: u'...' - ... + Expected: + u'f\xf6\xf6' + Got: + u'f\xc3\xb6\xc3\xb6' ********************************************************************** ... ********************************************************************** - ... - ********************************************************************** - ... - ********************************************************************** 1 items had failures: - 4 of 4 in test_doctest4.txt - ***Test Failed*** 4 failures. - (4, 4) + 2 of 4 in test_doctest4.txt + ***Test Failed*** 2 failures. + (2, 4) >>> doctest.master = None # Reset master. >>> doctest.testfile('test_doctest4.txt', encoding='utf-8') Modified: branches/jy3k/Lib/test/test_eof_jy.py =================================================================== --- branches/jy3k/Lib/test/test_eof_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_eof_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -45,6 +45,12 @@ except ImportError, cause: self.fail(cause) + def test_trailing_paren(self): + try: + import eof_fodder7 + except SyntaxError, cause: + self.assertEquals(cause.lineno, 5) + #============================================================================== def test_main(verbose=None): Modified: branches/jy3k/Lib/test/test_import_jy.py =================================================================== --- branches/jy3k/Lib/test/test_import_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_import_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -89,13 +89,11 @@ # Again ensure we didn't recompile self.assertEquals(bytecode, read(init_compiled), 'bytecode was recompiled') + def test_corrupt_bytecode(self): f = open("empty$py.class", "w") f.close() self.assertRaises(ImportError, __import__, "empty") - f = open("empty.py", "w") - f.close() - self.assertRaises(ImportError, __import__, "empty") class OverrideBuiltinsImportTestCase(unittest.TestCase): def test_override(self): Modified: branches/jy3k/Lib/test/test_java_integration.py =================================================================== --- branches/jy3k/Lib/test/test_java_integration.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_java_integration.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -7,7 +7,7 @@ from test import test_support from java.lang import (ExceptionInInitializerError, String, Runnable, System, Runtime, Math, Byte) -from java.math import BigDecimal +from java.math import BigDecimal, BigInteger from java.io import (FileInputStream, FileNotFoundException, FileOutputStream, FileWriter, OutputStreamWriter, UnsupportedEncodingException) from java.util import ArrayList, Date, HashMap, Hashtable, StringTokenizer, Vector @@ -56,6 +56,11 @@ b = BeanImplementation() self.assertEquals("name", b.getName()) self.assertEquals("name", b.name) + # Tests for #610576 + class SubBean(BeanImplementation): + def __init__(bself): + self.assertEquals("name", bself.getName()) + SubBean() class SysIntegrationTest(unittest.TestCase): @@ -262,7 +267,7 @@ self.assertEquals(len(treePath.path), 3, "Object[] not passed correctly") self.assertEquals(TreePath(treePath.path).path, treePath.path, "Object[] not passed and returned correctly") -class BigDecimalTest(unittest.TestCase): +class BigNumberTest(unittest.TestCase): def test_coerced_bigdecimal(self): from javatests import BigDecimalTest x = BigDecimal("123.4321") @@ -271,6 +276,11 @@ self.assertEqual(type(x), type(y), "BigDecimal coerced") self.assertEqual(x, y, "coerced BigDecimal not equal to directly created version") + def test_biginteger_in_long(self): + '''Checks for #608628, that long can take a BigInteger in its constructor''' + ns = '10000000000' + self.assertEquals(ns, str(long(BigInteger(ns)))) + class JavaStringTest(unittest.TestCase): def test_string_not_iterable(self): x = String('test') @@ -338,7 +348,7 @@ ImportTest, ColorTest, TreePathTest, - BigDecimalTest, + BigNumberTest, JavaStringTest, JavaDelegationTest, SecurityManagerTest) Modified: branches/jy3k/Lib/test/test_java_visibility.py =================================================================== --- branches/jy3k/Lib/test/test_java_visibility.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_java_visibility.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -4,7 +4,7 @@ import sys from test import test_support from java.lang import Byte, Class -from java.util import HashMap, Observable, Observer +from java.util import ArrayList, Collections, HashMap, Observable, Observer from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, Matryoshka, OnlySubclassable, OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results @@ -142,6 +142,14 @@ """Bug #452947 - Class of innerclass inst <> innerclass""" self.assertEquals(id(Matryoshka.Outermost), id(Matryoshka.makeOutermost().__class__)) + def test_super_methods_merged(self): + '''Checks that all signatures on a class' methods are found, not just the first for a name + + Bug #628315''' + synchList = Collections.synchronizedList(ArrayList()) + synchList.add("a string") + self.assertEquals("a string", synchList.remove(0)) + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), Copied: branches/jy3k/Lib/test/test_set_jy.py (from rev 5927, trunk/jython/Lib/test/test_set_jy.py) =================================================================== --- branches/jy3k/Lib/test/test_set_jy.py (rev 0) +++ branches/jy3k/Lib/test/test_set_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -0,0 +1,35 @@ +from test import test_support +import unittest + +from java.util import Random +from javatests import PySetInJavaTest + +class SetInJavaTest(unittest.TestCase): + "Tests for derived dict behaviour" + def test_using_PySet_as_Java_Set(self): + PySetInJavaTest.testPySetAsJavaSet() + + def test_accessing_items_added_in_java(self): + s = PySetInJavaTest.createPySetContainingJavaObjects() + for v in s: + self.assert_(v in s) + if isinstance(v, unicode): + self.assertEquals("value", v) + else: + v.nextInt()#Should be a java.util.Random; ensure we can call it + + def test_java_accessing_items_added_in_python(self): + # Test a type that should be coerced into a Java type, a Java instance + # that should be wrapped, and a Python instance that should pass + # through as itself with str, Random and tuple respectively. + s = set(["value", Random(), ("tuple", "of", "stuff")]) + PySetInJavaTest.accessAndRemovePySetItems(s) + self.assertEquals(0, len(s))# Check that the Java removal affected the underlying set + + + +def test_main(): + test_support.run_unittest(SetInJavaTest) + +if __name__ == '__main__': + test_main() Modified: branches/jy3k/Lib/test/test_traceback_jy.py =================================================================== --- branches/jy3k/Lib/test/test_traceback_jy.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/Lib/test/test_traceback_jy.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -50,8 +50,17 @@ # http://bugs.jython.org/issue437809 traceback.extract_stack() + def test_except_around_raising_call(self): + """[ #452526 ] traceback lineno is the except line""" + from test import except_in_raising_code + try: + except_in_raising_code.foo() + except NameError: + tb = sys.exc_info()[2] + self.assertEquals(6, tb.tb_next.tb_lineno) + else: + self.fail("Should've raised a NameError") - try: raise Exception('foo') except Exception: Modified: branches/jy3k/README.txt =================================================================== --- branches/jy3k/README.txt 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/README.txt 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,7 +1,7 @@ -Welcome to Jython 2.5b0 +Welcome to Jython 2.5b1 ======================= -This is the first beta of the 2.5 version of Jython. It +This is the second beta of the 2.5 version of Jython. It contains most of the new features for the 2.5 release. The release was compiled on Mac OS X with JDK 5 and requires JDK 5 to run. Deleted: branches/jy3k/bugtests/classes/test395j1.java =================================================================== --- branches/jy3k/bugtests/classes/test395j1.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test395j1.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,4 +0,0 @@ -public class test395j1 { - protected test395j1() { - } -} Deleted: branches/jy3k/bugtests/classes/test395j2.java =================================================================== --- branches/jy3k/bugtests/classes/test395j2.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test395j2.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,5 +0,0 @@ -public class test395j2 extends test395j1 { - private test395j2() { - super(); - } -} Deleted: branches/jy3k/bugtests/classes/test396j.java =================================================================== --- branches/jy3k/bugtests/classes/test396j.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/classes/test396j.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,8 +0,0 @@ -public abstract class test396j { - public test396j() { - abstractMethod(); - } - - public abstract void abstractMethod(); - -} Deleted: branches/jy3k/bugtests/test320.py =================================================================== --- branches/jy3k/bugtests/test320.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test320.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,28 +0,0 @@ -""" -[ #452526 ] traceback lineno is the except line -""" - -import support -import sys, traceback - -def test(): - print noname - -def foo(): - try: - - - test() - - - except ValueError: - print "shouldn't happen." - -try: - foo() -except: - tb = sys.exc_info()[2] - #print tb.tb_lineno - #traceback.print_tb(tb) - assert tb.tb_next.tb_lineno == 15 - Deleted: branches/jy3k/bugtests/test366.py =================================================================== --- branches/jy3k/bugtests/test366.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test366.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,17 +0,0 @@ -""" -[ 610576 ] Impl of abstract method not found -""" - -import support - -support.compileJava("test366i.java"); -support.compileJava("test366j.java"); - -import test366i, test366j - -class MyCls(test366j, test366i): - def __init__(self): - self.foo(); - -MyCls() - Deleted: branches/jy3k/bugtests/test373.py =================================================================== --- branches/jy3k/bugtests/test373.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test373.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,14 +0,0 @@ -""" -Test for bug [608628] long(java.math.BigInteger) does not work. -""" - -import support - -# local name bugtests/test381.py -ns = '10000000000' -import java -ns2 = str(long(java.math.BigInteger(ns))) -assert ns == ns2, ns2 - - - Deleted: branches/jy3k/bugtests/test391.py =================================================================== --- branches/jy3k/bugtests/test391.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test391.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,14 +0,0 @@ -''' -Checks that all methods on a class are found, not just the first interface that has a method of the same name. - -Reported in bug 628315. -''' -import support -import java - -synchList = java.util.Collections.synchronizedList(java.util.ArrayList()) -synchList.add("a string") - -if not synchList.remove(0) == 'a string': - raise support.TestError, "'a string' should've been returned by the call to remove. The object version of remove was probably called instead of the int version" - Deleted: branches/jy3k/bugtests/test395.py =================================================================== --- branches/jy3k/bugtests/test395.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test395.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,20 +0,0 @@ -""" -Classes with greater a protected constructor can be subclassed and instantiated -Tests bug #649582 -""" - -import support - -support.compileJava("classes/test395j1.java") -support.compileJava("classes/test395j2.java") - -import test395j2 - -class Subclass(test395j2): - def __init__(self): - test395j2.__init__(self) - -try: - Subclass() -except AttributeError: - raise support.TestWarning('Unable to access protected superclass constructor') Deleted: branches/jy3k/bugtests/test396.py =================================================================== --- branches/jy3k/bugtests/test396.py 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/bugtests/test396.py 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,19 +0,0 @@ -''' -Checks for bug 663592. Used to be that if an abstract Java class called an -abstract method implemented by a Python subclass in its constructor, an -AttributeError would be thrown. -''' -import support - -support.compileJava("classes/test396j.java") - -import test396j - -class Subclass(test396j): - def __init__(self): - test396j.__init__(self) - - def abstractMethod(self): - pass - -x = Subclass() Modified: branches/jy3k/build.xml =================================================================== --- branches/jy3k/build.xml 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/build.xml 2009-01-14 03:58:51 UTC (rev 5928) @@ -362,7 +362,9 @@ <exec executable="svnversion" failifexecutionfails="false" outputproperty="build.svn.revision"/> </target> - <target name="brand-version" depends="version-init, svnversion"> + <!-- skip-brand can be set in ant.properties or as a system property to keep from updating the + version.properties file and making the jar on every developer build. --> + <target name="brand-version" depends="version-init, svnversion" unless="skip-brand"> <condition property="build.svn.revision" value=""> <not> <isset property="build.svn.revision"/> @@ -520,7 +522,7 @@ <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> <zipfileset src="extlibs/constantine-0.4.jar"/> <rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/> - <zipfileset src="extlibs/xercesImpl.jar"/> + <zipfileset src="extlibs/xercesImpl-2.9.1.jar"/> <rule pattern="org.apache.**" result="org.python.apache.@1"/> <manifest> <attribute name="Main-Class" value="org.python.util.jython" /> @@ -720,6 +722,15 @@ <fileset dir="${dist.dir}"> <exclude name="${jython.dev.jar}"/> <exclude name="callbacker_test.jar"/> + <exclude name="extlibs/svnant-jars/**" /> + <exclude name="extlibs/antlr*.jar" /> + <exclude name="extlibs/asm*.jar" /> + <exclude name="extlibs/constantine*.jar" /> + <exclude name="extlibs/jarjar*.jar" /> + <exclude name="extlibs/junit*.jar" /> + <exclude name="extlibs/servlet-api*.jar" /> + <exclude name="extlibs/stringtemplate*.jar" /> + <exclude name="extlibs/xerces*.jar" /> </fileset> <manifest> <attribute name="Main-Class" value="org.python.util.install.Installation" /> Copied: branches/jy3k/extlibs/xercesImpl-2.9.1.jar (from rev 5927, trunk/jython/extlibs/xercesImpl-2.9.1.jar) =================================================================== (Binary files differ) Deleted: branches/jy3k/extlibs/xercesImpl.jar =================================================================== (Binary files differ) Modified: branches/jy3k/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/jy3k/src/org/python/antlr/PythonTokenSource.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/antlr/PythonTokenSource.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -146,6 +146,7 @@ } private void generateNewline(Token t) { + //System.out.println("generating newline from token: " + t); CommonToken newline = new CommonToken(PythonLexer.NEWLINE, "\n"); newline.setLine(t.getLine()); newline.setCharPositionInLine(t.getCharPositionInLine()); @@ -153,9 +154,12 @@ } private void handleEOF(CommonToken eof, CommonToken prev) { + //System.out.println("processing eof with token: " + prev); if (prev != null) { eof.setStartIndex(prev.getStopIndex()); eof.setStopIndex(prev.getStopIndex()); + eof.setLine(prev.getLine()); + eof.setCharPositionInLine(prev.getCharPositionInLine()); } } Modified: branches/jy3k/src/org/python/compiler/ProxyMaker.java =================================================================== --- branches/jy3k/src/org/python/compiler/ProxyMaker.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/compiler/ProxyMaker.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -703,9 +703,7 @@ addMethods(superclass, seenmethods); for (Class<?> iface : interfaces) { if (iface.isAssignableFrom(superclass)) { - Py.writeWarning("compiler", - "discarding redundant interface: "+ - iface.getName()); + Py.writeWarning("compiler", "discarding redundant interface: " + iface.getName()); continue; } classfile.addInterface(mapClass(iface)); Modified: branches/jy3k/src/org/python/core/BaseSet.java =================================================================== --- branches/jy3k/src/org/python/core/BaseSet.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/BaseSet.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -1,41 +1,35 @@ package org.python.core; +import java.lang.reflect.Array; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.Set; public abstract class BaseSet extends PyObject implements Set { /** The underlying Set. */ - protected Set _set; + protected Set<PyObject> _set; /** * Create a new Python set instance from the specified Set object. - * - * @param set An Set object. */ - protected BaseSet(Set set) { + protected BaseSet(Set<PyObject> set) { _set = set; } - protected BaseSet(PyType type, Set set) { + protected BaseSet(PyType type, Set<PyObject> set) { super(type); _set = set; } - protected void _update(PyObject data) throws PyIgnoreMethodTag { + protected void _update(PyObject data) { _update(_set, data); } /** * Update the underlying set with the contents of the iterable. - * - * @param data An iterable instance. - * @throws PyIgnoreMethodTag Ignore. */ - protected static Set _update(Set set, PyObject data) throws PyIgnoreMethodTag { + protected static Set<PyObject> _update(Set<PyObject> set, PyObject data) { if (data == null) { return set; } @@ -53,7 +47,7 @@ /** * The union of <code>this</code> with <code>other</code>. <p/> <br/> (I.e. all elements * that are in either set) - * + * * @param other * A <code>BaseSet</code> instance. * @return The union of the two sets as a new set. @@ -115,9 +109,9 @@ final PyObject baseset_difference(PyObject other) { BaseSet bs = (other instanceof BaseSet) ? (BaseSet)other : new PySet(other); - Set set = bs._set; + Set<PyObject> set = bs._set; BaseSet o = BaseSet.makeNewSet(getType()); - for (Object p : _set) { + for (PyObject p : _set) { if (!set.contains(p)) { o._set.add(p); } @@ -153,12 +147,12 @@ final PyObject baseset_symmetric_difference(PyObject other) { BaseSet bs = (other instanceof BaseSet) ? (BaseSet)other : new PySet(other); BaseSet o = BaseSet.makeNewSet(getType()); - for (Object p : _set) { + for (PyObject p : _set) { if (!bs._set.contains(p)) { o._set.add(p); } } - for (Object p : bs._set) { + for (PyObject p : bs._set) { if (!_set.contains(p)) { o._set.add(p); } @@ -206,7 +200,22 @@ } final PyObject baseset___iter__() { - return new PySetIterator(_set); + return new PyIterator() { + private int size = _set.size(); + + private Iterator<PyObject> iterator = _set.iterator(); + + @Override + public PyObject __iternext__() { + if (_set.size() != size) { + throw Py.RuntimeError("set changed size during iteration"); + } + if (iterator.hasNext()) { + return iterator.next(); + } + return null; + } + }; } public boolean __contains__(PyObject other) { @@ -257,7 +266,7 @@ } final PyObject baseset___le__(PyObject other) { - BaseSet bs = _binary_sanity_check(other); + _binary_sanity_check(other); return baseset_issubset(other); } @@ -266,7 +275,7 @@ } final PyObject baseset___ge__(PyObject other) { - BaseSet bs = _binary_sanity_check(other); + _binary_sanity_check(other); return baseset_issuperset(other); } @@ -299,7 +308,7 @@ public PyObject __reduce__() { return baseset___reduce__(); } - + final PyObject baseset___reduce__(){ PyObject args = new PyTuple(new PyList((PyObject)this)); PyObject dict = __findattr__("__dict__"); @@ -309,19 +318,6 @@ return new PyTuple(getType(), args, dict); } - /** - * Return this instance as a Java object. Only coerces to Collection and subinterfaces. - * - * @param c The Class to coerce to. - * @return the underlying HashSet (not a copy) - */ - public Object __tojava__(Class c) { - if (Collection.class.isAssignableFrom(c)) { - return Collections.unmodifiableSet(_set); - } - return super.__tojava__(c); - } - final PyObject baseset_union(PyObject other) { BaseSet result = BaseSet.makeNewSet(getType(), this); result._update(other); @@ -388,8 +384,8 @@ return name + "(...)"; } StringBuilder buf = new StringBuilder(name).append("(["); - for (Iterator i = _set.iterator(); i.hasNext();) { - buf.append(((PyObject)i.next()).__repr__().toString()); + for (Iterator<PyObject> i = _set.iterator(); i.hasNext();) { + buf.append((i.next()).__repr__().toString()); if (i.hasNext()) { buf.append(", "); } @@ -408,20 +404,20 @@ } /** - * Return a PyFrozenSet whose contents are shared with value when - * value is a BaseSet and pye is a TypeError. + * Return a PyFrozenSet whose contents are shared with value when value is a BaseSet and pye is + * a TypeError. * - * WARNING: The PyFrozenSet returned is only intended to be used - * temporarily (and internally); since its contents are shared - * with value, it could be mutated! - * - * This is better than special-casing behavior based on - * isinstance, because a Python subclass can override, say, - * __hash__ and all of a sudden you can't assume that a - * non-PyFrozenSet is unhashable anymore. + * WARNING: The PyFrozenSet returned is only intended to be used temporarily (and internally); + * since its contents are shared with value, it could be mutated! * - * @param pye The exception thrown from a hashable operation. - * @param value The object which was unhashable. + * This is better than special-casing behavior based on isinstance, because a Python subclass + * can override, say, __hash__ and all of a sudden you can't assume that a non-PyFrozenSet is + * unhashable anymore. + * + * @param pye + * The exception thrown from a hashable operation. + * @param value + * The object which was unhashable. * @return A PyFrozenSet if appropriate, otherwise the pye is rethrown */ protected final PyFrozenSet asFrozen(PyException pye, PyObject value) { @@ -442,7 +438,7 @@ protected static BaseSet makeNewSet(PyType type) { return makeNewSet(type, null); } - + /** * Create a new <et of type from iterable. * @@ -477,43 +473,89 @@ return _set.isEmpty(); } - public Object[] toArray() { - return _set.toArray(); - } - public boolean add(Object o) { - return _set.add(o); + return _set.add(Py.java2py(o)); } public boolean contains(Object o) { - return _set.contains(o); + return _set.contains(Py.java2py(o)); } public boolean remove(Object o) { - return _set.remove(o); + return _set.remove(Py.java2py(o)); } public boolean addAll(Collection c) { - return _set.addAll(c); + boolean added = false; + for (Object object : c) { + added |= add(object); + } + return added; } public boolean containsAll(Collection c) { - return _set.containsAll(c); + for (Object object : c) { + if (!_set.contains(Py.java2py(object))) { + return false; + } + } + return true; } public boolean removeAll(Collection c) { - return _set.removeAll(c); + boolean removed = false; + for (Object object : c) { + removed |= _set.remove(Py.java2py(object)); + } + return removed; } public boolean retainAll(Collection c) { - return _set.retainAll(c); + boolean modified = false; + Iterator e = iterator(); + while (e.hasNext()) { + if (!c.contains(e.next())) { + e.remove(); + modified = true; + } + } + return modified; } public Iterator iterator() { - return _set.iterator(); + return new Iterator() { + Iterator<PyObject> real = _set.iterator(); + + public boolean hasNext() { + return real.hasNext(); + } + + public Object next() { + return Py.tojava(real.next(), Object.class); + } + + public void remove() { + real.remove(); + } + }; } + public Object[] toArray() { + return toArray(new Object[size()]); + } + public Object[] toArray(Object a[]) { - return _set.toArray(a); + int size = size(); + if (a.length < size) { + a = (Object[])Array.newInstance(a.getClass().getComponentType(), size); + } + Iterator<PyObject> it = iterator(); + for (int i = 0; i < size; i++) { + a[i] = it.next(); + } + if (a.length > size) { + a[size] = null; + } + return a; } } Modified: branches/jy3k/src/org/python/core/CompilerFlags.java =================================================================== --- branches/jy3k/src/org/python/core/CompilerFlags.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/CompilerFlags.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -3,54 +3,44 @@ public class CompilerFlags { + private int co_flags; + public boolean nested_scopes = true; public boolean division; public boolean generator_allowed = true; - public boolean with_statement = false; - public boolean absolute_import = false; + public boolean with_statement; + public boolean absolute_import; - public boolean only_ast = false; - public boolean dont_imply_dedent = false; - public boolean source_is_utf8 = false; + public boolean only_ast; + public boolean dont_imply_dedent; + public boolean source_is_utf8; public String encoding; - - public CompilerFlags(){} + public CompilerFlags() {} + public CompilerFlags(int co_flags) { - if ((co_flags & org.python.core.PyTableCode.CO_NESTED) != 0) { - this.nested_scopes = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_FUTUREDIVISION) != 0) { - this.division = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_GENERATOR_ALLOWED) != 0) { - this.generator_allowed = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT) != 0) { - this.absolute_import = true; - } - if ((co_flags & org.python.core.PyTableCode.CO_WITH_STATEMENT) != 0) { - this.with_statement = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_ONLY_AST) != 0) { - this.only_ast = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_DONT_IMPLY_DEDENT) != 0) { - this.dont_imply_dedent = true; - } - if ((co_flags & org.python.core.PyTableCode.PyCF_SOURCE_IS_UTF8) != 0) { - this.source_is_utf8 = true; - } - + this.co_flags = co_flags; + nested_scopes = isEnabled(PyTableCode.CO_NESTED); + division = isEnabled(PyTableCode.CO_FUTUREDIVISION); + generator_allowed = isEnabled(PyTableCode.CO_GENERATOR_ALLOWED); + absolute_import = isEnabled(PyTableCode.CO_FUTURE_ABSOLUTE_IMPORT); + with_statement = isEnabled(PyTableCode.CO_WITH_STATEMENT); + only_ast = isEnabled(PyTableCode.PyCF_ONLY_AST); + dont_imply_dedent = isEnabled(PyTableCode.PyCF_DONT_IMPLY_DEDENT); + source_is_utf8 = isEnabled(PyTableCode.PyCF_SOURCE_IS_UTF8); } + private boolean isEnabled(int codeConstant) { + return (co_flags & codeConstant) != 0; + } + public String toString() { return String.format("CompilerFlags[division=%s nested_scopes=%s generators=%s " + "with_statement=%s absolute_import=%s only_ast=%s " + "dont_imply_dedent=%s source_is_utf8=%s]", division, nested_scopes, - generator_allowed, with_statement, absolute_import, only_ast, + generator_allowed, with_statement, absolute_import, only_ast, dont_imply_dedent, source_is_utf8); } - + } Modified: branches/jy3k/src/org/python/core/ParserFacade.java =================================================================== --- branches/jy3k/src/org/python/core/ParserFacade.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/ParserFacade.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -4,10 +4,13 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.Reader; +import java.io.Writer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; @@ -138,7 +141,7 @@ try { // prepBufReader takes care of encoding detection and universal // newlines: - bufReader = prepBufReader(stream, cflags, filename); + bufReader = prepBufReader(stream, cflags, filename, false); return parse(bufReader, kind, filename, cflags ); } catch (Throwable t) { throw fixParseError(bufReader, t, filename); @@ -223,7 +226,9 @@ private static ExpectedEncodingBufferedReader prepBufReader(InputStream input, CompilerFlags cflags, - String filename) throws IOException { + String filename, + boolean fromString) + throws IOException { input = new BufferedInputStream(input); boolean bom = adjustForBOM(input); String encoding = readEncoding(input); @@ -250,29 +255,45 @@ UniversalIOWrapper textIO = new UniversalIOWrapper(bufferedIO); input = new TextIOInputStream(textIO); - CharsetDecoder dec; + Charset cs; try { // Use ascii for the raw bytes when no encoding was specified - dec = Charset.forName(encoding == null ? "ascii" : encoding).newDecoder(); + if (encoding == null) { + if (fromString) { + cs = Charset.forName("ISO-8859-1"); + } else { + cs = Charset.forName("ascii"); + } + } else { + cs = Charset.forName(encoding); + } } catch (UnsupportedCharsetException exc) { throw new PySyntaxError("Unknown encoding: " + encoding, 1, 0, "", filename); } + CharsetDecoder dec = cs.newDecoder(); dec.onMalformedInput(CodingErrorAction.REPORT); dec.onUnmappableCharacter(CodingErrorAction.REPORT); return new ExpectedEncodingBufferedReader(new InputStreamReader(input, dec), encoding); } - private static ExpectedEncodingBufferedReader prepBufReader(String string, CompilerFlags cflags, - String filename) throws IOException { + private static ExpectedEncodingBufferedReader prepBufReader(String string, + CompilerFlags cflags, + String filename) throws IOException { + byte[] stringBytes; if (cflags.source_is_utf8) { // Passed unicode, re-encode the String to raw bytes // NOTE: This could be more efficient if we duplicate // prepBufReader/adjustForBOM/readEncoding to work on Readers, instead of // encoding - string = new PyUnicode(string).encode("utf-8"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + Writer w = new OutputStreamWriter(out, "utf-8"); + w.write(string); + w.close(); + stringBytes = out.toByteArray(); + } else { + stringBytes = StringUtil.toBytes(string); } - InputStream input = new ByteArrayInputStream(StringUtil.toBytes(string)); - return prepBufReader(input, cflags, filename); + return prepBufReader(new ByteArrayInputStream(stringBytes), cflags, filename, true); } /** Modified: branches/jy3k/src/org/python/core/PyDictionary.java =================================================================== --- branches/jy3k/src/org/python/core/PyDictionary.java 2009-01-14 03:42:42 UTC (rev 5927) +++ branches/jy3k/src/org/python/core/PyDictionary.java 2009-01-14 03:58:51 UTC (rev 5928) @@ -12,7 +12,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.python.core.PyMapSet.PySetIter; import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -27,7 +26,7 @@ public class PyDictionary extends PyObject implements ConcurrentMap { public static final PyType TYPE = PyType.fromClass(PyDictionary.class); - + protected final ConcurrentMap<PyObject, PyObject> table; /** @@ -39,7 +38,6 @@ /** * For derived types - * @param subtype */ public PyDictionary(PyType subtype) { super(subtype); @@ -47,31 +45,27 @@ } /** - * Create an new dictionary which is based on the hashtable. - * @param t the hashtable used. The supplied hashtable is used as - * is and must only contain PyObject key:value pairs. + * Create a new dictionary which is based on given map. */ public PyDictionary(Map<PyObject, PyObject> t) { table = new ConcurrentHashMap<PyObject, PyObject>(t); } - /** - * Create an new dictionary which is based on the map and for derived types. - * @param subtype - * @param t the hashtable used. The supplied hashtable is used as - * is and must only contain PyObject key:value pairs. + /** + * Create a new derived dictionary which is based on the given map. */ public PyDictionary(PyType subtype, Map<PyObject, PyObject> t) { super(subtype); table = new ConcurrentHashMap<PyObject, PyObject>(t); } - + /** * Create a new dictionary with the element as content. - * @param elements The initial elements that is inserted in the - * dictionary. Even numbered elements are keys, - * odd numbered elements are values. + * + * @param elements + * The initial elements that is inserted in the dictionary. Even numbered elements + * are keys, odd numbered elements are values. */ public PyDictionary(PyObject elements[]) { this(); @@ -85,7 +79,7 @@ protected final void dict___init__(PyObject[] args, String[] keywords) { updateCommon(args, keywords, "dict"); } - + public static PyObject fromkeys(PyObject keys) { return fromkeys(keys, Py.None); } @@ -210,10 +204,10 @@ } @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.dict___eq___doc) - final PyObject dict___eq__(PyObject ob_other) { + final PyObject dict___eq__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); - if (otherType != thisType && !thisType.isSubType(otherType) + if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return null; } @@ -291,7 +285,7 @@ final int dict___cmp__(PyObject ob_other) { PyType thisType = getType(); PyType otherType = ob_other.getType(); - if (otherType != thisType && !thisType.isSubType(otherType) + if (otherType != thisType && !thisType.isSubType(otherType) && !otherType.isSubType(thisType)) { return -2; } @@ -435,7 +429,7 @@ } for (int i = 0; i < keywords.length; i++) { dict___setitem__(Py.newString(keywords[i]), args[nargs + i]); - } + } } /** @@ -539,7 +533,7 @@ } } - + /** * Return a value based on key * from the dictionary. @@ -578,18 +572,17 @@ @ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) final PyObject dict_popitem() { - Iterator it = table.entrySet().iterator(); + Iterator<Entry<PyObject, PyObject>> it = table.entrySet().iterator(); if (!it.hasNext()) throw Py.KeyError("popitem(): dictionary is empty"); - Entry entry = (Entry)it.next(); - PyTuple tuple = new PyTuple( - (PyObject)entry.getKey(), (PyObject)entry.getValue()); + Entry<PyObject, PyObject> entry = it.next(); + PyTuple tuple = new PyTuple(entry.getKey(), entry.getValue()); it.remove(); return tuple; } /** - * Return a copy of the dictionarys list of (key, value) tuple + * Return a copy of the dictionary's list of (key, value) tuple * pairs. */ public PyList items() { @@ -606,7 +599,7 @@ } /** - * Return a copy of the dictionarys list of keys. + * Return a copy of the dictionary's list of keys. */ public PyList keys() { return dict_keys(); @@ -623,7 +616,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over (key, value) pairs. */ public PyObject iteritems() { return dict_iteritems(); @@ -635,7 +628,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over the dictionary's keys. */ public PyObject iterkeys() { return dict_iterkeys(); @@ -647,7 +640,7 @@ } /** - * Return an interator over (key, value) pairs. + * Returns an iterator over the dictionary's values. */ public PyObject itervalues() { return dict_itervalues(); @@ -703,7 +696,7 @@ iterator = items.iterator(); size = items.size(); } - + public PyObject __iternext__() { if (table.size() != size) { throw Py.RuntimeError("dictionary changed size during iteration"); @@ -716,13 +709,12 @@ } } - /* The following methods implement the java.util.Map interface - which allows PyDictionary to be passed to java methods that take - java.util.Map as a parameter. Basically, the Map methods are a - wrapper around the PyDictionary's Map container stored in member - variable 'table'. These methods simply convert java Object to - PyObjects on insertion, and PyObject to Objects on retrieval. */ - + /* + * The following methods implement the java.util.Map interface which allows PyDictionary to be + * passed to java methods that take java.util.Map as a parameter. Basically, the Map methods are + * a wrapper around the PyDictionary's Map container stored in member variable 'table'. These + * methods convert java Object to PyObjects on insertion, and PyObject to Objects on retrieval. + */ /** @see java.util.Map#entrySet() */ public Set entrySet() { return new PyMapEntrySet(table.entrySet()); @@ -733,17 +725,15 @@ return new PyMapKeyValSet(table.keySet()); } - /** Return a copy of the dictionarys list of values. */ + /** @see java.util.Map#values() */ public Collection values() { return new PyMapKeyValSet(table.values()); } - /** @see java.util.Map#putAll(Map map) */ public void putAll(Map map) { - Iterator i = map.entrySet().iterator(); - while (i.hasNext()) { - Entry entry = (Entry)i.next(); + for (Object o : map.entrySet()) { + Entry entry = (Entry)o; table.put(Py.java2py(entry.getKey()), Py.java2py(entry.getValue())); } } @@ -772,19 +762,19 @@ public boolean containsKey(Object key) { return table.containsKey(Py.java2py(key)); } - - /** @see java.util.Map#isEmpty(Object key) */ + + /** @see java.util.Map#isEmpty() */ public boolean isEmpty() { return table.isEmpty(); } - - /** @see java.util.Map#size(Object key) */ + + /** @see java.util.Map#size() */ public int size() { return table.size(); } /** Convert return values to java objects */ - static final Object tojava(Object val) { + final static Object tojava(Object val) { return val == null ? null : ((PyObject)val).__tojava__(Object.class); } @@ -805,19 +795,20 @@ } } + /** Basic implementation of Entry that just holds onto a key and value and returns them. */ -class SimpleEntry<K, V> implements Entry<K, V> { - - public SimpleEntry(K key, V value){ +class SimpleEntry implements Entry { + + public SimpleEntry(Object key, Object value){ this.key = key; this.value = value; } - - public K getKey() { + + public Object getKey() { return key; } - public V getValue() { + public Object getValue() { return value; } @@ -841,31 +832,29 @@ return key + "=" + value; } - public V setValue(V val) { + public Object setValue(Object val) { throw new UnsupportedOperationException("Not supported by this view"); } - protected K key; + protected Object key; - protected V value; + protected Object value; } /** - * Wrapper for a Entry object returned from the java.util.Set - * object which in turn is returned by the entrySet method of - * java.util.Map. This is needed to correctly convert from PyObjects - * to java Objects. Note that we take care in the equals and hashCode - * methods to make sure these methods are consistent with Entry - * objects that contain java Objects for a value so that on the java - * side they can be reliable compared. + * Wrapper for a Entry object returned from the java.util.Set object which in turn is returned by + * the entrySet method of java.util.Map. This is needed to correctly convert from PyObjects to java + * Objects. Note that we take care in the equals and hashCode methods to make sure these methods are + * consistent with Entry objects that contain java Objects for a value so that on the java side they + * can be reliable compared. */ class PyToJavaMapEntry extends SimpleEntry { - /** Create a copy of the Entry with Py.None coverted to null */ + /** Create a copy of the Entry with Py.None converted to null */ PyToJavaMapEntry(Entry entry) { super(entry.getKey(), entry.getValue()); } - + public boolean equals(Object o) { if (o == null || !(o instanceof Entry)) return false; Entry me = new JavaToPyMapEntry((Entry)o); @@ -877,7 +866,7 @@ public Object getKey() { return PyDictionary.tojava(key); } - + public Object getValue() { return PyDictionary.tojava(value); } @@ -892,24 +881,22 @@ } /** - * MapEntry Object for java MapEntry objects passed to the java.util.Set - * interface which is returned by the entrySet method of PyDictionary. - * Essentially like PyTojavaMapEntry, but going t... [truncated message content] |
From: <fwi...@us...> - 2009-01-14 03:42:48
|
Revision: 5927 http://jython.svn.sourceforge.net/jython/?rev=5927&view=rev Author: fwierzbicki Date: 2009-01-14 03:42:42 +0000 (Wed, 14 Jan 2009) Log Message: ----------- Small fix to grammar -- a "print" by itself should have it's NL attribute set to true as CPython does. Because "false" doesn't make sense in this context (it would be a no-op), the compiler doesn't check, so it passed unnoticed. Modified Paths: -------------- trunk/jython/grammar/Python.g Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-01-14 01:03:58 UTC (rev 5926) +++ trunk/jython/grammar/Python.g 2009-01-14 03:42:42 UTC (rev 5927) @@ -624,7 +624,7 @@ | RIGHTSHIFT t2=printlist2 -> ^(PRINT<Print>[$PRINT, actions.castExpr($t2.elts.get(0)), actions.castExprs($t2.elts, 1), $t2.newline]) | - -> ^(PRINT<Print>[$PRINT, null, new ArrayList<expr>(), false]) + -> ^(PRINT<Print>[$PRINT, null, new ArrayList<expr>(), true]) ) ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-14 01:04:11
|
Revision: 5926 http://jython.svn.sourceforge.net/jython/?rev=5926&view=rev Author: fwierzbicki Date: 2009-01-14 01:03:58 +0000 (Wed, 14 Jan 2009) Log Message: ----------- A first cut at some 2.6 parsing. Modified Paths: -------------- trunk/sandbox/wierzbicki/grammar26/grammar/Python.g trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/GrammarActions.java Modified: trunk/sandbox/wierzbicki/grammar26/grammar/Python.g =================================================================== --- trunk/sandbox/wierzbicki/grammar26/grammar/Python.g 2009-01-13 22:10:24 UTC (rev 5925) +++ trunk/sandbox/wierzbicki/grammar26/grammar/Python.g 2009-01-14 01:03:58 UTC (rev 5926) @@ -942,9 +942,9 @@ } ; -//except_clause: 'except' [test [',' test]] +//except_clause: 'except' [test [('as' | ',') test]] except_clause - : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] + : EXCEPT (t1=test[expr_contextType.Load] ((COMMA | AS) t2=test[expr_contextType.Store])?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] -> ^(EXCEPT<ExceptHandler>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), actions.castStmts($suite.stypes)]) ; @@ -1487,7 +1487,7 @@ } : argument[arguments, kws, gens, true] (COMMA argument[arguments, kws, gens, false])* (COMMA - ( STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? + ( STAR s=test[expr_contextType.Load] (COMMA argument[arguments, kws, gens, false])* (COMMA DOUBLESTAR k=test[expr_contextType.Load])? | DOUBLESTAR k=test[expr_contextType.Load] )? )? @@ -1741,8 +1741,12 @@ INT : // Hex '0' ('x' | 'X') ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ | // Octal - '0' ( '0' .. '7' )* - | '1'..'9' DIGITS* + '0' ('o' | 'O') ( '0' .. '7' )* + | '0' ( '0' .. '7' )* + | // Binary + '0' ('b' | 'B') ( '0' .. '1' )* + | // Decimal + '1'..'9' DIGITS* ; COMPLEX @@ -1761,7 +1765,7 @@ * should make us exit loop not continue. */ STRING - : ('r'|'u'|'ur'|'R'|'U'|'UR'|'uR'|'Ur')? + : ('r'|'u'|'b'|'ur'|'R'|'U'|'B'|'UR'|'uR'|'Ur')? ( '\'\'\'' (options {greedy=false;}:TRIAPOS)* '\'\'\'' | '"""' (options {greedy=false;}:TRIQUOTE)* '"""' | '"' (ESC|~('\\'|'\n'|'"'))* '"' @@ -1775,7 +1779,7 @@ ; STRINGPART - : {partial}?=> ('r'|'u'|'ur'|'R'|'U'|'UR'|'uR'|'Ur')? + : {partial}?=> ('r'|'u'|'b'|'ur'|'R'|'U'|'B'|'UR'|'uR'|'Ur')? ( '\'\'\'' ~('\'\'\'')* | '"""' ~('"""')* ) Modified: trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/GrammarActions.java 2009-01-13 22:10:24 UTC (rev 5925) +++ trunk/sandbox/wierzbicki/grammar26/src/org/python/antlr/GrammarActions.java 2009-01-14 01:03:58 UTC (rev 5926) @@ -350,6 +350,12 @@ if (s.startsWith("0x") || s.startsWith("0X")) { radix = 16; s = s.substring(2, s.length()); + } else if (s.startsWith("0o") || s.startsWith("0O")) { + radix = 8; + s = s.substring(2, s.length()); + } else if (s.startsWith("0b") || s.startsWith("0B")) { + radix = 2; + s = s.substring(2, s.length()); } else if (s.startsWith("0")) { radix = 8; } @@ -415,6 +421,10 @@ int end; boolean ustring = false; + if (quoteChar == 'b' || quoteChar == 'B') { + start++; + } + if (quoteChar == 'u' || quoteChar == 'U') { ustring = true; start++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-13 23:23:09
|
Revision: 5925 http://jython.svn.sourceforge.net/jython/?rev=5925&view=rev Author: cgroves Date: 2009-01-13 22:10:24 +0000 (Tue, 13 Jan 2009) Log Message: ----------- Allow importation from bytecode in a zip file even if the source isn't present Modified Paths: -------------- trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-01-13 02:36:27 UTC (rev 5924) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-01-13 22:10:24 UTC (rev 5925) @@ -315,7 +315,7 @@ String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); if (sourceTocEntry == null) { - return false; + return true;// If there is no source, assume the bytecode is ok } try { long bytecodeTime = dosTimeToEpoch(tocEntry.__finditem__(5).asInt(0), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-13 02:36:32
|
Revision: 5924 http://jython.svn.sourceforge.net/jython/?rev=5924&view=rev Author: fwierzbicki Date: 2009-01-13 02:36:27 +0000 (Tue, 13 Jan 2009) Log Message: ----------- A sandbox branch to allow parsing of 2.6 Python but not compiling or running 2.6. Really only intended for use by tools like NetBeans. It might make an okay start for post-2.5 once we really start doing that. Added Paths: ----------- trunk/sandbox/wierzbicki/grammar26/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-01-12 01:59:10
|
Revision: 5923 http://jython.svn.sourceforge.net/jython/?rev=5923&view=rev Author: pjenvey Date: 2009-01-12 01:31:59 +0000 (Mon, 12 Jan 2009) Log Message: ----------- bump copyright year Modified Paths: -------------- trunk/jython/LICENSE.txt trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/jython/LICENSE.txt =================================================================== --- trunk/jython/LICENSE.txt 2009-01-12 01:21:45 UTC (rev 5922) +++ trunk/jython/LICENSE.txt 2009-01-12 01:31:59 UTC (rev 5923) @@ -53,7 +53,7 @@ Jython 2.0, 2.1 License ================================ -Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Jython Developers +Copyright (c) 2000-2009 Jython Developers. All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-01-12 01:21:45 UTC (rev 5922) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-01-12 01:31:59 UTC (rev 5923) @@ -55,14 +55,14 @@ */ public static final PyObject copyright = Py.newString( - "Copyright (c) 2000-2008, Jython Developers\n" + + "Copyright (c) 2000-2009 Jython Developers.\n" + "All rights reserved.\n\n" + "Copyright (c) 2000 BeOpen.com.\n" + "All Rights Reserved.\n\n"+ - "Copyright (c) 2000 The Apache Software Foundation. All rights\n" + - "reserved.\n\n" + + "Copyright (c) 2000 The Apache Software Foundation.\n" + + "All rights reserved.\n\n" + "Copyright (c) 1995-2000 Corporation for National Research "+ "Initiatives.\n" + @@ -70,7 +70,7 @@ "Copyright (c) 1991-1995 Stichting Mathematisch Centrum, " + "Amsterdam.\n" + - "All Rights Reserved.\n\n"); + "All Rights Reserved."); private static Map<String,String> builtinNames; public static PyTuple builtin_module_names = null; @@ -1103,4 +1103,4 @@ builtins = PySystemState.getDefaultBuiltins(); warnoptions = PySystemState.warnoptions; } -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-12 01:21:50
|
Revision: 5922 http://jython.svn.sourceforge.net/jython/?rev=5922&view=rev Author: fwierzbicki Date: 2009-01-12 01:21:45 +0000 (Mon, 12 Jan 2009) Log Message: ----------- added test_nocond and lambdef_nocond rules. Modified Paths: -------------- branches/jy3k/grammar/Python.g Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-11 22:36:00 UTC (rev 5921) +++ branches/jy3k/grammar/Python.g 2009-01-12 01:21:45 UTC (rev 5922) @@ -1006,6 +1006,11 @@ | lambdef ; +test_nocond[expr_contextType ctype] + : or_test[ctype] + | lambdef_nocond + ; + //or_test: and_test ('or' and_test)* or_test[expr_contextType ctype] @after { @@ -1375,6 +1380,24 @@ } ; +//lambdef_nocond: 'lambda' [varargslist] ':' test_nocond +lambdef_nocond +@init { + expr etype = null; +} +@after { + $lambdef_nocond.tree = etype; +} + : LAMBDA (varargslist)? COLON test_nocond[expr_contextType.Load] + { + arguments a = $varargslist.args; + if (a == null) { + a = new arguments($LAMBDA, new ArrayList<arg>(), null, null, new ArrayList<arg>(), null, null, new ArrayList<expr>(), new ArrayList<expr>()); + } + etype = new Lambda($LAMBDA, a, actions.castExpr($test_nocond.tree)); + } + ; + //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer [Token begin, PythonTree tree] : LPAREN @@ -1616,9 +1639,9 @@ //comp_if: 'if' test_nocond [comp_iter] comp_if[List gens, List ifs] - : IF test[expr_contextType.Load] comp_iter[gens, ifs]? + : IF test_nocond[expr_contextType.Load] comp_iter[gens, ifs]? { - ifs.add(actions.castExpr($test.tree)); + ifs.add(actions.castExpr($test_nocond.tree)); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |