|
From: <cg...@us...> - 2008-12-12 03:29:55
|
Revision: 5737
http://jython.svn.sourceforge.net/jython/?rev=5737&view=rev
Author: cgroves
Date: 2008-12-12 03:29:49 +0000 (Fri, 12 Dec 2008)
Log Message:
-----------
Merged revisions 5730-5731,5733-5735 via svnmerge from
https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython
........
r5730 | pjenvey | 2008-12-09 23:34:57 -0800 (Tue, 09 Dec 2008) | 1 line
hide posixy stuff when not on posix
........
r5731 | pjenvey | 2008-12-10 00:10:31 -0800 (Wed, 10 Dec 2008) | 3 lines
merge in new test from:
http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_with.py -c 67684
........
r5733 | pjenvey | 2008-12-10 16:10:25 -0800 (Wed, 10 Dec 2008) | 4 lines
fail fast when path exists but isn't a normal file
suggested by Ethan Glasser-Camp
fixes #1199
........
r5734 | pjenvey | 2008-12-10 16:39:49 -0800 (Wed, 10 Dec 2008) | 1 line
COMPUTE_FRAMES implies COMPUTE_MAXS
........
r5735 | pjenvey | 2008-12-10 21:20:55 -0800 (Wed, 10 Dec 2008) | 6 lines
o fix imp.find_module not finding builtin modules
o add __builtin__ and sys to sys.builtin_module_names and another hack for
re-importing __builtin__ like we have for sys
fixes #1161
thanks Sven Reimers
........
Modified Paths:
--------------
branches/newstyle-java-types/Lib/os.py
branches/newstyle-java-types/Lib/test/test_import_jy.py
branches/newstyle-java-types/Lib/test/test_with.py
branches/newstyle-java-types/src/org/python/compiler/ClassFile.java
branches/newstyle-java-types/src/org/python/core/PySystemState.java
branches/newstyle-java-types/src/org/python/core/imp.java
branches/newstyle-java-types/src/org/python/modules/imp.java
branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporter.java
Property Changed:
----------------
branches/newstyle-java-types/
Property changes on: branches/newstyle-java-types
___________________________________________________________________
Modified: svnmerge-integrated
- /branches/nowalker:1-5263 /trunk/jython:1-5729 /branches/astwrite:1-5692
+ /branches/astwrite:1-5692 /branches/nowalker:1-5263 /trunk/jython:1-5736
Modified: svn:mergeinfo
- /trunk/jython:5565-5661,5670-5726
+ /trunk/jython:5565-5661,5670-5726,5730-5735
Modified: branches/newstyle-java-types/Lib/os.py
===================================================================
--- branches/newstyle-java-types/Lib/os.py 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/Lib/os.py 2008-12-12 03:29:49 UTC (rev 5737)
@@ -494,6 +494,9 @@
except:
raise
f = File(sys.getPath(path))
+ # XXX: jna-posix implements similar link detection in
+ # JavaFileStat.calculateSymlink, fallback to that instead when not
+ # native
abs_parent = f.getAbsoluteFile().getParentFile()
if not abs_parent:
# root isn't a link
@@ -669,29 +672,6 @@
except:
raise OSError(errno.EBADF, strerror(errno.EBADF))
-if _name == 'posix' and _native_posix:
- def link(src, dst):
- """link(src, dst)
-
- Create a hard link to a file.
- """
- _posix.link(sys.getPath(src), sys.getPath(dst))
-
- def symlink(src, dst):
- """symlink(src, dst)
-
- Create a symbolic link pointing to src named dst.
- """
- _posix.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.readlink(sys.getPath(path))
-
# Provide lazy popen*, and system objects
# Do these lazily, as most jython programs don't need them,
# and they are very expensive to initialize
@@ -906,66 +886,89 @@
The optional second argument can specify an alternate default."""
return environ.get(key, default)
-def getegid():
- """getegid() -> egid
+if _name == 'posix':
+ def link(src, dst):
+ """link(src, dst)
- Return the current process's effective group id."""
- return _posix.getegid()
+ Create a hard link to a file.
+ """
+ _posix.link(sys.getPath(src), sys.getPath(dst))
-def geteuid():
- """geteuid() -> euid
+ def symlink(src, dst):
+ """symlink(src, dst)
- Return the current process's effective user id."""
- return _posix.geteuid()
+ Create a symbolic link pointing to src named dst.
+ """
+ _posix.symlink(src, sys.getPath(dst))
-def getgid():
- """getgid() -> gid
+ def readlink(path):
+ """readlink(path) -> path
- Return the current process's group id."""
- return _posix.getgid()
+ Return a string representing the path to which the symbolic link
+ points.
+ """
+ return _posix.readlink(sys.getPath(path))
-def getlogin():
- """getlogin() -> string
+ def getegid():
+ """getegid() -> egid
- Return the actual login name."""
- return _posix.getlogin()
+ Return the current process's effective group id."""
+ return _posix.getegid()
-def getpgrp():
- """getpgrp() -> pgrp
+ def geteuid():
+ """geteuid() -> euid
- Return the current process group id."""
- return _posix.getpgrp()
+ Return the current process's effective user id."""
+ return _posix.geteuid()
-def getpid():
- """getpid() -> pid
+ def getgid():
+ """getgid() -> gid
- Return the current process id."""
- return _posix.getpid()
+ Return the current process's group id."""
+ return _posix.getgid()
-def getppid():
- """getppid() -> ppid
+ def getlogin():
+ """getlogin() -> string
- Return the parent's process id."""
- return _posix.getppid()
+ Return the actual login name."""
+ return _posix.getlogin()
-def getuid():
- """getuid() -> uid
+ def getpgrp():
+ """getpgrp() -> pgrp
- Return the current process's user id."""
- return _posix.getuid()
+ Return the current process group id."""
+ return _posix.getpgrp()
-def setpgrp():
- """setpgrp()
+ def getppid():
+ """getppid() -> ppid
- Make this process a session leader."""
- return _posix.setpgrp()
+ Return the parent's process id."""
+ return _posix.getppid()
-def setsid():
- """setsid()
+ def getuid():
+ """getuid() -> uid
- Call the system call setsid()."""
- return _posix.setsid()
+ Return the current process's user id."""
+ return _posix.getuid()
+ def setpgrp():
+ """setpgrp()
+
+ Make this process a session leader."""
+ return _posix.setpgrp()
+
+ def setsid():
+ """setsid()
+
+ Call the system call setsid()."""
+ return _posix.setsid()
+
+def getpid():
+ """getpid() -> pid
+
+ Return the current process id."""
+ return _posix.getpid()
+
def isatty(fileno):
"""isatty(fd) -> bool
Modified: branches/newstyle-java-types/Lib/test/test_import_jy.py
===================================================================
--- branches/newstyle-java-types/Lib/test/test_import_jy.py 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/Lib/test/test_import_jy.py 2008-12-12 03:29:49 UTC (rev 5737)
@@ -90,6 +90,7 @@
self.assertEquals(bytecode, read(init_compiled),
'bytecode was recompiled')
+
class OverrideBuiltinsImportTestCase(unittest.TestCase):
def test_override(self):
tests = [
@@ -127,9 +128,19 @@
finally:
__builtin__.__import__ = oldimp
+class ImpTestCase(unittest.TestCase):
+
+ def test_imp_find_module_builtins(self):
+ self.assertEqual(imp.find_module('sys'), (None, 'sys', ('', '', 6)))
+ self.assertEqual(imp.find_module('__builtin__'),
+ (None, '__builtin__', ('', '', 6)))
+ self.assertEqual(imp.find_module('imp'), (None, 'imp', ('', '', 6)))
+
+
def test_main():
- test_classes = [MislabeledImportTestCase, OverrideBuiltinsImportTestCase]
- test_support.run_unittest(*test_classes)
+ test_support.run_unittest(MislabeledImportTestCase,
+ OverrideBuiltinsImportTestCase,
+ ImpTestCase)
if __name__ == '__main__':
test_main()
Modified: branches/newstyle-java-types/Lib/test/test_with.py
===================================================================
--- branches/newstyle-java-types/Lib/test/test_with.py 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/Lib/test/test_with.py 2008-12-12 03:29:49 UTC (rev 5737)
@@ -505,7 +505,37 @@
self.assertRaises(GeneratorExit, shouldThrow)
+ def testErrorsInBool(self):
+ # issue4589: __exit__ return code may raise an exception
+ # when looking at its truth value.
+ class cm(object):
+ def __init__(self, bool_conversion):
+ class Bool:
+ def __nonzero__(self):
+ return bool_conversion()
+ self.exit_result = Bool()
+ def __enter__(self):
+ return 3
+ def __exit__(self, a, b, c):
+ return self.exit_result
+
+ def trueAsBool():
+ with cm(lambda: True):
+ self.fail("Should NOT see this")
+ trueAsBool()
+
+ def falseAsBool():
+ with cm(lambda: False):
+ self.fail("Should raise")
+ self.assertRaises(AssertionError, falseAsBool)
+
+ def failAsBool():
+ with cm(lambda: 1//0):
+ self.fail("Should NOT see this")
+ self.assertRaises(ZeroDivisionError, failAsBool)
+
+
class NonLocalFlowControlTestCase(unittest.TestCase,
ContextmanagerAssertionMixin):
Modified: branches/newstyle-java-types/src/org/python/compiler/ClassFile.java
===================================================================
--- branches/newstyle-java-types/src/org/python/compiler/ClassFile.java 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/src/org/python/compiler/ClassFile.java 2008-12-12 03:29:49 UTC (rev 5737)
@@ -46,7 +46,7 @@
this.interfaces = new String[0];
this.access = access;
- cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
+ cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
methodVisitors = Collections.synchronizedList(new ArrayList());
fieldVisitors = Collections.synchronizedList(new ArrayList());
}
Modified: branches/newstyle-java-types/src/org/python/core/PySystemState.java
===================================================================
--- branches/newstyle-java-types/src/org/python/core/PySystemState.java 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/src/org/python/core/PySystemState.java 2008-12-12 03:29:49 UTC (rev 5737)
@@ -709,6 +709,10 @@
private static void initBuiltins(Properties props) {
builtinNames = new Hashtable();
+ // add the oddball builtins that are specially handled
+ builtinNames.put("__builtin__", "");
+ builtinNames.put("sys", "");
+
// add builtins specified in the Setup.java file
for (int i=0; i < Setup.builtinModules.length; i++)
addBuiltin(Setup.builtinModules[i]);
@@ -727,7 +731,7 @@
builtin_module_names = new PyTuple(built_mod);
}
- static String getBuiltin(String name) {
+ public static String getBuiltin(String name) {
return (String)builtinNames.get(name);
}
Modified: branches/newstyle-java-types/src/org/python/core/imp.java
===================================================================
--- branches/newstyle-java-types/src/org/python/core/imp.java 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/src/org/python/core/imp.java 2008-12-12 03:29:49 UTC (rev 5737)
@@ -387,10 +387,13 @@
private static PyObject loadBuiltin(String name) {
if (name == "sys") {
- Py.writeComment(IMPORT_LOG, "'" + name + "' as sys in "
- + "builtin modules");
+ Py.writeComment(IMPORT_LOG, "'" + name + "' as sys in builtin modules");
return Py.java2py(Py.getSystemState());
}
+ if (name == "__builtin__") {
+ Py.writeComment(IMPORT_LOG, "'" + name + "' as __builtin__ in builtin modules");
+ return new PyModule("__builtin__", PySystemState.builtins);
+ }
String mod = PySystemState.getBuiltin(name);
if (mod != null) {
Class c = Py.findClassEx(mod, "builtin modules");
Modified: branches/newstyle-java-types/src/org/python/modules/imp.java
===================================================================
--- branches/newstyle-java-types/src/org/python/modules/imp.java 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/src/org/python/modules/imp.java 2008-12-12 03:29:49 UTC (rev 5737)
@@ -129,10 +129,6 @@
return null;
}
- public static PyObject find_module(String name) {
- return find_module(name, null);
- }
-
public static PyObject load_source(String modname, String filename) {
return load_source(modname, filename, null);
}
@@ -158,11 +154,20 @@
return mod;
}
+ public static PyObject find_module(String name) {
+ return find_module(name, Py.None);
+ }
+
public static PyObject find_module(String name, PyObject path) {
- if (path == null || path == Py.None) {
+ if (path == Py.None && PySystemState.getBuiltin(name) != null) {
+ return new PyTuple(Py.None, Py.newString(name),
+ new PyTuple(Py.EmptyString, Py.EmptyString,
+ Py.newInteger(C_BUILTIN)));
+ }
+
+ if (path == Py.None) {
path = Py.getSystemState().path;
}
-
for (PyObject p : path.asIterable()) {
ModuleInfo mi = findFromSource(name, p.toString(), false, true);
if(mi == null) {
Modified: branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporter.java
===================================================================
--- branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporter.java 2008-12-11 09:15:43 UTC (rev 5736)
+++ branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporter.java 2008-12-12 03:29:49 UTC (rev 5737)
@@ -115,8 +115,10 @@
prefix = "";
while (true) {
File fullPathFile = new File(sys.getPath(pathFile.getPath()));
- if (fullPathFile.isFile()) {
- archive = pathFile.getPath();
+ if (fullPathFile.exists()) {
+ if (fullPathFile.isFile()) {
+ archive = pathFile.getPath();
+ }
break;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|