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: <pj...@us...> - 2008-08-01 21:49:32
|
Revision: 5046 http://jython.svn.sourceforge.net/jython/?rev=5046&view=rev Author: pjenvey Date: 2008-08-01 21:49:29 +0000 (Fri, 01 Aug 2008) Log Message: ----------- fix instancemethod cmp to make test_class pass Modified Paths: -------------- branches/asm/Lib/test/regrtest.py branches/asm/Lib/test/test_class.py branches/asm/src/org/python/core/PyMethod.java Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-08-01 21:47:30 UTC (rev 5045) +++ branches/asm/Lib/test/regrtest.py 2008-08-01 21:49:29 UTC (rev 5046) @@ -1469,7 +1469,6 @@ 'java': """ test_ast - test_class test_codecencodings_cn test_codecencodings_hk test_codecencodings_jp Modified: branches/asm/Lib/test/test_class.py =================================================================== --- branches/asm/Lib/test/test_class.py 2008-08-01 21:47:30 UTC (rev 5045) +++ branches/asm/Lib/test/test_class.py 2008-08-01 21:49:29 UTC (rev 5046) @@ -250,8 +250,8 @@ del testme if sys.platform[:4] == 'java': - import java - java.lang.System.gc() + from test_weakref import extra_collect + extra_collect() # Interfering tests Modified: branches/asm/src/org/python/core/PyMethod.java =================================================================== --- branches/asm/src/org/python/core/PyMethod.java 2008-08-01 21:47:30 UTC (rev 5045) +++ branches/asm/src/org/python/core/PyMethod.java 2008-08-01 21:49:29 UTC (rev 5046) @@ -127,16 +127,20 @@ if (!(other instanceof PyMethod)) { return -2; } - PyMethod mother = (PyMethod)other; - if (im_self != mother.im_self) { - return System.identityHashCode(im_self) < - System.identityHashCode(mother.im_self) ? -1 : 1; + PyMethod otherMethod = (PyMethod)other; + int cmp = im_func._cmp(otherMethod.im_func); + if (cmp != 0) { + return cmp; } - if (im_func != mother.im_func) { - return System.identityHashCode(im_func) < - System.identityHashCode(mother.im_func) ? -1 : 1; + if (im_self == otherMethod.im_self) { + return 0; } - return 0; + if (im_self == null || otherMethod.im_self == null) { + return System.identityHashCode(im_self) < System.identityHashCode(otherMethod.im_self) + ? -1 : 1; + } else { + return im_self._cmp(otherMethod.im_self); + } } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-01 21:47:33
|
Revision: 5045 http://jython.svn.sourceforge.net/jython/?rev=5045&view=rev Author: pjenvey Date: 2008-08-01 21:47:30 +0000 (Fri, 01 Aug 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_class.py@52663 Added Paths: ----------- branches/asm/Lib/test/test_class.py Added: branches/asm/Lib/test/test_class.py =================================================================== --- branches/asm/Lib/test/test_class.py (rev 0) +++ branches/asm/Lib/test/test_class.py 2008-08-01 21:47:30 UTC (rev 5045) @@ -0,0 +1,412 @@ +"Test the functionality of Python classes implementing operators." + +from test.test_support import TestFailed + +testmeths = [ + +# Binary operations + "add", + "radd", + "sub", + "rsub", + "mul", + "rmul", + "div", + "rdiv", + "mod", + "rmod", + "divmod", + "rdivmod", + "pow", + "rpow", + "rshift", + "rrshift", + "lshift", + "rlshift", + "and", + "rand", + "or", + "ror", + "xor", + "rxor", + +# List/dict operations + "contains", + "getitem", + "getslice", + "setitem", + "setslice", + "delitem", + "delslice", + +# Unary operations + "neg", + "pos", + "abs", + +# generic operations + "init", + ] + +# These need to return something other than None +# "coerce", +# "hash", +# "str", +# "repr", +# "int", +# "long", +# "float", +# "oct", +# "hex", + +# These are separate because they can influence the test of other methods. +# "getattr", +# "setattr", +# "delattr", + +class AllTests: + def __coerce__(self, *args): + print "__coerce__:", args + return (self,) + args + + def __hash__(self, *args): + print "__hash__:", args + return hash(id(self)) + + def __str__(self, *args): + print "__str__:", args + return "AllTests" + + def __repr__(self, *args): + print "__repr__:", args + return "AllTests" + + def __int__(self, *args): + print "__int__:", args + return 1 + + def __float__(self, *args): + print "__float__:", args + return 1.0 + + def __long__(self, *args): + print "__long__:", args + return 1L + + def __oct__(self, *args): + print "__oct__:", args + return '01' + + def __hex__(self, *args): + print "__hex__:", args + return '0x1' + + def __cmp__(self, *args): + print "__cmp__:", args + return 0 + + def __del__(self, *args): + print "__del__:", args + +# Synthesize AllTests methods from the names in testmeths. + +method_template = """\ +def __%(method)s__(self, *args): + print "__%(method)s__:", args +""" + +for method in testmeths: + exec method_template % locals() in AllTests.__dict__ + +del method, method_template + +# this also tests __init__ of course. +testme = AllTests() + +# Binary operations + +testme + 1 +1 + testme + +testme - 1 +1 - testme + +testme * 1 +1 * testme + +if 1/2 == 0: + testme / 1 + 1 / testme +else: + # True division is in effect, so "/" doesn't map to __div__ etc; but + # the canned expected-output file requires that __div__ etc get called. + testme.__coerce__(1) + testme.__div__(1) + testme.__coerce__(1) + testme.__rdiv__(1) + +testme % 1 +1 % testme + +divmod(testme,1) +divmod(1, testme) + +testme ** 1 +1 ** testme + +testme >> 1 +1 >> testme + +testme << 1 +1 << testme + +testme & 1 +1 & testme + +testme | 1 +1 | testme + +testme ^ 1 +1 ^ testme + + +# List/dict operations + +class Empty: pass + +try: + 1 in Empty() + print 'failed, should have raised TypeError' +except TypeError: + pass + +1 in testme + +testme[1] +testme[1] = 1 +del testme[1] + +testme[:42] +testme[:42] = "The Answer" +del testme[:42] + +testme[2:1024:10] +testme[2:1024:10] = "A lot" +del testme[2:1024:10] + +testme[:42, ..., :24:, 24, 100] +testme[:42, ..., :24:, 24, 100] = "Strange" +del testme[:42, ..., :24:, 24, 100] + + +# Now remove the slice hooks to see if converting normal slices to slice +# object works. + +del AllTests.__getslice__ +del AllTests.__setslice__ +del AllTests.__delslice__ + +import sys +if sys.platform[:4] != 'java': + testme[:42] + testme[:42] = "The Answer" + del testme[:42] +else: + # This works under Jython, but the actual slice values are + # different. + print "__getitem__: (slice(0, 42, None),)" + print "__setitem__: (slice(0, 42, None), 'The Answer')" + print "__delitem__: (slice(0, 42, None),)" + +# Unary operations + +-testme ++testme +abs(testme) +int(testme) +long(testme) +float(testme) +oct(testme) +hex(testme) + +# And the rest... + +hash(testme) +repr(testme) +str(testme) + +testme == 1 +testme < 1 +testme > 1 +testme <> 1 +testme != 1 +1 == testme +1 < testme +1 > testme +1 <> testme +1 != testme + +# This test has to be last (duh.) + +del testme +if sys.platform[:4] == 'java': + import java + java.lang.System.gc() + +# Interfering tests + +class ExtraTests: + def __getattr__(self, *args): + print "__getattr__:", args + return "SomeVal" + + def __setattr__(self, *args): + print "__setattr__:", args + + def __delattr__(self, *args): + print "__delattr__:", args + +testme = ExtraTests() +testme.spam +testme.eggs = "spam, spam, spam and ham" +del testme.cardinal + + +# return values of some method are type-checked +class BadTypeClass: + def __int__(self): + return None + __float__ = __int__ + __long__ = __int__ + __str__ = __int__ + __repr__ = __int__ + __oct__ = __int__ + __hex__ = __int__ + +def check_exc(stmt, exception): + """Raise TestFailed if executing 'stmt' does not raise 'exception' + """ + try: + exec stmt + except exception: + pass + else: + raise TestFailed, "%s should raise %s" % (stmt, exception) + +check_exc("int(BadTypeClass())", TypeError) +check_exc("float(BadTypeClass())", TypeError) +check_exc("long(BadTypeClass())", TypeError) +check_exc("str(BadTypeClass())", TypeError) +check_exc("repr(BadTypeClass())", TypeError) +check_exc("oct(BadTypeClass())", TypeError) +check_exc("hex(BadTypeClass())", TypeError) + +# mixing up ints and longs is okay +class IntLongMixClass: + def __int__(self): + return 0L + + def __long__(self): + return 0 + +try: + int(IntLongMixClass()) +except TypeError: + raise TestFailed, "TypeError should not be raised" + +try: + long(IntLongMixClass()) +except TypeError: + raise TestFailed, "TypeError should not be raised" + + +# Test correct errors from hash() on objects with comparisons but no __hash__ + +class C0: + pass + +hash(C0()) # This should work; the next two should raise TypeError + +class C1: + def __cmp__(self, other): return 0 + +check_exc("hash(C1())", TypeError) + +class C2: + def __eq__(self, other): return 1 + +check_exc("hash(C2())", TypeError) + +# Test for SF bug 532646 + +class A: + pass +A.__call__ = A() +a = A() +try: + a() # This should not segfault +except RuntimeError: + pass +else: + raise TestFailed, "how could this not have overflowed the stack?" + + +# Tests for exceptions raised in instance_getattr2(). + +def booh(self): + raise AttributeError, "booh" + +class A: + a = property(booh) +try: + A().a # Raised AttributeError: A instance has no attribute 'a' +except AttributeError, x: + if str(x) != "booh": + print "attribute error for A().a got masked:", str(x) + +class E: + __eq__ = property(booh) +E() == E() # In debug mode, caused a C-level assert() to fail + +class I: + __init__ = property(booh) +try: + I() # In debug mode, printed XXX undetected error and raises AttributeError +except AttributeError, x: + pass +else: + print "attribute error for I.__init__ got masked" + + +# Test comparison and hash of methods +class A: + def __init__(self, x): + self.x = x + def f(self): + pass + def g(self): + pass + def __eq__(self, other): + return self.x == other.x + def __hash__(self): + return self.x +class B(A): + pass + +a1 = A(1) +a2 = A(2) +assert a1.f == a1.f +assert a1.f != a2.f +assert a1.f != a1.g +assert a1.f == A(1).f +assert hash(a1.f) == hash(a1.f) +assert hash(a1.f) == hash(A(1).f) + +assert A.f != a1.f +assert A.f != A.g +assert B.f == A.f +assert hash(B.f) == hash(A.f) + +# the following triggers a SystemError in 2.4 +a = A(hash(A.f.im_func)^(-1)) +hash(a.f) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-01 20:37:49
|
Revision: 5044 http://jython.svn.sourceforge.net/jython/?rev=5044&view=rev Author: fwierzbicki Date: 2008-08-01 20:37:46 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Better handling of bad dedent. Not perfect since it throws the wrong exception. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-01 20:22:22 UTC (rev 5043) +++ branches/asm/grammar/Python.g 2008-08-01 20:37:46 UTC (rev 5044) @@ -1385,8 +1385,10 @@ for (int i=0; i<spaces; i++) { indentation[i] = ' '; } - String s = new String(indentation); - emit(new ClassicToken(LEADING_WS,new String(indentation))); + ClassicToken c = new ClassicToken(LEADING_WS,new String(indentation)); + c.setLine(input.getLine()); + c.setCharPositionInLine(input.getCharPositionInLine()); + emit(c); } // kill trailing newline if present and then ignore ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-01 20:22:22 UTC (rev 5043) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-01 20:37:46 UTC (rev 5044) @@ -202,7 +202,7 @@ } else if (cpos < lastIndent) { // they dedented // how far back did we dedent? - int prevIndex = findPreviousIndent(cpos); + int prevIndex = findPreviousIndent(cpos, t); //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex); // generate DEDENTs for each indent level we backed up over for (int d = sp - 1; d >= prevIndex; d--) { @@ -255,13 +255,20 @@ } /** Return the index on stack of previous indent level == i else -1 */ - protected int findPreviousIndent(int i) { + protected int findPreviousIndent(int i, Token t) { for (int j = sp - 1; j >= 0; j--) { if (indentStack[j] == i) { return j; } } - return FIRST_CHAR_POSITION; + //The -2 is for the special case of getCharPositionInLine in multiline str nodes. + if (i == -1 || i == -2) { + return FIRST_CHAR_POSITION; + } + ParseException p = new ParseException("unindent does not match any outer indentation level"); + p.line = t.getLine(); + p.charPositionInLine = t.getCharPositionInLine(); + throw p; } public String stackString() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-01 20:22:24
|
Revision: 5043 http://jython.svn.sourceforge.net/jython/?rev=5043&view=rev Author: nriley Date: 2008-08-01 20:22:22 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Replace python.prepath with python.path. Modified Paths: -------------- branches/asm/NEWS branches/asm/src/org/python/core/PySystemState.java Modified: branches/asm/NEWS =================================================================== --- branches/asm/NEWS 2008-08-01 20:07:47 UTC (rev 5042) +++ branches/asm/NEWS 2008-08-01 20:22:22 UTC (rev 5043) @@ -2,6 +2,7 @@ Jython 2.5 Incompatible Changes + - The python.prepath property has been removed; use python.path instead. - To implement the Java Map interface, PyDictionary.values now returns a Collection instead of a PyList - The -E codec command line option (use a different codec when reading from Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-08-01 20:07:47 UTC (rev 5042) +++ branches/asm/src/org/python/core/PySystemState.java 2008-08-01 20:22:22 UTC (rev 5043) @@ -703,12 +703,11 @@ private static PyList initPath(Properties props, boolean standalone, String jarFileName) { PyList path = new PyList(); - addPaths(path, props.getProperty("python.prepath", "")); + addPaths(path, props.getProperty("python.path", "")); if (prefix != null) { String libpath = new File(prefix, "Lib").toString(); path.append(new PyString(libpath)); } - addPaths(path, props.getProperty("python.path", "")); if (standalone) { // standalone jython: add the /Lib directory inside JYTHON_JAR to the path addPaths(path, jarFileName + "/Lib"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-01 20:07:51
|
Revision: 5042 http://jython.svn.sourceforge.net/jython/?rev=5042&view=rev Author: nriley Date: 2008-08-01 20:07:47 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Support one-argument builtin apply. Modified Paths: -------------- branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-01 20:06:44 UTC (rev 5041) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-01 20:07:47 UTC (rev 5042) @@ -60,6 +60,8 @@ return Py.newUnicode(__builtin__.unichr(Py.py2int(arg1, "unichr(): 1st arg can't be coerced to int"))); case 7: return __builtin__.abs(arg1); + case 9: + return __builtin__.apply(arg1); case 11: return Py.newInteger(__builtin__.id(arg1)); case 12: @@ -335,7 +337,7 @@ dict.__setitem__("__debug__", Py.One); dict.__setitem__("abs", new BuiltinFunctions("abs", 7, 1)); - dict.__setitem__("apply", new BuiltinFunctions("apply", 9, 2, 3)); + dict.__setitem__("apply", new BuiltinFunctions("apply", 9, 1, 3)); dict.__setitem__("callable", new BuiltinFunctions("callable", 14, 1)); dict.__setitem__("coerce", new BuiltinFunctions("coerce", 13, 2)); dict.__setitem__("chr", new BuiltinFunctions("chr", 0, 1)); @@ -391,6 +393,10 @@ throw Py.TypeError("bad operand type for abs()"); } + public static PyObject apply(PyObject o) { + return o.__call__(); + } + public static PyObject apply(PyObject o, PyObject args) { return o.__call__(Py.make_array(args)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-01 20:06:47
|
Revision: 5041 http://jython.svn.sourceforge.net/jython/?rev=5041&view=rev Author: nriley Date: 2008-08-01 20:06:44 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Make the ihooks module importable. Modified Paths: -------------- branches/asm/CPythonLib.includes branches/asm/src/org/python/modules/imp.java Modified: branches/asm/CPythonLib.includes =================================================================== --- branches/asm/CPythonLib.includes 2008-08-01 00:50:28 UTC (rev 5040) +++ branches/asm/CPythonLib.includes 2008-08-01 20:06:44 UTC (rev 5041) @@ -69,6 +69,7 @@ htmllib.py HTMLParser.py httplib.py +ihooks.py imaplib.py imghdr.py inspect.py Modified: branches/asm/src/org/python/modules/imp.java =================================================================== --- branches/asm/src/org/python/modules/imp.java 2008-08-01 00:50:28 UTC (rev 5040) +++ branches/asm/src/org/python/modules/imp.java 2008-08-01 20:06:44 UTC (rev 5041) @@ -33,6 +33,7 @@ public static final int PY_COMPILED = 2; public static final int C_EXTENSION = 3; public static final int PKG_DIRECTORY = 5; + public static final int C_BUILTIN = 6; public static final int PY_FROZEN = 7; public static final int IMP_HOOK = 9; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-01 00:50:30
|
Revision: 5040 http://jython.svn.sourceforge.net/jython/?rev=5040&view=rev Author: fwierzbicki Date: 2008-08-01 00:50:28 +0000 (Fri, 01 Aug 2008) Log Message: ----------- remove unneeded member. Modified Paths: -------------- branches/asm/src/org/python/antlr/FailFastHandler.java branches/asm/src/org/python/antlr/ListErrorHandler.java Modified: branches/asm/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/asm/src/org/python/antlr/FailFastHandler.java 2008-07-31 23:59:25 UTC (rev 5039) +++ branches/asm/src/org/python/antlr/FailFastHandler.java 2008-08-01 00:50:28 UTC (rev 5040) @@ -6,7 +6,6 @@ import org.antlr.runtime.RecognitionException; public class FailFastHandler implements ErrorHandler { - private BaseRecognizer recognizer; public void reportError(BaseRecognizer br, RecognitionException re) { throw new ParseException(message(br,re), re); Modified: branches/asm/src/org/python/antlr/ListErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-07-31 23:59:25 UTC (rev 5039) +++ branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-08-01 00:50:28 UTC (rev 5040) @@ -6,7 +6,6 @@ import org.antlr.runtime.RecognitionException; public class ListErrorHandler implements ErrorHandler { - private BaseRecognizer recognizer; public void reportError(BaseRecognizer br, RecognitionException re) { br.reportError(re); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:59:27
|
Revision: 5039 http://jython.svn.sourceforge.net/jython/?rev=5039&view=rev Author: pjenvey Date: 2008-07-31 23:59:25 +0000 (Thu, 31 Jul 2008) Log Message: ----------- o filter operator slice args through __index__ o workaround Jython's lack of a real repeat/concat binop in test_operator Modified Paths: -------------- branches/asm/Lib/test/test_operator.py branches/asm/src/org/python/modules/operator.java Modified: branches/asm/Lib/test/test_operator.py =================================================================== --- branches/asm/Lib/test/test_operator.py 2008-07-31 23:57:11 UTC (rev 5038) +++ branches/asm/Lib/test/test_operator.py 2008-07-31 23:59:25 UTC (rev 5039) @@ -122,7 +122,9 @@ self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4]) self.failUnless(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7]) self.failUnless(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7]) - self.failUnlessRaises(TypeError, operator.concat, 13, 29) + if not test_support.is_jython: + # Jython concat is add + self.failUnlessRaises(TypeError, operator.concat, 13, 29) def test_countOf(self): self.failUnlessRaises(TypeError, operator.countOf) @@ -291,7 +293,9 @@ self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) self.failUnless(operator.repeat(a, 0) == []) - self.failUnlessRaises(TypeError, operator.repeat, 6, 7) + if not test_support.is_jython: + # Jython repeat is mul + self.failUnlessRaises(TypeError, operator.repeat, 6, 7) def test_rshift(self): self.failUnlessRaises(TypeError, operator.rshift) Modified: branches/asm/src/org/python/modules/operator.java =================================================================== --- branches/asm/src/org/python/modules/operator.java 2008-07-31 23:57:11 UTC (rev 5038) +++ branches/asm/src/org/python/modules/operator.java 2008-07-31 23:59:25 UTC (rev 5039) @@ -85,8 +85,8 @@ public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { switch (index) { - case 22: arg1.__delslice__(arg2, arg3); return Py.None; - case 24: return arg1.__getslice__(arg2, arg3); + case 22: arg1.__delslice__(arg2.__index__(), arg3.__index__()); return Py.None; + case 24: return arg1.__getslice__(arg2.__index__(), arg3.__index__()); case 25: arg1.__setitem__(arg2, arg3); return Py.None; default: throw info.unexpectedCall(3, false); @@ -98,7 +98,7 @@ { switch (index) { case 26: - arg1.__setslice__(arg2, arg3, arg4); + arg1.__setslice__(arg2.__index__(), arg3.__index__(), arg4); return Py.None; default: throw info.unexpectedCall(4, false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:57:13
|
Revision: 5038 http://jython.svn.sourceforge.net/jython/?rev=5038&view=rev Author: pjenvey Date: 2008-07-31 23:57:11 +0000 (Thu, 31 Jul 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_operator.py@54178 Added Paths: ----------- branches/asm/Lib/test/test_operator.py Added: branches/asm/Lib/test/test_operator.py =================================================================== --- branches/asm/Lib/test/test_operator.py (rev 0) +++ branches/asm/Lib/test/test_operator.py 2008-07-31 23:57:11 UTC (rev 5038) @@ -0,0 +1,490 @@ +import operator +import unittest + +from test import test_support + +class Seq1: + def __init__(self, lst): + self.lst = lst + def __len__(self): + return len(self.lst) + def __getitem__(self, i): + return self.lst[i] + def __add__(self, other): + return self.lst + other.lst + def __mul__(self, other): + return self.lst * other + def __rmul__(self, other): + return other * self.lst + +class Seq2(object): + def __init__(self, lst): + self.lst = lst + def __len__(self): + return len(self.lst) + def __getitem__(self, i): + return self.lst[i] + def __add__(self, other): + return self.lst + other.lst + def __mul__(self, other): + return self.lst * other + def __rmul__(self, other): + return other * self.lst + + +class OperatorTestCase(unittest.TestCase): + def test_lt(self): + self.failUnlessRaises(TypeError, operator.lt) + self.failUnlessRaises(TypeError, operator.lt, 1j, 2j) + self.failIf(operator.lt(1, 0)) + self.failIf(operator.lt(1, 0.0)) + self.failIf(operator.lt(1, 1)) + self.failIf(operator.lt(1, 1.0)) + self.failUnless(operator.lt(1, 2)) + self.failUnless(operator.lt(1, 2.0)) + + def test_le(self): + self.failUnlessRaises(TypeError, operator.le) + self.failUnlessRaises(TypeError, operator.le, 1j, 2j) + self.failIf(operator.le(1, 0)) + self.failIf(operator.le(1, 0.0)) + self.failUnless(operator.le(1, 1)) + self.failUnless(operator.le(1, 1.0)) + self.failUnless(operator.le(1, 2)) + self.failUnless(operator.le(1, 2.0)) + + def test_eq(self): + class C(object): + def __eq__(self, other): + raise SyntaxError + self.failUnlessRaises(TypeError, operator.eq) + self.failUnlessRaises(SyntaxError, operator.eq, C(), C()) + self.failIf(operator.eq(1, 0)) + self.failIf(operator.eq(1, 0.0)) + self.failUnless(operator.eq(1, 1)) + self.failUnless(operator.eq(1, 1.0)) + self.failIf(operator.eq(1, 2)) + self.failIf(operator.eq(1, 2.0)) + + def test_ne(self): + class C(object): + def __ne__(self, other): + raise SyntaxError + self.failUnlessRaises(TypeError, operator.ne) + self.failUnlessRaises(SyntaxError, operator.ne, C(), C()) + self.failUnless(operator.ne(1, 0)) + self.failUnless(operator.ne(1, 0.0)) + self.failIf(operator.ne(1, 1)) + self.failIf(operator.ne(1, 1.0)) + self.failUnless(operator.ne(1, 2)) + self.failUnless(operator.ne(1, 2.0)) + + def test_ge(self): + self.failUnlessRaises(TypeError, operator.ge) + self.failUnlessRaises(TypeError, operator.ge, 1j, 2j) + self.failUnless(operator.ge(1, 0)) + self.failUnless(operator.ge(1, 0.0)) + self.failUnless(operator.ge(1, 1)) + self.failUnless(operator.ge(1, 1.0)) + self.failIf(operator.ge(1, 2)) + self.failIf(operator.ge(1, 2.0)) + + def test_gt(self): + self.failUnlessRaises(TypeError, operator.gt) + self.failUnlessRaises(TypeError, operator.gt, 1j, 2j) + self.failUnless(operator.gt(1, 0)) + self.failUnless(operator.gt(1, 0.0)) + self.failIf(operator.gt(1, 1)) + self.failIf(operator.gt(1, 1.0)) + self.failIf(operator.gt(1, 2)) + self.failIf(operator.gt(1, 2.0)) + + def test_abs(self): + self.failUnlessRaises(TypeError, operator.abs) + self.failUnlessRaises(TypeError, operator.abs, None) + self.failUnless(operator.abs(-1) == 1) + self.failUnless(operator.abs(1) == 1) + + def test_add(self): + self.failUnlessRaises(TypeError, operator.add) + self.failUnlessRaises(TypeError, operator.add, None, None) + self.failUnless(operator.add(3, 4) == 7) + + def test_bitwise_and(self): + self.failUnlessRaises(TypeError, operator.and_) + self.failUnlessRaises(TypeError, operator.and_, None, None) + self.failUnless(operator.and_(0xf, 0xa) == 0xa) + + def test_concat(self): + self.failUnlessRaises(TypeError, operator.concat) + self.failUnlessRaises(TypeError, operator.concat, None, None) + self.failUnless(operator.concat('py', 'thon') == 'python') + self.failUnless(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4]) + self.failUnless(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7]) + self.failUnless(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7]) + self.failUnlessRaises(TypeError, operator.concat, 13, 29) + + def test_countOf(self): + self.failUnlessRaises(TypeError, operator.countOf) + self.failUnlessRaises(TypeError, operator.countOf, None, None) + self.failUnless(operator.countOf([1, 2, 1, 3, 1, 4], 3) == 1) + self.failUnless(operator.countOf([1, 2, 1, 3, 1, 4], 5) == 0) + + def test_delitem(self): + a = [4, 3, 2, 1] + self.failUnlessRaises(TypeError, operator.delitem, a) + self.failUnlessRaises(TypeError, operator.delitem, a, None) + self.failUnless(operator.delitem(a, 1) is None) + self.assert_(a == [4, 2, 1]) + + def test_delslice(self): + a = range(10) + self.failUnlessRaises(TypeError, operator.delslice, a) + self.failUnlessRaises(TypeError, operator.delslice, a, None, None) + self.failUnless(operator.delslice(a, 2, 8) is None) + self.assert_(a == [0, 1, 8, 9]) + operator.delslice(a, 0, test_support.MAX_Py_ssize_t) + self.assert_(a == []) + + def test_div(self): + self.failUnlessRaises(TypeError, operator.div, 5) + self.failUnlessRaises(TypeError, operator.div, None, None) + self.failUnless(operator.floordiv(5, 2) == 2) + + def test_floordiv(self): + self.failUnlessRaises(TypeError, operator.floordiv, 5) + self.failUnlessRaises(TypeError, operator.floordiv, None, None) + self.failUnless(operator.floordiv(5, 2) == 2) + + def test_truediv(self): + self.failUnlessRaises(TypeError, operator.truediv, 5) + self.failUnlessRaises(TypeError, operator.truediv, None, None) + self.failUnless(operator.truediv(5, 2) == 2.5) + + def test_getitem(self): + a = range(10) + self.failUnlessRaises(TypeError, operator.getitem) + self.failUnlessRaises(TypeError, operator.getitem, a, None) + self.failUnless(operator.getitem(a, 2) == 2) + + def test_getslice(self): + a = range(10) + self.failUnlessRaises(TypeError, operator.getslice) + self.failUnlessRaises(TypeError, operator.getslice, a, None, None) + self.failUnless(operator.getslice(a, 4, 6) == [4, 5]) + b = operator.getslice(a, 0, test_support.MAX_Py_ssize_t) + self.assert_(b == a) + + def test_indexOf(self): + self.failUnlessRaises(TypeError, operator.indexOf) + self.failUnlessRaises(TypeError, operator.indexOf, None, None) + self.failUnless(operator.indexOf([4, 3, 2, 1], 3) == 1) + self.assertRaises(ValueError, operator.indexOf, [4, 3, 2, 1], 0) + + def test_invert(self): + self.failUnlessRaises(TypeError, operator.invert) + self.failUnlessRaises(TypeError, operator.invert, None) + self.failUnless(operator.inv(4) == -5) + + def test_isCallable(self): + self.failUnlessRaises(TypeError, operator.isCallable) + class C: + pass + def check(self, o, v): + self.assert_(operator.isCallable(o) == callable(o) == v) + check(self, 4, 0) + check(self, operator.isCallable, 1) + check(self, C, 1) + check(self, C(), 0) + + def test_isMappingType(self): + self.failUnlessRaises(TypeError, operator.isMappingType) + self.failIf(operator.isMappingType(1)) + self.failIf(operator.isMappingType(operator.isMappingType)) + self.failUnless(operator.isMappingType(operator.__dict__)) + self.failUnless(operator.isMappingType({})) + + def test_isNumberType(self): + self.failUnlessRaises(TypeError, operator.isNumberType) + self.failUnless(operator.isNumberType(8)) + self.failUnless(operator.isNumberType(8j)) + self.failUnless(operator.isNumberType(8L)) + self.failUnless(operator.isNumberType(8.3)) + self.failIf(operator.isNumberType(dir())) + + def test_isSequenceType(self): + self.failUnlessRaises(TypeError, operator.isSequenceType) + self.failUnless(operator.isSequenceType(dir())) + self.failUnless(operator.isSequenceType(())) + self.failUnless(operator.isSequenceType(xrange(10))) + self.failUnless(operator.isSequenceType('yeahbuddy')) + self.failIf(operator.isSequenceType(3)) + class Dict(dict): pass + self.failIf(operator.isSequenceType(Dict())) + + def test_lshift(self): + self.failUnlessRaises(TypeError, operator.lshift) + self.failUnlessRaises(TypeError, operator.lshift, None, 42) + self.failUnless(operator.lshift(5, 1) == 10) + self.failUnless(operator.lshift(5, 0) == 5) + self.assertRaises(ValueError, operator.lshift, 2, -1) + + def test_mod(self): + self.failUnlessRaises(TypeError, operator.mod) + self.failUnlessRaises(TypeError, operator.mod, None, 42) + self.failUnless(operator.mod(5, 2) == 1) + + def test_mul(self): + self.failUnlessRaises(TypeError, operator.mul) + self.failUnlessRaises(TypeError, operator.mul, None, None) + self.failUnless(operator.mul(5, 2) == 10) + + def test_neg(self): + self.failUnlessRaises(TypeError, operator.neg) + self.failUnlessRaises(TypeError, operator.neg, None) + self.failUnless(operator.neg(5) == -5) + self.failUnless(operator.neg(-5) == 5) + self.failUnless(operator.neg(0) == 0) + self.failUnless(operator.neg(-0) == 0) + + def test_bitwise_or(self): + self.failUnlessRaises(TypeError, operator.or_) + self.failUnlessRaises(TypeError, operator.or_, None, None) + self.failUnless(operator.or_(0xa, 0x5) == 0xf) + + def test_pos(self): + self.failUnlessRaises(TypeError, operator.pos) + self.failUnlessRaises(TypeError, operator.pos, None) + self.failUnless(operator.pos(5) == 5) + self.failUnless(operator.pos(-5) == -5) + self.failUnless(operator.pos(0) == 0) + self.failUnless(operator.pos(-0) == 0) + + def test_pow(self): + self.failUnlessRaises(TypeError, operator.pow) + self.failUnlessRaises(TypeError, operator.pow, None, None) + self.failUnless(operator.pow(3,5) == 3**5) + self.failUnless(operator.__pow__(3,5) == 3**5) + self.assertRaises(TypeError, operator.pow, 1) + self.assertRaises(TypeError, operator.pow, 1, 2, 3) + + def test_repeat(self): + a = range(3) + self.failUnlessRaises(TypeError, operator.repeat) + self.failUnlessRaises(TypeError, operator.repeat, a, None) + self.failUnless(operator.repeat(a, 2) == a+a) + self.failUnless(operator.repeat(a, 1) == a) + self.failUnless(operator.repeat(a, 0) == []) + a = (1, 2, 3) + self.failUnless(operator.repeat(a, 2) == a+a) + self.failUnless(operator.repeat(a, 1) == a) + self.failUnless(operator.repeat(a, 0) == ()) + a = '123' + self.failUnless(operator.repeat(a, 2) == a+a) + self.failUnless(operator.repeat(a, 1) == a) + self.failUnless(operator.repeat(a, 0) == '') + a = Seq1([4, 5, 6]) + self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) + self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) + self.failUnless(operator.repeat(a, 0) == []) + a = Seq2([4, 5, 6]) + self.failUnless(operator.repeat(a, 2) == [4, 5, 6, 4, 5, 6]) + self.failUnless(operator.repeat(a, 1) == [4, 5, 6]) + self.failUnless(operator.repeat(a, 0) == []) + self.failUnlessRaises(TypeError, operator.repeat, 6, 7) + + def test_rshift(self): + self.failUnlessRaises(TypeError, operator.rshift) + self.failUnlessRaises(TypeError, operator.rshift, None, 42) + self.failUnless(operator.rshift(5, 1) == 2) + self.failUnless(operator.rshift(5, 0) == 5) + self.assertRaises(ValueError, operator.rshift, 2, -1) + + def test_contains(self): + self.failUnlessRaises(TypeError, operator.contains) + self.failUnlessRaises(TypeError, operator.contains, None, None) + self.failUnless(operator.contains(range(4), 2)) + self.failIf(operator.contains(range(4), 5)) + self.failUnless(operator.sequenceIncludes(range(4), 2)) + self.failIf(operator.sequenceIncludes(range(4), 5)) + + def test_setitem(self): + a = range(3) + self.failUnlessRaises(TypeError, operator.setitem, a) + self.failUnlessRaises(TypeError, operator.setitem, a, None, None) + self.failUnless(operator.setitem(a, 0, 2) is None) + self.assert_(a == [2, 1, 2]) + self.assertRaises(IndexError, operator.setitem, a, 4, 2) + + def test_setslice(self): + a = range(4) + self.failUnlessRaises(TypeError, operator.setslice, a) + self.failUnlessRaises(TypeError, operator.setslice, a, None, None, None) + self.failUnless(operator.setslice(a, 1, 3, [2, 1]) is None) + self.assert_(a == [0, 2, 1, 3]) + operator.setslice(a, 0, test_support.MAX_Py_ssize_t, []) + self.assert_(a == []) + + def test_sub(self): + self.failUnlessRaises(TypeError, operator.sub) + self.failUnlessRaises(TypeError, operator.sub, None, None) + self.failUnless(operator.sub(5, 2) == 3) + + def test_truth(self): + class C(object): + def __nonzero__(self): + raise SyntaxError + self.failUnlessRaises(TypeError, operator.truth) + self.failUnlessRaises(SyntaxError, operator.truth, C()) + self.failUnless(operator.truth(5)) + self.failUnless(operator.truth([0])) + self.failIf(operator.truth(0)) + self.failIf(operator.truth([])) + + def test_bitwise_xor(self): + self.failUnlessRaises(TypeError, operator.xor) + self.failUnlessRaises(TypeError, operator.xor, None, None) + self.failUnless(operator.xor(0xb, 0xc) == 0x7) + + def test_is(self): + a = b = 'xyzpdq' + c = a[:3] + b[3:] + self.failUnlessRaises(TypeError, operator.is_) + self.failUnless(operator.is_(a, b)) + self.failIf(operator.is_(a,c)) + + def test_is_not(self): + a = b = 'xyzpdq' + c = a[:3] + b[3:] + self.failUnlessRaises(TypeError, operator.is_not) + self.failIf(operator.is_not(a, b)) + self.failUnless(operator.is_not(a,c)) + + def test_attrgetter(self): + class A: + pass + a = A() + a.name = 'arthur' + f = operator.attrgetter('name') + self.assertEqual(f(a), 'arthur') + f = operator.attrgetter('rank') + self.assertRaises(AttributeError, f, a) + f = operator.attrgetter(2) + self.assertRaises(TypeError, f, a) + self.assertRaises(TypeError, operator.attrgetter) + + # multiple gets + record = A() + record.x = 'X' + record.y = 'Y' + record.z = 'Z' + self.assertEqual(operator.attrgetter('x','z','y')(record), ('X', 'Z', 'Y')) + self.assertRaises(TypeError, operator.attrgetter('x', (), 'y'), record) + + class C(object): + def __getattr(self, name): + raise SyntaxError + self.failUnlessRaises(AttributeError, operator.attrgetter('foo'), C()) + + def test_itemgetter(self): + a = 'ABCDE' + f = operator.itemgetter(2) + self.assertEqual(f(a), 'C') + f = operator.itemgetter(10) + self.assertRaises(IndexError, f, a) + + class C(object): + def __getitem(self, name): + raise SyntaxError + self.failUnlessRaises(TypeError, operator.itemgetter(42), C()) + + f = operator.itemgetter('name') + self.assertRaises(TypeError, f, a) + self.assertRaises(TypeError, operator.itemgetter) + + d = dict(key='val') + f = operator.itemgetter('key') + self.assertEqual(f(d), 'val') + f = operator.itemgetter('nonkey') + self.assertRaises(KeyError, f, d) + + # example used in the docs + inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)] + getcount = operator.itemgetter(1) + self.assertEqual(map(getcount, inventory), [3, 2, 5, 1]) + self.assertEqual(sorted(inventory, key=getcount), + [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]) + + # multiple gets + data = map(str, range(20)) + self.assertEqual(operator.itemgetter(2,10,5)(data), ('2', '10', '5')) + self.assertRaises(TypeError, operator.itemgetter(2, 'x', 5), data) + + def test_inplace(self): + class C(object): + def __iadd__ (self, other): return "iadd" + def __iand__ (self, other): return "iand" + def __idiv__ (self, other): return "idiv" + def __ifloordiv__(self, other): return "ifloordiv" + def __ilshift__ (self, other): return "ilshift" + def __imod__ (self, other): return "imod" + def __imul__ (self, other): return "imul" + def __ior__ (self, other): return "ior" + def __ipow__ (self, other): return "ipow" + def __irshift__ (self, other): return "irshift" + def __isub__ (self, other): return "isub" + def __itruediv__ (self, other): return "itruediv" + def __ixor__ (self, other): return "ixor" + def __getitem__(self, other): return 5 # so that C is a sequence + c = C() + self.assertEqual(operator.iadd (c, 5), "iadd") + self.assertEqual(operator.iand (c, 5), "iand") + self.assertEqual(operator.idiv (c, 5), "idiv") + self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv") + self.assertEqual(operator.ilshift (c, 5), "ilshift") + self.assertEqual(operator.imod (c, 5), "imod") + self.assertEqual(operator.imul (c, 5), "imul") + self.assertEqual(operator.ior (c, 5), "ior") + self.assertEqual(operator.ipow (c, 5), "ipow") + self.assertEqual(operator.irshift (c, 5), "irshift") + self.assertEqual(operator.isub (c, 5), "isub") + self.assertEqual(operator.itruediv (c, 5), "itruediv") + self.assertEqual(operator.ixor (c, 5), "ixor") + self.assertEqual(operator.iconcat (c, c), "iadd") + self.assertEqual(operator.irepeat (c, 5), "imul") + self.assertEqual(operator.__iadd__ (c, 5), "iadd") + self.assertEqual(operator.__iand__ (c, 5), "iand") + self.assertEqual(operator.__idiv__ (c, 5), "idiv") + self.assertEqual(operator.__ifloordiv__(c, 5), "ifloordiv") + self.assertEqual(operator.__ilshift__ (c, 5), "ilshift") + self.assertEqual(operator.__imod__ (c, 5), "imod") + self.assertEqual(operator.__imul__ (c, 5), "imul") + self.assertEqual(operator.__ior__ (c, 5), "ior") + self.assertEqual(operator.__ipow__ (c, 5), "ipow") + self.assertEqual(operator.__irshift__ (c, 5), "irshift") + self.assertEqual(operator.__isub__ (c, 5), "isub") + self.assertEqual(operator.__itruediv__ (c, 5), "itruediv") + self.assertEqual(operator.__ixor__ (c, 5), "ixor") + self.assertEqual(operator.__iconcat__ (c, c), "iadd") + self.assertEqual(operator.__irepeat__ (c, 5), "imul") + +def test_main(verbose=None): + import sys + test_classes = ( + OperatorTestCase, + ) + + test_support.run_unittest(*test_classes) + + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in xrange(len(counts)): + test_support.run_unittest(*test_classes) + gc.collect() + counts[i] = sys.gettotalrefcount() + print counts + +if __name__ == "__main__": + test_main(verbose=True) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:49:52
|
Revision: 5037 http://jython.svn.sourceforge.net/jython/?rev=5037&view=rev Author: pjenvey Date: 2008-07-31 23:49:50 +0000 (Thu, 31 Jul 2008) Log Message: ----------- fix a couple test_coercion cases: o fix broken PyComplex.__rfloordiv__ o prevent stack overflows when old style classes return __coerce__ args in reversed order Modified Paths: -------------- branches/asm/Misc/make_binops.py branches/asm/src/org/python/core/PyComplex.java branches/asm/src/org/python/core/PyInstance.java Modified: branches/asm/Misc/make_binops.py =================================================================== --- branches/asm/Misc/make_binops.py 2008-07-31 23:32:03 UTC (rev 5036) +++ branches/asm/Misc/make_binops.py 2008-07-31 23:49:50 UTC (rev 5037) @@ -153,10 +153,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__%(name)s__", o2); - else - return %(function)s; + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return %(function)s; + } finally { + --ts.recursion_depth; + } + } } } Modified: branches/asm/src/org/python/core/PyComplex.java =================================================================== --- branches/asm/src/org/python/core/PyComplex.java 2008-07-31 23:32:03 UTC (rev 5036) +++ branches/asm/src/org/python/core/PyComplex.java 2008-07-31 23:49:50 UTC (rev 5037) @@ -435,7 +435,7 @@ } public PyObject __rfloordiv__(PyObject left) { - return complex___floordiv__(left); + return complex___rfloordiv__(left); } @ExposedMethod(type = MethodType.BINARY) Modified: branches/asm/src/org/python/core/PyInstance.java =================================================================== --- branches/asm/src/org/python/core/PyInstance.java 2008-07-31 23:32:03 UTC (rev 5036) +++ branches/asm/src/org/python/core/PyInstance.java 2008-07-31 23:49:50 UTC (rev 5037) @@ -896,10 +896,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__add__", o2); - else - return o1._add(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._add(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -914,10 +924,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__radd__", o2); - else - return o2._add(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._add(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -943,10 +963,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__sub__", o2); - else - return o1._sub(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._sub(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -961,10 +991,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rsub__", o2); - else - return o2._sub(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._sub(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -990,10 +1030,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__mul__", o2); - else - return o1._mul(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._mul(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1008,10 +1058,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rmul__", o2); - else - return o2._mul(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._mul(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1037,10 +1097,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__div__", o2); - else - return o1._div(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._div(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1055,10 +1125,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rdiv__", o2); - else - return o2._div(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._div(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1084,10 +1164,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__floordiv__", o2); - else - return o1._floordiv(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._floordiv(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1102,10 +1192,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rfloordiv__", o2); - else - return o2._floordiv(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._floordiv(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1131,10 +1231,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__truediv__", o2); - else - return o1._truediv(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._truediv(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1149,10 +1259,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rtruediv__", o2); - else - return o2._truediv(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._truediv(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1178,10 +1298,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__mod__", o2); - else - return o1._mod(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._mod(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1196,10 +1326,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rmod__", o2); - else - return o2._mod(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._mod(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1225,10 +1365,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__divmod__", o2); - else - return o1._divmod(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._divmod(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1243,10 +1393,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rdivmod__", o2); - else - return o2._divmod(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._divmod(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1261,10 +1421,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__pow__", o2); - else - return o1._pow(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._pow(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1279,10 +1449,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rpow__", o2); - else - return o2._pow(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._pow(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1308,10 +1488,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__lshift__", o2); - else - return o1._lshift(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._lshift(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1326,10 +1516,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rlshift__", o2); - else - return o2._lshift(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._lshift(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1355,10 +1555,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rshift__", o2); - else - return o1._rshift(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._rshift(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1373,10 +1583,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rrshift__", o2); - else - return o2._rshift(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._rshift(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1402,10 +1622,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__and__", o2); - else - return o1._and(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._and(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1420,10 +1650,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rand__", o2); - else - return o2._and(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._and(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1449,10 +1689,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__or__", o2); - else - return o1._or(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._or(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1467,10 +1717,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__ror__", o2); - else - return o2._or(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._or(o1); + } finally { + --ts.recursion_depth; + } + } } } @@ -1496,10 +1756,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__xor__", o2); - else - return o1._xor(o2); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o1._xor(o2); + } finally { + --ts.recursion_depth; + } + } } } @@ -1514,10 +1784,20 @@ else { PyObject o1 = ((PyObject[])ctmp)[0]; PyObject o2 = ((PyObject[])ctmp)[1]; - if (this == o1) // Prevent recusion if __coerce__ return self + if (this == o1) { + // Prevent recusion if __coerce__ return self return invoke_ex("__rxor__", o2); - else - return o2._xor(o1); + } + else { + ThreadState ts = Py.getThreadState(); + if (ts.recursion_depth++ > ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum recursion depth exceeded"); + try { + return o2._xor(o1); + } finally { + --ts.recursion_depth; + } + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:32:07
|
Revision: 5036 http://jython.svn.sourceforge.net/jython/?rev=5036&view=rev Author: pjenvey Date: 2008-07-31 23:32:03 +0000 (Thu, 31 Jul 2008) Log Message: ----------- support threading._RLock, as twisted uses it fixes #1079 Modified Paths: -------------- branches/asm/Lib/threading.py Modified: branches/asm/Lib/threading.py =================================================================== --- branches/asm/Lib/threading.py 2008-07-31 23:18:33 UTC (rev 5035) +++ branches/asm/Lib/threading.py 2008-07-31 23:32:03 UTC (rev 5036) @@ -52,7 +52,10 @@ global _trace_hook _trace_hook = func -class RLock(object): +def RLock(*args, **kwargs): + return _RLock(*args, **kwargs) + +class _RLock(object): def __init__(self): self._lock = ReentrantLock() self.__owner = None @@ -84,7 +87,7 @@ def _is_owned(self): return self._lock.isHeldByCurrentThread() -Lock = RLock +Lock = _RLock class Condition(object): def __init__(self, lock=None): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:18:35
|
Revision: 5035 http://jython.svn.sourceforge.net/jython/?rev=5035&view=rev Author: pjenvey Date: 2008-07-31 23:18:33 +0000 (Thu, 31 Jul 2008) Log Message: ----------- sync with a couple of manual changes PyInstance has had Modified Paths: -------------- branches/asm/Misc/make_binops.py Modified: branches/asm/Misc/make_binops.py =================================================================== --- branches/asm/Misc/make_binops.py 2008-07-31 23:16:37 UTC (rev 5034) +++ branches/asm/Misc/make_binops.py 2008-07-31 23:18:33 UTC (rev 5035) @@ -100,8 +100,8 @@ template1 = comment + """\ public %(ret)s __%(name)s__() { PyObject ret = invoke("__%(name)s__"); - if (ret instanceof %(ret)s) - return (%(ret)s)ret; + if (%(checks)s) + return %(cast)sret; throw Py.TypeError("__%(name)s__() should return a %(retname)s"); } @@ -115,17 +115,33 @@ string = 'PyString', 'string' ops = [('hex', string), ('oct', string), - ('int', ('PyInteger', 'int')), ('float', ('PyFloat', 'float')), - ('long', ('PyLong', 'long')), ('complex', ('PyComplex', 'complex')), + ('int', ('PyObject', 'int'), ('PyLong', 'PyInteger')), + ('float', ('PyFloat', 'float')), + ('long', ('PyObject', 'long'), ('PyLong', 'PyInteger')), + ('complex', ('PyComplex', 'complex')), ('pos', None), ('neg', None), ('abs', None), ('invert', None)] fp.write(' // Unary ops\n\n') -for name, ret in ops: +for item in ops: + checks = None + if len(item) == 2: + name, ret = item + else: + name, ret, checks = item if ret is None: fp.write(template2 % {'name':name}) else: ret, retname = ret - fp.write(template1 % {'name':name, 'ret':ret, 'retname':retname}) + if checks: + checks = ' || '.join(['ret instanceof %s' % check for check in checks]) + else: + checks = 'ret instanceof %s' % ret + if ret == 'PyObject': + cast = '' + else: + cast = '(%s)' % ret + fp.write(template1 % {'name':name, 'ret':ret, 'retname':retname, + 'checks':checks, 'cast':cast}) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 23:16:40
|
Revision: 5034 http://jython.svn.sourceforge.net/jython/?rev=5034&view=rev Author: pjenvey Date: 2008-07-31 23:16:37 +0000 (Thu, 31 Jul 2008) Log Message: ----------- move __index__ out of the generated code section Modified Paths: -------------- branches/asm/src/org/python/core/PyInstance.java Modified: branches/asm/src/org/python/core/PyInstance.java =================================================================== --- branches/asm/src/org/python/core/PyInstance.java 2008-07-31 22:07:13 UTC (rev 5033) +++ branches/asm/src/org/python/core/PyInstance.java 2008-07-31 23:16:37 UTC (rev 5034) @@ -759,7 +759,28 @@ return ((PyTuple)ret).getArray(); } + /** + * Implements the __index__ method by looking it up + * in the instance's dictionary and calling it if it is found. + **/ + public PyObject __index__() { + PyObject ret; + try { + ret = invoke("__index__"); + } catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) { + throw pye; + } + throw Py.TypeError("object cannot be interpreted as an index"); + } + if (ret instanceof PyInteger || ret instanceof PyLong) { + return ret; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)", + ret.getType().fastGetName())); + } + // Generated by make_binops.py // Unary ops @@ -862,27 +883,6 @@ return invoke("__invert__"); } - /** - * Implements the __index__ method by looking it up - * in the instance's dictionary and calling it if it is found. - **/ - public PyObject __index__() { - PyObject ret; - try { - ret = invoke("__index__"); - } catch (PyException pye) { - if (!Py.matchException(pye, Py.AttributeError)) { - throw pye; - } - throw Py.TypeError("object cannot be interpreted as an index"); - } - if (ret instanceof PyInteger || ret instanceof PyLong) { - return ret; - } - throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)", - ret.getType().fastGetName())); - } - // Binary ops /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 22:07:18
|
Revision: 5033 http://jython.svn.sourceforge.net/jython/?rev=5033&view=rev Author: pjenvey Date: 2008-07-31 22:07:13 +0000 (Thu, 31 Jul 2008) Log Message: ----------- deprecate complex divmod(), // and % Modified Paths: -------------- branches/asm/src/org/python/core/PyComplex.java Modified: branches/asm/src/org/python/core/PyComplex.java =================================================================== --- branches/asm/src/org/python/core/PyComplex.java 2008-07-31 20:50:59 UTC (rev 5032) +++ branches/asm/src/org/python/core/PyComplex.java 2008-07-31 22:07:13 UTC (rev 5033) @@ -490,6 +490,7 @@ } private static PyObject _mod(PyComplex value, PyComplex right) { + Py.warning(Py.DeprecationWarning, "complex divmod(), // and % are deprecated"); PyComplex z = (PyComplex) _div(value, right); z.real = Math.floor(z.real); @@ -521,6 +522,7 @@ } private static PyObject _divmod(PyComplex value, PyComplex right) { + Py.warning(Py.DeprecationWarning, "complex divmod(), // and % are deprecated"); PyComplex z = (PyComplex) _div(value, right); z.real = Math.floor(z.real); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-31 20:51:02
|
Revision: 5032 http://jython.svn.sourceforge.net/jython/?rev=5032&view=rev Author: fwierzbicki Date: 2008-07-31 20:50:59 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Tightened up signature of ErrorHandler and added a ListErrorHandler that mimics Antlr default behavior for error handling. Modified Paths: -------------- branches/asm/src/org/python/antlr/ErrorHandler.java branches/asm/src/org/python/antlr/FailFastHandler.java Added Paths: ----------- branches/asm/src/org/python/antlr/ListErrorHandler.java Modified: branches/asm/src/org/python/antlr/ErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ErrorHandler.java 2008-07-31 20:13:12 UTC (rev 5031) +++ branches/asm/src/org/python/antlr/ErrorHandler.java 2008-07-31 20:50:59 UTC (rev 5032) @@ -2,11 +2,12 @@ import org.antlr.runtime.BaseRecognizer; import org.antlr.runtime.IntStream; +import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; interface ErrorHandler { void reportError(BaseRecognizer br, RecognitionException re); - void recover(BaseRecognizer br, RecognitionException re); void recover(BaseRecognizer br, IntStream input, RecognitionException re); + void recover(Lexer lex, RecognitionException re); boolean isRecoverable(); } Modified: branches/asm/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/asm/src/org/python/antlr/FailFastHandler.java 2008-07-31 20:13:12 UTC (rev 5031) +++ branches/asm/src/org/python/antlr/FailFastHandler.java 2008-07-31 20:50:59 UTC (rev 5032) @@ -2,6 +2,7 @@ import org.antlr.runtime.BaseRecognizer; import org.antlr.runtime.IntStream; +import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; public class FailFastHandler implements ErrorHandler { @@ -11,8 +12,8 @@ throw new ParseException(message(br,re), re); } - public void recover(BaseRecognizer br, RecognitionException re) { - throw new ParseException(message(br,re), re); + public void recover(Lexer lex, RecognitionException re) { + throw new ParseException(message(lex,re), re); } public void recover(BaseRecognizer br, IntStream input, RecognitionException re) { Added: branches/asm/src/org/python/antlr/ListErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ListErrorHandler.java (rev 0) +++ branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-07-31 20:50:59 UTC (rev 5032) @@ -0,0 +1,27 @@ +package org.python.antlr; + +import org.antlr.runtime.BaseRecognizer; +import org.antlr.runtime.IntStream; +import org.antlr.runtime.Lexer; +import org.antlr.runtime.RecognitionException; + +public class ListErrorHandler implements ErrorHandler { + private BaseRecognizer recognizer; + + public void reportError(BaseRecognizer br, RecognitionException re) { + br.reportError(re); + } + + public void recover(Lexer lex, RecognitionException re) { + lex.recover(re); + } + + public void recover(BaseRecognizer br, IntStream input, RecognitionException re) { + br.recover(input, re); + } + + public boolean isRecoverable() { + return true; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-31 20:13:15
|
Revision: 5031 http://jython.svn.sourceforge.net/jython/?rev=5031&view=rev Author: fwierzbicki Date: 2008-07-31 20:13:12 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Fixed generator args check (antlr3.1b2 broke this, fixed it again). Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-31 19:50:45 UTC (rev 5030) +++ branches/asm/grammar/Python.g 2008-07-31 20:13:12 UTC (rev 5031) @@ -1051,17 +1051,14 @@ | DOUBLESTAR kwargs=test[expr_contextType.Load] )? )? { if ($a2 != null) { - if ($a1.gen) { + if ($a1.tree.getType() == GenFor) { throwGenExpNotSoleArg($a1.tree); } - //FIXME: not working in 3.1b2 - /* for (int i=0;i<$a2.size();i++) { - if (((argument_return)$a2.get(i)).gen) { + if (((PythonTree)$a2.get(i)).getType() == GenFor) { throwGenExpNotSoleArg(((argument_return)$a2.get(i)).tree); } } - */ } } -> ^(Args argument+) ^(StarArgs $starargs)? ^(KWArgs $kwargs)? @@ -1072,13 +1069,12 @@ ; //argument: test [gen_for] | test '=' test # Really [keyword '='] test -argument[boolean first] returns [boolean gen] +argument[boolean first] : t1=test[expr_contextType.Load] ( (ASSIGN t2=test[expr_contextType.Load]) -> ^(Keyword ^(Arg $t1) ^(Value $t2)?) | gen_for { if (!first) { throwGenExpNotSoleArg($gen_for.tree); } - $gen = true; } -> ^(GenFor $t1 gen_for) | -> ^(Arg $t1) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 19:50:52
|
Revision: 5030 http://jython.svn.sourceforge.net/jython/?rev=5030&view=rev Author: pjenvey Date: 2008-07-31 19:50:45 +0000 (Thu, 31 Jul 2008) Log Message: ----------- o fix test_softspace and reset softspace (and append a newline) in various places (equiv. of CPython's ceval.c::Py_FlushLine) o fix traceback source lines without trailing newlines (fixes #1087) Modified Paths: -------------- branches/asm/Lib/test/regrtest.py branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/PyTraceback.java branches/asm/src/org/python/core/StdoutWrapper.java branches/asm/src/org/python/util/PythonInterpreter.java Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/Lib/test/regrtest.py 2008-07-31 19:50:45 UTC (rev 5030) @@ -1493,7 +1493,6 @@ test_pyclbr test_quopri test_random - test_softspace test_syntax test_trace test_ucn Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/Py.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -992,6 +992,7 @@ exceptHook.__call__(exc.type, exc.value, exc.traceback); } catch (PyException exc2) { exc2.normalize(); + flushLine(); stderr.println("Error in sys.excepthook:"); displayException(exc2.type, exc2.value, exc2.traceback, file); stderr.println(); @@ -1006,12 +1007,13 @@ ts.exception = null; } - public static void displayException(PyObject type, PyObject value, - PyObject tb, PyObject file) { + public static void displayException(PyObject type, PyObject value, PyObject tb, + PyObject file) { StdoutWrapper stderr = Py.stderr; if (file != null) { stderr = new FixedFileWrapper(file); } + flushLine(); if (tb instanceof PyTraceback) { stderr.print(((PyTraceback) tb).dumpStack()); @@ -1317,6 +1319,10 @@ stdout.println(); } + public static void flushLine() { + stdout.flushLine(); + } + /* * A collection of convenience functions for converting PyObjects to Java primitives */ Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/PySystemState.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -342,6 +342,7 @@ Py.printException(exc); } } + Py.flushLine(); } public ClassLoader getClassLoader() { Modified: branches/asm/src/org/python/core/PyTraceback.java =================================================================== --- branches/asm/src/org/python/core/PyTraceback.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/PyTraceback.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -90,6 +90,11 @@ i++; } line = line.substring(i); + if (!line.endsWith("\n")) { + line += "\n"; + } + } else { + line = null; } return line; } Modified: branches/asm/src/org/python/core/StdoutWrapper.java =================================================================== --- branches/asm/src/org/python/core/StdoutWrapper.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/core/StdoutWrapper.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -46,7 +46,11 @@ if (obj instanceof PyFile) { ((PyFile) obj).flush(); } else { - obj.invoke("flush"); + try { + obj.invoke("flush"); + } catch (PyException pye) { + // ok + } } } @@ -68,7 +72,7 @@ write(StringUtil.fromBytes(data, off, len)); } - public void clearSoftspace() { + public void flushLine() { PyObject obj = myFile(); if (obj instanceof PyFile) { @@ -83,45 +87,63 @@ if (ss != null && ss.__nonzero__()) { obj.invoke("write", Py.Newline); } - obj.invoke("flush"); + try { + obj.invoke("flush"); + } catch (PyException pye) { + // ok + } obj.__setattr__("softspace", Py.Zero); } } public void print(PyObject o, boolean space, boolean newline) { - PyString string = o.__str__(); PyObject obj = myFile(); if (obj instanceof PyFile) { - PyFile file = (PyFile) obj; + PyFile file = (PyFile)obj; + if (file.softspace) { + file.write(" "); + file.softspace = false; + } + PyString string = o.__str__(); String s = string.toString(); + int len = s.length(); + file.write(s); + if (o instanceof PyString) { + if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) + || s.charAt(len - 1) == ' ') { + file.softspace = space; + } + } else { + file.softspace = space; + } if (newline) { - s = s + "\n"; + file.write("\n"); + file.softspace = false; } - if (file.softspace) { - s = " " + s; - } - file.write(s); file.flush(); - if (space && s.endsWith("\n")) { - space = false; - } - file.softspace = space; } else { PyObject ss = obj.__findattr__("softspace"); if (ss != null && ss.__nonzero__()) { obj.invoke("write", Py.Space); + obj.__setattr__("softspace", Py.Zero); } + PyString string = o.__str__(); + String s = o.toString(); + int len = s.length(); obj.invoke("write", string); + if (o instanceof PyString) { + if (len == 0 || !Character.isWhitespace(s.charAt(len - 1)) + || s.charAt(len - 1) == ' ') { + obj.__setattr__("softspace", space ? Py.One : Py.Zero); + } + } else { + obj.__setattr__("softspace", space ? Py.One : Py.Zero); + } if (newline) { obj.invoke("write", Py.Newline); + obj.__setattr__("softspace", Py.Zero); } - // obj.invoke("flush"); - - if (space && string.toString().endsWith("\n")) { - space = false; - } - obj.__setattr__("softspace", space ? Py.One : Py.Zero); } } Modified: branches/asm/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/asm/src/org/python/util/PythonInterpreter.java 2008-07-31 18:47:34 UTC (rev 5029) +++ branches/asm/src/org/python/util/PythonInterpreter.java 2008-07-31 19:50:45 UTC (rev 5030) @@ -121,6 +121,7 @@ setState(); Py.exec(Py.compile_flags(s, "<string>", "exec",cflags), locals, locals); + Py.flushLine(); } /** @@ -131,6 +132,7 @@ public void exec(PyObject code) { setState(); Py.exec(code, locals, locals); + Py.flushLine(); } /** @@ -141,6 +143,7 @@ public void execfile(String s) { setState(); __builtin__.execfile_flags(s, locals, locals, cflags); + Py.flushLine(); } public void execfile(java.io.InputStream s) { @@ -150,6 +153,7 @@ public void execfile(java.io.InputStream s, String name) { setState(); Py.runCode((PyCode)Py.compile_flags(s, name, "exec",cflags), locals, locals); + Py.flushLine(); } // Getting and setting the locals dictionary This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-31 18:47:37
|
Revision: 5029 http://jython.svn.sourceforge.net/jython/?rev=5029&view=rev Author: pjenvey Date: 2008-07-31 18:47:34 +0000 (Thu, 31 Jul 2008) Log Message: ----------- rearrange imports to fix test_threaded_import -- a bogus fix, but also what CPython did for this problem Modified Paths: -------------- branches/asm/Lib/os.py branches/asm/Lib/random.py Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-31 16:14:55 UTC (rev 5028) +++ branches/asm/Lib/os.py 2008-07-31 18:47:34 UTC (rev 5029) @@ -46,7 +46,8 @@ import stat as _stat import sys from java.io import File -from org.python.core.io import FileDescriptors +from org.python.core import PyFile +from org.python.core.io import FileDescriptors, FileIO, IOBase # Mapping of: os._name: [name list, shell command list] _os_map = dict(nt=[ @@ -537,7 +538,6 @@ if rawio.closed(): raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) - from org.python.core import PyFile try: fp = PyFile(rawio, '<fdopen>', mode, bufsize) except IOError: @@ -588,7 +588,6 @@ # Default to reading reading = True - from org.python.core.io import FileIO if truncating and not writing: # Explicitly truncate, writing will truncate anyway FileIO(filename, 'w').close() @@ -966,8 +965,6 @@ if isinstance(fileno, FileDescriptor): return _posix.isatty(fileno) - from org.python.core.io import IOBase - if not isinstance(fileno, IOBase): print fileno raise TypeError('a file descriptor is required') Modified: branches/asm/Lib/random.py =================================================================== --- branches/asm/Lib/random.py 2008-07-31 16:14:55 UTC (rev 5028) +++ branches/asm/Lib/random.py 2008-07-31 18:47:34 UTC (rev 5029) @@ -38,6 +38,7 @@ a single Python step, and is, therefore, threadsafe. """ +import time from types import BuiltinMethodType as _BuiltinMethodType from math import log as _log, exp as _exp, pi as _pi, e as _e from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin @@ -96,7 +97,6 @@ """ if a is None: - import time a = long(time.time() * 256) # use fractional seconds super(Random, self).seed(a) self.gauss_next = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-31 16:15:04
|
Revision: 5028 http://jython.svn.sourceforge.net/jython/?rev=5028&view=rev Author: fwierzbicki Date: 2008-07-31 16:14:55 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Adding a Jython specific version of CommonErrorNode to use when there are errors in the AST but we want to continue parsing (for now this is only of use by external tools, but I'm considering making it an option since the information can be useful. Thanks to Allan Davis for the original version of CommonErrorNode. I've refactored his version so that PythonErrorNode does not repeat much of CommonErrorNode and put the creation logic into PythonTreeAdaptor. I have also added an interface ErrorHandler that allows the error handling in antlr to be customized. FailFastHandler implements the default behavior of dying on the first parse error. I also made the parse error output more useful, and factored a BaseParser out of the org/python/antlr/*Parser classes. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonPartial.g branches/asm/grammar/PythonWalker.g branches/asm/src/org/python/antlr/ExpressionParser.java branches/asm/src/org/python/antlr/InteractiveParser.java branches/asm/src/org/python/antlr/ModuleParser.java branches/asm/src/org/python/antlr/ParseException.java branches/asm/src/org/python/antlr/PythonTree.java branches/asm/src/org/python/antlr/PythonTreeAdaptor.java Added Paths: ----------- branches/asm/src/org/python/antlr/BaseParser.java branches/asm/src/org/python/antlr/ErrorHandler.java branches/asm/src/org/python/antlr/FailFastHandler.java branches/asm/src/org/python/antlr/PythonErrorNode.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/grammar/Python.g 2008-07-31 16:14:55 UTC (rev 5028) @@ -182,16 +182,19 @@ } @members { - //If you want to use antlr's default error recovery mechanisms change this - //and the same one in the lexer to true. - public boolean antlrErrorHandling = false; - //XXX: only used for single_input -- seems kludgy. public boolean inSingle = false; - private boolean seenSingleOuterSuite = false; boolean debugOn = false; + private ErrorHandler errorHandler; + + private boolean seenSingleOuterSuite = false; + + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } + private void debug(String message) { if (debugOn) { System.out.println(message); @@ -398,7 +401,7 @@ protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { - if (antlrErrorHandling) { + if (errorHandler.isRecoverable()) { super.mismatch(input, ttype, follow); } else { throw new MismatchedTokenException(ttype, input); @@ -408,7 +411,7 @@ protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException { - if (antlrErrorHandling) { + if (errorHandler.isRecoverable()) { return super.recoverFromMismatchedToken(input, ttype, follow); } mismatch(input, ttype, follow); @@ -419,13 +422,9 @@ @rulecatch { catch (RecognitionException re) { - if (antlrErrorHandling) { - reportError(re); - recover(input,re); - retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); - } else { - throw new ParseException(re); - } + errorHandler.reportError(this, re); + errorHandler.recover(this, input,re); + retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); } } @@ -440,44 +439,55 @@ * 4] */ -//If you want to use antlr's default error recovery mechanisms change this -//and the same one in the parser to true. -public boolean antlrErrorHandling = false; +//If you want to use another error recovery mechanisms change this +//and the same one in the parser. +private ErrorHandler errorHandler; //XXX: Hopefully we can remove inSingle when we get PyCF_DONT_IMPLY_DEDENT support. public boolean inSingle = false; int implicitLineJoiningLevel = 0; int startPos=-1; - public Token nextToken() { - if (antlrErrorHandling) { - return super.nextToken(); - } - while (true) { - state.token = null; - state.channel = Token.DEFAULT_CHANNEL; - state.tokenStartCharIndex = input.index(); - state.tokenStartCharPositionInLine = input.getCharPositionInLine(); - state.tokenStartLine = input.getLine(); - state.text = null; - if ( input.LA(1)==CharStream.EOF ) { - return Token.EOF_TOKEN; - } - try { - mTokens(); - if ( state.token==null ) { - emit(); - } - else if ( state.token==Token.SKIP_TOKEN ) { - continue; - } - return state.token; - } - catch (RecognitionException re) { - throw new ParseException(re); - } - } + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; } + + /** + * Taken directly from antlr's Lexer.java -- needs to be re-integrated every time + * we upgrade from Antlr (need to consider a Lexer subclass, though the issue would + * remain). + */ + public Token nextToken() { + while (true) { + state.token = null; + state.channel = Token.DEFAULT_CHANNEL; + state.tokenStartCharIndex = input.index(); + state.tokenStartCharPositionInLine = input.getCharPositionInLine(); + state.tokenStartLine = input.getLine(); + state.text = null; + if ( input.LA(1)==CharStream.EOF ) { + return Token.EOF_TOKEN; + } + try { + mTokens(); + if ( state.token==null ) { + emit(); + } + else if ( state.token==Token.SKIP_TOKEN ) { + continue; + } + return state.token; + } + catch (NoViableAltException nva) { + errorHandler.reportError(this, nva); + errorHandler.recover(this, nva); // throw out current char and try again + } + catch (RecognitionException re) { + errorHandler.reportError(this, re); + // match() routine has already called recover() + } + } + } } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE Modified: branches/asm/grammar/PythonPartial.g =================================================================== --- branches/asm/grammar/PythonPartial.g 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/grammar/PythonPartial.g 2008-07-31 16:14:55 UTC (rev 5028) @@ -165,7 +165,7 @@ return state.token; } catch (RecognitionException re) { - throw new ParseException(re); + throw new ParseException("failed partial", re); } } } Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/grammar/PythonWalker.g 2008-07-31 16:14:55 UTC (rev 5028) @@ -90,7 +90,13 @@ } @members { boolean debugOn = false; + private ErrorHandler errorHandler; + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } + + public void debug(String message) { if (debugOn) { System.out.println(message); @@ -283,8 +289,9 @@ } @rulecatch { -catch (RecognitionException r) { - throw new ParseException(r); +catch (RecognitionException re) { + errorHandler.reportError(this, re); + errorHandler.recover(this, input,re); } } Added: branches/asm/src/org/python/antlr/BaseParser.java =================================================================== --- branches/asm/src/org/python/antlr/BaseParser.java (rev 0) +++ branches/asm/src/org/python/antlr/BaseParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,36 @@ +package org.python.antlr; + +import org.antlr.runtime.CharStream; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; +import org.antlr.runtime.tree.CommonTree; +import org.antlr.runtime.tree.CommonTreeAdaptor; +import org.antlr.runtime.tree.CommonTreeNodeStream; +import org.antlr.runtime.tree.Tree; +import org.antlr.runtime.tree.TreeAdaptor; +import org.python.antlr.ast.modType; +import org.python.antlr.ast.Module; +import org.python.antlr.ast.stmtType; + +public class BaseParser { + public static class PyLexer extends PythonLexer { + public PyLexer(CharStream lexer) { + super(lexer); + } + + public Token nextToken() { + startPos = getCharPositionInLine(); + return super.nextToken(); + } + } + + protected CharStream charStream; + protected boolean partial; + protected ErrorHandler errorHandler = new FailFastHandler(); + + public void setAntlrErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } +} Added: branches/asm/src/org/python/antlr/ErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ErrorHandler.java (rev 0) +++ branches/asm/src/org/python/antlr/ErrorHandler.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,12 @@ +package org.python.antlr; + +import org.antlr.runtime.BaseRecognizer; +import org.antlr.runtime.IntStream; +import org.antlr.runtime.RecognitionException; + +interface ErrorHandler { + void reportError(BaseRecognizer br, RecognitionException re); + void recover(BaseRecognizer br, RecognitionException re); + void recover(BaseRecognizer br, IntStream input, RecognitionException re); + boolean isRecoverable(); +} Modified: branches/asm/src/org/python/antlr/ExpressionParser.java =================================================================== --- branches/asm/src/org/python/antlr/ExpressionParser.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/ExpressionParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -14,22 +14,8 @@ import org.python.antlr.ast.Module; import org.python.antlr.ast.stmtType; -public class ExpressionParser { +public class ExpressionParser extends BaseParser { - private CharStream charStream; - - //Extract superclass from this and the other XParsers. - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - public ExpressionParser(CharStream cs) { this.charStream = cs; } @@ -37,11 +23,13 @@ public modType parse() { modType tree = null; PythonLexer lexer = new PyLexer(this.charStream); + lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); + parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); try { @@ -49,6 +37,7 @@ CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); nodes.setTokenStream(tokens); PythonWalker walker = new PythonWalker(nodes); + walker.setErrorHandler(errorHandler); tree = walker.expression(); } catch (RecognitionException e) { //XXX: this can't happen. Need to strip the throws from antlr Added: branches/asm/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/asm/src/org/python/antlr/FailFastHandler.java (rev 0) +++ branches/asm/src/org/python/antlr/FailFastHandler.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,31 @@ +package org.python.antlr; + +import org.antlr.runtime.BaseRecognizer; +import org.antlr.runtime.IntStream; +import org.antlr.runtime.RecognitionException; + +public class FailFastHandler implements ErrorHandler { + private BaseRecognizer recognizer; + + public void reportError(BaseRecognizer br, RecognitionException re) { + throw new ParseException(message(br,re), re); + } + + public void recover(BaseRecognizer br, RecognitionException re) { + throw new ParseException(message(br,re), re); + } + + public void recover(BaseRecognizer br, IntStream input, RecognitionException re) { + throw new ParseException(message(br,re), re); + } + + public boolean isRecoverable() { + return false; + } + + private String message(BaseRecognizer br, RecognitionException re) { + String hdr = br.getErrorHeader(re); + String msg = br.getErrorMessage(re, br.getTokenNames()); + return hdr+" "+msg; + } +} Modified: branches/asm/src/org/python/antlr/InteractiveParser.java =================================================================== --- branches/asm/src/org/python/antlr/InteractiveParser.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/InteractiveParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -17,22 +17,10 @@ import org.python.antlr.ast.Module; import org.python.antlr.ast.stmtType; -public class InteractiveParser { +public class InteractiveParser extends BaseParser { private BufferedReader bufreader; - //Extract superclass from this and the other XParsers. - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - public static class PPLexer extends PythonPartialLexer { public PPLexer(CharStream lexer) { super(lexer); @@ -51,6 +39,7 @@ public modType parse() throws IOException { modType tree = null; PythonLexer lexer = new PyLexer(new NoCloseReaderStream(bufreader)); + lexer.setErrorHandler(errorHandler); //XXX: Hopefully we can remove inSingle when we get PyCF_DONT_IMPLY_DEDENT support. lexer.inSingle = true; CommonTokenStream tokens = new CommonTokenStream(lexer); @@ -58,6 +47,7 @@ PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); + parser.setErrorHandler(errorHandler); parser.inSingle = true; parser.setTreeAdaptor(new PythonTreeAdaptor()); @@ -66,6 +56,7 @@ CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); nodes.setTokenStream(tokens); PythonWalker walker = new PythonWalker(nodes); + walker.setErrorHandler(errorHandler); tree = walker.interactive(); } catch (RecognitionException e) { //I am only throwing ParseExceptions, but "throws RecognitionException" still gets Modified: branches/asm/src/org/python/antlr/ModuleParser.java =================================================================== --- branches/asm/src/org/python/antlr/ModuleParser.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/ModuleParser.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -14,22 +14,7 @@ import org.python.antlr.ast.Module; import org.python.antlr.ast.stmtType; -public class ModuleParser { - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - - - private CharStream charStream; - private boolean partial; - +public class ModuleParser extends BaseParser { public ModuleParser(CharStream cs) { this(cs, false); } @@ -42,17 +27,20 @@ public modType file_input() { modType tree = null; PythonLexer lexer = new PyLexer(this.charStream); + lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); + parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); try { PythonParser.file_input_return r = parser.file_input(); CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree); nodes.setTokenStream(tokens); PythonWalker walker = new PythonWalker(nodes); + walker.setErrorHandler(errorHandler); tree = walker.module(); if (tree == null) { //XXX: seems like I should be able to get antlr to give me an empty Module instead @@ -66,4 +54,5 @@ return tree; } + } Modified: branches/asm/src/org/python/antlr/ParseException.java =================================================================== --- branches/asm/src/org/python/antlr/ParseException.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/ParseException.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -25,8 +25,8 @@ super(message); } - public ParseException(RecognitionException r) { - super(getErrorMessage(r)); + public ParseException(String message, RecognitionException r) { + super(message); input = r.input; index = r.index; token = r.token; @@ -37,120 +37,4 @@ approximateLineInfo = r.approximateLineInfo; } - /** - * getErrorMessage is a modified version of org.antlr.runtime.BaseRecognizer's - * method of the same name from * antlr-3.1 beta1. When we upgrade we should - * make sure to remain consistent. - */ - private static String getErrorMessage(RecognitionException e) { - String msg = e.getMessage(); - String tokenNames[] = PythonParser.tokenNames; - if ( e instanceof UnwantedTokenException ) { - UnwantedTokenException ute = (UnwantedTokenException)e; - String tokenName="<unknown>"; - if ( ute.expecting== Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[ute.expecting]; - } - msg = "extraneous input "+getTokenErrorDisplay(ute.getUnexpectedToken())+ - " expecting "+tokenName; - } - else if ( e instanceof MissingTokenException ) { - MissingTokenException mte = (MissingTokenException)e; - String tokenName="<unknown>"; - if ( mte.expecting== Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[mte.expecting]; - } - msg = "missing "+tokenName+" at "+getTokenErrorDisplay(e.token); - } - if ( e instanceof MismatchedTokenException ) { - MismatchedTokenException mte = (MismatchedTokenException)e; - String tokenName="<unknown>"; - if ( mte.expecting== Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[mte.expecting]; - } - msg = "mismatched input "+getTokenErrorDisplay(e.token)+ - " expecting "+tokenName; - } - else if ( e instanceof MismatchedTreeNodeException ) { - MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e; - String tokenName="<unknown>"; - if ( mtne.expecting==Token.EOF ) { - tokenName = "EOF"; - } - else { - tokenName = tokenNames[mtne.expecting]; - } - msg = "mismatched tree node: "+mtne.node+ - " expecting "+tokenName; - } - else if ( e instanceof NoViableAltException ) { - NoViableAltException nvae = (NoViableAltException)e; - // for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>" - // and "(decision="+nvae.decisionNumber+") and - // "state "+nvae.stateNumber - msg = "no viable alternative at input "+getTokenErrorDisplay(e.token); - } - else if ( e instanceof EarlyExitException ) { - EarlyExitException eee = (EarlyExitException)e; - // for development, can add "(decision="+eee.decisionNumber+")" - msg = "required (...)+ loop did not match anything at input "+ - getTokenErrorDisplay(e.token); - } - else if ( e instanceof MismatchedSetException ) { - MismatchedSetException mse = (MismatchedSetException)e; - msg = "mismatched input "+getTokenErrorDisplay(e.token)+ - " expecting set "+mse.expecting; - } - else if ( e instanceof MismatchedNotSetException ) { - MismatchedNotSetException mse = (MismatchedNotSetException)e; - msg = "mismatched input "+getTokenErrorDisplay(e.token)+ - " expecting set "+mse.expecting; - } - else if ( e instanceof FailedPredicateException ) { - FailedPredicateException fpe = (FailedPredicateException)e; - msg = "rule "+fpe.ruleName+" failed predicate: {"+ - fpe.predicateText+"}?"; - } - return msg; - } - - private static String getTokenErrorDisplay(Token t) { - if (t == null) { - return ""; - } else { - return t.getText(); - } - } - - public int getOffset() { - if (input != null) { - if (input instanceof CharStream) { - return index; - } else { - return ((CommonToken)token).getStartIndex(); - } - } - return -1; - } - - public String info() { - return "info: " + - "input:" + input + - "\nindex:" + index + - "\ntoken:" + token + - "\nnode:" + node + - "\nc:" + c + - "\nline:" + line + - "\ncharPositionInLine:" + charPositionInLine + - "\napproximateLineInfo:" + approximateLineInfo; - } } Added: branches/asm/src/org/python/antlr/PythonErrorNode.java =================================================================== --- branches/asm/src/org/python/antlr/PythonErrorNode.java (rev 0) +++ branches/asm/src/org/python/antlr/PythonErrorNode.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -0,0 +1,38 @@ +package org.python.antlr; + +import org.antlr.runtime.Token; +import org.antlr.runtime.TokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.tree.CommonErrorNode; + +/** A node representing erroneous token range in token stream + */ +public class PythonErrorNode extends PythonTree { + + private CommonErrorNode errorNode; + + public PythonErrorNode(TokenStream input, Token start, Token stop, + RecognitionException e) { + this.errorNode = new CommonErrorNode(input, start, stop, e); + } + + public PythonErrorNode(CommonErrorNode errorNode){ + this.errorNode = errorNode; + } + + public boolean isNil() { + return errorNode.isNil(); + } + + public int getType() { + return errorNode.getType(); + } + + public String getText() { + return errorNode.getText(); + } + + public String toString() { + return errorNode.toString(); + } +} Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -30,6 +30,12 @@ /** What index is this node in the child list? Range: 0..n-1 */ public int childIndex = -1; + /** + * The empty constructor is intended only for use by PythonErrorNode. + */ + public PythonTree() { + } + public PythonTree(int ttype, Token t) { CommonToken c = new CommonToken(ttype, t.getText()); c.setLine(t.getLine()); Modified: branches/asm/src/org/python/antlr/PythonTreeAdaptor.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-07-31 16:03:59 UTC (rev 5027) +++ branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-07-31 16:14:55 UTC (rev 5028) @@ -1,7 +1,9 @@ package org.python.antlr; import org.antlr.runtime.CommonToken; +import org.antlr.runtime.RecognitionException; import org.antlr.runtime.Token; +import org.antlr.runtime.TokenStream; import org.antlr.runtime.tree.CommonTreeAdaptor; public class PythonTreeAdaptor extends CommonTreeAdaptor { @@ -45,6 +47,14 @@ return new PythonTree(token); } + public Object errorNode(TokenStream input, Token start, Token stop, + RecognitionException e) + { + PythonErrorNode t = new PythonErrorNode(input, start, stop, e); + //System.out.println("returning error node '"+t+"' @index="+input.index()); + return t; + } + public Object dupNode(Object t) { if (t == null) { return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-31 16:04:08
|
Revision: 5027 http://jython.svn.sourceforge.net/jython/?rev=5027&view=rev Author: nriley Date: 2008-07-31 16:03:59 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Update Eclipse classpath to Antlr 3.1b2. Modified Paths: -------------- branches/asm/.classpath Modified: branches/asm/.classpath =================================================================== --- branches/asm/.classpath 2008-07-31 13:10:57 UTC (rev 5026) +++ branches/asm/.classpath 2008-07-31 16:03:59 UTC (rev 5027) @@ -15,6 +15,6 @@ <classpathentry kind="lib" path="extlibs/servlet-api-2.5.jar"/> <classpathentry kind="lib" path="build/jarjar"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> - <classpathentry kind="lib" path="extlibs/antlr-runtime-3.1b1.jar"/> + <classpathentry kind="lib" path="extlibs/antlr-runtime-3.1b2.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-31 13:11:05
|
Revision: 5026 http://jython.svn.sourceforge.net/jython/?rev=5026&view=rev Author: fwierzbicki Date: 2008-07-31 13:10:57 +0000 (Thu, 31 Jul 2008) Log Message: ----------- Switch to Antlr 3.1b2. Modified Paths: -------------- branches/asm/build.xml branches/asm/grammar/Python.g Added Paths: ----------- branches/asm/extlibs/antlr-3.1b2.jar branches/asm/extlibs/antlr-runtime-3.1b2.jar branches/asm/extlibs/stringtemplate-3.2.jar Removed Paths: ------------- branches/asm/extlibs/antlr-3.1b1.jar branches/asm/extlibs/antlr-runtime-3.1b1.jar branches/asm/extlibs/stringtemplate-3.1b1.jar Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-07-30 23:00:32 UTC (rev 5025) +++ branches/asm/build.xml 2008-07-31 13:10:57 UTC (rev 5026) @@ -156,8 +156,8 @@ <pathelement path="${extlibs.dir}/mysql-connector-java-5.1.6.jar" /> <pathelement path="${extlibs.dir}/postgresql-8.3-603.jdbc4.jar" /> <pathelement path="${extlibs.dir}/antlr-2.7.7.jar" /> - <pathelement path="${extlibs.dir}/antlr-3.1b1.jar" /> - <pathelement path="${extlibs.dir}/stringtemplate-3.1b1.jar" /> + <pathelement path="${extlibs.dir}/antlr-3.1b2.jar" /> + <pathelement path="${extlibs.dir}/stringtemplate-3.2.jar" /> </path> <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> @@ -501,7 +501,7 @@ <target name="jarjar" depends="init,needed-check" unless="jarjar.notneeded"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="extlibs/jarjar-0.7.jar"/> <jarjar destfile="${output.dir}/jarjar.jar"> - <zipfileset src="extlibs/antlr-runtime-3.1b1.jar"/> + <zipfileset src="extlibs/antlr-runtime-3.1b2.jar"/> <zipfileset src="extlibs/asm-3.1.jar"/> <zipfileset src="extlibs/asm-commons-3.1.jar"/> <zipfileset src="extlibs/asm-util-3.1.jar"/> Property changes on: branches/asm/extlibs/antlr-3.1b2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: branches/asm/extlibs/antlr-runtime-3.1b2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: branches/asm/extlibs/stringtemplate-3.2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-30 23:00:32 UTC (rev 5025) +++ branches/asm/grammar/Python.g 2008-07-31 13:10:57 UTC (rev 5026) @@ -1044,11 +1044,14 @@ if ($a1.gen) { throwGenExpNotSoleArg($a1.tree); } + //FIXME: not working in 3.1b2 + /* for (int i=0;i<$a2.size();i++) { if (((argument_return)$a2.get(i)).gen) { throwGenExpNotSoleArg(((argument_return)$a2.get(i)).tree); } } + */ } } -> ^(Args argument+) ^(StarArgs $starargs)? ^(KWArgs $kwargs)? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-30 23:00:38
|
Revision: 5025 http://jython.svn.sourceforge.net/jython/?rev=5025&view=rev Author: pjenvey Date: 2008-07-30 23:00:32 +0000 (Wed, 30 Jul 2008) Log Message: ----------- include functools Modified Paths: -------------- branches/asm/CPythonLib.includes Modified: branches/asm/CPythonLib.includes =================================================================== --- branches/asm/CPythonLib.includes 2008-07-30 22:39:24 UTC (rev 5024) +++ branches/asm/CPythonLib.includes 2008-07-30 23:00:32 UTC (rev 5025) @@ -56,6 +56,7 @@ formatter.py fpformat.py ftplib.py +functools.py getopt.py gettext.py glob.py This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-30 22:39:29
|
Revision: 5024 http://jython.svn.sourceforge.net/jython/?rev=5024&view=rev Author: pjenvey Date: 2008-07-30 22:39:24 +0000 (Wed, 30 Jul 2008) Log Message: ----------- add a builtin _functools.partial type Modified Paths: -------------- branches/asm/CoreExposed.includes branches/asm/Lib/test/test_functools.py branches/asm/src/org/python/modules/Setup.java branches/asm/src/templates/mappings Added Paths: ----------- branches/asm/src/org/python/modules/_functools/ branches/asm/src/org/python/modules/_functools/PyPartial.java branches/asm/src/org/python/modules/_functools/PyPartialDerived.java branches/asm/src/org/python/modules/_functools/_functools.java branches/asm/src/templates/partial.derived Removed Paths: ------------- branches/asm/Lib/functools.py Modified: branches/asm/CoreExposed.includes =================================================================== --- branches/asm/CoreExposed.includes 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/CoreExposed.includes 2008-07-30 22:39:24 UTC (rev 5024) @@ -36,6 +36,7 @@ org/python/core/PyUnicode.class org/python/core/PyXRange.class org/python/modules/_codecs$EncodingMap.class +org/python/modules/_functools/PyPartial.class org/python/modules/_weakref/CallableProxyType.class org/python/modules/_weakref/ReferenceType.class org/python/modules/_weakref/ProxyType.class Deleted: branches/asm/Lib/functools.py =================================================================== --- branches/asm/Lib/functools.py 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/Lib/functools.py 2008-07-30 22:39:24 UTC (rev 5024) @@ -1,63 +0,0 @@ -"""functools.py - Tools for working with functions and callable objects -""" -# Python module wrapper for _functools C module -# to allow utilities written in Python to be added -# to the functools module. -# Written by Nick Coghlan <ncoghlan at gmail.com> -# Copyright (C) 2006 Python Software Foundation. -# See C source code for _functools credits/copyright - -class partial(object): - - def __init__(*args, **kw): - self = args[0] - self.fn, self.args, self.kw = (args[1], args[2:], kw) - - def __call__(self, *args, **kw): - if kw and self.kw: - d = self.kw.copy() - d.update(kw) - else: - d = kw or self.kw - return self.fn(*(self.args + args), **d) - -# update_wrapper() and wraps() are tools to help write -# wrapper functions that can handle naive introspection - -WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__') -WRAPPER_UPDATES = ('__dict__',) -def update_wrapper(wrapper, - wrapped, - assigned = WRAPPER_ASSIGNMENTS, - updated = WRAPPER_UPDATES): - """Update a wrapper function to look like the wrapped function - - wrapper is the function to be updated - wrapped is the original function - assigned is a tuple naming the attributes assigned directly - from the wrapped function to the wrapper function (defaults to - functools.WRAPPER_ASSIGNMENTS) - updated is a tuple naming the attributes off the wrapper that - are updated with the corresponding attribute from the wrapped - function (defaults to functools.WRAPPER_UPDATES) - """ - for attr in assigned: - setattr(wrapper, attr, getattr(wrapped, attr)) - for attr in updated: - getattr(wrapper, attr).update(getattr(wrapped, attr)) - # Return the wrapper so this can be used as a decorator via partial() - return wrapper - -def wraps(wrapped, - assigned = WRAPPER_ASSIGNMENTS, - updated = WRAPPER_UPDATES): - """Decorator factory to apply update_wrapper() to a wrapper function - - Returns a decorator that invokes update_wrapper() with the decorated - function as the wrapper argument and the arguments to wraps() as the - remaining arguments. Default arguments are as for update_wrapper(). - This is a convenience function to simplify applying partial() to - update_wrapper(). - """ - return partial(update_wrapper, wrapped=wrapped, - assigned=assigned, updated=updated) Modified: branches/asm/Lib/test/test_functools.py =================================================================== --- branches/asm/Lib/test/test_functools.py 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/Lib/test/test_functools.py 2008-07-30 22:39:24 UTC (rev 5024) @@ -131,6 +131,9 @@ p = proxy(f) self.assertEqual(f.func, p.func) f = None + if test_support.is_jython: + from test_weakref import extra_collect + extra_collect() self.assertRaises(ReferenceError, getattr, p, 'func') def test_with_bound_and_unbound_methods(self): @@ -159,7 +162,7 @@ updated=functools.WRAPPER_UPDATES): # Check attributes were assigned for name in assigned: - self.failUnless(getattr(wrapper, name) is getattr(wrapped, name)) + self.failUnless(getattr(wrapper, name) == getattr(wrapped, name)) # Check attributes were updated for name in updated: wrapper_attr = getattr(wrapper, name) Modified: branches/asm/src/org/python/modules/Setup.java =================================================================== --- branches/asm/src/org/python/modules/Setup.java 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/src/org/python/modules/Setup.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -54,6 +54,7 @@ "zipimport:org.python.modules.zipimport.zipimport", "collections:org.python.modules.collections.Collections", "gc", - "_hashlib" + "_hashlib", + "_functools:org.python.modules._functools._functools" }; } Added: branches/asm/src/org/python/modules/_functools/PyPartial.java =================================================================== --- branches/asm/src/org/python/modules/_functools/PyPartial.java (rev 0) +++ branches/asm/src/org/python/modules/_functools/PyPartial.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,171 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._functools; + +import java.util.HashMap; +import java.util.Map; + +import org.python.core.Py; +import org.python.core.PyDictionary; +import org.python.core.PyNewWrapper; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyStringMap; +import org.python.core.PyTuple; +import org.python.core.PyType; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; + +@ExposedType(name = "_functools.partial") +public class PyPartial extends PyObject { + + public static final PyType TYPE = PyType.fromClass(PyPartial.class); + + /** The wrapped callable. */ + @ExposedGet + public PyObject func; + + /** Callable's args. */ + public PyObject[] args; + + /** Callable's keywords. */ + private String[] keywords; + + /** Lazily created dict for extra attributes. */ + private PyObject __dict__; + + public PyPartial() { + super(TYPE); + } + + public PyPartial(PyType subType) { + super(subType); + } + + @ExposedNew + public static PyObject partial___new__(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + if (args.length - keywords.length < 1) { + throw Py.TypeError("type 'partial' takes at least one argument"); + } + + PyObject func = args[0]; + if (!func.isCallable()) { + throw Py.TypeError("the first argument must be callable"); + } + + PyObject[] noFunc = new PyObject[args.length - 1]; + System.arraycopy(args, 1, noFunc, 0, args.length - 1); + args = noFunc; + + PyPartial partial; + if (new_.for_type == subtype) { + partial = new PyPartial(); + } else { + partial = new PyPartialDerived(subtype); + } + + partial.func = func; + partial.args = args; + partial.keywords = keywords; + return partial; + } + + @Override + public PyObject __call__(PyObject[] args, String[] keywords) { + return partial___call__(args, keywords); + } + + @ExposedMethod + public PyObject partial___call__(PyObject[] args, String[] keywords) { + PyObject[] argAppl; + String[] kwAppl; + int partialArgc = this.args.length - this.keywords.length; + int argc = args.length - keywords.length; + + if (partialArgc == 0 && this.keywords.length == 0) { + argAppl = args; + kwAppl = keywords; + } else if (argc == 0 && keywords.length == 0) { + argAppl = this.args; + kwAppl = this.keywords; + } else { + // first merge keywords to determine the keyword count + HashMap<String, PyObject> merged = new HashMap<String, PyObject>(); + int i; + for (i = 0; i < this.keywords.length; i++) { + String keyword = this.keywords[i]; + PyObject value = this.args[partialArgc + i]; + merged.put(keyword, value); + } + for (i = 0; i < keywords.length; i++) { + String keyword = keywords[i]; + PyObject value = args[argc + i]; + merged.put(keyword, value); + } + int keywordc = merged.size(); + + // finally merge into args and keywords arrays + argAppl = new PyObject[partialArgc + argc + keywordc]; + System.arraycopy(this.args, 0, argAppl, 0, partialArgc); + System.arraycopy(args, 0, argAppl, partialArgc, argc); + + kwAppl = new String[keywordc]; + i = 0; + int j = partialArgc + argc; + for (Map.Entry<String, PyObject> entry : merged.entrySet()) { + kwAppl[i++] = entry.getKey(); + argAppl[j++] = entry.getValue(); + } + } + return func.__call__(argAppl, kwAppl); + } + + @ExposedGet(name = "args") + public PyObject getArgs() { + PyObject[] justArgs; + if (keywords.length == 0) { + justArgs = args; + } else { + int argc = args.length - keywords.length; + justArgs = new PyObject[argc]; + System.arraycopy(args, 0, justArgs, 0, argc); + } + return new PyTuple(justArgs); + } + + @ExposedGet(name = "keywords") + public PyObject getKeywords() { + if (keywords.length == 0) { + return Py.None; + } + int argc = args.length - keywords.length; + PyObject kwDict = new PyDictionary(); + for (int i = 0; i < keywords.length; i++) { + kwDict.__setitem__(Py.newString(keywords[i]), args[argc + i]); + } + return kwDict; + } + + @ExposedGet(name = "__dict__") + public PyObject getDict() { + ensureDict(); + return __dict__; + } + + @ExposedSet(name = "__dict__") + public void setDict(PyObject val) { + if (!(val instanceof PyStringMap) && !(val instanceof PyDictionary)) { + throw Py.TypeError("setting partial object's dictionary to a non-dict"); + } + __dict__ = val; + } + + private void ensureDict() { + if (__dict__ == null) { + __dict__ = new PyStringMap(); + } + } +} Added: branches/asm/src/org/python/modules/_functools/PyPartialDerived.java =================================================================== --- branches/asm/src/org/python/modules/_functools/PyPartialDerived.java (rev 0) +++ branches/asm/src/org/python/modules/_functools/PyPartialDerived.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,1104 @@ +/* Generated file, do not modify. See jython/src/templates/gderived.py. */ +package org.python.modules._functools; + +import org.python.core.*; + +public class PyPartialDerived extends PyPartial implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + + public PyPartialDerived(PyType subtype) { + super(subtype); + slots=new PyObject[subtype.getNumSlots()]; + } + + public PyString __str__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__str__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__str__(); + } + + public PyString __repr__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__repr__(); + } + + public PyString __hex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__hex__(); + } + + public PyString __oct__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__oct__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__oct__(); + } + + public PyFloat __float__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__float__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyFloat) + return(PyFloat)res; + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); + } + return super.__float__(); + } + + public PyComplex __complex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__complex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyComplex) + return(PyComplex)res; + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); + } + return super.__complex__(); + } + + public PyObject __pos__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pos__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__pos__(); + } + + public PyObject __neg__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__neg__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__neg__(); + } + + public PyObject __abs__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__abs__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__abs__(); + } + + public PyObject __invert__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__invert__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__invert__(); + } + + public PyObject __reduce__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__reduce__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__reduce__(); + } + + public PyObject __add__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__add__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__add__(other); + } + + public PyObject __radd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__radd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__radd__(other); + } + + public PyObject __sub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__sub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__sub__(other); + } + + public PyObject __rsub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rsub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rsub__(other); + } + + public PyObject __mul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mul__(other); + } + + public PyObject __rmul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmul__(other); + } + + public PyObject __div__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__div__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__div__(other); + } + + public PyObject __rdiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdiv__(other); + } + + public PyObject __floordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__floordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__floordiv__(other); + } + + public PyObject __rfloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rfloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rfloordiv__(other); + } + + public PyObject __truediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__truediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__truediv__(other); + } + + public PyObject __rtruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rtruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rtruediv__(other); + } + + public PyObject __mod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mod__(other); + } + + public PyObject __rmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmod__(other); + } + + public PyObject __divmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__divmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__divmod__(other); + } + + public PyObject __rdivmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdivmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdivmod__(other); + } + + public PyObject __rpow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rpow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rpow__(other); + } + + public PyObject __lshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lshift__(other); + } + + public PyObject __rlshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rlshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rlshift__(other); + } + + public PyObject __rshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rshift__(other); + } + + public PyObject __rrshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rrshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rrshift__(other); + } + + public PyObject __and__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__and__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__and__(other); + } + + public PyObject __rand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rand__(other); + } + + public PyObject __or__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__or__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__or__(other); + } + + public PyObject __ror__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ror__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ror__(other); + } + + public PyObject __xor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__xor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__xor__(other); + } + + public PyObject __rxor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rxor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rxor__(other); + } + + public PyObject __lt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lt__(other); + } + + public PyObject __le__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__le__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__le__(other); + } + + public PyObject __gt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__gt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__gt__(other); + } + + public PyObject __ge__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ge__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ge__(other); + } + + public PyObject __eq__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__eq__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__eq__(other); + } + + public PyObject __ne__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ne__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ne__(other); + } + + public PyObject __iadd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iadd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iadd__(other); + } + + public PyObject __isub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__isub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__isub__(other); + } + + public PyObject __imul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imul__(other); + } + + public PyObject __idiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__idiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__idiv__(other); + } + + public PyObject __ifloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ifloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ifloordiv__(other); + } + + public PyObject __itruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__itruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__itruediv__(other); + } + + public PyObject __imod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imod__(other); + } + + public PyObject __ipow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ipow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ipow__(other); + } + + public PyObject __ilshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ilshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ilshift__(other); + } + + public PyObject __irshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__irshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__irshift__(other); + } + + public PyObject __iand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iand__(other); + } + + public PyObject __ior__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ior__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ior__(other); + } + + public PyObject __ixor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ixor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ixor__(other); + } + + public PyObject __int__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__int__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) + return(PyObject)res; + throw Py.TypeError("__int__"+" should return an integer"); + } + return super.__int__(); + } + + public PyObject __long__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__long__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyLong||res instanceof PyInteger) + return res; + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); + } + return super.__long__(); + } + + public int hashCode() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hash__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) { + return((PyInteger)res).getValue(); + } else + if (res instanceof PyLong) { + return((PyLong)res).getValue().intValue(); + } + throw Py.TypeError("__hash__ should return a int"); + } + if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { + throw Py.TypeError("unhashable type"); + } + return super.hashCode(); + } + + public PyUnicode __unicode__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__unicode__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyUnicode) + return(PyUnicode)res; + if (res instanceof PyString) + return new PyUnicode((PyString)res); + throw Py.TypeError("__unicode__"+" should return a "+"unicode"); + } + return super.__unicode__(); + } + + public int __cmp__(PyObject other) { + PyType self_type=getType(); + PyType[]where_type=new PyType[1]; + PyObject impl=self_type.lookup_where("__cmp__",where_type); + // Full Compatibility with CPython __cmp__: + // If the derived type don't override __cmp__, the + // *internal* super().__cmp__ should be called, not the + // exposed one. The difference is that the exposed __cmp__ + // throws a TypeError if the argument is an instance of the same type. + if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { + return super.__cmp__(other); + } + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res instanceof PyInteger) { + int v=((PyInteger)res).getValue(); + return v<0?-1:v>0?1:0; + } + throw Py.TypeError("__cmp__ should return a int"); + } + + public boolean __nonzero__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__nonzero__"); + if (impl==null) { + impl=self_type.lookup("__len__"); + if (impl==null) + return super.__nonzero__(); + } + return impl.__get__(this,self_type).__call__().__nonzero__(); + } + + public boolean __contains__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__contains__"); + if (impl==null) + return super.__contains__(o); + return impl.__get__(this,self_type).__call__(o).__nonzero__(); + } + + public int __len__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__len__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) + return((PyInteger)res).getValue(); + throw Py.TypeError("__len__ should return a int"); + } + return super.__len__(); + } + + public PyObject __iter__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iter__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + impl=self_type.lookup("__getitem__"); + if (impl==null) + return super.__iter__(); + return new PySequenceIter(this); + } + + public PyObject __iternext__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("next"); + if (impl!=null) { + try { + return impl.__get__(this,self_type).__call__(); + } catch (PyException exc) { + if (Py.matchException(exc,Py.StopIteration)) + return null; + throw exc; + } + } + return super.__iternext__(); // ??? + } + + public PyObject __finditem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(key); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __getitem__(PyObject key) { + // Same as __finditem__, without swallowing LookupErrors. This allows + // __getitem__ implementations written in Python to raise custom + // exceptions (such as subclasses of KeyError). + // + // We are forced to duplicate the code, instead of defining __finditem__ + // in terms of __getitem__. That's because PyObject defines __getitem__ + // in terms of __finditem__. Therefore, we would end with an infinite + // loop when self_type.lookup("__getitem__") returns null: + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ + // + // By duplicating the (short) lookup and call code, we are safe, because + // the call chains will be: + // + // __finditem__ -> super.__finditem__ + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ + + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(key); + return super.__getitem__(key); + } + + public void __setitem__(PyObject key,PyObject value) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key,value); + return; + } + super.__setitem__(key,value); + } + + public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); + } + return super.__getslice__(start,stop,step); + } + + public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); + return; + } + super.__setslice__(start,stop,step,value); + } + + public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); + return; + } + super.__delslice__(start,stop,step); + } + + public void __delitem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key); + return; + } + super.__delitem__(key); + } + + public PyObject __call__(PyObject args[],String keywords[]) { + ThreadState ts=Py.getThreadState(); + if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); + try { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__call__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(args,keywords); + return super.__call__(args,keywords); + } finally { + --ts.recursion_depth; + } + } + + public PyObject __findattr__(String name) { + PyType self_type=getType(); + PyObject getattribute=self_type.lookup("__getattribute__"); + PyString py_name=null; + try { + if (getattribute!=null) { + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + } else { + return super.__findattr__(name); + } + } catch (PyException e) { + if (Py.matchException(e,Py.AttributeError)) { + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) + try { + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); + } catch (PyException e1) { + if (!Py.matchException(e1,Py.AttributeError)) + throw e1; + } + return null; + } + throw e; + } + } + + public void __setattr__(String name,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); + return; + } + super.__setattr__(name,value); + } + + public void __delattr__(String name) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); + return; + } + super.__delattr__(name); + } + + public PyObject __get__(PyObject obj,PyObject type) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__get__"); + if (impl!=null) { + if (obj==null) + obj=Py.None; + if (type==null) + type=Py.None; + return impl.__get__(this,self_type).__call__(obj,type); + } + return super.__get__(obj,type); + } + + public void __set__(PyObject obj,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__set__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj,value); + return; + } + super.__set__(obj,value); + } + + public void __delete__(PyObject obj) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delete__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj); + return; + } + super.__delete__(obj); + } + + public PyObject __pow__(PyObject other,PyObject modulo) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pow__"); + if (impl!=null) { + PyObject res; + if (modulo==null) { + res=impl.__get__(this,self_type).__call__(other); + } else { + res=impl.__get__(this,self_type).__call__(other,modulo); + } + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__pow__(other,modulo); + } + + public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { + PyType self_type=getType(); + if (self_type.isSubType(type)) { + PyObject impl=self_type.lookup("__init__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(args,keywords); + if (res!=Py.None) { + throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); + } + } + } + } + + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + + public Object __tojava__(Class c) { + // If we are not being asked by the "default" conversion to java, then + // we can provide this as the result, as long as it is a instance of the + // specified class. Without this, derived.__tojava__(PyObject.class) + // would broke. (And that's not pure speculation: PyReflectedFunction's + // ReflectedArgs asks for things like that). + if ((c!=Object.class)&&(c.isInstance(this))) { + return this; + } + // Otherwise, we call the derived __tojava__, if it exists: + PyType self_type=getType(); + PyObject impl=self_type.lookup("__tojava__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava__(Object.class); + return super.__tojava__(c); + } + + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + +} Added: branches/asm/src/org/python/modules/_functools/_functools.java =================================================================== --- branches/asm/src/org/python/modules/_functools/_functools.java (rev 0) +++ branches/asm/src/org/python/modules/_functools/_functools.java 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,24 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._functools; + +import org.python.core.ClassDictInit; +import org.python.core.Py; +import org.python.core.PyObject; +import org.python.core.PyString; + +/** + * The Python _functools module. + */ +public class _functools implements ClassDictInit { + + public static final PyString __doc__ = new PyString("Tools that operate on functions."); + + public static void classDictInit(PyObject dict) { + dict.__setitem__("__name__", new PyString("_functools")); + dict.__setitem__("__doc__", __doc__); + dict.__setitem__("partial", PyPartial.TYPE); + + // Hide from Python + dict.__setitem__("classDictInit", null); + } +} Modified: branches/asm/src/templates/mappings =================================================================== --- branches/asm/src/templates/mappings 2008-07-30 19:57:16 UTC (rev 5023) +++ branches/asm/src/templates/mappings 2008-07-30 22:39:24 UTC (rev 5024) @@ -24,6 +24,7 @@ local.derived:org.python.modules.thread.PyLocalDerived module.derived:org.python.core.PyModuleDerived object.derived:org.python.core.PyObjectDerived +partial.derived:org.python.modules._functools.PyPartialDerived property.derived:org.python.core.PyPropertyDerived random.derived:org.python.modules.random.PyRandomDerived set.derived:org.python.core.PySetDerived Added: branches/asm/src/templates/partial.derived =================================================================== --- branches/asm/src/templates/partial.derived (rev 0) +++ branches/asm/src/templates/partial.derived 2008-07-30 22:39:24 UTC (rev 5024) @@ -0,0 +1,4 @@ +base_class: PyPartial +want_dict: false +ctr: +incl: object This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-30 19:57:26
|
Revision: 5023 http://jython.svn.sourceforge.net/jython/?rev=5023&view=rev Author: zyasoft Date: 2008-07-30 19:57:16 +0000 (Wed, 30 Jul 2008) Log Message: ----------- Changed default format for __getformat__/__setformat__ to "IEEE, big-endian", and supported switching back and forth with "unknown". Modified Paths: -------------- branches/asm/Lib/test/test_float_jy.py branches/asm/src/org/python/core/PyFloat.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/Lib/test/test_float_jy.py =================================================================== --- branches/asm/Lib/test/test_float_jy.py 2008-07-30 15:46:31 UTC (rev 5022) +++ branches/asm/Lib/test/test_float_jy.py 2008-07-30 19:57:16 UTC (rev 5023) @@ -7,7 +7,7 @@ import unittest from test import test_support -jython = sys.platform.startswith('java') +jython = test_support.is_jython class FloatTestCase(unittest.TestCase): @@ -67,14 +67,12 @@ def test_nan(self): self.assert_(type(float('NaN')), float) - # XXX: FIXME - #self.assert_(type(float('nan')), float) + self.assert_(type(float('nan')), float) self.assertEqual(long(float('NaN')), 0) def test_infinity(self): self.assert_(type(float('Infinity')), float) - # XXX: FIXME - #self.assert_(type(float('inf')), float) + self.assert_(type(float('inf')), float) self.assertRaises(OverflowError, long, float('Infinity')) def test_float_none(self): Modified: branches/asm/src/org/python/core/PyFloat.java =================================================================== --- branches/asm/src/org/python/core/PyFloat.java 2008-07-30 15:46:31 UTC (rev 5022) +++ branches/asm/src/org/python/core/PyFloat.java 2008-07-30 19:57:16 UTC (rev 5023) @@ -584,26 +584,58 @@ return float___getnewargs__(); } + // standard singleton issues apply here to __getformat__/__setformat__, + // but this is what Python demands + + public enum Format { + UNKNOWN ("unknown"), + BE ("IEEE, big-endian"), + LE ("IEEE, little-endian"); + + private final String format; + Format(String format) { + this.format = format; + } + public String format() { return format; } + } + + // subset of IEEE-754, the JVM is big-endian + public static volatile Format double_format = Format.BE; + public static volatile Format float_format = Format.BE; + @ExposedClassMethod public static String float___getformat__(PyType type, String typestr) { - if (!"double".equals(typestr) && !"float".equals(typestr)) { + if ("double".equals(typestr)) { + return double_format.format(); + } else if ("float".equals(typestr)) { + return float_format.format(); + } else { throw Py.ValueError("__getformat__() argument 1 must be 'double' or 'float'"); } - return "unknown"; } - + @ExposedClassMethod public static void float___setformat__(PyType type, String typestr, String format) { + Format new_format = null; if (!"double".equals(typestr) && !"float".equals(typestr)) { throw Py.ValueError("__setformat__() argument 1 must be 'double' or 'float'"); } - if ("IEEE, little-endian".equals(format) || "IEEE, big-endian".equals(format)) { - throw Py.ValueError(String.format("can only set %s format to 'unknown' or the " - + "detected platform value", typestr)); - } else if (!"unknown".equals(format)) { - throw Py.ValueError("__setformat__() argument 2 must be 'unknown', " - + "'IEEE, little-endian' or 'IEEE, big-endian'"); - } + if (Format.LE.format().equals(format)) { + throw Py.ValueError(String.format("can only set %s format to 'unknown' or the " + "detected platform value", typestr)); + } else if (Format.BE.format().equals(format)) { + new_format = Format.BE; + } else if (Format.UNKNOWN.format().equals(format)) { + new_format = Format.UNKNOWN; + } else { + throw Py.ValueError("__setformat__() argument 2 must be 'unknown', " + "'IEEE, little-endian' or 'IEEE, big-endian'"); + } + if (new_format != null) { + if ("double".equals(typestr)) { + double_format = new_format; + } else { + float_format = new_format; + } + } } public boolean isMappingType() { return false; } Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-30 15:46:31 UTC (rev 5022) +++ branches/asm/src/org/python/modules/struct.java 2008-07-30 19:57:16 UTC (rev 5023) @@ -748,8 +748,13 @@ } Object unpack(ByteStream buf) { - int v = LEreadInt(buf); - return Py.newFloat(Float.intBitsToFloat(v)); + int bits = LEreadInt(buf); + float v = Float.intBitsToFloat(bits); + if (PyFloat.float_format == PyFloat.Format.UNKNOWN && ( + Float.isInfinite(v) || Float.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } @@ -763,7 +768,12 @@ Object unpack(ByteStream buf) { long bits = (LEreadInt(buf) & 0xFFFFFFFFL) + (((long)LEreadInt(buf)) << 32); - return Py.newFloat(Double.longBitsToDouble(bits)); + double v = Double.longBitsToDouble(bits); + if (PyFloat.double_format == PyFloat.Format.UNKNOWN && + (Double.isInfinite(v) || Double.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } @@ -775,8 +785,13 @@ } Object unpack(ByteStream buf) { - int v = BEreadInt(buf); - return Py.newFloat(Float.intBitsToFloat(v)); + int bits = BEreadInt(buf); + float v = Float.intBitsToFloat(bits); + if (PyFloat.float_format == PyFloat.Format.UNKNOWN && ( + Float.isInfinite(v) || Float.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } @@ -788,9 +803,14 @@ } Object unpack(ByteStream buf) { - long bits = (((long)BEreadInt(buf)) << 32) + - (BEreadInt(buf) & 0xFFFFFFFFL); - return Py.newFloat(Double.longBitsToDouble(bits)); + long bits = (((long) BEreadInt(buf)) << 32) + + (BEreadInt(buf) & 0xFFFFFFFFL); + double v = Double.longBitsToDouble(bits); + if (PyFloat.double_format == PyFloat.Format.UNKNOWN && + (Double.isInfinite(v) || Double.isNaN(v))) { + throw Py.ValueError("can't unpack IEEE 754 special value on non-IEEE platform"); + } + return Py.newFloat(v); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-30 15:46:36
|
Revision: 5022 http://jython.svn.sourceforge.net/jython/?rev=5022&view=rev Author: zyasoft Date: 2008-07-30 15:46:31 +0000 (Wed, 30 Jul 2008) Log Message: ----------- Support inf, -inf, nan literals (and any uppercasing). struct.pack("d") ducktypes like CPython and calls __float__. This fixes a number of issues for PyAMF. Modified Paths: -------------- branches/asm/src/org/python/core/PyFloat.java branches/asm/src/org/python/core/PyString.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/org/python/core/PyFloat.java =================================================================== --- branches/asm/src/org/python/core/PyFloat.java 2008-07-29 22:40:05 UTC (rev 5021) +++ branches/asm/src/org/python/core/PyFloat.java 2008-07-30 15:46:31 UTC (rev 5022) @@ -105,6 +105,10 @@ } private String formatDouble(int precision) { + if (Double.isNaN(value)) { + return "nan"; + } + String result = String.format("%%.%dg", precision); result = Py.newString(result).__mod__(this).toString(); Modified: branches/asm/src/org/python/core/PyString.java =================================================================== --- branches/asm/src/org/python/core/PyString.java 2008-07-29 22:40:05 UTC (rev 5021) +++ branches/asm/src/org/python/core/PyString.java 2008-07-30 15:46:31 UTC (rev 5022) @@ -1510,6 +1510,10 @@ try { // Double.valueOf allows format specifier ("d" or "f") at the end String lowSval = sval.toLowerCase(); + if (lowSval.equals("nan")) return Double.NaN; + else if (lowSval.equals("inf")) return Double.POSITIVE_INFINITY; + else if (lowSval.equals("-inf")) return Double.NEGATIVE_INFINITY; + if (lowSval.endsWith("d") || lowSval.endsWith("f")) { throw new NumberFormatException("format specifiers not allowed"); } Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-29 22:40:05 UTC (rev 5021) +++ branches/asm/src/org/python/modules/struct.java 2008-07-30 15:46:31 UTC (rev 5022) @@ -351,8 +351,6 @@ } double get_float(PyObject value) { - if (!(value instanceof PyFloat)) - throw StructError("required argument is not an float"); return value.__float__().getValue(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |