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: <nr...@us...> - 2009-12-09 07:49:02
|
Revision: 6956 http://jython.svn.sourceforge.net/jython/?rev=6956&view=rev Author: nriley Date: 2009-12-09 07:48:45 +0000 (Wed, 09 Dec 2009) Log Message: ----------- Fix incorrect conversion of AttributeError to NoSuchMethodException (#1490) in JSR 223 interface. Thanks to Robert Macaulay. Modified Paths: -------------- trunk/jython/src/org/python/jsr223/PyScriptEngine.java Modified: trunk/jython/src/org/python/jsr223/PyScriptEngine.java =================================================================== --- trunk/jython/src/org/python/jsr223/PyScriptEngine.java 2009-12-08 03:07:15 UTC (rev 6955) +++ trunk/jython/src/org/python/jsr223/PyScriptEngine.java 2009-12-09 07:48:45 UTC (rev 6956) @@ -96,9 +96,13 @@ if (!(thiz instanceof PyObject)) { thiz = Py.java2py(thiz); } - return ((PyObject) thiz).invoke(name, Py.javas2pys(args)).__tojava__(Object.class); + PyObject method = ((PyObject) thiz).__findattr__(name); + if (method == null) { + throw new NoSuchMethodException(name); + } + return method.__call__(Py.javas2pys(args)).__tojava__(Object.class); } catch (PyException pye) { - return throwInvokeException(pye, name); + throw scriptException(pye); } } @@ -111,7 +115,7 @@ } return function.__call__(Py.javas2pys(args)).__tojava__(Object.class); } catch (PyException pye) { - return throwInvokeException(pye, name); + throw scriptException(pye); } } @@ -134,24 +138,19 @@ new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { - PyObject result = thiz.invoke(method.getName(), Py.javas2pys(args)); + PyObject pyMethod = thiz.__findattr__(method.getName()); + if (pyMethod == null) + throw new NoSuchMethodException(method.getName()); + PyObject result = pyMethod.__call__(Py.javas2pys(args)); return result.__tojava__(Object.class); } catch (PyException pye) { - return throwInvokeException(pye, method.getName()); + throw scriptException(pye); } } }); return proxy; } - private static Object throwInvokeException(PyException pye, String methodName) - throws ScriptException, NoSuchMethodException { - if (pye.match(Py.AttributeError)) { - throw new NoSuchMethodException(methodName); - } - throw scriptException(pye); - } - private static ScriptException scriptException(PyException pye) { ScriptException se = null; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-12-08 03:07:35
|
Revision: 6955 http://jython.svn.sourceforge.net/jython/?rev=6955&view=rev Author: pjenvey Date: 2009-12-08 03:07:15 +0000 (Tue, 08 Dec 2009) Log Message: ----------- tie POSIXHandler verbosity to the global verbosity flag Modified Paths: -------------- trunk/jython/src/org/python/modules/posix/PythonPOSIXHandler.java Modified: trunk/jython/src/org/python/modules/posix/PythonPOSIXHandler.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PythonPOSIXHandler.java 2009-12-03 03:22:11 UTC (rev 6954) +++ trunk/jython/src/org/python/modules/posix/PythonPOSIXHandler.java 2009-12-08 03:07:15 UTC (rev 6955) @@ -12,6 +12,7 @@ import org.jruby.ext.posix.POSIXHandler; import org.python.core.imp; +import org.python.core.Options; import org.python.core.Py; import org.python.core.PyObject; @@ -42,7 +43,7 @@ } public boolean isVerbose() { - return false; + return Options.verbose >= Py.DEBUG; } public File getCurrentWorkingDirectory() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-12-03 03:22:33
|
Revision: 6954 http://jython.svn.sourceforge.net/jython/?rev=6954&view=rev Author: pjenvey Date: 2009-12-03 03:22:11 +0000 (Thu, 03 Dec 2009) Log Message: ----------- fix ConcurrentHashSet serialization: Object isn't serializable fixes #1511 Modified Paths: -------------- trunk/jython/Lib/test/test_set_jy.py trunk/jython/NEWS trunk/jython/src/org/python/core/util/ConcurrentHashSet.java Modified: trunk/jython/Lib/test/test_set_jy.py =================================================================== --- trunk/jython/Lib/test/test_set_jy.py 2009-12-01 09:51:33 UTC (rev 6953) +++ trunk/jython/Lib/test/test_set_jy.py 2009-12-03 03:22:11 UTC (rev 6954) @@ -2,6 +2,8 @@ from test import test_support if test_support.is_jython: + from java.io import (ByteArrayInputStream, ByteArrayOutputStream, + ObjectInputStream, ObjectOutputStream) from java.util import Random from javatests import PySetInJavaTest @@ -48,7 +50,18 @@ # Check that the Java removal affected the underlying set self.assertEquals(0, len(s)) + def test_serialization(self): + s = set(range(5, 10)) + output = ByteArrayOutputStream() + serializer = ObjectOutputStream(output) + serializer.writeObject(s) + serializer.close() + input = ByteArrayInputStream(output.toByteArray()) + unserializer = ObjectInputStream(input) + self.assertEqual(s, unserializer.readObject()) + + def test_main(): tests = [SetTestCase] if test_support.is_jython: Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-12-01 09:51:33 UTC (rev 6953) +++ trunk/jython/NEWS 2009-12-03 03:22:11 UTC (rev 6954) @@ -12,6 +12,7 @@ - [ 1477 ] os.setpgrp and posix.setpgrp fail with TypeError - [ 1396 ] Assigning os module funcs as class attributes incompatible with CPython - [ 1504 ] Inheriting twice from the same Java interface causes MRO problems + - [ 1511 ] PySet doesn't support Java serialization - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/org/python/core/util/ConcurrentHashSet.java =================================================================== --- trunk/jython/src/org/python/core/util/ConcurrentHashSet.java 2009-12-01 09:51:33 UTC (rev 6953) +++ trunk/jython/src/org/python/core/util/ConcurrentHashSet.java 2009-12-03 03:22:11 UTC (rev 6954) @@ -17,26 +17,23 @@ public class ConcurrentHashSet<E> extends AbstractSet<E> implements Serializable { /** The backing Map. */ - private final ConcurrentMap<E, Object> map; + private final ConcurrentMap<E, Boolean> map; /** Backing's KeySet. */ private transient Set<E> keySet; - /** Dummy value to associate with the key in the backing map. */ - private static final Object PRESENT = new Object(); - public ConcurrentHashSet() { - map = new ConcurrentHashMap<E, Object>(); + map = new ConcurrentHashMap<E, Boolean>(); keySet = map.keySet(); } public ConcurrentHashSet(int initialCapacity) { - map = new ConcurrentHashMap<E, Object>(initialCapacity); + map = new ConcurrentHashMap<E, Boolean>(initialCapacity); keySet = map.keySet(); } public ConcurrentHashSet(int initialCapacity, float loadFactor, int concurrencyLevel) { - map = new ConcurrentHashMap<E, Object>(initialCapacity, loadFactor, concurrencyLevel); + map = new ConcurrentHashMap<E, Boolean>(initialCapacity, loadFactor, concurrencyLevel); keySet = map.keySet(); } @@ -72,7 +69,7 @@ @Override public boolean add(E e) { - return map.put(e, PRESENT) == null; + return map.put(e, Boolean.TRUE) == null; } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-12-01 09:51:46
|
Revision: 6953 http://jython.svn.sourceforge.net/jython/?rev=6953&view=rev Author: thobes Date: 2009-12-01 09:51:33 +0000 (Tue, 01 Dec 2009) Log Message: ----------- Updated bootstrap script and eclipse build configurations in my sandbox. Modified Paths: -------------- trunk/sandbox/tobias/.classpath trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch trunk/sandbox/tobias/bootstrap Modified: trunk/sandbox/tobias/.classpath =================================================================== --- trunk/sandbox/tobias/.classpath 2009-11-30 23:27:03 UTC (rev 6952) +++ trunk/sandbox/tobias/.classpath 2009-12-01 09:51:33 UTC (rev 6953) @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry excluding="com/ziclix/python/sql/|com/ziclix/python/sql/connect/|com/ziclix/python/sql/handler/|com/ziclix/python/sql/pipe/|com/ziclix/python/sql/pipe/csv/|com/ziclix/python/sql/pipe/db/|com/ziclix/python/sql/procedure/|com/ziclix/python/sql/resource/|com/ziclix/python/sql/util/" kind="src" path="jython/src"/> - <classpathentry kind="src" path="ssa/src"/> <classpathentry excluding="org/python/compiler/advanced/ast/" kind="src" path="compiler/src"/> <classpathentry excluding="org/python/code/CodeTable.java|org/python/code/SpecializedCode.java|org/python/frame/JavaFrameAccessor.java" kind="src" path="util/src"/> <classpathentry kind="src" path="bytecode/src"/> @@ -11,17 +10,20 @@ <classpathentry kind="src" path="jython/build/gensrc"/> <classpathentry kind="src" path="jython/tests/java"/> <classpathentry kind="src" path="compiler/test"/> - <classpathentry kind="src" path="ssa/test"/> + <classpathentry kind="src" path="ssa/src/main/java"/> + <classpathentry kind="src" path="ssa/src/test/java"/> <classpathentry kind="lib" path="jython/Demo/jreload/example.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-2.7.7.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-3.1.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-commons-3.1.jar"/> <classpathentry kind="lib" path="jython/extlibs/asm-util-3.1.jar"/> - <classpathentry kind="lib" path="jython/extlibs/constantine-0.4.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="lib" path="jython/extlibs/constantine.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jffi-Darwin.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jffi.jar"/> + <classpathentry kind="lib" path="jython/extlibs/jnr-posix.jar"/> <classpathentry kind="lib" path="jython/extlibs/cpptasks/cpptasks.jar"/> <classpathentry kind="lib" path="jython/extlibs/jarjar-0.7.jar"/> - <classpathentry kind="lib" path="jython/extlibs/jna-posix.jar"/> - <classpathentry kind="lib" path="jython/extlibs/jna.jar"/> <classpathentry kind="lib" path="jython/extlibs/junit-3.8.2.jar"/> <classpathentry kind="lib" path="jython/extlibs/libreadline-java-0.8.jar"/> <classpathentry kind="lib" path="jython/extlibs/mysql-connector-java-5.1.6.jar"/> @@ -38,7 +40,6 @@ <classpathentry kind="lib" path="jython/Lib/test/classimport_Lib.jar"/> <classpathentry kind="lib" path="jython/Lib/test/classimport.jar"/> <classpathentry kind="lib" path="jython/Lib/test/syspath_import.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.5.0 (Mac OS X default)"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-3.1.3.jar"/> <classpathentry kind="lib" path="jython/extlibs/antlr-runtime-3.1.3.jar"/> Modified: trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch =================================================================== --- trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-11-30 23:27:03 UTC (rev 6952) +++ trunk/sandbox/tobias/.externalToolBuilders/Build preparation.launch 2009-12-01 09:51:33 UTC (rev 6953) @@ -1,28 +1,24 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="brand-version,antlr_gen,"/> <stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="brand-version,antlr_gen,"/> <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> <booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> -<listEntry value="/advanced-compiler/jython/build.xml"/> -</listAttribute> -<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> -<listEntry value="1"/> -</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"/> <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> -<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="advanced-compiler"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/> <mapAttribute key="org.eclipse.ui.externaltools.ATTR_ANT_PROPERTIES"> -<mapEntry key="eclipse.pdebuild.scripts" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/scripts/"/> <mapEntry key="eclipse.running" value="true"/> -<mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> -<mapEntry key="eclipse.home" value="/Library/eclipse"/> <mapEntry key="compile.dir" value="${project_loc:/target/build}"/> +<mapEntry key="eclipse.home" value="/Library/eclipse"/> <mapEntry key="eclipse.pdebuild.templates" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/templates/"/> +<mapEntry key="eclipse.pdebuild.home" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/./"/> +<mapEntry key="eclipse.pdebuild.scripts" value="/Library/eclipse/plugins/org.eclipse.pde.build_3.4.1.R34x_v20080805/scripts/"/> </mapAttribute> -<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/advanced-compiler/jython/build.xml}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/jython-extended/jython/build.xml}"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> <booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> <stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/> Modified: trunk/sandbox/tobias/bootstrap =================================================================== --- trunk/sandbox/tobias/bootstrap 2009-11-30 23:27:03 UTC (rev 6952) +++ trunk/sandbox/tobias/bootstrap 2009-12-01 09:51:33 UTC (rev 6953) @@ -71,7 +71,7 @@ build elif [ 0 -eq 0 ]; then # disable the next branch - it is too slow... - echo -n + false elif [ -n "`which svn`" ]; then # TODO: speed up this comparison - then it can be enabled... BASE_REVISION=`svn info | grep ^Revision` This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2009-11-30 23:27:11
|
Revision: 6952 http://jython.svn.sourceforge.net/jython/?rev=6952&view=rev Author: thobes Date: 2009-11-30 23:27:03 +0000 (Mon, 30 Nov 2009) Log Message: ----------- Added an initial implementation of automatic coercion of function objects to any single method interface. Modified Paths: -------------- trunk/jython/src/org/python/core/PyFunction.java Modified: trunk/jython/src/org/python/core/PyFunction.java =================================================================== --- trunk/jython/src/org/python/core/PyFunction.java 2009-11-29 16:11:42 UTC (rev 6951) +++ trunk/jython/src/org/python/core/PyFunction.java 2009-11-30 23:27:03 UTC (rev 6952) @@ -1,6 +1,10 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + import org.python.expose.ExposedDelete; import org.python.expose.ExposedGet; import org.python.expose.ExposedMethod; @@ -388,6 +392,24 @@ public String toString() { return String.format("<function %s at %s>", __name__, Py.idstr(this)); } + + @Override + public Object __tojava__(Class<?> c) { + // Automatically coerce to single method interfaces + if (c.isInterface() && c.getDeclaredMethods().length == 1) { + return Proxy.newProxyInstance(c.getClassLoader(), new Class[]{c}, new InvocationHandler() { + // XXX: not the most efficient implementation - the invocation handler could be shared + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (args == null || args.length == 0) { + return __call__().__tojava__(method.getReturnType()); + } else { + return __call__(Py.javas2pys(args)).__tojava__(method.getReturnType()); + } + } + }); + } + return super.__tojava__( c ); + } @Override public boolean isMappingType() { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-11-29 16:11:51
|
Revision: 6951 http://jython.svn.sourceforge.net/jython/?rev=6951&view=rev Author: amak Date: 2009-11-29 16:11:42 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Fixing a bug with callable_query_string. Making treatment more strict when no value is supplied. Added unit tests to cover varying scenarios. modjy crashes if any query string parameters are not set with '=' http://bugs.jython.org/issue1507 Modified Paths: -------------- trunk/jython/Lib/modjy/modjy_publish.py trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java Modified: trunk/jython/Lib/modjy/modjy_publish.py =================================================================== --- trunk/jython/Lib/modjy/modjy_publish.py 2009-11-25 08:48:20 UTC (rev 6950) +++ trunk/jython/Lib/modjy/modjy_publish.py 2009-11-29 16:11:42 UTC (rev 6951) @@ -42,11 +42,16 @@ callable_name = self.params['app_callable_name'] if self.params['callable_query_name']: query_string = req.getQueryString() - if query_string and '=' in query_string: + if query_string: for name_val in query_string.split('&'): - name, value = name_val.split('=') + if name_val.find('=') != -1: + name, value = name_val.split('=', 1) + else: + name, value = name_val, '' if name == self.params['callable_query_name']: callable_name = value + else: + callable_name = '' return source_uri, callable_name def get_app_object(self, req, environ): @@ -55,7 +60,7 @@ environ["PATH_INFO"] = path_info environ["PATH_TRANSLATED"] = File(self.app_directory, path_info).getPath() - if self.params['app_import_name'] is not None: + if self.params['app_import_name']: return self.get_app_object_importable(self.params['app_import_name']) else: if self.cache is None: Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java 2009-11-25 08:48:20 UTC (rev 6950) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestAppInvocation.java 2009-11-29 16:11:42 UTC (rev 6951) @@ -68,6 +68,16 @@ return importPath.toString(); } + public void testAppImportCallableNoValue() throws Exception { + appInvocationTestSetUp(); + String importableName = setupAppImport("WSGIHandlerFunction"); + setAppImportable(""); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + public void testAppImportCallable() throws Exception { appInvocationTestSetUp(); String importableName = setupAppImport("WSGIHandlerFunction"); @@ -183,4 +193,66 @@ doGet(); assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); } + + protected void callableQueryAppInvocationTestSetUp() throws Exception { + baseSetUp(); + setRealPath("/test_apps_dir", "test_apps_dir"); + setAppDir("$/test_apps_dir"); + setAppFile("invocation_tests.py"); + // Callable query names should never fall back on app_callable_name + setAppName("should_never_be_called"); + setCallableQueryName(""); + setQueryString(""); + } + + public void testCallableQueryString() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object=valid_callable"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("valid_callable invoked", result); + } + + public void testCallableQueryStringNoParam() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testCallableQueryStringParamNoValue() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testCallableQueryStringParamTwoValues() throws Exception { + // This has to fail, because a python identifier cannot contain an '=' + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object=valid_callable=extra_value"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + + public void testCallableQueryStringParamNonExistentValue() throws Exception { + callableQueryAppInvocationTestSetUp(); + setCallableQueryName("python_object"); + setQueryString("python_object=invalid_callable"); + createServlet(); + doGet(); + String result = getOutput(); + assertEquals("Status code != 500: ServerError, =='" + getStatus() + "'", 500, getStatus()); + } + } Modified: trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java =================================================================== --- trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-11-25 08:48:20 UTC (rev 6950) +++ trunk/jython/tests/modjy/java/com/xhaus/modjy/ModjyTestBase.java 2009-11-29 16:11:42 UTC (rev 6951) @@ -173,6 +173,10 @@ setInitParameter("app_callable_name", app_name); } + public void setCallableQueryName(String query_name) { + setInitParameter("callable_query_name", query_name); + } + public void setAppImportable(String app_path) { setAppDir(""); setAppFile(""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-25 08:48:39
|
Revision: 6950 http://jython.svn.sourceforge.net/jython/?rev=6950&view=rev Author: pjenvey Date: 2009-11-25 08:48:20 +0000 (Wed, 25 Nov 2009) Log Message: ----------- correct the fix for #1297 (r6263) to avoid potentially adding the type's proxy to its mro twice fixes #1504 Modified Paths: -------------- trunk/jython/Lib/test/test_java_subclasses.py trunk/jython/NEWS 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-11-24 02:15:34 UTC (rev 6949) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-11-25 08:48:20 UTC (rev 6950) @@ -10,6 +10,7 @@ from java.util import Date, Hashtable, Vector from java.awt import Color, Component, Dimension, Rectangle +from javax.swing import ComboBoxModel, ListModel from javax.swing.table import AbstractTableModel from org.python.tests import BeanInterface, Callbacker, Coercions, OwnMethodCaller @@ -45,6 +46,15 @@ c.run() self.assertEquals(calls, ["ComparableRunner.compareTo", "Runner.run"]) + def test_inherit_interface_twice(self): + # http://bugs.jython.org/issue1504 + class A(ListModel): pass + class B(A, ComboBoxModel): pass + # Regression caused B's proxy to occur in B's mro twice. That + # caused the declaration of C to fail with an inconsistent mro + class C(B): pass + + class TableModelTest(unittest.TestCase): def test_class_coercion(self): '''Python type instances coerce to a corresponding Java wrapper type in Object.getClass''' @@ -328,3 +338,7 @@ PythonSubclassesTest, AbstractOnSyspathTest, ContextClassloaderTest) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-11-24 02:15:34 UTC (rev 6949) +++ trunk/jython/NEWS 2009-11-25 08:48:20 UTC (rev 6950) @@ -11,6 +11,7 @@ - [ 1499 ] PostgreSQL datahandler should return Decimals instead of floats for NUMERIC/DECIMAL columns - [ 1477 ] os.setpgrp and posix.setpgrp fail with TypeError - [ 1396 ] Assigning os module funcs as class attributes incompatible with CPython + - [ 1504 ] Inheriting twice from the same Java interface causes MRO problems - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-11-24 02:15:34 UTC (rev 6949) +++ trunk/jython/src/org/python/core/PyType.java 2009-11-25 08:48:20 UTC (rev 6950) @@ -891,6 +891,7 @@ PyObject[] computeMro(MROMergeState[] toMerge, List<PyObject> mro) { boolean addedProxy = false; + PyType proxyAsType = javaProxy == null ? null : PyType.fromClass(((Class<?>)javaProxy)); scan : for (int i = 0; i < toMerge.length; i++) { if (toMerge[i].isMerged()) { continue scan; @@ -911,14 +912,16 @@ // This exposes the methods from the proxy generated for this class in addition to // those generated for the superclass while allowing methods from the superclass to // remain visible from the proxies. + mro.add(proxyAsType); addedProxy = true; - mro.add(PyType.fromClass(((Class<?>)javaProxy))); } mro.add(candidate); + // Was that our own proxy? + addedProxy |= candidate == proxyAsType; for (MROMergeState element : toMerge) { element.noteMerged(candidate); } - i = -1;// restart scan + i = -1; // restart scan } for (MROMergeState mergee : toMerge) { if (!mergee.isMerged()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-24 02:15:52
|
Revision: 6949 http://jython.svn.sourceforge.net/jython/?rev=6949&view=rev Author: pjenvey Date: 2009-11-24 02:15:34 +0000 (Tue, 24 Nov 2009) Log Message: ----------- lazily set stat_result's module name to fix pickling on Windows Modified Paths: -------------- trunk/jython/src/org/python/modules/posix/PyStatResult.java Modified: trunk/jython/src/org/python/modules/posix/PyStatResult.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PyStatResult.java 2009-11-22 22:09:52 UTC (rev 6948) +++ trunk/jython/src/org/python/modules/posix/PyStatResult.java 2009-11-24 02:15:34 UTC (rev 6949) @@ -17,11 +17,16 @@ import org.python.expose.ExposedType; import org.python.expose.MethodType; -@ExposedType(name = "posix.stat_result", isBaseType = false) +@ExposedType(name = "stat_result", isBaseType = false) public class PyStatResult extends PyTuple { public static final PyType TYPE = PyType.fromClass(PyStatResult.class); + static { + // Can only determine the module name during runtime + TYPE.setName(PosixModule.getOSName() + "." + TYPE.fastGetName()); + } + @ExposedGet public PyObject st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-22 22:10:11
|
Revision: 6948 http://jython.svn.sourceforge.net/jython/?rev=6948&view=rev Author: pjenvey Date: 2009-11-22 22:09:52 +0000 (Sun, 22 Nov 2009) Log Message: ----------- finally move the remaining functions to PosixModule, hide posix's __docs__ fixes #1396 Modified Paths: -------------- trunk/jython/Lib/os.py trunk/jython/NEWS trunk/jython/src/org/python/modules/Setup.java trunk/jython/src/org/python/modules/posix/PosixModule.java Removed Paths: ------------- trunk/jython/Lib/nt.py trunk/jython/Lib/posix.py Deleted: trunk/jython/Lib/nt.py =================================================================== --- trunk/jython/Lib/nt.py 2009-11-22 20:24:31 UTC (rev 6947) +++ trunk/jython/Lib/nt.py 2009-11-22 22:09:52 UTC (rev 6948) @@ -1,2 +0,0 @@ -from posix import __all__ -from posix import * Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2009-11-22 20:24:31 UTC (rev 6947) +++ trunk/jython/Lib/os.py 2009-11-22 22:09:52 UTC (rev 6948) @@ -39,7 +39,7 @@ return [n for n in dir(module) if n[0] != '_'] name = 'java' -if '_posix' in _names: +if 'posix' in _names: _name = 'posix' linesep = '\n' from posix import * @@ -53,7 +53,7 @@ __all__.extend(_get_exports_list(posix)) del posix -elif '_nt' in _names: +elif 'nt' in _names: _name = 'nt' linesep = '\r\n' from nt import * @@ -67,7 +67,7 @@ __all__.extend(_get_exports_list(nt)) del nt -elif '_os2' in _names: +elif 'os2' in _names: _name = 'os2' linesep = '\r\n' from os2 import * @@ -85,7 +85,7 @@ __all__.extend(_get_exports_list(os2)) del os2 -elif '_ce' in _names: +elif 'ce' in _names: _name = 'ce' linesep = '\r\n' from ce import * @@ -100,7 +100,7 @@ __all__.extend(_get_exports_list(ce)) del ce -elif '_riscos' in _names: +elif 'riscos' in _names: _name = 'riscos' linesep = '\n' from riscos import * @@ -663,3 +663,42 @@ bytes += read(_urandomfd, n - len(bytes)) close(_urandomfd) return bytes + +# Supply os.popen() +def popen(cmd, mode='r', bufsize=-1): + """popen(command [, mode='r' [, bufsize]]) -> pipe + + Open a pipe to/from a command returning a file object. + """ + if not isinstance(cmd, (str, unicode)): + raise TypeError('invalid cmd type (%s, expected string)' % type(cmd)) + if mode not in ('r', 'w'): + raise ValueError("invalid mode %r" % mode) + import subprocess + if mode == 'r': + proc = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + stdout=subprocess.PIPE) + return _wrap_close(proc.stdout, proc) + elif mode == 'w': + proc = subprocess.Popen(cmd, bufsize=bufsize, shell=True, + stdin=subprocess.PIPE) + return _wrap_close(proc.stdin, proc) + +# Helper for popen() -- a proxy for a file whose close waits for the process +class _wrap_close(object): + def __init__(self, stream, proc): + self._stream = stream + self._proc = proc + def close(self): + self._stream.close() + returncode = self._proc.wait() + if returncode == 0: + return None + if _name == 'nt': + return returncode + else: + return returncode + def __getattr__(self, name): + return getattr(self._stream, name) + def __iter__(self): + return iter(self._stream) Deleted: trunk/jython/Lib/posix.py =================================================================== --- trunk/jython/Lib/posix.py 2009-11-22 20:24:31 UTC (rev 6947) +++ trunk/jython/Lib/posix.py 2009-11-22 22:09:52 UTC (rev 6948) @@ -1,209 +0,0 @@ -""" -This module provides access to operating system functionality that is -standardized by the C Standard and the POSIX standard (a thinly -disguised Unix interface). Refer to the library manual and -corresponding Unix manual entries for more information on calls. -""" -try: - import _posix - from _posix import * -except: - import _nt as _posix - from _nt import * -import errno -import sys - -__all__ = [name for name in _posix.__all__ if not name.startswith('__doc__')] -__all__.extend(['getenv', 'isatty', 'popen', 'putenv', - 'rename', 'rmdir', 'system', - 'unsetenv', 'urandom', 'utime']) - -_name = _posix.__name__[1:] - -# Java class representing the size of a time_t. internal use, lazily set -_time_t = None - -# For urandom -urandom_source = None - -def rename(path, newpath): - """rename(old, new) - - Rename a file or directory. - """ - from java.io import File - if not File(sys.getPath(path)).renameTo(File(sys.getPath(newpath))): - raise OSError(0, "couldn't rename file", path) - -def rmdir(path): - """rmdir(path) - - Remove a directory.""" - from java.io import File - f = File(sys.getPath(path)) - if not f.exists(): - raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) - elif not f.isDirectory(): - raise OSError(errno.ENOTDIR, strerror(errno.ENOTDIR), path) - elif not f.delete(): - raise OSError(0, "couldn't delete directory", path) - -def utime(path, times): - """utime(path, (atime, mtime)) - utime(path, None) - - Set the access and modification time of the file to the given values. - If the second form is used, set the access and modification times to the - current time. - - Due to Java limitations, on some platforms only the modification time - may be changed. - """ - if path is None: - raise TypeError('path must be specified, not None') - - if times is None: - atimeval = mtimeval = None - elif isinstance(times, tuple) and len(times) == 2: - atimeval = _to_timeval(times[0]) - mtimeval = _to_timeval(times[1]) - else: - raise TypeError('utime() arg 2 must be a tuple (atime, mtime)') - - _posix_impl.utimes(path, atimeval, mtimeval) - -def _to_timeval(seconds): - """Convert seconds (with a fraction) from epoch to a 2 item tuple of - seconds, microseconds from epoch as longs - """ - global _time_t - if _time_t is None: - from java.lang import Integer, Long - try: - 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 - - try: - floor = long(seconds) - except TypeError: - raise TypeError('an integer is required') - if not _time_t.MIN_VALUE <= floor <= _time_t.MAX_VALUE: - raise OverflowError('long int too large to convert to int') - - # usec can't exceed 1000000 - usec = long((seconds - floor) * 1e6) - if usec < 0: - # If rounding gave us a negative number, truncate - usec = 0 - return floor, usec - -def system(command): - """system(command) -> exit_status - - Execute the command (a string) in a subshell. - """ - import subprocess - return subprocess.call(command, shell=True) - -def popen(command, mode='r', bufsize=-1): - """popen(command [, mode='r' [, bufsize]]) -> pipe - - Open a pipe to/from a command returning a file object. - """ - import subprocess - if mode == 'r': - proc = subprocess.Popen(command, bufsize=bufsize, shell=True, - stdout=subprocess.PIPE) - return _wrap_close(proc.stdout, proc) - elif mode == 'w': - proc = subprocess.Popen(command, bufsize=bufsize, shell=True, - stdin=subprocess.PIPE) - return _wrap_close(proc.stdin, proc) - else: - raise OSError(errno.EINVAL, strerror(errno.EINVAL)) - -# Helper for popen() -- a proxy for a file whose close waits for the process -class _wrap_close(object): - def __init__(self, stream, proc): - self._stream = stream - self._proc = proc - def close(self): - self._stream.close() - returncode = self._proc.wait() - if returncode == 0: - return None - if _name == 'nt': - return returncode - else: - return returncode - def __getattr__(self, name): - return getattr(self._stream, name) - def __iter__(self): - return iter(self._stream) - -def putenv(key, value): - """putenv(key, value) - - Change or add an environment variable. - """ - # XXX: put/unset/getenv should probably be deprecated - import os - os.environ[key] = value - -def unsetenv(key): - """unsetenv(key) - - Delete an environment variable. - """ - import os - try: - del os.environ[key] - except KeyError: - pass - -def getenv(key, default=None): - """Get an environment variable, return None if it doesn't exist. - The optional second argument can specify an alternate default.""" - import os - return os.environ.get(key, default) - -def isatty(fileno): - """isatty(fd) -> bool - - Return True if the file descriptor 'fd' is an open file descriptor - connected to the slave end of a terminal.""" - from java.io import FileDescriptor - - if isinstance(fileno, int): - if fileno == 0: - fd = getattr(FileDescriptor, 'in') - elif fileno == 1: - fd = FileDescriptor.out - elif fileno == 2: - fd = FileDescriptor.err - else: - raise NotImplemented('Integer file descriptor compatibility only ' - 'available for stdin, stdout and stderr (0-2)') - - return _posix_impl.isatty(fd) - - if isinstance(fileno, FileDescriptor): - return _posix_impl.isatty(fileno) - - from org.python.core.io import IOBase - if not isinstance(fileno, IOBase): - raise TypeError('a file descriptor is required') - - return fileno.isatty() - -def urandom(n): - global urandom_source - if urandom_source is None: - from java.security import SecureRandom - urandom_source = SecureRandom() - import jarray - buffer = jarray.zeros(n, 'b') - urandom_source.nextBytes(buffer) - return buffer.tostring() Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-11-22 20:24:31 UTC (rev 6947) +++ trunk/jython/NEWS 2009-11-22 22:09:52 UTC (rev 6948) @@ -10,6 +10,7 @@ - [ 1496 ] fix os.listdir errno for non-existing dirs - [ 1499 ] PostgreSQL datahandler should return Decimals instead of floats for NUMERIC/DECIMAL columns - [ 1477 ] os.setpgrp and posix.setpgrp fail with TypeError + - [ 1396 ] Assigning os module funcs as class attributes incompatible with CPython - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/org/python/modules/Setup.java =================================================================== --- trunk/jython/src/org/python/modules/Setup.java 2009-11-22 20:24:31 UTC (rev 6947) +++ trunk/jython/src/org/python/modules/Setup.java 2009-11-22 22:09:52 UTC (rev 6948) @@ -59,6 +59,6 @@ "_ast:org.python.antlr.ast.AstModule", "_marshal", "_threading:org.python.modules._threading._threading", - "_" + PosixModule.getOSName() + ":org.python.modules.posix.PosixModule" + PosixModule.getOSName() + ":org.python.modules.posix.PosixModule" }; } Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-11-22 20:24:31 UTC (rev 6947) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-11-22 22:09:52 UTC (rev 6948) @@ -5,6 +5,7 @@ import com.kenai.constantine.platform.Errno; import java.io.File; +import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; @@ -12,12 +13,15 @@ import java.nio.channels.Channel; import java.nio.channels.ClosedChannelException; import java.nio.channels.FileChannel; +import java.security.SecureRandom; +import java.util.Iterator; import java.util.Map; import org.jruby.ext.posix.FileStat; import org.jruby.ext.posix.JavaPOSIX; import org.jruby.ext.posix.POSIX; import org.jruby.ext.posix.POSIXFactory; +import org.jruby.ext.posix.util.Platform; import org.python.core.ClassDictInit; import org.python.core.Py; @@ -25,12 +29,15 @@ import org.python.core.PyDictionary; import org.python.core.PyException; import org.python.core.PyFile; +import org.python.core.PyFloat; +import org.python.core.PyInteger; import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyTuple; import org.python.core.ThreadState; import org.python.core.imp; +import org.python.core.io.IOBase; import org.python.core.io.FileDescriptors; import org.python.core.io.FileIO; import org.python.core.io.RawIOBase; @@ -38,13 +45,7 @@ import org.python.core.util.StringUtil; /** - * The underlying _posix or _nt module, named depending on the platform. - * - * This currently contains only some of the basics of the posix/nt modules (which are - * implemented in Python), most importantly things like PythonPOSIXHandler that are slower - * to instantiate and thus would affect startup time. - * - * Eventually more if not all of the pure Python module should end up here. + * The posix/nt module, depending on the platform. */ public class PosixModule implements ClassDictInit { @@ -79,6 +80,11 @@ /** os.path.realpath function for use by chdir. Lazily loaded. */ private static PyObject realpath; + /** Lazily initialzed singleton source for urandom. */ + private static class UrandomSource { + static final SecureRandom INSTANCE = new SecureRandom(); + } + public static void classDictInit(PyObject dict) { // only expose the open flags we support dict.__setitem__("O_RDONLY", Py.newInteger(O_RDONLY)); @@ -116,9 +122,18 @@ dict.__setitem__("getOSName", null); dict.__setitem__("badFD", null); - dict.__setitem__("__all__", dict.invoke("keys")); + // Hide __doc__s + PyList keys = (PyList)dict.invoke("keys"); + for (Iterator<?> it = keys.listIterator(); it.hasNext();) { + String key = (String)it.next(); + if (key.startsWith("__doc__")) { + it.remove(); + dict.__setitem__(key, null); + } + } + dict.__setitem__("__all__", keys); - dict.__setitem__("__name__", new PyString("_" + os.getModuleName())); + dict.__setitem__("__name__", new PyString(os.getModuleName())); dict.__setitem__("__doc__", __doc__); } @@ -377,6 +392,42 @@ return posix.getpgrp(); } + public static PyString __doc__isatty = new PyString( + "isatty(fd) -> bool\n\n" + + "Return True if the file descriptor 'fd' is an open file descriptor\n" + + "connected to the slave end of a terminal."); + public static boolean isatty(PyObject fdObj) { + if (fdObj instanceof PyInteger) { + FileDescriptor fd; + switch (fdObj.asInt()) { + case 0: + fd = FileDescriptor.in; + break; + case 1: + fd = FileDescriptor.out; + break; + case 2: + fd = FileDescriptor.err; + break; + default: + throw Py.NotImplementedError("Integer file descriptor compatibility only " + + "available for stdin, stdout and stderr (0-2)"); + } + return posix.isatty(fd); + } + + Object tojava = fdObj.__tojava__(FileDescriptor.class); + if (tojava != Py.NoConversion) { + return posix.isatty((FileDescriptor)tojava); + } + + tojava = fdObj.__tojava__(IOBase.class); + if (tojava == Py.NoConversion) { + throw Py.TypeError("a file descriptor is required"); + } + return ((IOBase)tojava).isatty(); + } + public static PyString __doc__kill = new PyString( "kill(pid, sig)\n\n" + "Kill a process with a signal."); @@ -534,6 +585,26 @@ return new FileIO(path, fileIOMode); } + public static PyString __doc__popen = new PyString( + "popen(command [, mode='r' [, bufsize]]) -> pipe\n\n" + + "Open a pipe to/from a command returning a file object."); + public static PyObject popen(PyObject[] args, String[] kwds) { + // XXX: popen lives in posix in 2.x, but moves to os in 3.x. It's easier for us to + // keep it in os + // import os; return os.popen(*args, **kwargs) + return imp.load("os").__getattr__("popen").__call__(args, kwds); + } + + public static PyString __doc__putenv = new PyString( + "putenv(key, value)\n\n" + + "Change or add an environment variable."); + public static void putenv(String key, String value) { + // XXX: Consider deprecating putenv/unsetenv + // import os; os.environ[key] = value + PyObject environ = imp.load("os").__getattr__("environ"); + environ.__setitem__(key, new PyString(value)); + } + public static PyString __doc__read = new PyString( "read(fd, buffersize) -> string\n\n" + "Read a file descriptor."); @@ -564,6 +635,32 @@ unlink(path); } + public static PyString __doc__rename = new PyString( + "rename(old, new)\n\n" + + "Rename a file or directory."); + public static void rename(String oldpath, String newpath) { + if (!new RelativeFile(oldpath).renameTo(new RelativeFile(newpath))) { + PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't rename file")); + throw new PyException(Py.OSError, args); + } + } + + public static PyString __doc__rmdir = new PyString( + "rmdir(path)\n\n" + + "Remove a directory."); + public static void rmdir(String path) { + File file = new RelativeFile(path); + if (!file.exists()) { + throw Py.OSError(Errno.ENOENT, path); + } else if (!file.isDirectory()) { + throw Py.OSError(Errno.ENOTDIR, path); + } else if (!file.delete()) { + PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't delete directory"), + new PyString(path)); + throw new PyException(Py.OSError, args); + } + } + public static PyString __doc__setpgrp = new PyString( "setpgrp()\n\n" + "Make this process a session leader."); @@ -610,6 +707,15 @@ posix.symlink(src, absolutePath(dst)); } + public static PyString __doc__system = new PyString( + "system(command) -> exit_status\n\n" + + "Execute the command (a string) in a subshell."); + public static void system(PyObject command) { + // import subprocess; subprocess.call(command, shell=True) + imp.load("subprocess").invoke("call", command, new PyObject[] {Py.True}, + new String[] {"shell"}); + } + public static PyString __doc__umask = new PyString( "umask(new_mask) -> old_mask\n\n" + "Set the current numeric umask and return the previous umask."); @@ -638,6 +744,47 @@ } } + public static PyString __doc__utime = new PyString( + "utime(path, (atime, mtime))\n" + + "utime(path, None)\n\n" + + "Set the access and modified time of the file to the given values. If the\n" + + "second form is used, set the access and modified times to the current time."); + public static void utime(String path, PyObject times) { + long[] atimeval; + long[] mtimeval; + + if (times == Py.None) { + atimeval = mtimeval = null; + } else if (times instanceof PyTuple && times.__len__() == 2) { + atimeval = extractTimeval(times.__getitem__(0)); + mtimeval = extractTimeval(times.__getitem__(1)); + } else { + throw Py.TypeError("utime() arg 2 must be a tuple (atime, mtime)"); + } + posix.utimes(absolutePath(path), atimeval, mtimeval); + } + + /** + * Convert seconds (with a possible fraction) from epoch to a 2 item array of seconds, + * microseconds from epoch as longs. + * + * @param seconds a PyObject number + * @return a 2 item long[] + */ + private static long[] extractTimeval(PyObject seconds) { + long[] timeval = new long[] {Platform.IS_32_BIT ? seconds.asInt() : seconds.asLong(), 0L}; + if (seconds instanceof PyFloat) { + // can't exceed 1000000 + long usec = (long)((seconds.asDouble() % 1.0) * 1e6); + if (usec < 0) { + // If rounding gave us a negative number, truncate + usec = 0; + } + timeval[1] = usec; + } + return timeval; + } + public static PyString __doc__wait = new PyString( "wait() -> (pid, status)\n\n" + "Wait for completion of a child process."); @@ -674,6 +821,30 @@ } } + public static PyString __doc__unsetenv = new PyString( + "unsetenv(key)\n\n" + + "Delete an environment variable."); + public static void unsetenv(String key) { + // import os; try: del os.environ[key]; except KeyError: pass + PyObject environ = imp.load("os").__getattr__("environ"); + try { + environ.__delitem__(key); + } catch (PyException pye) { + if (!pye.match(Py.KeyError)) { + throw pye; + } + } + } + + public static PyString __doc__urandom = new PyString( + "urandom(n) -> str\n\n" + + "Return a string of n random bytes suitable for cryptographic use."); + public static PyObject urandom(int n) { + byte[] buf = new byte[n]; + UrandomSource.INSTANCE.nextBytes(buf); + return new PyString(StringUtil.fromBytes(buf)); + } + /** * Helper function for the subprocess module, returns the potential shell commands for * this OS. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-22 20:24:52
|
Revision: 6947 http://jython.svn.sourceforge.net/jython/?rev=6947&view=rev Author: pjenvey Date: 2009-11-22 20:24:31 +0000 (Sun, 22 Nov 2009) Log Message: ----------- o add PyObject.asLong, remove asLong(int) uses o fix PyString not overriding asDouble o asDouble already __float__s for us in Condition.wait Modified Paths: -------------- trunk/jython/Lib/test/test_builtin_jy.py trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/PyInteger.java trunk/jython/src/org/python/core/PyLong.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyString.java trunk/jython/src/org/python/modules/_threading/Condition.java trunk/jython/src/org/python/modules/random/PyRandom.java Modified: trunk/jython/Lib/test/test_builtin_jy.py =================================================================== --- trunk/jython/Lib/test/test_builtin_jy.py 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/Lib/test/test_builtin_jy.py 2009-11-22 20:24:31 UTC (rev 6947) @@ -136,6 +136,8 @@ def test_round_non_float(self): self.assertEqual(round(self.Foo(), 1), 3.1) + # 2.5/2.5.1 regression + self.assertRaises(TypeError, round, '1.5') class ExecEvalTest(unittest.TestCase): Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/core/PyFile.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -464,11 +464,7 @@ file_truncate(); return; } - try { - file_truncate(position.asLong(0)); - } catch (PyObject.ConversionException ce) { - throw Py.TypeError("an integer is required"); - } + file_truncate(position.asLong()); } final synchronized void file_truncate(long position) { Modified: trunk/jython/src/org/python/core/PyInteger.java =================================================================== --- trunk/jython/src/org/python/core/PyInteger.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/core/PyInteger.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -854,4 +854,9 @@ public int asInt() { return getValue(); } + + @Override + public long asLong() { + return getValue(); + } } Modified: trunk/jython/src/org/python/core/PyLong.java =================================================================== --- trunk/jython/src/org/python/core/PyLong.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/core/PyLong.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -199,7 +199,7 @@ } public long asLong(int index) { - return getLong(Long.MIN_VALUE, Long.MAX_VALUE, "long too big to convert"); + return asLong(); } public int asInt(int index) { @@ -213,6 +213,11 @@ "long int too large to convert to int"); } + @Override + public long asLong() { + return getLong(Long.MIN_VALUE, Long.MAX_VALUE, "long too big to convert"); + } + public Object __tojava__(Class c) { try { if (c == Byte.TYPE || c == Byte.class) { Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/core/PyObject.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -4006,6 +4006,11 @@ throw new ConversionException(index); } + /** + * Convert this object into an int. Throws a PyException on failure. + * + * @return an int value + */ public int asInt() { PyObject intObj; try { @@ -4016,7 +4021,7 @@ } throw pye; } - if (!(intObj instanceof PyInteger) && !(intObj instanceof PyLong)) { + if (!(intObj instanceof PyInteger || intObj instanceof PyLong)) { // Shouldn't happen except with buggy builtin types throw Py.TypeError("nb_int should return int object"); } @@ -4028,6 +4033,28 @@ } /** + * Convert this object longo an long. Throws a PyException on failure. + * + * @return an long value + */ + public long asLong() { + PyObject longObj; + try { + longObj = __long__(); + } catch (PyException pye) { + if (pye.match(Py.AttributeError)) { + throw Py.TypeError("an integer is required"); + } + throw pye; + } + if (!(longObj instanceof PyLong)) { + // Shouldn't happen except with buggy builtin types + throw Py.TypeError("integer conversion failed"); + } + return longObj.asLong(); + } + + /** * Convert this object into a double. Throws a PyException on failure. * * @return a double value Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/core/PyString.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -2459,13 +2459,29 @@ @Override public int asInt() { - // We have to override asInt because we override __int__, but generally don't want - // implicit atoi conversions for the base types. blah + // We have to override asInt/Long/Double because we override __int/long/float__, + // but generally don't want implicit atoi conversions for the base types. blah + asNumberCheck("__int__", "an integer"); + return super.asInt(); + } + + @Override + public long asLong() { + asNumberCheck("__long__", "an integer"); + return super.asLong(); + } + + @Override + public double asDouble() { + asNumberCheck("__float__", "a float"); + return super.asDouble(); + } + + private void asNumberCheck(String methodName, String description) { PyType type = getType(); - if (type == PyString.TYPE || type == PyUnicode.TYPE || type.lookup("__int__") == null) { - throw Py.TypeError("an integer is required"); + if (type == PyString.TYPE || type == PyUnicode.TYPE || type.lookup(methodName) == null) { + throw Py.TypeError(description + " is required"); } - return super.asInt(); } public String asName(int index) throws PyObject.ConversionException { Modified: trunk/jython/src/org/python/modules/_threading/Condition.java =================================================================== --- trunk/jython/src/org/python/modules/_threading/Condition.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/modules/_threading/Condition.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -86,7 +86,7 @@ if (timeout == Py.None) { _condition.await(); } else { - long nanos = (long) (timeout.__float__().asDouble() * 1e9); + long nanos = (long) (timeout.asDouble() * 1e9); _condition.awaitNanos(nanos); } } Modified: trunk/jython/src/org/python/modules/random/PyRandom.java =================================================================== --- trunk/jython/src/org/python/modules/random/PyRandom.java 2009-11-17 16:16:14 UTC (rev 6946) +++ trunk/jython/src/org/python/modules/random/PyRandom.java 2009-11-22 20:24:31 UTC (rev 6947) @@ -19,7 +19,6 @@ import org.python.expose.ExposedNew; import org.python.expose.ExposedType; - @ExposedType(name = "_random.Random") public class PyRandom extends PyObject { @@ -41,46 +40,39 @@ * uses the value, else it uses the hash function of PyObject */ @ExposedMethod(defaults = "null") - final PyObject Random_seed(PyObject seed) { + final void Random_seed(PyObject seed) { + long n; if (seed == null) { seed = new PyLong(System.currentTimeMillis()); } if (seed instanceof PyLong) { PyLong max = new PyLong(Long.MAX_VALUE); - PyLong seed_modulus = (PyLong)(seed.__mod__(max)); - this.javaRandom.setSeed(seed_modulus.asLong(0)); + n = seed.__mod__(max).asLong(); } else if (seed instanceof PyInteger) { - this.javaRandom.setSeed(((PyInteger)seed).getValue()); + n = seed.asLong(); } else { - this.javaRandom.setSeed(seed.hashCode()); + n = seed.hashCode(); } - - // duplicating the _randommodule.c::init_by_array return - return Py.None; + this.javaRandom.setSeed(n); } @ExposedNew @ExposedMethod - public void Random___init__(PyObject[] args, String[] keywords) {} + final void Random___init__(PyObject[] args, String[] keywords) {} @ExposedMethod - public PyObject Random_jumpahead(PyObject arg0) { - long inc; - if (arg0 instanceof PyLong) { - inc=((PyLong)arg0).asLong(0); - } else if (arg0 instanceof PyInteger) { - inc=((PyInteger)arg0).getValue(); - } else { - throw Py.TypeError("jumpahead requires an integer"); + final void Random_jumpahead(PyObject arg0) { + if (!(arg0 instanceof PyInteger || arg0 instanceof PyLong)) { + throw Py.TypeError(String.format("jumpahead requires an integer, not '%s'", + arg0.getType().fastGetName())); } - for(int i=0;i<inc;i++) { + for (long i = arg0.asLong(); i > 0; i--) { this.javaRandom.nextInt(); } - return Py.None; } @ExposedMethod - public PyObject Random_setstate(PyObject arg0) { + final void Random_setstate(PyObject arg0) { if (!(arg0 instanceof PyTuple)) { throw Py.TypeError("state vector must be a tuple"); } @@ -104,13 +96,10 @@ } catch (ClassNotFoundException e) { throw Py.SystemError("state vector invalid: "+e.getMessage()); } - - // duplicating the _randommodule.c::random_setstate return - return Py.None; } @ExposedMethod - public PyObject Random_getstate() { + final PyObject Random_getstate() { try { ByteArrayOutputStream bout=new ByteArrayOutputStream(); ObjectOutputStream oout=new ObjectOutputStream(bout); @@ -134,7 +123,7 @@ * problems. */ @ExposedMethod - public PyObject Random_random() { + final PyObject Random_random() { long a=this.javaRandom.nextInt()>>>5; long b=this.javaRandom.nextInt()>>>6; double ret=(a*67108864.0+b)*(1.0/9007199254740992.0); @@ -142,7 +131,7 @@ } @ExposedMethod - public PyLong Random_getrandbits(int k) { + final PyLong Random_getrandbits(int k) { return new PyLong(new BigInteger(k, javaRandom)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fi...@us...> - 2009-11-17 16:16:21
|
Revision: 6946 http://jython.svn.sourceforge.net/jython/?rev=6946&view=rev Author: fijal Date: 2009-11-17 16:16:14 +0000 (Tue, 17 Nov 2009) Log Message: ----------- This seems to be not necessary any more (Jim Baker agrees btw) Removed Paths: ------------- trunk/CVSROOT/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-16 01:58:12
|
Revision: 6945 http://jython.svn.sourceforge.net/jython/?rev=6945&view=rev Author: pjenvey Date: 2009-11-16 01:58:00 +0000 (Mon, 16 Nov 2009) Log Message: ----------- fix chown's visibility and posix.setpgrp and port the remaining posix calls to PosixModule fixes #1477 Modified Paths: -------------- trunk/jython/Lib/posix.py trunk/jython/NEWS trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/Lib/posix.py =================================================================== --- trunk/jython/Lib/posix.py 2009-11-15 05:18:17 UTC (rev 6944) +++ trunk/jython/Lib/posix.py 2009-11-16 01:58:00 UTC (rev 6945) @@ -14,7 +14,7 @@ import sys __all__ = [name for name in _posix.__all__ if not name.startswith('__doc__')] -__all__.extend(['fsync', 'getenv', 'isatty', 'popen', 'putenv', +__all__.extend(['getenv', 'isatty', 'popen', 'putenv', 'rename', 'rmdir', 'system', 'unsetenv', 'urandom', 'utime']) @@ -169,153 +169,6 @@ import os return os.environ.get(key, default) -if _name == 'posix': - def symlink(src, dst): - """symlink(src, dst) - - Create a symbolic link pointing to src named dst. - """ - _posix_impl.symlink(src, sys.getPath(dst)) - - def readlink(path): - """readlink(path) -> path - - Return a string representing the path to which the symbolic link - points. - """ - return _posix_impl.readlink(sys.getPath(path)) - - def getegid(): - """getegid() -> egid - - Return the current process's effective group id.""" - return _posix_impl.getegid() - - def geteuid(): - """geteuid() -> euid - - Return the current process's effective user id.""" - return _posix_impl.geteuid() - - def getgid(): - """getgid() -> gid - - Return the current process's group id.""" - return _posix_impl.getgid() - - def getlogin(): - """getlogin() -> string - - Return the actual login name.""" - return _posix_impl.getlogin() - - def getpgrp(): - """getpgrp() -> pgrp - - Return the current process group id.""" - return _posix_impl.getpgrp() - - def getppid(): - """getppid() -> ppid - - Return the parent's process id.""" - return _posix_impl.getppid() - - def getuid(): - """getuid() -> uid - - Return the current process's user id.""" - return _posix_impl.getuid() - - def setpgrp(): - """setpgrp() - - Make this process a session leader.""" - return _posix_impl.setpgrp() - - def setsid(): - """setsid() - - Call the system call setsid().""" - return _posix_impl.setsid() - - # This implementation of fork partially works on - # Jython. Diagnosing what works, what doesn't, and fixing it is - # left for another day. In any event, this would only be - # marginally useful. - - # def fork(): - # """fork() -> pid - # - # Fork a child process. - # Return 0 to child process and PID of child to parent process.""" - # return _posix_impl.fork() - - def kill(pid, sig): - """kill(pid, sig) - - Kill a process with a signal.""" - return _posix_impl.kill(pid, sig) - - def wait(): - """wait() -> (pid, status) - - Wait for completion of a child process.""" - import jarray - status = jarray.zeros(1, 'i') - res_pid = _posix_impl.wait(status) - if res_pid == -1: - raise OSError(status[0], strerror(status[0])) - return res_pid, status[0] - - def waitpid(pid, options): - """waitpid(pid, options) -> (pid, status) - - Wait for completion of a given child process.""" - import jarray - status = jarray.zeros(1, 'i') - res_pid = _posix_impl.waitpid(pid, status, options) - if res_pid == -1: - raise OSError(status[0], strerror(status[0])) - return res_pid, status[0] - - def fdatasync(fd): - """fdatasync(fildes) - - force write of file with filedescriptor to disk. - does not force update of metadata. - """ - _fsync(fd, False) - - __all__.extend(['symlink', 'readlink', 'getegid', 'geteuid', - 'getgid', 'getlogin', 'getpgrp', 'getppid', 'getuid', - 'setpgrp', 'setsid', 'kill', 'wait', 'waitpid', - 'fdatasync']) - -def fsync(fd): - """fsync(fildes) - - force write of file with filedescriptor to disk. - """ - _fsync(fd, True) - -def _fsync(fd, metadata): - """Internal fsync impl""" - from org.python.core.io import FileDescriptors - rawio = FileDescriptors.get(fd) - rawio.checkClosed() - - from java.io import IOException - from java.nio.channels import FileChannel - channel = rawio.getChannel() - if not isinstance(channel, FileChannel): - raise OSError(errno.EINVAL, strerror(errno.EINVAL)) - - try: - channel.force(metadata) - except IOException, ioe: - raise OSError(ioe) - def isatty(fileno): """isatty(fd) -> bool Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-11-15 05:18:17 UTC (rev 6944) +++ trunk/jython/NEWS 2009-11-16 01:58:00 UTC (rev 6945) @@ -9,6 +9,7 @@ - [ 1470 ] os.mkdir Errno difference from cpython - [ 1496 ] fix os.listdir errno for non-existing dirs - [ 1499 ] PostgreSQL datahandler should return Decimals instead of floats for NUMERIC/DECIMAL columns + - [ 1477 ] os.setpgrp and posix.setpgrp fail with TypeError - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-11-15 05:18:17 UTC (rev 6944) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-11-16 01:58:00 UTC (rev 6945) @@ -9,6 +9,9 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; +import java.nio.channels.Channel; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.FileChannel; import java.util.Map; import org.jruby.ext.posix.FileStat; @@ -199,7 +202,7 @@ public static PyString __doc__chown = new PyString( "chown(path, uid, gid)\n\n" + "Change the owner and group id of path to the numeric uid and gid."); - @Hide(OS.POSIX) + @Hide(OS.NT) public static void chown(String path, int uid, int gid) { if (posix.chown(absolutePath(path), uid, gid) < 0) { throw errorFromErrno(path); @@ -248,6 +251,43 @@ } } + public static PyString __doc__fdatasync = new PyString( + "fdatasync(fildes)\n\n" + + "force write of file with filedescriptor to disk.\n" + + "does not force update of metadata."); + @Hide(OS.NT) + public static void fdatasync(PyObject fd) { + fsync(fd, false); + } + + public static PyString __doc__fsync = new PyString( + "fsync(fildes)\n\n" + + "force write of file with filedescriptor to disk."); + public static void fsync(PyObject fd) { + fsync(fd, true); + } + + /** + * Internal fsync implementation. + */ + private static void fsync(PyObject fd, boolean metadata) { + RawIOBase rawIO = FileDescriptors.get(fd); + rawIO.checkClosed(); + Channel channel = rawIO.getChannel(); + if (!(channel instanceof FileChannel)) { + throw Py.OSError(Errno.EINVAL); + } + + try { + ((FileChannel)channel).force(metadata); + } catch (ClosedChannelException cce) { + // In the rare case it's closed but the rawIO wasn't + throw Py.ValueError("I/O operation on closed file"); + } catch (IOException ioe) { + throw Py.OSError(ioe); + } + } + public static PyString __doc__ftruncate = new PyString( "ftruncate(fd, length)\n\n" + "Truncate a file to a specified length."); @@ -273,6 +313,54 @@ return Py.newUnicode(Py.getSystemState().getCurrentWorkingDir()); } + public static PyString __doc__getegid = new PyString( + "getegid() -> egid\n\n" + + "Return the current process's effective group id."); + @Hide(OS.NT) + public static int getegid() { + return posix.getegid(); + } + + public static PyString __doc__geteuid = new PyString( + "geteuid() -> euid\n\n" + + "Return the current process's effective user id."); + @Hide(OS.NT) + public static int geteuid() { + return posix.geteuid(); + } + + public static PyString __doc__getgid = new PyString( + "getgid() -> gid\n\n" + + "Return the current process's group id."); + @Hide(OS.NT) + public static int getgid() { + return posix.getgid(); + } + + public static PyString __doc__getlogin = new PyString( + "getlogin() -> string\n\n" + + "Return the actual login name."); + @Hide(OS.NT) + public static PyObject getlogin() { + return new PyString(posix.getlogin()); + } + + public static PyString __doc__getppid = new PyString( + "getppid() -> ppid\n\n" + + "Return the parent's process id."); + @Hide(OS.NT) + public static int getppid() { + return posix.getppid(); + } + + public static PyString __doc__getuid = new PyString( + "getuid() -> uid\n\n" + + "Return the current process's user id."); + @Hide(OS.NT) + public static int getuid() { + return posix.getuid(); + } + public static PyString __doc__getpid = new PyString( "getpid() -> pid\n\n" + "Return the current process id"); @@ -281,6 +369,46 @@ return posix.getpid(); } + public static PyString __doc__getpgrp = new PyString( + "getpgrp() -> pgrp\n\n" + + "Return the current process group id."); + @Hide(OS.NT) + public static int getpgrp() { + return posix.getpgrp(); + } + + public static PyString __doc__kill = new PyString( + "kill(pid, sig)\n\n" + + "Kill a process with a signal."); + @Hide(OS.NT) + public static void kill(int pid, int sig) { + if (posix.kill(pid, sig) < 0) { + throw errorFromErrno(); + } + } + + public static PyString __doc__lchmod = new PyString( + "lchmod(path, mode)\n\n" + + "Change the access permissions of a file. If path is a symlink, this\n" + + "affects the link itself rather than the target."); + @Hide(OS.NT) + public static void lchmod(String path, int mode) { + if (posix.lchmod(absolutePath(path), mode) < 0) { + throw errorFromErrno(path); + } + } + + public static PyString __doc__lchown = new PyString( + "lchown(path, uid, gid)\n\n" + + "Change the owner and group id of path to the numeric uid and gid.\n" + + "This function will not follow symbolic links."); + @Hide(OS.NT) + public static void lchown(String path, int uid, int gid) { + if (posix.lchown(absolutePath(path), uid, gid) < 0) { + throw errorFromErrno(path); + } + } + public static PyString __doc__link = new PyString( "link(src, dst)\n\n" + "Create a hard link to a file."); @@ -417,6 +545,18 @@ } } + public static PyString __doc__readlink = new PyString( + "readlink(path) -> path\n\n" + + "Return a string representing the path to which the symbolic link points."); + @Hide(OS.NT) + public static String readlink(String path) { + try { + return posix.readlink(absolutePath(path)); + } catch (IOException ioe) { + throw Py.OSError(ioe); + } + } + public static PyString __doc__remove = new PyString( "remove(path)\n\n" + "Remove a file (same as unlink(path))."); @@ -424,6 +564,26 @@ unlink(path); } + public static PyString __doc__setpgrp = new PyString( + "setpgrp()\n\n" + + "Make this process a session leader."); + @Hide(OS.NT) + public static void setpgrp() { + if (posix.setpgrp(0, 0) < 0) { + throw errorFromErrno(); + } + } + + public static PyString __doc__setsid = new PyString( + "setsid()\n\n" + + "Call the system call setsid()."); + @Hide(OS.NT) + public static void setsid() { + if (posix.setsid() < 0) { + throw errorFromErrno(); + } + } + public static PyString __doc__strerror = new PyString( "strerror(code) -> string\n\n" + "Translate an error code to a message string."); @@ -441,6 +601,15 @@ return new PyString(errno.toString()); } + public static PyString __doc__symlink = new PyString( + "symlink(src, dst)\n\n" + + "Create a symbolic link pointing to src named dst."); + @Hide(OS.NT) + public static void symlink(String src, String dst) { + ensurePath(src); + posix.symlink(src, absolutePath(dst)); + } + public static PyString __doc__umask = new PyString( "umask(new_mask) -> old_mask\n\n" + "Set the current numeric umask and return the previous umask."); @@ -469,6 +638,31 @@ } } + public static PyString __doc__wait = new PyString( + "wait() -> (pid, status)\n\n" + + "Wait for completion of a child process."); + @Hide(OS.NT) + public static PyObject wait$() { + int[] status = new int[1]; + int pid = posix.wait(status); + if (pid < 0) { + throw errorFromErrno(); + } + return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0])); + } + + public static PyString __doc__waitpid = new PyString( + "wait() -> (pid, status)\n\n" + + "Wait for completion of a child process."); + public static PyObject waitpid(int pid, int options) { + int[] status = new int[1]; + pid = posix.waitpid(pid, status, options); + if (pid < 0) { + throw errorFromErrno(); + } + return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0])); + } + public static PyString __doc__write = new PyString( "write(fd, string) -> byteswritten\n\n" + "Write a string to a file descriptor."); @@ -539,6 +733,10 @@ return Py.OSError(Errno.EBADF); } + private static PyException errorFromErrno() { + return Py.OSError(Errno.valueOf(posix.errno())); + } + private static PyException errorFromErrno(String path) { return Py.OSError(Errno.valueOf(posix.errno()), path); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-15 05:18:36
|
Revision: 6944 http://jython.svn.sourceforge.net/jython/?rev=6944&view=rev Author: pjenvey Date: 2009-11-15 05:18:17 +0000 (Sun, 15 Nov 2009) Log Message: ----------- bump jaffl to 0.4.1-0effe2244983 to fix alignment issues on 32 bit sparc Modified Paths: -------------- trunk/jython/extlibs/jaffl.jar Modified: trunk/jython/extlibs/jaffl.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-15 00:58:55
|
Revision: 6943 http://jython.svn.sourceforge.net/jython/?rev=6943&view=rev Author: pjenvey Date: 2009-11-15 00:58:31 +0000 (Sun, 15 Nov 2009) Log Message: ----------- default time fields to int to match CPython Modified Paths: -------------- trunk/jython/src/org/python/modules/posix/PyStatResult.java Modified: trunk/jython/src/org/python/modules/posix/PyStatResult.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PyStatResult.java 2009-11-11 03:18:09 UTC (rev 6942) +++ trunk/jython/src/org/python/modules/posix/PyStatResult.java 2009-11-15 00:58:31 UTC (rev 6943) @@ -75,8 +75,8 @@ return new PyStatResult(Py.newInteger(stat.mode()), Py.newLong(stat.ino()), Py.newLong(stat.dev()), Py.newInteger(stat.nlink()), Py.newInteger(stat.uid()), Py.newInteger(stat.gid()), - Py.newLong(stat.st_size()), Py.newLong(stat.atime()), - Py.newLong(stat.mtime()), Py.newLong(stat.ctime())); + Py.newLong(stat.st_size()), Py.newInteger(stat.atime()), + Py.newInteger(stat.mtime()), Py.newInteger(stat.ctime())); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wme...@us...> - 2009-11-11 03:18:18
|
Revision: 6942 http://jython.svn.sourceforge.net/jython/?rev=6942&view=rev Author: wmeissner Date: 2009-11-11 03:18:09 +0000 (Wed, 11 Nov 2009) Log Message: ----------- Update jffi Modified Paths: -------------- branches/ctypes-jffi/build.xml branches/ctypes-jffi/extlibs/jffi-i386-SunOS.jar branches/ctypes-jffi/extlibs/jffi-x86_64-SunOS.jar branches/ctypes-jffi/extlibs/jffi.jar Added Paths: ----------- branches/ctypes-jffi/extlibs/jffi-i386-Windows.jar Modified: branches/ctypes-jffi/build.xml =================================================================== --- branches/ctypes-jffi/build.xml 2009-11-09 00:08:21 UTC (rev 6941) +++ branches/ctypes-jffi/build.xml 2009-11-11 03:18:09 UTC (rev 6942) @@ -194,6 +194,7 @@ <pathelement path="${extlibs.dir}/jna-posix.jar"/> <pathelement path="${extlibs.dir}/jffi.jar"/> <pathelement path="${extlibs.dir}/jffi-Darwin.jar"/> + <pathelement path="${extlibs.dir}/jffi-i386-Windows.jar"/> <pathelement path="${extlibs.dir}/jffi-i386-SunOS.jar"/> <pathelement path="${extlibs.dir}/jffi-x86_64-SunOS.jar"/> </path> @@ -576,6 +577,7 @@ <zipfileset src="extlibs/jna.jar"/> <zipfileset src="extlibs/jffi.jar"/> <zipfileset src="extlibs/jffi-Darwin.jar"/> + <zipfileset src="extlibs/jffi-i386-Windows.jar"/> <zipfileset src="extlibs/jffi-i386-SunOS.jar"/> <zipfileset src="extlibs/jffi-x86_64-SunOS.jar"/> <zipfileset src="extlibs/jna-posix.jar"/> Modified: branches/ctypes-jffi/extlibs/jffi-i386-SunOS.jar =================================================================== (Binary files differ) Added: branches/ctypes-jffi/extlibs/jffi-i386-Windows.jar =================================================================== (Binary files differ) Property changes on: branches/ctypes-jffi/extlibs/jffi-i386-Windows.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: branches/ctypes-jffi/extlibs/jffi-x86_64-SunOS.jar =================================================================== (Binary files differ) Modified: branches/ctypes-jffi/extlibs/jffi.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-09 00:08:41
|
Revision: 6941 http://jython.svn.sourceforge.net/jython/?rev=6941&view=rev Author: pjenvey Date: 2009-11-09 00:08:21 +0000 (Mon, 09 Nov 2009) Log Message: ----------- swap jna/jna-posix for jffi 0.6.2/jaffl 0.4.1-57919f3abc0a/jnr-posix 1.0.6-044e3646a308 Modified Paths: -------------- trunk/jython/.classpath trunk/jython/build.xml Added Paths: ----------- trunk/jython/extlibs/jaffl.jar trunk/jython/extlibs/jffi-Darwin.jar trunk/jython/extlibs/jffi-i386-FreeBSD.jar trunk/jython/extlibs/jffi-i386-Linux.jar trunk/jython/extlibs/jffi-i386-OpenBSD.jar trunk/jython/extlibs/jffi-i386-SunOS.jar trunk/jython/extlibs/jffi-i386-Windows.jar trunk/jython/extlibs/jffi-ppc-AIX.jar trunk/jython/extlibs/jffi-s390x-Linux.jar trunk/jython/extlibs/jffi-sparc-SunOS.jar trunk/jython/extlibs/jffi-sparcv9-SunOS.jar trunk/jython/extlibs/jffi-x86_64-FreeBSD.jar trunk/jython/extlibs/jffi-x86_64-Linux.jar trunk/jython/extlibs/jffi-x86_64-OpenBSD.jar trunk/jython/extlibs/jffi-x86_64-SunOS.jar trunk/jython/extlibs/jffi.jar trunk/jython/extlibs/jnr-posix.jar Removed Paths: ------------- trunk/jython/extlibs/jna-posix.jar trunk/jython/extlibs/jna.jar Modified: trunk/jython/.classpath =================================================================== --- trunk/jython/.classpath 2009-11-08 22:59:13 UTC (rev 6940) +++ trunk/jython/.classpath 2009-11-09 00:08:21 UTC (rev 6941) @@ -17,10 +17,25 @@ <classpathentry kind="lib" path="extlibs/asm-3.1.jar"/> <classpathentry kind="lib" path="extlibs/asm-commons-3.1.jar"/> <classpathentry kind="lib" path="extlibs/constantine.jar"/> - <classpathentry kind="lib" path="extlibs/jna-posix.jar"/> <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/jar/jdom.jar"/> <classpathentry kind="lib" path="extlibs/mockrunner-0.4.1/lib/jdk1.5/j2ee1.3/mockrunner-servlet.jar"/> - <classpathentry kind="lib" path="extlibs/jna.jar"/> <classpathentry kind="lib" path="extlibs/livetribe-jsr223-2.0.5.jar"/> + <classpathentry kind="lib" path="extlibs/jaffl.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-Darwin.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-i386-FreeBSD.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-i386-Linux.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-i386-OpenBSD.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-i386-SunOS.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-i386-Windows.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-ppc-AIX.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-s390x-Linux.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-sparc-SunOS.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-sparcv9-SunOS.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-x86_64-FreeBSD.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-x86_64-Linux.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-x86_64-OpenBSD.jar"/> + <classpathentry kind="lib" path="extlibs/jffi-x86_64-SunOS.jar"/> + <classpathentry kind="lib" path="extlibs/jffi.jar"/> + <classpathentry kind="lib" path="extlibs/jnr-posix.jar"/> <classpathentry kind="output" path="build/classes"/> </classpath> Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-11-08 22:59:13 UTC (rev 6940) +++ trunk/jython/build.xml 2009-11-09 00:08:21 UTC (rev 6941) @@ -190,8 +190,23 @@ <pathelement path="${extlibs.dir}/asm-3.1.jar" /> <pathelement path="${extlibs.dir}/asm-commons-3.1.jar" /> <pathelement path="${extlibs.dir}/constantine.jar" /> - <pathelement path="${extlibs.dir}/jna.jar"/> - <pathelement path="${extlibs.dir}/jna-posix.jar"/> + <pathelement path="${extlibs.dir}/jaffl.jar"/> + <pathelement path="${extlibs.dir}/jffi-Darwin.jar"/> + <pathelement path="${extlibs.dir}/jffi-i386-FreeBSD.jar"/> + <pathelement path="${extlibs.dir}/jffi-i386-Linux.jar"/> + <pathelement path="${extlibs.dir}/jffi-i386-OpenBSD.jar"/> + <pathelement path="${extlibs.dir}/jffi-i386-SunOS.jar"/> + <pathelement path="${extlibs.dir}/jffi-i386-Windows.jar"/> + <pathelement path="${extlibs.dir}/jffi-ppc-AIX.jar"/> + <pathelement path="${extlibs.dir}/jffi-s390x-Linux.jar"/> + <pathelement path="${extlibs.dir}/jffi-sparc-SunOS.jar"/> + <pathelement path="${extlibs.dir}/jffi-sparcv9-SunOS.jar"/> + <pathelement path="${extlibs.dir}/jffi-x86_64-FreeBSD.jar"/> + <pathelement path="${extlibs.dir}/jffi-x86_64-Linux.jar"/> + <pathelement path="${extlibs.dir}/jffi-x86_64-OpenBSD.jar"/> + <pathelement path="${extlibs.dir}/jffi-x86_64-SunOS.jar"/> + <pathelement path="${extlibs.dir}/jffi.jar"/> + <pathelement path="${extlibs.dir}/jnr-posix.jar"/> </path> <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> @@ -569,8 +584,23 @@ <zipfileset src="extlibs/asm-commons-3.1.jar"/> <zipfileset src="extlibs/asm-util-3.1.jar"/> <rule pattern="org.objectweb.asm.**" result="org.python.objectweb.asm.@1"/> - <zipfileset src="extlibs/jna.jar"/> - <zipfileset src="extlibs/jna-posix.jar"/> + <zipfileset src="extlibs/jaffl.jar"/> + <zipfileset src="extlibs/jffi-Darwin.jar"/> + <zipfileset src="extlibs/jffi-i386-FreeBSD.jar"/> + <zipfileset src="extlibs/jffi-i386-Linux.jar"/> + <zipfileset src="extlibs/jffi-i386-OpenBSD.jar"/> + <zipfileset src="extlibs/jffi-i386-SunOS.jar"/> + <zipfileset src="extlibs/jffi-i386-Windows.jar"/> + <zipfileset src="extlibs/jffi-ppc-AIX.jar"/> + <zipfileset src="extlibs/jffi-s390x-Linux.jar"/> + <zipfileset src="extlibs/jffi-sparc-SunOS.jar"/> + <zipfileset src="extlibs/jffi-sparcv9-SunOS.jar"/> + <zipfileset src="extlibs/jffi-x86_64-FreeBSD.jar"/> + <zipfileset src="extlibs/jffi-x86_64-Linux.jar"/> + <zipfileset src="extlibs/jffi-x86_64-OpenBSD.jar"/> + <zipfileset src="extlibs/jffi-x86_64-SunOS.jar"/> + <zipfileset src="extlibs/jffi.jar"/> + <zipfileset src="extlibs/jnr-posix.jar"/> <!-- <rule pattern="com.sun.jna.**" result="org.python.jna.@1"/> --> <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> <zipfileset src="extlibs/constantine.jar"/> Added: trunk/jython/extlibs/jaffl.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jaffl.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-Darwin.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-Darwin.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-i386-FreeBSD.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-i386-FreeBSD.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-i386-Linux.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-i386-Linux.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-i386-OpenBSD.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-i386-OpenBSD.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-i386-SunOS.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-i386-SunOS.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-i386-Windows.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-i386-Windows.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-ppc-AIX.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-ppc-AIX.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-s390x-Linux.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-s390x-Linux.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-sparc-SunOS.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-sparc-SunOS.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-sparcv9-SunOS.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-sparcv9-SunOS.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-x86_64-FreeBSD.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-x86_64-FreeBSD.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-x86_64-Linux.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-x86_64-Linux.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-x86_64-OpenBSD.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-x86_64-OpenBSD.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi-x86_64-SunOS.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi-x86_64-SunOS.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/jffi.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jffi.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: trunk/jython/extlibs/jna-posix.jar =================================================================== (Binary files differ) Deleted: trunk/jython/extlibs/jna.jar =================================================================== (Binary files differ) Added: trunk/jython/extlibs/jnr-posix.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/jnr-posix.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-11-08 22:59:42
|
Revision: 6940 http://jython.svn.sourceforge.net/jython/?rev=6940&view=rev Author: pjenvey Date: 2009-11-08 22:59:13 +0000 (Sun, 08 Nov 2009) Log Message: ----------- convert gid/uids to ints Modified Paths: -------------- trunk/jython/Lib/grp.py trunk/jython/Lib/pwd.py Modified: trunk/jython/Lib/grp.py =================================================================== --- trunk/jython/Lib/grp.py 2009-11-08 22:28:36 UTC (rev 6939) +++ trunk/jython/Lib/grp.py 2009-11-08 22:59:13 UTC (rev 6940) @@ -35,7 +35,7 @@ attrs = ['gr_name', 'gr_passwd', 'gr_gid', 'gr_mem'] def __new__(cls, grp): - grp = (newString(grp.name), newString(grp.password), grp.GID, + grp = (newString(grp.name), newString(grp.password), int(grp.GID), [newString(member) for member in grp.members]) return tuple.__new__(cls, grp) Modified: trunk/jython/Lib/pwd.py =================================================================== --- trunk/jython/Lib/pwd.py 2009-11-08 22:28:36 UTC (rev 6939) +++ trunk/jython/Lib/pwd.py 2009-11-08 22:59:13 UTC (rev 6940) @@ -29,8 +29,8 @@ 'pw_dir', 'pw_shell'] def __new__(cls, pwd): - pwd = (newString(pwd.loginName), newString(pwd.password), pwd.UID, - pwd.GID, newString(pwd.GECOS), newString(pwd.home), + pwd = (newString(pwd.loginName), newString(pwd.password), int(pwd.UID), + int(pwd.GID), newString(pwd.GECOS), newString(pwd.home), newString(pwd.shell)) return tuple.__new__(cls, pwd) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2009-11-04 01:11:32
|
Revision: 6937 http://jython.svn.sourceforge.net/jython/?rev=6937&view=rev Author: leosoto Date: 2009-11-04 01:11:20 +0000 (Wed, 04 Nov 2009) Log Message: ----------- Fix for issue 1499: PostgreSQL data handler now return Decimals for NUMERIC columns Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-10-31 01:48:29 UTC (rev 6936) +++ trunk/jython/NEWS 2009-11-04 01:11:20 UTC (rev 6937) @@ -8,6 +8,7 @@ - [ 1493 ] tarfile.extractall() throws "AttributeError: 'module' object has no attribute 'chown'" when called by root - [ 1470 ] os.mkdir Errno difference from cpython - [ 1496 ] fix os.listdir errno for non-existing dirs + - [ 1499 ] PostgreSQL datahandler should return Decimals instead of floats for NUMERIC/DECIMAL columns - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java =================================================================== --- trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java 2009-10-31 01:48:29 UTC (rev 6936) +++ trunk/jython/src/com/ziclix/python/sql/handler/PostgresqlDataHandler.java 2009-11-04 01:11:20 UTC (rev 6937) @@ -61,7 +61,7 @@ case Types.DECIMAL: BigDecimal bd = set.getBigDecimal(col); - obj = (bd == null) ? Py.None : Py.newFloat(bd.doubleValue()); + obj = (bd == null) ? Py.None : Py.newDecimal(bd.toString()); break; case Types.OTHER: @@ -78,7 +78,6 @@ default : obj = super.getPyObject(set, col, type); } - return (set.wasNull() || (obj == null)) ? Py.None : obj; } @@ -108,7 +107,7 @@ } else { varchar = (String) object.__tojava__(String.class); } - + stmt.setObject(index, varchar, type); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-31 01:48:38
|
Revision: 6936 http://jython.svn.sourceforge.net/jython/?rev=6936&view=rev Author: pjenvey Date: 2009-10-31 01:48:29 +0000 (Sat, 31 Oct 2009) Log Message: ----------- only use the Group/Passwd interface API, and convert the unicode values to regular strs Modified Paths: -------------- trunk/jython/Lib/grp.py trunk/jython/Lib/pwd.py Modified: trunk/jython/Lib/grp.py =================================================================== --- trunk/jython/Lib/grp.py 2009-10-31 01:46:11 UTC (rev 6935) +++ trunk/jython/Lib/grp.py 2009-10-31 01:48:29 UTC (rev 6936) @@ -18,6 +18,7 @@ __all__ = ['getgrgid', 'getgrnam', 'getgrall'] from os import _name, _posix_impl +from org.python.core.Py import newString if _name == 'nt': raise ImportError, 'grp module not supported on Windows' @@ -34,8 +35,9 @@ attrs = ['gr_name', 'gr_passwd', 'gr_gid', 'gr_mem'] def __new__(cls, grp): - return tuple.__new__(cls, (grp.gr_name, grp.gr_passwd, grp.gr_gid, - list(grp.getMembers()))) + grp = (newString(grp.name), newString(grp.password), grp.GID, + [newString(member) for member in grp.members]) + return tuple.__new__(cls, grp) def __getattr__(self, attr): try: Modified: trunk/jython/Lib/pwd.py =================================================================== --- trunk/jython/Lib/pwd.py 2009-10-31 01:46:11 UTC (rev 6935) +++ trunk/jython/Lib/pwd.py 2009-10-31 01:48:29 UTC (rev 6936) @@ -11,6 +11,7 @@ __all__ = ['getpwuid', 'getpwnam', 'getpwall'] from os import _name, _posix_impl +from org.python.core.Py import newString if _name == 'nt': raise ImportError, 'pwd module not supported on Windows' @@ -28,7 +29,10 @@ 'pw_dir', 'pw_shell'] def __new__(cls, pwd): - return tuple.__new__(cls, (getattr(pwd, attr) for attr in cls.attrs)) + pwd = (newString(pwd.loginName), newString(pwd.password), pwd.UID, + pwd.GID, newString(pwd.GECOS), newString(pwd.home), + newString(pwd.shell)) + return tuple.__new__(cls, pwd) def __getattr__(self, attr): try: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-31 01:46:36
|
Revision: 6935 http://jython.svn.sourceforge.net/jython/?rev=6935&view=rev Author: pjenvey Date: 2009-10-31 01:46:11 +0000 (Sat, 31 Oct 2009) Log Message: ----------- speedup the stat call as it can easily be performance critical, fix some __doc__ strings Modified Paths: -------------- trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-30 23:53:24 UTC (rev 6934) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-10-31 01:46:11 UTC (rev 6935) @@ -18,6 +18,7 @@ import org.python.core.ClassDictInit; import org.python.core.Py; +import org.python.core.PyBuiltinFunction; import org.python.core.PyDictionary; import org.python.core.PyException; import org.python.core.PyFile; @@ -25,6 +26,7 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyTuple; +import org.python.core.ThreadState; import org.python.core.imp; import org.python.core.io.FileDescriptors; import org.python.core.io.FileIO; @@ -85,6 +87,7 @@ dict.__setitem__("O_TRUNC", Py.newInteger(O_TRUNC)); dict.__setitem__("O_EXCL", Py.newInteger(O_EXCL)); + // os.access flags dict.__setitem__("F_OK", Py.newInteger(F_OK)); dict.__setitem__("X_OK", Py.newInteger(X_OK)); dict.__setitem__("W_OK", Py.newInteger(W_OK)); @@ -99,6 +102,10 @@ dict.__setitem__("error", Py.OSError); dict.__setitem__("stat_result", PyStatResult.TYPE); + // Faster call paths + dict.__setitem__("lstat", new LstatFunction()); + dict.__setitem__("stat", new StatFunction()); + // Hide from Python Hider.hideFunctions(PosixModule.class, dict, os, nativePosix); dict.__setitem__("classDictInit", null); @@ -252,21 +259,21 @@ } } - public static PyString __doc___getcwd = new PyString( + public static PyString __doc__getcwd = new PyString( "getcwd() -> path\n\n" + "Return a string representing the current working directory."); public static PyObject getcwd() { return Py.newString(Py.getSystemState().getCurrentWorkingDir()); } - public static PyString __doc___getcwdu = new PyString( + public static PyString __doc__getcwdu = new PyString( "getcwd() -> path\n\n" + "Return a unicode string representing the current working directory."); public static PyObject getcwdu() { return Py.newUnicode(Py.getSystemState().getCurrentWorkingDir()); } - public static PyString __doc___getpid = new PyString( + public static PyString __doc__getpid = new PyString( "getpid() -> pid\n\n" + "Return the current process id"); @Hide(posixImpl = PosixImpl.JAVA) @@ -324,13 +331,6 @@ } } - public static PyString __doc__lstat = new PyString( - "lstat(path) -> stat result\n\n" + - "Like stat(path), but do not follow symbolic links."); - public static PyObject lstat(String path) { - return PyStatResult.fromFileStat(posix.lstat(absolutePath(path))); - } - public static PyString __doc__mkdir = new PyString( "mkdir(path [, mode=0777])\n\n" + "Create a directory."); @@ -424,15 +424,6 @@ unlink(path); } - public static PyString __doc__stat = new PyString( - "stat(path) -> stat result\n\n" + - "Perform a stat system call on the given path.\n\n" + - "Note that some platforms may return only a small subset of the\n" + - "standard fields"); - public static PyObject stat(String path) { - return PyStatResult.fromFileStat(posix.stat(absolutePath(path))); - } - public static PyString __doc__strerror = new PyString( "strerror(code) -> string\n\n" + "Translate an error code to a message string."); @@ -559,4 +550,42 @@ public static String getOSName() { return os.getModuleName(); } + + static class LstatFunction extends PyBuiltinFunction { + LstatFunction() { + super("lstat", + "lstat(path) -> stat result\n\n" + + "Like stat(path), but do not follow symbolic links."); + } + + @Override + public PyObject __call__(ThreadState state, PyObject pathObj) { + if (!(pathObj instanceof PyString)) { + throw Py.TypeError(String.format("coercing to Unicode: need string or buffer, %s " + + "found", pathObj.getType().fastGetName())); + } + String absolutePath = absolutePath(pathObj.toString()); + return PyStatResult.fromFileStat(posix.lstat(absolutePath)); + } + } + + static class StatFunction extends PyBuiltinFunction { + StatFunction() { + super("stat", + "stat(path) -> stat result\n\n" + + "Perform a stat system call on the given path.\n\n" + + "Note that some platforms may return only a small subset of the\n" + + "standard fields"); + } + + @Override + public PyObject __call__(ThreadState state, PyObject pathObj) { + if (!(pathObj instanceof PyString)) { + throw Py.TypeError(String.format("coercing to Unicode: need string or buffer, %s " + + "found", pathObj.getType().fastGetName())); + } + String absolutePath = absolutePath(pathObj.toString()); + return PyStatResult.fromFileStat(posix.stat(absolutePath)); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-30 23:53:43
|
Revision: 6934 http://jython.svn.sourceforge.net/jython/?rev=6934&view=rev Author: pjenvey Date: 2009-10-30 23:53:24 +0000 (Fri, 30 Oct 2009) Log Message: ----------- remove the unneeded Generics workaround and always specify the cached TYPE to BaseSet Modified Paths: -------------- trunk/jython/src/org/python/core/BaseSet.java trunk/jython/src/org/python/core/PyFrozenSet.java trunk/jython/src/org/python/core/PySet.java Modified: trunk/jython/src/org/python/core/BaseSet.java =================================================================== --- trunk/jython/src/org/python/core/BaseSet.java 2009-10-30 01:34:16 UTC (rev 6933) +++ trunk/jython/src/org/python/core/BaseSet.java 2009-10-30 23:53:24 UTC (rev 6934) @@ -12,12 +12,8 @@ protected Set<PyObject> _set; /** - * Create a new Python set instance from the specified Set object. + * Create a new Python set of type from the specified Set object. */ - protected BaseSet(Set<PyObject> set) { - _set = set; - } - protected BaseSet(PyType type, Set<PyObject> set) { super(type); _set = set; Modified: trunk/jython/src/org/python/core/PyFrozenSet.java =================================================================== --- trunk/jython/src/org/python/core/PyFrozenSet.java 2009-10-30 01:34:16 UTC (rev 6933) +++ trunk/jython/src/org/python/core/PyFrozenSet.java 2009-10-30 23:53:24 UTC (rev 6934) @@ -15,11 +15,11 @@ public static final PyType TYPE = PyType.fromClass(PyFrozenSet.class); public PyFrozenSet() { - super(new HashSet<PyObject>()); + super(TYPE, new HashSet<PyObject>()); } public PyFrozenSet(PyObject data) { - super(_update(new HashSet<PyObject>(), data)); + this(TYPE, data); } public PyFrozenSet(PyType type, PyObject data) { Modified: trunk/jython/src/org/python/core/PySet.java =================================================================== --- trunk/jython/src/org/python/core/PySet.java 2009-10-30 01:34:16 UTC (rev 6933) +++ trunk/jython/src/org/python/core/PySet.java 2009-10-30 23:53:24 UTC (rev 6934) @@ -2,7 +2,6 @@ import java.util.Iterator; import java.util.NoSuchElementException; -import java.util.Set; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -16,22 +15,17 @@ public static final PyType TYPE = PyType.fromClass(PySet.class); public PySet() { - super(concurrentSet()); + this(TYPE); } public PySet(PyType type) { - super(type, concurrentSet()); + super(type, Generic.<PyObject>concurrentSet()); } public PySet(PyObject data) { - super(_update(concurrentSet(), data)); + super(TYPE, _update(Generic.<PyObject>concurrentSet(), data)); } - /** Contextualize the needed Set<PyObject> type paramaters (generics workaround). */ - private static Set<PyObject> concurrentSet() { - return Generic.concurrentSet(); - } - @ExposedNew @ExposedMethod(doc = BuiltinDocs.set___init___doc) final void set___init__(PyObject[] args, String[] kwds) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-30 01:34:27
|
Revision: 6933 http://jython.svn.sourceforge.net/jython/?rev=6933&view=rev Author: pjenvey Date: 2009-10-30 01:34:16 +0000 (Fri, 30 Oct 2009) Log Message: ----------- correct the numeric check on the right side Modified Paths: -------------- trunk/jython/Lib/test/test_builtin_jy.py trunk/jython/src/org/python/core/PyObject.java Modified: trunk/jython/Lib/test/test_builtin_jy.py =================================================================== --- trunk/jython/Lib/test/test_builtin_jy.py 2009-10-29 07:19:33 UTC (rev 6932) +++ trunk/jython/Lib/test/test_builtin_jy.py 2009-10-30 01:34:16 UTC (rev 6933) @@ -29,6 +29,7 @@ # http://bugs.jython.org/issue1449 for numeric in 1, 2L, 3.0, 4j: self.assertTrue(numeric < Ellipsis) + self.assertTrue(Ellipsis > numeric) class LoopTest(unittest.TestCase): Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-10-29 07:19:33 UTC (rev 6932) +++ trunk/jython/src/org/python/core/PyObject.java 2009-10-30 01:34:16 UTC (rev 6933) @@ -1321,7 +1321,7 @@ // different type: compare type names; numbers are smaller String typeName = isNumberType() ? "" : type.fastGetName(); - String otherTypeName = otherType.isNumberType() ? "" : otherType.fastGetName(); + String otherTypeName = other.isNumberType() ? "" : otherType.fastGetName(); result = typeName.compareTo(otherTypeName); if (result == 0) { // Same type name, or (more likely) incomparable numeric types This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-29 07:19:39
|
Revision: 6932 http://jython.svn.sourceforge.net/jython/?rev=6932&view=rev Author: pjenvey Date: 2009-10-29 07:19:33 +0000 (Thu, 29 Oct 2009) Log Message: ----------- getJavaProxy with a fallback seems to do what we need a little more efficiently than __tojava__, + cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PyReflectedField.java Modified: trunk/jython/src/org/python/core/PyReflectedField.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedField.java 2009-10-29 06:58:50 UTC (rev 6931) +++ trunk/jython/src/org/python/core/PyReflectedField.java 2009-10-29 07:19:33 UTC (rev 6932) @@ -1,13 +1,18 @@ -// Copyright (c) Corporation for National Research Initiatives +/* + * Copyright (c) Corporation for National Research Initiatives + * Copyright (c) Jython Developers + */ package org.python.core; import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class PyReflectedField extends PyObject { + public Field field; - public PyReflectedField() {} + public PyReflectedField() { + } public PyReflectedField(Field field) { this.field = field; @@ -17,9 +22,13 @@ public PyObject _doget(PyObject self) { Object iself = null; if (!Modifier.isStatic(field.getModifiers())) { - if (self == null) + if (self == null) { return this; - iself = Py.tojava(self, field.getDeclaringClass()); + } + iself = self.getJavaProxy(); + if (iself == null) { + iself = self; + } } Object value; @@ -37,10 +46,12 @@ Object iself = null; if (!Modifier.isStatic(field.getModifiers())) { if (self == null) { - throw Py.AttributeError("set instance variable as static: "+ - field.toString()); + throw Py.AttributeError("set instance variable as static: " + field.toString()); } - iself = Py.tojava(self, field.getDeclaringClass()); + iself = self.getJavaProxy(); + if (iself == null) { + iself = self; + } } Object fvalue = Py.tojava(value, field.getType()); @@ -54,6 +65,6 @@ @Override public String toString() { - return "<reflected field "+field.toString()+" "+Py.idstr(this)+">"; + return String.format("<reflected field %s at %s>", field, Py.idstr(this)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-29 06:59:18
|
Revision: 6931 http://jython.svn.sourceforge.net/jython/?rev=6931&view=rev Author: pjenvey Date: 2009-10-29 06:58:50 +0000 (Thu, 29 Oct 2009) Log Message: ----------- base the initial CHM capacity off the passed in Map Modified Paths: -------------- trunk/jython/src/org/python/core/PyDictionary.java trunk/jython/src/org/python/core/PyStringMap.java Modified: trunk/jython/src/org/python/core/PyDictionary.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionary.java 2009-10-29 04:57:43 UTC (rev 6930) +++ trunk/jython/src/org/python/core/PyDictionary.java 2009-10-29 06:58:50 UTC (rev 6931) @@ -13,6 +13,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentHashMap; import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedMethod; @@ -36,34 +37,40 @@ * Create an empty dictionary. */ public PyDictionary() { - super(TYPE); - table = Generic.concurrentMap(); + this(TYPE); } /** + * Create a dictionary of type with the specified initial capacity. + */ + public PyDictionary(PyType type, int capacity) { + super(type); + table = new ConcurrentHashMap<PyObject, PyObject>(capacity, Generic.CHM_LOAD_FACTOR, + Generic.CHM_CONCURRENCY_LEVEL); + } + + /** * For derived types */ - public PyDictionary(PyType subtype) { - super(subtype); + public PyDictionary(PyType type) { + super(type); table = Generic.concurrentMap(); } /** * Create a new dictionary which is based on given map. */ - public PyDictionary(Map<PyObject, PyObject> t) { - super(TYPE); - table = Generic.concurrentMap(); - table.putAll(t); + public PyDictionary(Map<PyObject, PyObject> map) { + this(TYPE, map); } /** * Create a new derived dictionary which is based on the given map. */ - public PyDictionary(PyType subtype, Map<PyObject, PyObject> t) { - super(subtype); - table = Generic.concurrentMap(); - table.putAll(t); + public PyDictionary(PyType type, Map<PyObject, PyObject> map) { + this(type, Math.max((int) (map.size() / Generic.CHM_LOAD_FACTOR) + 1, + Generic.CHM_INITIAL_CAPACITY)); + table.putAll(map); } Modified: trunk/jython/src/org/python/core/PyStringMap.java =================================================================== --- trunk/jython/src/org/python/core/PyStringMap.java 2009-10-29 04:57:43 UTC (rev 6930) +++ trunk/jython/src/org/python/core/PyStringMap.java 2009-10-29 06:58:50 UTC (rev 6931) @@ -44,8 +44,8 @@ } public PyStringMap(Map<Object, PyObject> map) { - super(getLazyType()); - table = Generic.concurrentMap(); + this(Math.max((int) (map.size() / Generic.CHM_LOAD_FACTOR) + 1, + Generic.CHM_INITIAL_CAPACITY)); table.putAll(map); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-10-29 04:57:55
|
Revision: 6930 http://jython.svn.sourceforge.net/jython/?rev=6930&view=rev Author: pjenvey Date: 2009-10-29 04:57:43 +0000 (Thu, 29 Oct 2009) Log Message: ----------- expose PyStringMap so unsuspecting users of it avoid reflection costs Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/src/org/python/core/PyStringMap.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2009-10-29 04:28:03 UTC (rev 6929) +++ trunk/jython/CoreExposed.includes 2009-10-29 04:57:43 UTC (rev 6930) @@ -37,6 +37,7 @@ org/python/core/PySlot.class org/python/core/PyStaticMethod.class org/python/core/PyString.class +org/python/core/PyStringMap.class org/python/core/PySuper.class org/python/core/PyTraceback.class org/python/core/PyTuple.class Modified: trunk/jython/src/org/python/core/PyStringMap.java =================================================================== --- trunk/jython/src/org/python/core/PyStringMap.java 2009-10-29 04:28:03 UTC (rev 6929) +++ trunk/jython/src/org/python/core/PyStringMap.java 2009-10-29 04:57:43 UTC (rev 6930) @@ -1,4 +1,7 @@ -// Copyright (c) Corporation for National Research Initiatives +/* + * Copyright (c) Corporation for National Research Initiatives + * Copyright (c) Jython Developers + */ package org.python.core; import java.util.Collection; @@ -9,14 +12,25 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +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; /** * Special fast dict implementation for __dict__ instances. Allows interned String keys in addition * to PyObject unlike PyDictionary. */ +@ExposedType(name = "stringmap", isBaseType = false) public class PyStringMap extends PyObject { + /** + * TYPE computed lazily, PyStringMap is used early in the bootstrap process and + * statically calling fromClass(PyStringMap.class) is unsafe. + */ + private static PyType lazyType; + private final ConcurrentMap<Object, PyObject> table; public PyStringMap() { @@ -24,11 +38,13 @@ } public PyStringMap(int capacity) { + super(getLazyType()); table = new ConcurrentHashMap<Object, PyObject>(capacity, Generic.CHM_LOAD_FACTOR, Generic.CHM_CONCURRENCY_LEVEL); } public PyStringMap(Map<Object, PyObject> map) { + super(getLazyType()); table = Generic.concurrentMap(); table.putAll(map); } @@ -40,14 +56,37 @@ } } + private static PyType getLazyType() { + if (lazyType == null) { + lazyType = PyType.fromClass(PyStringMap.class); + } + return lazyType; + } + + @ExposedNew + final static PyObject stringmap_new(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + PyStringMap map = new PyStringMap(); + map.stringmap_update(args, keywords); + return map; + } + + @Override public int __len__() { + return stringmap___len__(); + } + + @ExposedMethod(doc = BuiltinDocs.dict___len___doc) + final int stringmap___len__() { return table.size(); } + @Override public boolean __nonzero__() { return table.size() != 0; } + @Override public PyObject __finditem__(String key) { if (key == null) { return null; @@ -55,6 +94,7 @@ return table.get(key); } + @Override public PyObject __finditem__(PyObject key) { if (key instanceof PyString) { return __finditem__(((PyString)key).internedString()); @@ -71,7 +111,13 @@ } } + @Override public PyObject __getitem__(PyObject key) { + return stringmap___getitem__(key); + } + + @ExposedMethod(doc = BuiltinDocs.dict___getitem___doc) + final PyObject stringmap___getitem__(PyObject key) { if (key instanceof PyString) { return __getitem__(((PyString)key).internedString()); } else { @@ -84,10 +130,17 @@ } } + @Override public PyObject __iter__() { - return iterkeys(); + return stringmap___iter__(); } + @ExposedMethod(doc = BuiltinDocs.dict___iter___doc) + final PyObject stringmap___iter__() { + return stringmap_iterkeys(); + } + + @Override public void __setitem__(String key, PyObject value) { if (value == null) { table.remove(key); @@ -96,7 +149,13 @@ } } + @Override public void __setitem__(PyObject key, PyObject value) { + stringmap___setitem__(key, value); + } + + @ExposedMethod(doc = BuiltinDocs.dict___setitem___doc) + final void stringmap___setitem__(PyObject key, PyObject value) { if (value == null) { table.remove(pyToKey(key)); } else if (key instanceof PyString) { @@ -106,6 +165,7 @@ } } + @Override public void __delitem__(String key) { Object ret = table.remove(key); if (ret == null) { @@ -113,7 +173,13 @@ } } + @Override public void __delitem__(PyObject key) { + stringmap___delitem__(key); + } + + @ExposedMethod(doc = BuiltinDocs.dict___delitem___doc) + final void stringmap___delitem__(PyObject key) { if (key instanceof PyString) { __delitem__(((PyString)key).internedString()); } else { @@ -128,10 +194,21 @@ * Remove all items from the dictionary. */ public void clear() { + stringmap_clear(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_clear_doc) + final void stringmap_clear() { table.clear(); } + @Override public String toString() { + return stringmap_toString(); + } + + @ExposedMethod(names = {"__repr__", "__str__"}, doc = BuiltinDocs.dict___str___doc) + final String stringmap_toString() { ThreadState ts = Py.getThreadState(); if (!ts.enterRepr(this)) { return "{...}"; @@ -158,7 +235,13 @@ return buf.toString(); } + @Override public int __cmp__(PyObject other) { + return stringmap___cmp__(other); + } + + @ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.dict___cmp___doc) + final int stringmap___cmp__(PyObject other) { if (!(other instanceof PyStringMap || other instanceof PyDictionary)) { return -2; } @@ -204,26 +287,42 @@ } public boolean has_key(PyObject key) { + return stringmap_has_key(key); + } + + @ExposedMethod(doc = BuiltinDocs.dict_has_key_doc) + final boolean stringmap_has_key(PyObject key) { return table.containsKey(pyToKey(key)); } + @Override + public boolean __contains__(PyObject o) { + return stringmap___contains__(o); + } + + @ExposedMethod(doc = BuiltinDocs.dict___contains___doc) + final boolean stringmap___contains__(PyObject o) { + return stringmap_has_key(o); + } + /** - * Return this[key] if the key exists in the mapping, default_object is returned otherwise. + * Return this[key] if the key exists in the mapping, defaultObj is returned otherwise. * * @param key * the key to lookup in the mapping. - * @param default_object + * @param defaultObj * the value to return if the key does not exists in the mapping. */ - public PyObject get(PyObject key, PyObject default_object) { - PyObject o = __finditem__(key); - if (o == null) { - return default_object; - } else { - return o; - } + public PyObject get(PyObject key, PyObject defaultObj) { + return stringmap_get(key, defaultObj); } + @ExposedMethod(defaults = "Py.None", doc = BuiltinDocs.dict_get_doc) + final PyObject stringmap_get(PyObject key, PyObject defaultObj) { + PyObject obj = __finditem__(key); + return obj == null ? defaultObj : obj; + } + /** * Return this[key] if the key exists in the mapping, None is returned otherwise. * @@ -231,20 +330,30 @@ * the key to lookup in the mapping. */ public PyObject get(PyObject key) { - return get(key, Py.None); + return stringmap_get(key, Py.None); } /** * Return a shallow copy of the dictionary. */ public PyStringMap copy() { + return stringmap_copy(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_copy_doc) + final PyStringMap stringmap_copy() { return new PyStringMap(table); } + public void update(PyObject other) { + stringmap_update(new PyObject[] {other}, Py.NoKeywords); + } + /** * Insert all the key:value pairs from <code>dict</code> into this mapping. */ - public void update(PyObject[] args, String[] keywords) { + @ExposedMethod(doc = BuiltinDocs.dict_update_doc) + final void stringmap_update(PyObject[] args, String[] keywords) { int nargs = args.length - keywords.length; if (nargs > 1) { throw PyBuiltinCallable.DefaultInfo.unexpectedCall(nargs, false, "update", 0, 1); @@ -339,19 +448,25 @@ * the default value to insert in the mapping if key does not already exist. */ public PyObject setdefault(PyObject key, PyObject failobj) { + return stringmap_setdefault(key, failobj); + } + + @ExposedMethod(defaults = "Py.None", doc = BuiltinDocs.dict_setdefault_doc) + final PyObject stringmap_setdefault(PyObject key, PyObject failobj) { Object internedKey = (key instanceof PyString) ? ((PyString)key).internedString() : key; PyObject oldValue = table.putIfAbsent(internedKey, failobj); - if (oldValue == null) { - return failobj; - } else { - return oldValue; - } + return oldValue == null ? failobj : oldValue; } /** * Return a random (key, value) tuple pair and remove the pair from the mapping. */ public PyObject popitem() { + return stringmap_popitem(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_popitem_doc) + final PyObject stringmap_popitem() { Iterator<Entry<Object, PyObject>> it = table.entrySet().iterator(); if (!it.hasNext()) { throw Py.KeyError("popitem(): dictionary is empty"); @@ -366,10 +481,15 @@ if (table.size() == 0) { throw Py.KeyError("pop(): dictionary is empty"); } - return pop(key, null); + return stringmap_pop(key, null); } public PyObject pop(PyObject key, PyObject failobj) { + return stringmap_pop(key, failobj); + } + + @ExposedMethod(defaults = "null", doc = BuiltinDocs.dict_pop_doc) + final PyObject stringmap_pop(PyObject key, PyObject failobj) { PyObject value = table.remove(pyToKey(key)); if (value == null) { if (failobj == null) { @@ -385,9 +505,14 @@ * Return a copy of the mappings list of (key, value) tuple pairs. */ public PyList items() { - return new PyList(iteritems()); + return stringmap_items(); } + @ExposedMethod(doc = BuiltinDocs.dict_items_doc) + final PyList stringmap_items() { + return new PyList(stringmap_iteritems()); + } + private PyTuple itemTuple(Entry<Object, PyObject> entry) { return new PyTuple(keyToPy(entry.getKey()), entry.getValue()); } @@ -397,6 +522,11 @@ * storing String or PyObject objects */ public PyList keys() { + return stringmap_keys(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_keys_doc) + final PyList stringmap_keys() { PyObject[] keyArray = new PyObject[table.size()]; int i = 0; for (Object key : table.keySet()) { @@ -409,6 +539,11 @@ * Return a copy of the mappings list of values. */ public PyList values() { + return stringmap_values(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_values_doc) + final PyList stringmap_values() { return new PyList(table.values()); } @@ -416,15 +551,25 @@ * return an iterator over (key, value) pairs */ public PyObject iteritems() { + return stringmap_iteritems(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_iteritems_doc) + final PyObject stringmap_iteritems() { return new ItemsIter(table.entrySet()); } /** * return an iterator over the keys */ - // Python allows one to change the dict while iterating over it, - // including deletion. Java does not. Can we resolve with CHM? public PyObject iterkeys() { + return stringmap_iterkeys(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_iterkeys_doc) + final PyObject stringmap_iterkeys() { + // Python allows one to change the dict while iterating over it, including + // deletion. Java does not. Can we resolve with CHM? return new KeysIter(table.keySet()); } @@ -432,10 +577,25 @@ * return an iterator over the values */ public PyObject itervalues() { + return stringmap_itervalues(); + } + + @ExposedMethod(doc = BuiltinDocs.dict_itervalues_doc) + final PyObject stringmap_itervalues() { return new ValuesIter(table.values()); } @Override + public int hashCode() { + return stringmap___hash__(); + } + + @ExposedMethod(doc = BuiltinDocs.dict___hash___doc) + final int stringmap___hash__() { + throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); + } + + @Override public boolean isMappingType() { return true; } @@ -456,6 +616,7 @@ size = c.size(); } + @Override public PyObject __iternext__() { if (table.size() != size) { throw Py.RuntimeError("dictionary changed size during iteration"); @@ -475,7 +636,8 @@ super(c); } - public PyObject stringMapNext() { + @Override + public PyObject stringMapNext() { return iterator.next(); } } @@ -486,6 +648,7 @@ super(s); } + @Override protected PyObject stringMapNext() { return keyToPy(iterator.next()); } @@ -497,6 +660,7 @@ super(s); } + @Override public PyObject stringMapNext() { return itemTuple(iterator.next()); } @@ -517,8 +681,4 @@ return pyKey; } } - - public int hashCode() { - throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |