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: <fwi...@us...> - 2008-08-13 19:48:16
|
Revision: 5171 http://jython.svn.sourceforge.net/jython/?rev=5171&view=rev Author: fwierzbicki Date: 2008-08-13 19:48:08 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Make errtext optional in test_syntax and fixed illegal delete of function call. Modified Paths: -------------- branches/asm/Lib/test/test_syntax.py branches/asm/grammar/PythonWalker.g branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/Lib/test/test_syntax.py =================================================================== --- branches/asm/Lib/test/test_syntax.py 2008-08-13 19:25:13 UTC (rev 5170) +++ branches/asm/Lib/test/test_syntax.py 2008-08-13 19:48:08 UTC (rev 5171) @@ -424,27 +424,34 @@ class SyntaxTestCase(unittest.TestCase): - def _check_error(self, code, errtext, + def _check_error(self, code, errtext=None, filename="<testcase>", mode="exec", subclass=None): """Check that compiling code raises SyntaxError with errtext. errtest is a regular expression that must be present in the test of the exception raised. If subclass is specified it is the expected subclass of SyntaxError (e.g. IndentationError). + + XXX: Made errtext optional, since the exact wording of exceptions + is implementation dependant. """ try: compile(code, filename, mode) except SyntaxError, err: if subclass and not isinstance(err, subclass): self.fail("SyntaxError is not a %s" % subclass.__name__) - mo = re.search(errtext, str(err)) - if mo is None: - self.fail("SyntaxError did not contain '%r'" % (errtext,)) + if errtext is not None: + mo = re.search(errtext, str(err)) + if mo is None: + self.fail("SyntaxError did not contain '%r'" % (errtext,)) else: self.fail("compile() did not raise SyntaxError") def test_assign_call(self): - self._check_error("f() = 1", "assign") + if test_support.is_jython: + self._check_error("f() = 1") + else: + self._check_error("f() = 1", "assign") def test_assign_del(self): self._check_error("del f()", "delete") @@ -489,7 +496,10 @@ subclass=IndentationError) def test_kwargs_last(self): - self._check_error("int(base=10, '2')", "non-keyword arg") + if test_support.is_jython: + self._check_error("int(base=10, '2')") + else: + self._check_error("int(base=10, '2')", "non-keyword arg") def test_main(): test_support.run_unittest(SyntaxTestCase) Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-13 19:25:13 UTC (rev 5170) +++ branches/asm/grammar/PythonWalker.g 2008-08-13 19:48:08 UTC (rev 5171) @@ -439,6 +439,7 @@ del_stmt : ^(DELETE elts[expr_contextType.Del]) { exprType[] t = (exprType[])$elts.etypes.toArray(new exprType[$elts.etypes.size()]); + actions.checkDelete(t); $stmts::statements.add(new Delete($DELETE, t)); } ; Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 19:25:13 UTC (rev 5170) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 19:48:08 UTC (rev 5171) @@ -499,4 +499,13 @@ } } } + + void checkDelete(exprType[] exprs) { + for(int i=0;i<exprs.length;i++) { + if (exprs[i] instanceof Call) { + errorHandler.error("can't delete function call", exprs[i]); + } + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 19:25:19
|
Revision: 5170 http://jython.svn.sourceforge.net/jython/?rev=5170&view=rev Author: fwierzbicki Date: 2008-08-13 19:25:13 +0000 (Wed, 13 Aug 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_syntax.py@54954 Added Paths: ----------- branches/asm/Lib/test/test_syntax.py Added: branches/asm/Lib/test/test_syntax.py =================================================================== --- branches/asm/Lib/test/test_syntax.py (rev 0) +++ branches/asm/Lib/test/test_syntax.py 2008-08-13 19:25:13 UTC (rev 5170) @@ -0,0 +1,500 @@ +"""This module tests SyntaxErrors. + +Here's an example of the sort of thing that is tested. + +>>> def f(x): +... global x +Traceback (most recent call last): +SyntaxError: name 'x' is local and global + +The tests are all raise SyntaxErrors. They were created by checking +each C call that raises SyntaxError. There are several modules that +raise these exceptions-- ast.c, compile.c, future.c, pythonrun.c, and +symtable.c. + +The parser itself outlaws a lot of invalid syntax. None of these +errors are tested here at the moment. We should add some tests; since +there are infinitely many programs with invalid syntax, we would need +to be judicious in selecting some. + +The compiler generates a synthetic module name for code executed by +doctest. Since all the code comes from the same module, a suffix like +[1] is appended to the module name, As a consequence, changing the +order of tests in this module means renumbering all the errors after +it. (Maybe we should enable the ellipsis option for these tests.) + +In ast.c, syntax errors are raised by calling ast_error(). + +Errors from set_context(): + +TODO(jhylton): "assignment to None" is inconsistent with other messages + +>>> obj.None = 1 +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[1]>, line 1) + +>>> None = 1 +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[2]>, line 1) + +It's a syntax error to assign to the empty tuple. Why isn't it an +error to assign to the empty list? It will always raise some error at +runtime. + +>>> () = 1 +Traceback (most recent call last): +SyntaxError: can't assign to () (<doctest test.test_syntax[3]>, line 1) + +>>> f() = 1 +Traceback (most recent call last): +SyntaxError: can't assign to function call (<doctest test.test_syntax[4]>, line 1) + +>>> del f() +Traceback (most recent call last): +SyntaxError: can't delete function call (<doctest test.test_syntax[5]>, line 1) + +>>> a + 1 = 2 +Traceback (most recent call last): +SyntaxError: can't assign to operator (<doctest test.test_syntax[6]>, line 1) + +>>> (x for x in x) = 1 +Traceback (most recent call last): +SyntaxError: can't assign to generator expression (<doctest test.test_syntax[7]>, line 1) + +>>> 1 = 1 +Traceback (most recent call last): +SyntaxError: can't assign to literal (<doctest test.test_syntax[8]>, line 1) + +>>> "abc" = 1 +Traceback (most recent call last): +SyntaxError: can't assign to literal (<doctest test.test_syntax[9]>, line 1) + +>>> `1` = 1 +Traceback (most recent call last): +SyntaxError: can't assign to repr (<doctest test.test_syntax[10]>, line 1) + +If the left-hand side of an assignment is a list or tuple, an illegal +expression inside that contain should still cause a syntax error. +This test just checks a couple of cases rather than enumerating all of +them. + +>>> (a, "b", c) = (1, 2, 3) +Traceback (most recent call last): +SyntaxError: can't assign to literal (<doctest test.test_syntax[11]>, line 1) + +>>> [a, b, c + 1] = [1, 2, 3] +Traceback (most recent call last): +SyntaxError: can't assign to operator (<doctest test.test_syntax[12]>, line 1) + +>>> a if 1 else b = 1 +Traceback (most recent call last): +SyntaxError: can't assign to conditional expression (<doctest test.test_syntax[13]>, line 1) + +From compiler_complex_args(): + +>>> def f(None=1): +... pass +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[14]>, line 1) + + +From ast_for_arguments(): + +>>> def f(x, y=1, z): +... pass +Traceback (most recent call last): +SyntaxError: non-default argument follows default argument (<doctest test.test_syntax[15]>, line 1) + +>>> def f(x, None): +... pass +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[16]>, line 1) + +>>> def f(*None): +... pass +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[17]>, line 1) + +>>> def f(**None): +... pass +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[18]>, line 1) + + +From ast_for_funcdef(): + +>>> def None(x): +... pass +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[19]>, line 1) + + +From ast_for_call(): + +>>> def f(it, *varargs): +... return list(it) +>>> L = range(10) +>>> f(x for x in L) +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +>>> f(x for x in L, 1) +Traceback (most recent call last): +SyntaxError: Generator expression must be parenthesized if not sole argument (<doctest test.test_syntax[23]>, line 1) +>>> f((x for x in L), 1) +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + +>>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, +... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, +... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, +... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, +... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, +... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, +... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, +... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, +... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, +... i100, i101, i102, i103, i104, i105, i106, i107, i108, +... i109, i110, i111, i112, i113, i114, i115, i116, i117, +... i118, i119, i120, i121, i122, i123, i124, i125, i126, +... i127, i128, i129, i130, i131, i132, i133, i134, i135, +... i136, i137, i138, i139, i140, i141, i142, i143, i144, +... i145, i146, i147, i148, i149, i150, i151, i152, i153, +... i154, i155, i156, i157, i158, i159, i160, i161, i162, +... i163, i164, i165, i166, i167, i168, i169, i170, i171, +... i172, i173, i174, i175, i176, i177, i178, i179, i180, +... i181, i182, i183, i184, i185, i186, i187, i188, i189, +... i190, i191, i192, i193, i194, i195, i196, i197, i198, +... i199, i200, i201, i202, i203, i204, i205, i206, i207, +... i208, i209, i210, i211, i212, i213, i214, i215, i216, +... i217, i218, i219, i220, i221, i222, i223, i224, i225, +... i226, i227, i228, i229, i230, i231, i232, i233, i234, +... i235, i236, i237, i238, i239, i240, i241, i242, i243, +... i244, i245, i246, i247, i248, i249, i250, i251, i252, +... i253, i254, i255) +Traceback (most recent call last): +SyntaxError: more than 255 arguments (<doctest test.test_syntax[25]>, line 1) + +The actual error cases counts positional arguments, keyword arguments, +and generator expression arguments separately. This test combines the +three. + +>>> f(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, +... i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, +... i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, +... i34, i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, +... i45, i46, i47, i48, i49, i50, i51, i52, i53, i54, i55, +... i56, i57, i58, i59, i60, i61, i62, i63, i64, i65, i66, +... i67, i68, i69, i70, i71, i72, i73, i74, i75, i76, i77, +... i78, i79, i80, i81, i82, i83, i84, i85, i86, i87, i88, +... i89, i90, i91, i92, i93, i94, i95, i96, i97, i98, i99, +... i100, i101, i102, i103, i104, i105, i106, i107, i108, +... i109, i110, i111, i112, i113, i114, i115, i116, i117, +... i118, i119, i120, i121, i122, i123, i124, i125, i126, +... i127, i128, i129, i130, i131, i132, i133, i134, i135, +... i136, i137, i138, i139, i140, i141, i142, i143, i144, +... i145, i146, i147, i148, i149, i150, i151, i152, i153, +... i154, i155, i156, i157, i158, i159, i160, i161, i162, +... i163, i164, i165, i166, i167, i168, i169, i170, i171, +... i172, i173, i174, i175, i176, i177, i178, i179, i180, +... i181, i182, i183, i184, i185, i186, i187, i188, i189, +... i190, i191, i192, i193, i194, i195, i196, i197, i198, +... i199, i200, i201, i202, i203, i204, i205, i206, i207, +... i208, i209, i210, i211, i212, i213, i214, i215, i216, +... i217, i218, i219, i220, i221, i222, i223, i224, i225, +... i226, i227, i228, i229, i230, i231, i232, i233, i234, +... i235, i236, i237, i238, i239, i240, i241, i242, i243, +... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, +... i252=1, i253=1, i254=1, i255=1) +Traceback (most recent call last): +SyntaxError: more than 255 arguments (<doctest test.test_syntax[26]>, line 1) + +>>> f(lambda x: x[0] = 3) +Traceback (most recent call last): +SyntaxError: lambda cannot contain assignment (<doctest test.test_syntax[27]>, line 1) + +The grammar accepts any test (basically, any expression) in the +keyword slot of a call site. Test a few different options. + +>>> f(x()=2) +Traceback (most recent call last): +SyntaxError: keyword can't be an expression (<doctest test.test_syntax[28]>, line 1) +>>> f(a or b=1) +Traceback (most recent call last): +SyntaxError: keyword can't be an expression (<doctest test.test_syntax[29]>, line 1) +>>> f(x.y=1) +Traceback (most recent call last): +SyntaxError: keyword can't be an expression (<doctest test.test_syntax[30]>, line 1) + + +From ast_for_expr_stmt(): + +>>> (x for x in x) += 1 +Traceback (most recent call last): +SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_syntax[31]>, line 1) +>>> None += 1 +Traceback (most recent call last): +SyntaxError: assignment to None (<doctest test.test_syntax[32]>, line 1) +>>> f() += 1 +Traceback (most recent call last): +SyntaxError: illegal expression for augmented assignment (<doctest test.test_syntax[33]>, line 1) + + +Test continue in finally in weird combinations. + +continue in for loop under finally shouuld be ok. + + >>> def test(): + ... try: + ... pass + ... finally: + ... for abc in range(10): + ... continue + ... print abc + >>> test() + 9 + +Start simple, a continue in a finally should not be allowed. + + >>> def test(): + ... for abc in range(10): + ... try: + ... pass + ... finally: + ... continue + ... + Traceback (most recent call last): + ... + SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[36]>, line 6) + +This is essentially a continue in a finally which should not be allowed. + + >>> def test(): + ... for abc in range(10): + ... try: + ... pass + ... finally: + ... try: + ... continue + ... except: + ... pass + Traceback (most recent call last): + ... + SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[37]>, line 7) + + >>> def foo(): + ... try: + ... pass + ... finally: + ... continue + Traceback (most recent call last): + ... + SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[38]>, line 5) + + >>> def foo(): + ... for a in (): + ... try: pass + ... finally: continue + Traceback (most recent call last): + ... + SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[39]>, line 4) + + >>> def foo(): + ... for a in (): + ... try: pass + ... finally: + ... try: + ... continue + ... finally: pass + Traceback (most recent call last): + ... + SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[40]>, line 6) + + >>> def foo(): + ... for a in (): + ... try: pass + ... finally: + ... try: + ... pass + ... except: + ... continue + Traceback (most recent call last): + ... + SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[41]>, line 8) + +There is one test for a break that is not in a loop. The compiler +uses a single data structure to keep track of try-finally and loops, +so we need to be sure that a break is actually inside a loop. If it +isn't, there should be a syntax error. + + >>> try: + ... print 1 + ... break + ... print 2 + ... finally: + ... print 3 + Traceback (most recent call last): + ... + SyntaxError: 'break' outside loop (<doctest test.test_syntax[42]>, line 3) + +This should probably raise a better error than a SystemError (or none at all). +In 2.5 there was a missing exception and an assert was triggered in a debug +build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514 + + >>> while 1: + ... while 2: + ... while 3: + ... while 4: + ... while 5: + ... while 6: + ... while 8: + ... while 9: + ... while 10: + ... while 11: + ... while 12: + ... while 13: + ... while 14: + ... while 15: + ... while 16: + ... while 17: + ... while 18: + ... while 19: + ... while 20: + ... while 21: + ... while 22: + ... break + Traceback (most recent call last): + ... + SystemError: too many statically nested blocks + +This tests assignment-context; there was a bug in Python 2.5 where compiling +a complex 'if' (one with 'elif') would fail to notice an invalid suite, +leading to spurious errors. + + >>> if 1: + ... x() = 1 + ... elif 1: + ... pass + Traceback (most recent call last): + ... + SyntaxError: can't assign to function call (<doctest test.test_syntax[44]>, line 2) + + >>> if 1: + ... pass + ... elif 1: + ... x() = 1 + Traceback (most recent call last): + ... + SyntaxError: can't assign to function call (<doctest test.test_syntax[45]>, line 4) + + >>> if 1: + ... x() = 1 + ... elif 1: + ... pass + ... else: + ... pass + Traceback (most recent call last): + ... + SyntaxError: can't assign to function call (<doctest test.test_syntax[46]>, line 2) + + >>> if 1: + ... pass + ... elif 1: + ... x() = 1 + ... else: + ... pass + Traceback (most recent call last): + ... + SyntaxError: can't assign to function call (<doctest test.test_syntax[47]>, line 4) + + >>> if 1: + ... pass + ... elif 1: + ... pass + ... else: + ... x() = 1 + Traceback (most recent call last): + ... + SyntaxError: can't assign to function call (<doctest test.test_syntax[48]>, line 6) + +""" + +import re +import unittest +import warnings + +from test import test_support + +class SyntaxTestCase(unittest.TestCase): + + def _check_error(self, code, errtext, + filename="<testcase>", mode="exec", subclass=None): + """Check that compiling code raises SyntaxError with errtext. + + errtest is a regular expression that must be present in the + test of the exception raised. If subclass is specified it + is the expected subclass of SyntaxError (e.g. IndentationError). + """ + try: + compile(code, filename, mode) + except SyntaxError, err: + if subclass and not isinstance(err, subclass): + self.fail("SyntaxError is not a %s" % subclass.__name__) + mo = re.search(errtext, str(err)) + if mo is None: + self.fail("SyntaxError did not contain '%r'" % (errtext,)) + else: + self.fail("compile() did not raise SyntaxError") + + def test_assign_call(self): + self._check_error("f() = 1", "assign") + + def test_assign_del(self): + self._check_error("del f()", "delete") + + def test_global_err_then_warn(self): + # Bug tickler: The SyntaxError raised for one global statement + # shouldn't be clobbered by a SyntaxWarning issued for a later one. + source = re.sub('(?m)^ *:', '', """\ + :def error(a): + : global a # SyntaxError + :def warning(): + : b = 1 + : global b # SyntaxWarning + :""") + warnings.filterwarnings(action='ignore', category=SyntaxWarning) + self._check_error(source, "global") + warnings.filters.pop(0) + + def test_break_outside_loop(self): + self._check_error("break", "outside loop") + + def test_delete_deref(self): + source = re.sub('(?m)^ *:', '', """\ + :def foo(x): + : def bar(): + : print x + : del x + :""") + self._check_error(source, "nested scope") + + def test_unexpected_indent(self): + self._check_error("foo()\n bar()\n", "unexpected indent", + subclass=IndentationError) + + def test_no_indent(self): + self._check_error("if 1:\nfoo()", "expected an indented block", + subclass=IndentationError) + + def test_bad_outdent(self): + self._check_error("if 1:\n foo()\n bar()", + "unindent does not match .* level", + subclass=IndentationError) + + def test_kwargs_last(self): + self._check_error("int(base=10, '2')", "non-keyword arg") + +def test_main(): + test_support.run_unittest(SyntaxTestCase) + from test import test_syntax + test_support.run_doctest(test_syntax, verbosity=True) + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 16:21:21
|
Revision: 5169 http://jython.svn.sourceforge.net/jython/?rev=5169&view=rev Author: fwierzbicki Date: 2008-08-13 16:21:18 +0000 (Wed, 13 Aug 2008) Log Message: ----------- remove comment that is no longer True, thanks to Leo Soto for pointing this out. Modified Paths: -------------- branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 14:52:12 UTC (rev 5168) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 16:21:18 UTC (rev 5169) @@ -446,8 +446,6 @@ return new Call(t, func, a, k, starargs, kwargs); } - //FIXME: just calling __neg__ for now - can be better. Also does not parse expressions like - // --2 correctly (should give ^(USub -2) but gives 2). exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 14:52:18
|
Revision: 5168 http://jython.svn.sourceforge.net/jython/?rev=5168&view=rev Author: fwierzbicki Date: 2008-08-13 14:52:12 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Jython can handle atof with hex floats and large unicode values. Modified Paths: -------------- branches/asm/Lib/test/test_builtin.py Modified: branches/asm/Lib/test/test_builtin.py =================================================================== --- branches/asm/Lib/test/test_builtin.py 2008-08-13 05:13:54 UTC (rev 5167) +++ branches/asm/Lib/test/test_builtin.py 2008-08-13 14:52:12 UTC (rev 5168) @@ -2,7 +2,7 @@ import test.test_support, unittest from test.test_support import fcmp, have_unicode, TESTFN, unlink, \ - run_unittest + run_unittest, is_jython from operator import neg import sys, warnings, cStringIO, random, UserDict @@ -548,12 +548,24 @@ self.assertEqual(float(314L), 314.0) self.assertEqual(float(" 3.14 "), 3.14) self.assertRaises(ValueError, float, " 0x3.1 ") - self.assertRaises(ValueError, float, " -0x3.p-1 ") + #XXX: Java can handle conversions of BinaryExponentIndicator (the p + # below) as well as floating hex. Thanks to Tobias Ivarsson for + # noticing this in the Java Language Spec. For us this is + # cross-platform - and the comments for this checkin by Neal + # Norwitz say this check is part of making things more platform + # neutral. I'm leaving this test out until we find out whether or + # not this is an implementation detail of CPython + if not is_jython: + self.assertRaises(ValueError, float, " -0x3.p-1 ") if have_unicode: self.assertEqual(float(unicode(" 3.14 ")), 3.14) self.assertEqual(float(unicode(" \u0663.\u0661\u0664 ",'raw-unicode-escape')), 3.14) # Implementation limitation in PyFloat_FromString() - self.assertRaises(ValueError, float, unicode("1"*10000)) + # XXX: but not in Jython. + if is_jython: + self.assertEquals(float(unicode("1"*10000)), float(unicode("1"*10000))) + else: + self.assertRaises(ValueError, float, unicode("1"*10000)) # @run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE') # def test_float_with_comma(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-13 05:13:57
|
Revision: 5167 http://jython.svn.sourceforge.net/jython/?rev=5167&view=rev Author: pjenvey Date: 2008-08-13 05:13:54 +0000 (Wed, 13 Aug 2008) Log Message: ----------- branches/pep352 was merged to branches/asm in r4729 Removed Paths: ------------- branches/pep352/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 03:48:03
|
Revision: 5166 http://jython.svn.sourceforge.net/jython/?rev=5166&view=rev Author: fwierzbicki Date: 2008-08-13 03:48:00 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Remove direct exception throwing for tooling. Modified Paths: -------------- branches/asm/src/org/python/antlr/ErrorHandler.java branches/asm/src/org/python/antlr/FailFastHandler.java branches/asm/src/org/python/antlr/GrammarActions.java 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-08-13 00:53:09 UTC (rev 5165) +++ branches/asm/src/org/python/antlr/ErrorHandler.java 2008-08-13 03:48:00 UTC (rev 5166) @@ -20,4 +20,6 @@ sliceType errorSlice(PythonTree t); stmtType errorStmt(PythonTree t); + //exceptions + void error(String message, PythonTree t); } Modified: branches/asm/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/asm/src/org/python/antlr/FailFastHandler.java 2008-08-13 00:53:09 UTC (rev 5165) +++ branches/asm/src/org/python/antlr/FailFastHandler.java 2008-08-13 03:48:00 UTC (rev 5166) @@ -47,6 +47,10 @@ throw new ParseException("Bad Stmt Node", t); } + public void error(String message, PythonTree t) { + throw new ParseException(message, t); + } + private String message(BaseRecognizer br, RecognitionException re) { String hdr = br.getErrorHeader(re); String msg = br.getErrorMessage(re, br.getTokenNames()); Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 00:53:09 UTC (rev 5165) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 03:48:00 UTC (rev 5166) @@ -97,7 +97,7 @@ } void throwGenExpNotSoleArg(PythonTree t) { - throw new ParseException("Generator expression must be parenthesized if not sole argument", t); + errorHandler.error("Generator expression must be parenthesized if not sole argument", t); } exprType[] makeExprs(List exprs) { @@ -482,17 +482,17 @@ void cantBeNone(PythonTree e) { if (e.getText().equals("None")) { - throw new ParseException("can't be None", e); + errorHandler.error("can't be None", e); } } void checkAssign(exprType e) { if (e instanceof Name && ((Name)e).id.equals("None")) { - throw new ParseException("assignment to None", e); + errorHandler.error("assignment to None", e); } else if (e instanceof GeneratorExp) { - throw new ParseException("can't assign to generator expression", e); + errorHandler.error("can't assign to generator expression", e); } else if (e instanceof Num) { - throw new ParseException("can't assign to number", e); + errorHandler.error("can't assign to number", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? exprType[] elts = ((Tuple)e).elts; Modified: branches/asm/src/org/python/antlr/ListErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-08-13 00:53:09 UTC (rev 5165) +++ branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-08-13 03:48:00 UTC (rev 5166) @@ -47,4 +47,8 @@ return new ErrorStmt(t); } + public void error(String message, PythonTree t) { + System.err.println(message); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 00:53:12
|
Revision: 5165 http://jython.svn.sourceforge.net/jython/?rev=5165&view=rev Author: fwierzbicki Date: 2008-08-13 00:53:09 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Avoiding a test for constant folding -- I think it is an implementation detail though I think it wouldn't be too hard to fix in the grammar. It's just not a top priority. Modified Paths: -------------- branches/asm/Lib/test/test_compile.py Modified: branches/asm/Lib/test/test_compile.py =================================================================== --- branches/asm/Lib/test/test_compile.py 2008-08-13 00:30:38 UTC (rev 5164) +++ branches/asm/Lib/test/test_compile.py 2008-08-13 00:53:09 UTC (rev 5165) @@ -239,8 +239,12 @@ self.fail("How many bits *does* this machine have???") # Verify treatment of contant folding on -(sys.maxint+1) # i.e. -2147483648 on 32 bit platforms. Should return int, not long. - self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int)) - self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long)) + # XXX: I'd call this an implementation detail, but one that should be + # fairly easy and moderately worthwhile to implement. Still it is low + # on the list, so leaving it out of jython for now. + if not test_support.is_jython: + self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int)) + self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long)) if sys.maxint == 9223372036854775807: def test_32_63_bit_values(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 00:30:40
|
Revision: 5164 http://jython.svn.sourceforge.net/jython/?rev=5164&view=rev Author: fwierzbicki Date: 2008-08-13 00:30:38 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Before this check-in there was an AST inconsistency with CPython. To pick one example, CPython's AST for --1 is (USub(-1)) and Jython is (Usub(Usub(1)). This fixes that inconsistency. Modified Paths: -------------- branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-12 22:58:47 UTC (rev 5163) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 00:30:38 UTC (rev 5164) @@ -4,6 +4,10 @@ import org.antlr.runtime.Token; import org.python.core.Py; +import org.python.core.PyComplex; +import org.python.core.PyFloat; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyUnicode; @@ -85,7 +89,6 @@ public class GrammarActions { private ErrorHandler errorHandler = null; - public GrammarActions() { } @@ -448,10 +451,31 @@ exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; - if (num.n instanceof PyObject) { - num.n = ((PyObject)num.n).__neg__(); + if (num.n instanceof PyInteger) { + int v = ((PyInteger)num.n).getValue(); + if (v > 0) { + num.n = new PyInteger(-v); + return num; + } + } else if (num.n instanceof PyLong) { + BigInteger v = ((PyLong)num.n).getValue(); + if (v.compareTo(BigInteger.ZERO) == 1) { + num.n = new PyLong(v.negate()); + return num; + } + } else if (num.n instanceof PyFloat) { + double v = ((PyFloat)num.n).getValue(); + if (v > 0) { + num.n = new PyFloat(-v); + return num; + } + } else if (num.n instanceof PyComplex) { + double v = ((PyComplex)num.n).imag; + if (v > 0) { + num.n = new PyComplex(0,-v); + return num; + } } - return num; } return new UnaryOp(t, unaryopType.USub, o); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-12 22:58:49
|
Revision: 5163 http://jython.svn.sourceforge.net/jython/?rev=5163&view=rev Author: leosoto Date: 2008-08-12 22:58:47 +0000 (Tue, 12 Aug 2008) Log Message: ----------- subprocess.Popen now "inherits" os.environ if env is not explictely set. Fixes #1104 Modified Paths: -------------- branches/asm/Lib/subprocess.py Added Paths: ----------- branches/asm/Lib/test/test_subprocess_jy.py Modified: branches/asm/Lib/subprocess.py =================================================================== --- branches/asm/Lib/subprocess.py 2008-08-12 19:47:24 UTC (rev 5162) +++ branches/asm/Lib/subprocess.py 2008-08-12 22:58:47 UTC (rev 5163) @@ -1156,11 +1156,16 @@ except java.lang.IllegalArgumentException, iae: raise OSError(iae.getMessage() or iae) - if env is not None: - builder_env = builder.environment() - builder_env.clear() - builder_env.putAll(dict(env)) + if env is None: + # This is for compatibility with the CPython implementation, + # that ends up calling os.execvp(). So os.environ is "inherited" + # there if env is not explicitly set. + env = os.environ + builder_env = builder.environment() + builder_env.clear() + builder_env.putAll(dict(env)) + if cwd is None: cwd = os.getcwd() elif not os.path.exists(cwd): Added: branches/asm/Lib/test/test_subprocess_jy.py =================================================================== --- branches/asm/Lib/test/test_subprocess_jy.py (rev 0) +++ branches/asm/Lib/test/test_subprocess_jy.py 2008-08-12 22:58:47 UTC (rev 5163) @@ -0,0 +1,23 @@ +"Tests for cmp() compatibility with CPython" +import unittest +import os +import sys +from test import test_support +from subprocess import Popen, PIPE + +class EnvironmentInheritanceTest(unittest.TestCase): + def testDefaultEnvIsInherited(self): + # Test for issue #1104 + os.environ['foo'] = 'something' + p1 = Popen([sys.executable, "-c", + 'import os, sys; sys.stdout.write(os.environ["foo"])'], + stdout=PIPE) + self.assertEquals('something', p1.stdout.read()) + +def test_main(): + test_support.run_unittest(EnvironmentInheritanceTest) + +if __name__ == '__main__': + test_main() + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 19:47:26
|
Revision: 5162 http://jython.svn.sourceforge.net/jython/?rev=5162&view=rev Author: fwierzbicki Date: 2008-08-12 19:47:24 +0000 (Tue, 12 Aug 2008) Log Message: ----------- fixes, workarounds, and a couple of punts for test_compile.py. Modified Paths: -------------- branches/asm/Lib/test/test_compile.py branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/Lib/test/test_compile.py =================================================================== --- branches/asm/Lib/test/test_compile.py 2008-08-12 18:57:22 UTC (rev 5161) +++ branches/asm/Lib/test/test_compile.py 2008-08-12 19:47:24 UTC (rev 5162) @@ -80,6 +80,9 @@ exec 'z = b' in m except TypeError: pass + #XXX: Jython calls this a NameError + except NameError: + pass else: self.fail('Did not validate globals as a real dict') @@ -91,6 +94,9 @@ exec 'z = a' in g, m except TypeError: pass + #XXX: Jython calls this an AttributeError + except AttributeError: + pass else: self.fail('Did not validate locals as a mapping') @@ -261,7 +267,9 @@ stmts = [ 'None = 0', 'None += 0', - '__builtins__.None = 0', + #XXX: None is specifically allowed as a dotted name for Java + # integration purposes in Jython. + #'__builtins__.None = 0', 'def None(): pass', 'class None: pass', '(a, None) = 0, 0', Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-12 18:57:22 UTC (rev 5161) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-12 19:47:24 UTC (rev 5162) @@ -138,6 +138,7 @@ if (nameToken == null) { return errorHandler.errorStmt(t); } + cantBeNone(nameToken); argumentsType a; if (args != null) { a = args; @@ -319,6 +320,7 @@ if (nameToken == null) { return errorHandler.errorStmt(t); } + cantBeNone(nameToken); exprType[] b = (exprType[])bases.toArray(new exprType[bases.size()]); stmtType[] s = (stmtType[])body.toArray(new stmtType[body.size()]); return new ClassDef(t, nameToken.getText(), b, s); @@ -407,6 +409,7 @@ if (target == null || iter == null) { return errorHandler.errorStmt(t); } + cantBeNone(target); stmtType[] o; if (orelse != null) { o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); @@ -453,6 +456,12 @@ return new UnaryOp(t, unaryopType.USub, o); } + void cantBeNone(PythonTree e) { + if (e.getText().equals("None")) { + throw new ParseException("can't be None", e); + } + } + void checkAssign(exprType e) { if (e instanceof Name && ((Name)e).id.equals("None")) { throw new ParseException("assignment to None", e); @@ -460,6 +469,12 @@ throw new ParseException("can't assign to generator expression", e); } else if (e instanceof Num) { throw new ParseException("can't assign to number", e); + } else if (e instanceof Tuple) { + //XXX: performance problem? Any way to do this better? + exprType[] elts = ((Tuple)e).elts; + for (int i=0;i<elts.length;i++) { + checkAssign(elts[i]); + } } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 18:57:24
|
Revision: 5161 http://jython.svn.sourceforge.net/jython/?rev=5161&view=rev Author: fwierzbicki Date: 2008-08-12 18:57:22 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Since the comment for test_leading_newlines suggests that this may be CPython implementation specific, skip. Modified Paths: -------------- branches/asm/Lib/test/test_compile.py Modified: branches/asm/Lib/test/test_compile.py =================================================================== --- branches/asm/Lib/test/test_compile.py 2008-08-12 18:40:38 UTC (rev 5160) +++ branches/asm/Lib/test/test_compile.py 2008-08-12 18:57:22 UTC (rev 5161) @@ -176,10 +176,11 @@ # the first line of code starts after 256, correct line numbers # in tracebacks are still produced. def test_leading_newlines(self): - s256 = "".join(["\n"] * 256 + ["spam"]) - co = compile(s256, 'fn', 'exec') - self.assertEqual(co.co_firstlineno, 257) - self.assertEqual(co.co_lnotab, '') + if not test_support.is_jython: + s256 = "".join(["\n"] * 256 + ["spam"]) + co = compile(s256, 'fn', 'exec') + self.assertEqual(co.co_firstlineno, 257) + self.assertEqual(co.co_lnotab, '') def test_literals_with_leading_zeroes(self): for arg in ["077787", "0xj", "0x.", "0e", "090000000000000", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 18:40:40
|
Revision: 5160 http://jython.svn.sourceforge.net/jython/?rev=5160&view=rev Author: fwierzbicki Date: 2008-08-12 18:40:38 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Trailing commas not allowed outside of parens. Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-12 18:24:24 UTC (rev 5159) +++ branches/asm/grammar/Python.g 2008-08-12 18:40:38 UTC (rev 5160) @@ -582,13 +582,13 @@ -> ^(FROM ^(Level DOT*)? ^(Value dotted_name)? ^(IMPORT STAR)) | import_as_names -> ^(FROM ^(Level DOT*)? ^(Value dotted_name)? ^(IMPORT import_as_names)) - | LPAREN import_as_names RPAREN + | LPAREN import_as_names COMMA? RPAREN -> ^(FROM ^(Level DOT*)? ^(Value dotted_name)? ^(IMPORT import_as_names)) ) ; //import_as_names: import_as_name (',' import_as_name)* [','] -import_as_names : import_as_name (COMMA! import_as_name)* (COMMA!)? +import_as_names : import_as_name (COMMA! import_as_name)* ; //import_as_name: NAME [('as' | NAME) NAME] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 18:24:26
|
Revision: 5159 http://jython.svn.sourceforge.net/jython/?rev=5159&view=rev Author: fwierzbicki Date: 2008-08-12 18:24:24 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Don't try really long args on Jython for now. Modified Paths: -------------- branches/asm/Lib/test/test_compile.py Modified: branches/asm/Lib/test/test_compile.py =================================================================== --- branches/asm/Lib/test/test_compile.py 2008-08-12 18:17:00 UTC (rev 5158) +++ branches/asm/Lib/test/test_compile.py 2008-08-12 18:24:24 UTC (rev 5159) @@ -124,8 +124,10 @@ # EXTENDED_ARG/JUMP_ABSOLUTE here return x ''' % ((longexpr,)*10) - exec code - self.assertEqual(f(5), 0) + #Exceeds 65535 byte limit on methods in the JVM. + if not test_support.is_jython: + exec code + self.assertEqual(f(5), 0) def test_complex_args(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 18:17:05
|
Revision: 5158 http://jython.svn.sourceforge.net/jython/?rev=5158&view=rev Author: fwierzbicki Date: 2008-08-12 18:17:00 +0000 (Tue, 12 Aug 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_compile.py@65007 Added Paths: ----------- branches/asm/Lib/test/test_compile.py Added: branches/asm/Lib/test/test_compile.py =================================================================== --- branches/asm/Lib/test/test_compile.py (rev 0) +++ branches/asm/Lib/test/test_compile.py 2008-08-12 18:17:00 UTC (rev 5158) @@ -0,0 +1,413 @@ +import unittest +import warnings +import sys +from test import test_support + +class TestSpecifics(unittest.TestCase): + + def test_debug_assignment(self): + # catch assignments to __debug__ + self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single') + import __builtin__ + prev = __builtin__.__debug__ + setattr(__builtin__, '__debug__', 'sure') + setattr(__builtin__, '__debug__', prev) + + def test_argument_handling(self): + # detect duplicate positional and keyword arguments + self.assertRaises(SyntaxError, eval, 'lambda a,a:0') + self.assertRaises(SyntaxError, eval, 'lambda a,a=1:0') + self.assertRaises(SyntaxError, eval, 'lambda a=1,a=1:0') + try: + exec 'def f(a, a): pass' + self.fail("duplicate arguments") + except SyntaxError: + pass + try: + exec 'def f(a = 0, a = 1): pass' + self.fail("duplicate keyword arguments") + except SyntaxError: + pass + try: + exec 'def f(a): global a; a = 1' + self.fail("variable is global and local") + except SyntaxError: + pass + + def test_syntax_error(self): + self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec") + + def test_none_keyword_arg(self): + self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec") + + def test_duplicate_global_local(self): + try: + exec 'def f(a): global a; a = 1' + self.fail("variable is global and local") + except SyntaxError: + pass + + def test_exec_with_general_mapping_for_locals(self): + + class M: + "Test mapping interface versus possible calls from eval()." + def __getitem__(self, key): + if key == 'a': + return 12 + raise KeyError + def __setitem__(self, key, value): + self.results = (key, value) + def keys(self): + return list('xyz') + + m = M() + g = globals() + exec 'z = a' in g, m + self.assertEqual(m.results, ('z', 12)) + try: + exec 'z = b' in g, m + except NameError: + pass + else: + self.fail('Did not detect a KeyError') + exec 'z = dir()' in g, m + self.assertEqual(m.results, ('z', list('xyz'))) + exec 'z = globals()' in g, m + self.assertEqual(m.results, ('z', g)) + exec 'z = locals()' in g, m + self.assertEqual(m.results, ('z', m)) + try: + exec 'z = b' in m + except TypeError: + pass + else: + self.fail('Did not validate globals as a real dict') + + class A: + "Non-mapping" + pass + m = A() + try: + exec 'z = a' in g, m + except TypeError: + pass + else: + self.fail('Did not validate locals as a mapping') + + # Verify that dict subclasses work as well + class D(dict): + def __getitem__(self, key): + if key == 'a': + return 12 + return dict.__getitem__(self, key) + d = D() + exec 'z = a' in g, d + self.assertEqual(d['z'], 12) + + def test_extended_arg(self): + longexpr = 'x = x or ' + '-x' * 2500 + code = ''' +def f(x): + %s + %s + %s + %s + %s + %s + %s + %s + %s + %s + # the expressions above have no effect, x == argument + while x: + x -= 1 + # EXTENDED_ARG/JUMP_ABSOLUTE here + return x +''' % ((longexpr,)*10) + exec code + self.assertEqual(f(5), 0) + + def test_complex_args(self): + + def comp_args((a, b)): + return a,b + self.assertEqual(comp_args((1, 2)), (1, 2)) + + def comp_args((a, b)=(3, 4)): + return a, b + self.assertEqual(comp_args((1, 2)), (1, 2)) + self.assertEqual(comp_args(), (3, 4)) + + def comp_args(a, (b, c)): + return a, b, c + self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3)) + + def comp_args(a=2, (b, c)=(3, 4)): + return a, b, c + self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3)) + self.assertEqual(comp_args(), (2, 3, 4)) + + def test_argument_order(self): + try: + exec 'def f(a=1, (b, c)): pass' + self.fail("non-default args after default") + except SyntaxError: + pass + + def test_float_literals(self): + # testing bad float literals + self.assertRaises(SyntaxError, eval, "2e") + self.assertRaises(SyntaxError, eval, "2.0e+") + self.assertRaises(SyntaxError, eval, "1e-") + self.assertRaises(SyntaxError, eval, "3-4e/21") + + def test_indentation(self): + # testing compile() of indented block w/o trailing newline" + s = """ +if 1: + if 2: + pass""" + compile(s, "<string>", "exec") + + # This test is probably specific to CPython and may not generalize + # to other implementations. We are trying to ensure that when + # the first line of code starts after 256, correct line numbers + # in tracebacks are still produced. + def test_leading_newlines(self): + s256 = "".join(["\n"] * 256 + ["spam"]) + co = compile(s256, 'fn', 'exec') + self.assertEqual(co.co_firstlineno, 257) + self.assertEqual(co.co_lnotab, '') + + def test_literals_with_leading_zeroes(self): + for arg in ["077787", "0xj", "0x.", "0e", "090000000000000", + "080000000000000", "000000000000009", "000000000000008"]: + self.assertRaises(SyntaxError, eval, arg) + + self.assertEqual(eval("0777"), 511) + self.assertEqual(eval("0777L"), 511) + self.assertEqual(eval("000777"), 511) + self.assertEqual(eval("0xff"), 255) + self.assertEqual(eval("0xffL"), 255) + self.assertEqual(eval("0XfF"), 255) + self.assertEqual(eval("0777."), 777) + self.assertEqual(eval("0777.0"), 777) + self.assertEqual(eval("000000000000000000000000000000000000000000000000000777e0"), 777) + self.assertEqual(eval("0777e1"), 7770) + self.assertEqual(eval("0e0"), 0) + self.assertEqual(eval("0000E-012"), 0) + self.assertEqual(eval("09.5"), 9.5) + self.assertEqual(eval("0777j"), 777j) + self.assertEqual(eval("00j"), 0j) + self.assertEqual(eval("00.0"), 0) + self.assertEqual(eval("0e3"), 0) + self.assertEqual(eval("090000000000000."), 90000000000000.) + self.assertEqual(eval("090000000000000.0000000000000000000000"), 90000000000000.) + self.assertEqual(eval("090000000000000e0"), 90000000000000.) + self.assertEqual(eval("090000000000000e-0"), 90000000000000.) + self.assertEqual(eval("090000000000000j"), 90000000000000j) + self.assertEqual(eval("000000000000007"), 7) + self.assertEqual(eval("000000000000008."), 8.) + self.assertEqual(eval("000000000000009."), 9.) + self.assertEqual(eval("020000000000.0"), 20000000000.0) + self.assertEqual(eval("037777777777e0"), 37777777777.0) + self.assertEqual(eval("01000000000000000000000.0"), + 1000000000000000000000.0) + + def test_unary_minus(self): + # Verify treatment of unary minus on negative numbers SF bug #660455 + if sys.maxint == 2147483647: + # 32-bit machine + all_one_bits = '0xffffffff' + self.assertEqual(eval(all_one_bits), 4294967295L) + self.assertEqual(eval("-" + all_one_bits), -4294967295L) + elif sys.maxint == 9223372036854775807: + # 64-bit machine + all_one_bits = '0xffffffffffffffff' + self.assertEqual(eval(all_one_bits), 18446744073709551615L) + self.assertEqual(eval("-" + all_one_bits), -18446744073709551615L) + else: + self.fail("How many bits *does* this machine have???") + # Verify treatment of contant folding on -(sys.maxint+1) + # i.e. -2147483648 on 32 bit platforms. Should return int, not long. + self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int)) + self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long)) + + if sys.maxint == 9223372036854775807: + def test_32_63_bit_values(self): + a = +4294967296 # 1 << 32 + b = -4294967296 # 1 << 32 + c = +281474976710656 # 1 << 48 + d = -281474976710656 # 1 << 48 + e = +4611686018427387904 # 1 << 62 + f = -4611686018427387904 # 1 << 62 + g = +9223372036854775807 # 1 << 63 - 1 + h = -9223372036854775807 # 1 << 63 - 1 + + for variable in self.test_32_63_bit_values.func_code.co_consts: + if variable is not None: + self.assertTrue(isinstance(variable, int)) + + def test_sequence_unpacking_error(self): + # Verify sequence packing/unpacking with "or". SF bug #757818 + i,j = (1, -1) or (-1, 1) + self.assertEqual(i, 1) + self.assertEqual(j, -1) + + def test_none_assignment(self): + stmts = [ + 'None = 0', + 'None += 0', + '__builtins__.None = 0', + 'def None(): pass', + 'class None: pass', + '(a, None) = 0, 0', + 'for None in range(10): pass', + 'def f(None): pass', + ] + for stmt in stmts: + stmt += "\n" + self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single') + self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') + + def test_import(self): + succeed = [ + 'import sys', + 'import os, sys', + 'import os as bar', + 'import os.path as bar', + 'from __future__ import nested_scopes, generators', + 'from __future__ import (nested_scopes,\ngenerators)', + 'from __future__ import (nested_scopes,\ngenerators,)', + 'from sys import stdin, stderr, stdout', + 'from sys import (stdin, stderr,\nstdout)', + 'from sys import (stdin, stderr,\nstdout,)', + 'from sys import (stdin\n, stderr, stdout)', + 'from sys import (stdin\n, stderr, stdout,)', + 'from sys import stdin as si, stdout as so, stderr as se', + 'from sys import (stdin as si, stdout as so, stderr as se)', + 'from sys import (stdin as si, stdout as so, stderr as se,)', + ] + fail = [ + 'import (os, sys)', + 'import (os), (sys)', + 'import ((os), (sys))', + 'import (sys', + 'import sys)', + 'import (os,)', + 'import os As bar', + 'import os.path a bar', + 'from sys import stdin As stdout', + 'from sys import stdin a stdout', + 'from (sys) import stdin', + 'from __future__ import (nested_scopes', + 'from __future__ import nested_scopes)', + 'from __future__ import nested_scopes,\ngenerators', + 'from sys import (stdin', + 'from sys import stdin)', + 'from sys import stdin, stdout,\nstderr', + 'from sys import stdin si', + 'from sys import stdin,' + 'from sys import (*)', + 'from sys import (stdin,, stdout, stderr)', + 'from sys import (stdin, stdout),', + ] + for stmt in succeed: + compile(stmt, 'tmp', 'exec') + for stmt in fail: + self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') + + def test_for_distinct_code_objects(self): + # SF bug 1048870 + def f(): + f1 = lambda x=1: x + f2 = lambda x=2: x + return f1, f2 + f1, f2 = f() + self.assertNotEqual(id(f1.func_code), id(f2.func_code)) + + def test_unicode_encoding(self): + code = u"# -*- coding: utf-8 -*-\npass\n" + self.assertRaises(SyntaxError, compile, code, "tmp", "exec") + + def test_subscripts(self): + # SF bug 1448804 + # Class to make testing subscript results easy + class str_map(object): + def __init__(self): + self.data = {} + def __getitem__(self, key): + return self.data[str(key)] + def __setitem__(self, key, value): + self.data[str(key)] = value + def __delitem__(self, key): + del self.data[str(key)] + def __contains__(self, key): + return str(key) in self.data + d = str_map() + # Index + d[1] = 1 + self.assertEqual(d[1], 1) + d[1] += 1 + self.assertEqual(d[1], 2) + del d[1] + self.assertEqual(1 in d, False) + # Tuple of indices + d[1, 1] = 1 + self.assertEqual(d[1, 1], 1) + d[1, 1] += 1 + self.assertEqual(d[1, 1], 2) + del d[1, 1] + self.assertEqual((1, 1) in d, False) + # Simple slice + d[1:2] = 1 + self.assertEqual(d[1:2], 1) + d[1:2] += 1 + self.assertEqual(d[1:2], 2) + del d[1:2] + self.assertEqual(slice(1, 2) in d, False) + # Tuple of simple slices + d[1:2, 1:2] = 1 + self.assertEqual(d[1:2, 1:2], 1) + d[1:2, 1:2] += 1 + self.assertEqual(d[1:2, 1:2], 2) + del d[1:2, 1:2] + self.assertEqual((slice(1, 2), slice(1, 2)) in d, False) + # Extended slice + d[1:2:3] = 1 + self.assertEqual(d[1:2:3], 1) + d[1:2:3] += 1 + self.assertEqual(d[1:2:3], 2) + del d[1:2:3] + self.assertEqual(slice(1, 2, 3) in d, False) + # Tuple of extended slices + d[1:2:3, 1:2:3] = 1 + self.assertEqual(d[1:2:3, 1:2:3], 1) + d[1:2:3, 1:2:3] += 1 + self.assertEqual(d[1:2:3, 1:2:3], 2) + del d[1:2:3, 1:2:3] + self.assertEqual((slice(1, 2, 3), slice(1, 2, 3)) in d, False) + # Ellipsis + d[...] = 1 + self.assertEqual(d[...], 1) + d[...] += 1 + self.assertEqual(d[...], 2) + del d[...] + self.assertEqual(Ellipsis in d, False) + # Tuple of Ellipses + d[..., ...] = 1 + self.assertEqual(d[..., ...], 1) + d[..., ...] += 1 + self.assertEqual(d[..., ...], 2) + del d[..., ...] + self.assertEqual((Ellipsis, Ellipsis) in d, False) + + def test_nested_classes(self): + # Verify that it does not leak + compile("class A:\n class B: pass", 'tmp', 'exec') + +def test_main(): + test_support.run_unittest(TestSpecifics) + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 18:11:41
|
Revision: 5157 http://jython.svn.sourceforge.net/jython/?rev=5157&view=rev Author: fwierzbicki Date: 2008-08-12 18:11:38 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Disallow encodings from unicode input. Fixes one test in test_compile.py. Modified Paths: -------------- branches/asm/src/org/python/core/CompilerFlags.java branches/asm/src/org/python/core/ParserFacade.java branches/asm/src/org/python/core/PyTableCode.java branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/src/org/python/core/CompilerFlags.java =================================================================== --- branches/asm/src/org/python/core/CompilerFlags.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/CompilerFlags.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -6,11 +6,13 @@ public boolean nested_scopes = true; public boolean division; public boolean generator_allowed = true; - public boolean only_ast = false; - public boolean dont_imply_dedent = false; public boolean with_statement = false; public boolean absolute_import = false; + public boolean only_ast = false; + public boolean dont_imply_dedent = false; + public boolean source_is_utf8 = false; + public String encoding; public CompilerFlags(){} @@ -37,13 +39,18 @@ if ((co_flags & org.python.core.PyTableCode.PyCF_DONT_IMPLY_DEDENT) != 0) { this.dont_imply_dedent = true; } + if ((co_flags & org.python.core.PyTableCode.PyCF_SOURCE_IS_UTF8) != 0) { + this.source_is_utf8 = true; + } + } - + public String toString() { return String.format("CompilerFlags[division=%s nested_scopes=%s generators=%s " + "with_statement=%s absolute_import=%s only_ast=%s " - + "dont_imply_dedent=%s]", division, nested_scopes, generator_allowed, - with_statement, absolute_import, only_ast, dont_imply_dedent); + + "dont_imply_dedent=%s source_is_utf8=%s]", division, nested_scopes, + generator_allowed, with_statement, absolute_import, only_ast, + dont_imply_dedent, source_is_utf8); } } Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -199,13 +199,17 @@ InputStream bstream = new BufferedInputStream(istream); bom = adjustForBOM(bstream); encoding = readEncoding(bstream); - if(encoding == null) { + + if (encoding == null) { if (bom) { encoding = "UTF-8"; } else if (cflags != null && cflags.encoding != null) { encoding = cflags.encoding; } + } else if (cflags.source_is_utf8) { + throw new ParseException("encoding declaration in Unicode string"); } + // Enable universal newlines mode on the input StreamIO rawIO = new StreamIO(bstream, true); org.python.core.io.BufferedReader bufferedIO = Modified: branches/asm/src/org/python/core/PyTableCode.java =================================================================== --- branches/asm/src/org/python/core/PyTableCode.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/PyTableCode.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -32,17 +32,19 @@ final public static int CO_GENERATOR = 0x0020; // these are defined in __future__.py - final public static int CO_NESTED = 0x0010; - final public static int CO_GENERATOR_ALLOWED = 0x0; - final public static int CO_FUTUREDIVISION = 0x2000; + final public static int CO_NESTED = 0x0010; + final public static int CO_GENERATOR_ALLOWED = 0x0; + final public static int CO_FUTUREDIVISION = 0x2000; final public static int CO_FUTURE_ABSOLUTE_IMPORT = 0x4000; - final public static int CO_WITH_STATEMENT = 0x8000; + final public static int CO_WITH_STATEMENT = 0x8000; //XXX: I'm not positive that this is the right place for these constants. + final public static int PyCF_SOURCE_IS_UTF8 = 0x0100; final public static int PyCF_DONT_IMPLY_DEDENT = 0x0200; final public static int PyCF_ONLY_AST = 0x0400; - final public static int CO_ALL_FEATURES = PyCF_DONT_IMPLY_DEDENT|PyCF_ONLY_AST|CO_NESTED| + final public static int CO_ALL_FEATURES = PyCF_DONT_IMPLY_DEDENT|PyCF_ONLY_AST| + PyCF_SOURCE_IS_UTF8|CO_NESTED| CO_GENERATOR_ALLOWED| CO_FUTUREDIVISION| CO_FUTURE_ABSOLUTE_IMPORT|CO_WITH_STATEMENT; Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-12 17:17:12 UTC (rev 5156) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-12 18:11:38 UTC (rev 5157) @@ -276,6 +276,9 @@ dont_inherit = Py.py2boolean(args[4]); } + if (args[0] instanceof PyUnicode) { + flags += PyTableCode.PyCF_SOURCE_IS_UTF8; + } return __builtin__.compile(args[0].toString(), args[1].toString(), args[2].toString(), flags, dont_inherit); case 29: return __builtin__.map(args); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-12 17:17:15
|
Revision: 5156 http://jython.svn.sourceforge.net/jython/?rev=5156&view=rev Author: fwierzbicki Date: 2008-08-12 17:17:12 +0000 (Tue, 12 Aug 2008) Log Message: ----------- Implement BOM handling as much as CPython 2.5 does. Altered bad_coding2.py because Java, unlike CPython accepts "utf8" as a synonymn for "utf-8" Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java Added Paths: ----------- branches/asm/Lib/test/bad_coding2.py Added: branches/asm/Lib/test/bad_coding2.py =================================================================== --- branches/asm/Lib/test/bad_coding2.py (rev 0) +++ branches/asm/Lib/test/bad_coding2.py 2008-08-12 17:17:12 UTC (rev 5156) @@ -0,0 +1,5 @@ +#coding: uft8 +print '我' + +#Changed for Jython because the original "coding: utf8" is supposed to be a +#misspelling, but Java accepts this spelling for an encoding. Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-11 23:27:27 UTC (rev 5155) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-12 17:17:12 UTC (rev 5156) @@ -39,6 +39,8 @@ public class ParserFacade { + private static int MARK_LIMIT = 100000; + private ParserFacade() {} static String getLine(BufferedReader reader, int line) { @@ -192,12 +194,18 @@ private static BufferedReader prepBufreader(InputStream istream, CompilerFlags cflags, String filename) throws IOException { + boolean bom = false; + String encoding = null; InputStream bstream = new BufferedInputStream(istream); - String encoding = readEncoding(bstream); - if(encoding == null && cflags != null && cflags.encoding != null) { - encoding = cflags.encoding; + bom = adjustForBOM(bstream); + encoding = readEncoding(bstream); + if(encoding == null) { + if (bom) { + encoding = "UTF-8"; + } else if (cflags != null && cflags.encoding != null) { + encoding = cflags.encoding; + } } - // Enable universal newlines mode on the input StreamIO rawIO = new StreamIO(bstream, true); org.python.core.io.BufferedReader bufferedIO = @@ -224,13 +232,40 @@ BufferedReader bufreader = new BufferedReader(reader); - bufreader.mark(100000); + bufreader.mark(MARK_LIMIT); return bufreader; } + /** + * Check for a BOM mark at the begginning of stream. If there is a BOM + * mark, advance the stream passed it. If not, reset() to start at the + * beginning of the stream again. + * + * Only checks for EF BB BF right now, since that is all that CPython 2.5 + * Checks. + * + * @return true if a BOM was found and skipped. + * @throws ParseException if only part of a BOM is matched. + * + */ + private static boolean adjustForBOM(InputStream stream) throws IOException { + stream.mark(3); + int ch = stream.read(); + if (ch == 0xEF) { + if (stream.read() != 0xBB) { + throw new ParseException("Incomplete BOM at beginning of file"); + } + if (stream.read() != 0xBF) { + throw new ParseException("Incomplete BOM at beginning of file"); + } + return true; + } + stream.reset(); + return false; + } private static String readEncoding(InputStream stream) throws IOException { - stream.mark(100000); + stream.mark(MARK_LIMIT); String encoding = null; BufferedReader br = new BufferedReader(new InputStreamReader(stream), 512); for (int i = 0; i < 2; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-11 23:27:44
|
Revision: 5155 http://jython.svn.sourceforge.net/jython/?rev=5155&view=rev Author: leosoto Date: 2008-08-11 23:27:27 +0000 (Mon, 11 Aug 2008) Log Message: ----------- __findattr__ refactor. The overridable version is not called __findattr_ex__ (in the abscense of a better name), and can return null or raise AttributeError, whatever is more efficient for the implementing code. This makes *Derived getattr() more correct and fixes #1041 and #1095. Modified Paths: -------------- branches/asm/Lib/test/test_descr_jy.py branches/asm/src/com/ziclix/python/sql/PyConnection.java branches/asm/src/com/ziclix/python/sql/PyCursor.java branches/asm/src/com/ziclix/python/sql/PyExtendedCursor.java branches/asm/src/com/ziclix/python/sql/PyStatement.java branches/asm/src/com/ziclix/python/sql/connect/Connect.java branches/asm/src/com/ziclix/python/sql/connect/Connectx.java branches/asm/src/com/ziclix/python/sql/connect/Lookup.java branches/asm/src/com/ziclix/python/sql/util/BCP.java branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBaseException.java branches/asm/src/org/python/core/PyBaseExceptionDerived.java branches/asm/src/org/python/core/PyBooleanDerived.java branches/asm/src/org/python/core/PyClass.java branches/asm/src/org/python/core/PyClassMethodDerived.java branches/asm/src/org/python/core/PyComplexDerived.java branches/asm/src/org/python/core/PyDictionaryDerived.java branches/asm/src/org/python/core/PyEnumerateDerived.java branches/asm/src/org/python/core/PyFileDerived.java branches/asm/src/org/python/core/PyFloatDerived.java branches/asm/src/org/python/core/PyFrame.java branches/asm/src/org/python/core/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyInstance.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyJavaClass.java branches/asm/src/org/python/core/PyJavaPackage.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyMethod.java branches/asm/src/org/python/core/PyModule.java branches/asm/src/org/python/core/PyModuleDerived.java branches/asm/src/org/python/core/PyObject.java branches/asm/src/org/python/core/PyObjectDerived.java branches/asm/src/org/python/core/PyPropertyDerived.java branches/asm/src/org/python/core/PySetDerived.java branches/asm/src/org/python/core/PySliceDerived.java branches/asm/src/org/python/core/PyStringDerived.java branches/asm/src/org/python/core/PySuper.java branches/asm/src/org/python/core/PySuperDerived.java branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/PyTableCode.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyType.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.java branches/asm/src/org/python/modules/_csv/PyDialectDerived.java branches/asm/src/org/python/modules/_functools/PyPartialDerived.java branches/asm/src/org/python/modules/_weakref/ProxyType.java branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java branches/asm/src/org/python/modules/collections/PyDequeDerived.java branches/asm/src/org/python/modules/random/PyRandomDerived.java branches/asm/src/org/python/modules/sre/MatchObject.java branches/asm/src/org/python/modules/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java branches/asm/src/templates/object.derived Modified: branches/asm/Lib/test/test_descr_jy.py =================================================================== --- branches/asm/Lib/test/test_descr_jy.py 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/Lib/test/test_descr_jy.py 2008-08-11 23:27:27 UTC (rev 5155) @@ -73,6 +73,29 @@ else: self.assert_(False, "should have raised TypeError") + def test_raising_custom_attribute_error(self): + class RaisesCustomMsg(object): + def __get__(self, instance, type): + raise AttributeError("Custom message") + + + class CustomAttributeError(AttributeError): pass + + class RaisesCustomErr(object): + def __get__(self, instance, type): + raise CustomAttributeError + + class Foo(object): + custom_msg = RaisesCustomMsg() + custom_err = RaisesCustomErr() + + self.assertRaises(CustomAttributeError, lambda: Foo().custom_err) + try: + Foo().custom_msg + self.assert_(False) # Previous line should raise AttributteError + except AttributeError, e: + self.assertEquals("Custom message", str(e)) + class SubclassDescrTestCase(unittest.TestCase): def test_subclass_cmp_right_op(self): @@ -144,7 +167,7 @@ # Test strs, unicode, lists and tuples mapping = [] - + # + binop mapping.append((lambda o: 'foo' + o, TypeError, "cannot concatenate 'str' and 'B' objects", @@ -293,12 +316,32 @@ self.assertRaises(AttributeError, func, old) self.assertRaises(TypeError, func, new) +class GetAttrTestCase(unittest.TestCase): + def test_raising_custom_attribute_error(self): + # Very similar to + # test_descr_jy.TestDescrTestCase.test_raising_custom_attribute_error + class BarAttributeError(AttributeError): pass + class Bar(object): + def __getattr__(self, name): + raise BarAttributeError + + class Foo(object): + def __getattr__(self, name): + raise AttributeError("Custom message") + self.assertRaises(BarAttributeError, lambda: Bar().x) + try: + Foo().x + self.assert_(False) # Previous line should raise AttributteError + except AttributeError, e: + self.assertEquals("Custom message", str(e)) + def test_main(): test_support.run_unittest(TestDescrTestCase, SubclassDescrTestCase, InPlaceTestCase, - DescrExceptionsTestCase) + DescrExceptionsTestCase, + GetAttrTestCase) if __name__ == '__main__': test_main() Modified: branches/asm/src/com/ziclix/python/sql/PyConnection.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/PyConnection.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/PyConnection.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -178,7 +178,7 @@ * @param name the name of the attribute of interest * @return the value for the attribute of the specified name */ - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if ("autocommit".equals(name)) { try { @@ -230,7 +230,7 @@ return Py.newBoolean(closed); } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/PyCursor.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/PyCursor.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/PyCursor.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -196,7 +196,7 @@ * @param name * @return the attribute for the given name */ - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if ("arraysize".equals(name)) { return Py.newInteger(arraysize); @@ -236,7 +236,7 @@ } catch (Throwable t) {} } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/PyExtendedCursor.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/PyExtendedCursor.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/PyExtendedCursor.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -131,7 +131,7 @@ * @param name the name of the attribute of interest * @return the value for the attribute of the specified name */ - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if ("__methods__".equals(name)) { return __methods__; @@ -139,7 +139,7 @@ return __members__; } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/PyStatement.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/PyStatement.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/PyStatement.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -161,7 +161,7 @@ * @param name * @return the attribute for the given name */ - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if ("style".equals(name)) { return Py.newInteger(style); @@ -175,7 +175,7 @@ return __members__; } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/connect/Connect.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/connect/Connect.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/connect/Connect.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -32,19 +32,11 @@ public Connect() { } - /** - * Method __findattr__ - * - * @param String name - * @return PyObject - */ - public PyObject __findattr__(String name) { - + public PyObject __findattr_ex__(String name) { if ("__doc__".equals(name)) { return _doc; } - - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/connect/Connectx.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/connect/Connectx.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/connect/Connectx.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -43,19 +43,11 @@ public Connectx() { } - /** - * Method __findattr__ - * - * @param String name - * @return PyObject - */ - public PyObject __findattr__(String name) { - + public PyObject __findattr_ex__(String name) { if ("__doc__".equals(name)) { return doc; } - - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/connect/Lookup.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/connect/Lookup.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/connect/Lookup.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -44,13 +44,13 @@ * @param name * @return PyObject */ - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if ("__doc__".equals(name)) { return _doc; } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/com/ziclix/python/sql/util/BCP.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/util/BCP.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/com/ziclix/python/sql/util/BCP.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -128,7 +128,7 @@ * @param name * @return the attribute for the given name */ - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if ("destinationDataHandler".equals(name)) { return Py.java2py(this.destDH); @@ -140,7 +140,7 @@ return Py.newInteger(this.queuesize); } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyBaseException.java =================================================================== --- branches/asm/src/org/python/core/PyBaseException.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyBaseException.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -101,7 +101,7 @@ return Py.None; } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { return BaseException___findattr__(name); } @@ -113,7 +113,7 @@ } } - return super.__findattr__(name); + return super.__findattr_ex__(name); } public void __setattr__(String name, PyObject value) { Modified: branches/asm/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -948,30 +948,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyClass.java =================================================================== --- branches/asm/src/org/python/core/PyClass.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyClass.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -228,7 +228,7 @@ return result[0]; } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if (name == "__dict__") { return __dict__; } @@ -245,7 +245,7 @@ PyObject[] result = lookupGivingClass(name, false); if (result[0] == null) { - return super.__findattr__(name); + return super.__findattr_ex__(name); } // xxx do we need to use result[1] (wherefound) for java cases for backw // comp? Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyFrame.java =================================================================== --- branches/asm/src/org/python/core/PyFrame.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyFrame.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -168,7 +168,7 @@ // f_exc_traceback } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if (name == "f_locals") { return getLocals(); } else if (name == "f_trace") { @@ -177,7 +177,7 @@ } return Py.None; } - return super.__findattr__(name); + return super.__findattr_ex__(name); } /** Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyInstance.java =================================================================== --- branches/asm/src/org/python/core/PyInstance.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyInstance.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -200,7 +200,7 @@ return __findattr__(name, true); } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { return __findattr__(name, false); } Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyJavaClass.java =================================================================== --- branches/asm/src/org/python/core/PyJavaClass.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyJavaClass.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -753,7 +753,7 @@ } private PyStringMap missingAttributes = null; - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { if (name == "__dict__") { if (__dict__ == null) initialize(); Modified: branches/asm/src/org/python/core/PyJavaPackage.java =================================================================== --- branches/asm/src/org/python/core/PyJavaPackage.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyJavaPackage.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -132,7 +132,7 @@ } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyObject ret = __dict__.__finditem__(name); if (ret != null) return ret; Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -972,30 +972,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyMethod.java =================================================================== --- branches/asm/src/org/python/core/PyMethod.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyMethod.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -55,13 +55,27 @@ } @Override - public PyObject __findattr__(String name) { - PyObject ret = super.__findattr__(name); + public PyObject __findattr_ex__(String name) { + return instancemethod___findattr_ex__(name); + } + + final PyObject instancemethod___findattr_ex__(String name) { + PyObject ret = super.__findattr_ex__(name); if (ret != null) { return ret; } - return im_func.__findattr__(name); + return im_func.__findattr_ex__(name); } + + @ExposedMethod + final PyObject instancemethod___getattribute__(PyObject arg0) { + String name = asName(arg0); + PyObject ret = instancemethod___findattr_ex__(name); + if (ret == null) { + noAttributeError(name); + } + return ret; + } @Override public PyObject __get__(PyObject obj, PyObject type) { Modified: branches/asm/src/org/python/core/PyModule.java =================================================================== --- branches/asm/src/org/python/core/PyModule.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyModule.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -128,21 +128,6 @@ return null; } - public PyObject __findattr__(String name) { - return module___findattr__(name); - } - - final PyObject module___findattr__(String name) { - if (__dict__ != null) { - PyObject attr = __dict__.__finditem__(name); - if (attr != null) { - return attr; - } - } - - return super.__findattr__(name); - } - public void __setattr__(String name, PyObject value) { module___setattr__(name, value); } Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -948,30 +948,44 @@ } } - public PyObject __findattr__(String name) { + public PyObject __findattr_ex__(String name) { PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. PyObject getattribute=self_type.lookup("__getattribute__"); PyString py_name=null; + PyException firstAttributeError=null; try { if (getattribute!=null) { - return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); } else { - return super.__findattr__(name); + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation } } 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; + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. } - throw e; } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; } public void __setattr__(String name,PyObject value) { Modified: branches/asm/src/org/python/core/PyObject.java =================================================================== --- branches/asm/src/org/python/core/PyObject.java 2008-08-11 22:24:20 UTC (rev 5154) +++ branches/asm/src/org/python/core/PyObject.java 2008-08-11 23:27:27 UTC (rev 5155) @@ -734,12 +734,8 @@ * <code>__findattr__(name.internedString)</code> with the appropriate * args. * - * Classes that wish to implement __getattr__ should override this method - * instead (with the appropriate semantics. + * @param name the name to lookup in this namespace * - * @param name - * the name to lookup in this namespace - * * @return the value corresponding to name or null if name is not found */ public final PyObject __findattr__(PyString name) { @@ -758,36 +754,58 @@ * @param name the name to lookup in this namespace * <b> must be an interned string </b>. * @return the value corresponding to name or null if name is not found - * - * @see #__findattr__(PyString) **/ - public PyObject __findattr__(String name) { + public final PyObject __findattr__(String name) { + try { + return __findattr_ex__(name); + } catch (PyException exc) { + if (Py.matchException(exc, Py.AttributeError)) { + return null; + } + throw exc; + } + } + + /** + * Attribute lookup hook. If the attribute is not found, null may be + * returned or a Py.AttributeError can be thrown, whatever is more + * correct, efficient and/or convenient for the implementing cl... [truncated message content] |
From: <pj...@us...> - 2008-08-11 22:24:26
|
Revision: 5154 http://jython.svn.sourceforge.net/jython/?rev=5154&view=rev Author: pjenvey Date: 2008-08-11 22:24:20 +0000 (Mon, 11 Aug 2008) Log Message: ----------- make the stepless slice ops more consistent with the compiler by passing null for step instead of Py.One, fixes test_operator.test_setslice Modified Paths: -------------- branches/asm/src/org/python/core/PyObject.java Modified: branches/asm/src/org/python/core/PyObject.java =================================================================== --- branches/asm/src/org/python/core/PyObject.java 2008-08-11 19:48:31 UTC (rev 5153) +++ branches/asm/src/org/python/core/PyObject.java 2008-08-11 22:24:20 UTC (rev 5154) @@ -629,15 +629,15 @@ } public PyObject __getslice__(PyObject start, PyObject stop) { - return __getslice__(start, stop, Py.One); + return __getslice__(start, stop, null); } public void __setslice__(PyObject start, PyObject stop, PyObject value) { - __setslice__(start, stop, Py.One, value); + __setslice__(start, stop, null, value); } public void __delslice__(PyObject start, PyObject stop) { - __delslice__(start, stop, Py.One); + __delslice__(start, stop, null); } /*The basic functions to implement an iterator */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-11 19:48:38
|
Revision: 5153 http://jython.svn.sourceforge.net/jython/?rev=5153&view=rev Author: fwierzbicki Date: 2008-08-11 19:48:31 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Moved buffered stream creation from many places to one place. Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-11 19:25:46 UTC (rev 5152) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-11 19:48:31 UTC (rev 5153) @@ -96,22 +96,21 @@ String kind, String filename, CompilerFlags cflags) { - BufferedInputStream bstream = new BufferedInputStream(stream); //FIXME: npe? BufferedReader bufreader = null; modType node = null; try { if (kind.equals("eval")) { - bufreader = prepBufreader(bstream, cflags, filename); + bufreader = prepBufreader(stream, cflags, filename); CharStream cs = new NoCloseReaderStream(bufreader); ExpressionParser e = new ExpressionParser(cs, filename); node = e.parse(); } else if (kind.equals("single")) { - bufreader = prepBufreader(bstream, cflags, filename); + bufreader = prepBufreader(stream, cflags, filename); InteractiveParser i = new InteractiveParser(bufreader, filename); node = i.parse(); } else if (kind.equals("exec")) { - bufreader = prepBufreader(bstream, cflags, filename); + bufreader = prepBufreader(stream, cflags, filename); CharStream cs = new NoCloseReaderStream(bufreader); ModuleParser g = new ModuleParser(cs, filename); node = g.file_input(); @@ -137,19 +136,18 @@ String filename, CompilerFlags cflags, boolean stdprompt) { - ByteArrayInputStream bi = new ByteArrayInputStream( + ByteArrayInputStream istream = new ByteArrayInputStream( StringUtil.toBytes(string)); - BufferedInputStream bstream = bstream = new BufferedInputStream(bi); //FIXME: npe? BufferedReader bufreader = null; modType node = null; try { if (kind.equals("single")) { - bufreader = prepBufreader(bstream, cflags, filename); + bufreader = prepBufreader(istream, cflags, filename); InteractiveParser i = new InteractiveParser(bufreader, filename); node = i.parse(); } else if (kind.equals("eval")) { - bufreader = prepBufreader(bstream, cflags, filename); + bufreader = prepBufreader(istream, cflags, filename); CharStream cs = new NoCloseReaderStream(bufreader); ExpressionParser e = new ExpressionParser(cs, filename); node = e.parse(); @@ -194,29 +192,30 @@ private static BufferedReader prepBufreader(InputStream istream, CompilerFlags cflags, String filename) throws IOException { - String encoding = readEncoding(istream); + InputStream bstream = new BufferedInputStream(istream); + String encoding = readEncoding(bstream); if(encoding == null && cflags != null && cflags.encoding != null) { encoding = cflags.encoding; } // Enable universal newlines mode on the input - StreamIO rawIO = new StreamIO(istream, true); + StreamIO rawIO = new StreamIO(bstream, true); org.python.core.io.BufferedReader bufferedIO = new org.python.core.io.BufferedReader(rawIO, 0); UniversalIOWrapper textIO = new UniversalIOWrapper(bufferedIO); - istream = new TextIOInputStream(textIO); + bstream = new TextIOInputStream(textIO); Reader reader; if(encoding != null) { try { - reader = new InputStreamReader(istream, encoding); + reader = new InputStreamReader(bstream, encoding); } catch(UnsupportedEncodingException exc) { throw new PySyntaxError("Encoding '" + encoding + "' isn't supported by this JVM.", 0, 0, "", filename); } } else { try { // Default to ISO-8859-1 to get bytes off the input stream since it leaves their values alone. - reader = new InputStreamReader(istream, "ISO-8859-1"); + reader = new InputStreamReader(bstream, "ISO-8859-1"); } catch(UnsupportedEncodingException e) { // This JVM is whacked, it doesn't even have iso-8859-1 throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-11 19:25:58
|
Revision: 5152 http://jython.svn.sourceforge.net/jython/?rev=5152&view=rev Author: fwierzbicki Date: 2008-08-11 19:25:46 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Tightened up eval and uncommented tests in test_jy_compile. Modified Paths: -------------- branches/asm/Lib/test/test_jy_compile.py branches/asm/grammar/Python.g branches/asm/grammar/PythonPartial.g Modified: branches/asm/Lib/test/test_jy_compile.py =================================================================== --- branches/asm/Lib/test/test_jy_compile.py 2008-08-11 18:31:41 UTC (rev 5151) +++ branches/asm/Lib/test/test_jy_compile.py 2008-08-11 19:25:46 UTC (rev 5152) @@ -148,13 +148,10 @@ ai("a = 'a\\ ") ai("a = 'a\\\n") - #XXX: eval is hopelessly permissive right now -- but the rest of this - # test_jy_compile is really important to me for flagging new bugs - - # so commenting out some of these for now. - ###ai("a = 1","eval") - ###ai("a = (","eval") + ai("a = 1","eval") + ai("a = (","eval") ai("]","eval") - ###ai("())","eval") + ai("())","eval") ai("[}","eval") ai("9+","eval") ai("lambda z:","eval") Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-11 18:31:41 UTC (rev 5151) +++ branches/asm/grammar/Python.g 2008-08-11 19:25:46 UTC (rev 5152) @@ -298,7 +298,7 @@ ; //eval_input: testlist NEWLINE* ENDMARKER -eval_input : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* -> ^(Expression testlist) +eval_input : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* EOF -> ^(Expression testlist) ; //not in CPython's Grammar file Modified: branches/asm/grammar/PythonPartial.g =================================================================== --- branches/asm/grammar/PythonPartial.g 2008-08-11 18:31:41 UTC (rev 5151) +++ branches/asm/grammar/PythonPartial.g 2008-08-11 19:25:46 UTC (rev 5152) @@ -193,7 +193,7 @@ ; //eval_input: testlist NEWLINE* ENDMARKER -eval_input : (NEWLINE)* testlist? (NEWLINE)* +eval_input : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* ENDMARKER ; decorators: decorator+ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-11 18:31:54
|
Revision: 5151 http://jython.svn.sourceforge.net/jython/?rev=5151&view=rev Author: fwierzbicki Date: 2008-08-11 18:31:41 +0000 (Mon, 11 Aug 2008) Log Message: ----------- remove LeadingSpaceSkippingStream and replace with LEADING_WS in Python.g. No idea what I was thinking with LeadingSpaceSkippingStream... Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/core/ParserFacade.java Removed Paths: ------------- branches/asm/src/org/python/antlr/LeadingSpaceSkippingStream.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-11 16:43:44 UTC (rev 5150) +++ branches/asm/grammar/Python.g 2008-08-11 18:31:41 UTC (rev 5151) @@ -298,7 +298,7 @@ ; //eval_input: testlist NEWLINE* ENDMARKER -eval_input : (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* -> ^(Expression testlist) +eval_input : LEADING_WS? (NEWLINE)* testlist[expr_contextType.Load] (NEWLINE)* -> ^(Expression testlist) ; //not in CPython's Grammar file Deleted: branches/asm/src/org/python/antlr/LeadingSpaceSkippingStream.java =================================================================== --- branches/asm/src/org/python/antlr/LeadingSpaceSkippingStream.java 2008-08-11 16:43:44 UTC (rev 5150) +++ branches/asm/src/org/python/antlr/LeadingSpaceSkippingStream.java 2008-08-11 18:31:41 UTC (rev 5151) @@ -1,39 +0,0 @@ -package org.python.antlr; - -import java.io.InputStream; -import java.io.IOException; - -public class LeadingSpaceSkippingStream extends InputStream { - - private InputStream inputStream; - private boolean maybeLeadingSpaces = true; - - public LeadingSpaceSkippingStream(InputStream is) { - inputStream = is; - } - - public int read() throws IOException { - int i = inputStream.read(); - while (maybeLeadingSpaces) { - if (i != ' ') { - maybeLeadingSpaces = false; - } else { - i = inputStream.read(); - } - } - return i; - } - - public boolean markSupported() { - return inputStream.markSupported(); - } - - public void mark(int readAheadLimit) { - inputStream.mark(readAheadLimit); - } - - public void reset() throws IOException { - maybeLeadingSpaces = true; - inputStream.reset(); - } -} Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-11 16:43:44 UTC (rev 5150) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-11 18:31:41 UTC (rev 5151) @@ -18,7 +18,6 @@ import org.python.antlr.ExpressionParser; import org.python.antlr.InteractiveParser; -import org.python.antlr.LeadingSpaceSkippingStream; import org.python.antlr.ParseException; import org.python.antlr.ModuleParser; import org.python.antlr.NoCloseReaderStream; @@ -103,7 +102,7 @@ modType node = null; try { if (kind.equals("eval")) { - bufreader = prepBufreader(new LeadingSpaceSkippingStream(bstream), cflags, filename); + bufreader = prepBufreader(bstream, cflags, filename); CharStream cs = new NoCloseReaderStream(bufreader); ExpressionParser e = new ExpressionParser(cs, filename); node = e.parse(); @@ -117,7 +116,7 @@ ModuleParser g = new ModuleParser(cs, filename); node = g.file_input(); } else { - throw Py.ValueError("parse kind must be eval, exec, " + "or single"); + throw Py.ValueError("parse kind must be eval, exec, or single"); } } catch (Throwable t) { throw fixParseError(bufreader, t, filename); @@ -150,12 +149,12 @@ InteractiveParser i = new InteractiveParser(bufreader, filename); node = i.parse(); } else if (kind.equals("eval")) { - bufreader = prepBufreader(new LeadingSpaceSkippingStream(bstream), cflags, filename); + bufreader = prepBufreader(bstream, cflags, filename); CharStream cs = new NoCloseReaderStream(bufreader); ExpressionParser e = new ExpressionParser(cs, filename); node = e.parse(); } else { - throw Py.ValueError("parse kind must be eval, exec, " + "or single"); + throw Py.ValueError("parse kind must be eval, exec, or single"); } } catch (Throwable t) { PyException p = fixParseError(bufreader, t, filename); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-11 16:43:51
|
Revision: 5150 http://jython.svn.sourceforge.net/jython/?rev=5150&view=rev Author: fwierzbicki Date: 2008-08-11 16:43:44 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Added 3 arg and 4 arg __call__ Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-11 12:44:54 UTC (rev 5149) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-11 16:43:44 UTC (rev 5150) @@ -1444,6 +1444,19 @@ visit(values[1]); code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); break; + case 3: + visit(values[0]); + visit(values[1]); + visit(values[2]); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + break; + case 4: + visit(values[0]); + visit(values[1]); + visit(values[2]); + visit(values[3]); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")" + $pyObj); + break; default: makeArray(values); code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-11 12:45:01
|
Revision: 5149 http://jython.svn.sourceforge.net/jython/?rev=5149&view=rev Author: fwierzbicki Date: 2008-08-11 12:44:54 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Switch to for-each syntax in walker. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-11 07:03:25 UTC (rev 5148) +++ branches/asm/grammar/Python.g 2008-08-11 12:44:54 UTC (rev 5149) @@ -178,7 +178,6 @@ import org.python.core.PyUnicode; import java.math.BigInteger; -import java.util.Iterator; } @members { Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-11 07:03:25 UTC (rev 5148) +++ branches/asm/grammar/PythonWalker.g 2008-08-11 12:44:54 UTC (rev 5149) @@ -987,10 +987,8 @@ boolean extslice = false; if ($subscriptlist.isTuple) { sliceType[] st; - Iterator iter = sltypes.iterator(); List etypes = new ArrayList(); - while (iter.hasNext()) { - Object o = iter.next(); + for (Object o : sltypes) { if (o instanceof Index) { Index i = (Index)o; etypes.add(i.value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-11 07:03:28
|
Revision: 5148 http://jython.svn.sourceforge.net/jython/?rev=5148&view=rev Author: pjenvey Date: 2008-08-11 07:03:25 +0000 (Mon, 11 Aug 2008) Log Message: ----------- cleanup/coding standards Modified Paths: -------------- branches/asm/src/org/python/core/PySlice.java Modified: branches/asm/src/org/python/core/PySlice.java =================================================================== --- branches/asm/src/org/python/core/PySlice.java 2008-08-11 06:59:28 UTC (rev 5147) +++ branches/asm/src/org/python/core/PySlice.java 2008-08-11 07:03:25 UTC (rev 5148) @@ -7,103 +7,98 @@ import org.python.expose.ExposedType; /** - * A python slice object. + * The Python slice object. */ - @ExposedType(name = "slice") public class PySlice extends PyObject { - + public static final PyType TYPE = PyType.fromClass(PySlice.class); - + + @ExposedGet + public PyObject start = Py.None; + + @ExposedGet + public PyObject stop = Py.None; + + @ExposedGet + public PyObject step = Py.None; + + public PySlice() { + this(TYPE); + } + + public PySlice(PyType type) { + super(type); + } + + public PySlice(PyObject start, PyObject stop, PyObject step) { + this(TYPE); + if (start != null) { + this.start = start; + } + if (stop != null) { + this.stop = stop; + } + if (step != null) { + this.step = step; + } + } + @ExposedNew @ExposedMethod final void slice___init__(PyObject[] args, String[] keywords) { - if(args.length == 0) { + if (args.length == 0) { throw Py.TypeError("slice expected at least 1 arguments, got " + args.length); - } else if(args.length > 3) { + } else if (args.length > 3) { throw Py.TypeError("slice expected at most 3 arguments, got " + args.length); } ArgParser ap = new ArgParser("slice", args, keywords, "start", "stop", "step"); - if(args.length == 1) { + if (args.length == 1) { stop = ap.getPyObject(0); - } else if(args.length == 2) { + } else if (args.length == 2) { start = ap.getPyObject(0); stop = ap.getPyObject(1); - } else if(args.length == 3) { + } else if (args.length == 3) { start = ap.getPyObject(0); stop = ap.getPyObject(1); step = ap.getPyObject(2); } } - public PySlice(PyObject start, PyObject stop, PyObject step) { - this(TYPE); - if(start != null) { - this.start = start; - } - if(stop != null) { - this.stop = stop; - } - if(step != null) { - this.step = step; - } - } - - public PySlice(PyType type) { - super(type); - } - - public PySlice() { - this(TYPE); - } - - public final PyObject getStart() { - return start; - } - - public final PyObject getStop() { - return stop; - } - - public final PyObject getStep() { - return step; - } - - public int hashCode() { + public int hashCode() { return slice___hash__(); } @ExposedMethod final int slice___hash__() { throw Py.TypeError("unhashable type"); - } + } public PyString __str__() { - return new PyString(getStart().__repr__() + ":" + getStop().__repr__() + ":" + - getStep().__repr__()); + return new PyString(getStart().__repr__() + ":" + getStop().__repr__() + ":" + + getStep().__repr__()); } public PyString __repr__() { - return new PyString("slice(" + getStart().__repr__() + ", " + - getStop().__repr__() + ", " + - getStep().__repr__() + ")"); + return new PyString("slice(" + getStart().__repr__() + ", " + getStop().__repr__() + ", " + + getStep().__repr__() + ")"); } public PyObject __eq__(PyObject o) { - if(getType() != o.getType() && !(getType().isSubType(o.getType()))) { + if (getType() != o.getType() && !(getType().isSubType(o.getType()))) { return null; } - if(this == o) { + if (this == o) { return Py.True; } PySlice oSlice = (PySlice)o; - if(eq(getStart(), oSlice.getStart()) && eq(getStop(), oSlice.getStop()) - && eq(getStep(), oSlice.getStep())) { + if (eq(getStart(), oSlice.getStart()) && eq(getStop(), oSlice.getStop()) + && eq(getStep(), oSlice.getStep())) { return Py.True; } return Py.False; } - + private static final boolean eq(PyObject o1, PyObject o2) { return o1._cmp(o2) == 0; } @@ -111,25 +106,22 @@ public PyObject __ne__(PyObject o) { return __eq__(o).__not__(); } - + + public PyObject indices(PyObject len) { + return slice_indices(len); + } + @ExposedMethod - public PyObject slice_indices(PyObject len) { + final PyObject slice_indices(PyObject len) { int[] indices = indicesEx(len.asIndex(Py.OverflowError)); return new PyTuple(Py.newInteger(indices[0]), Py.newInteger(indices[1]), Py.newInteger(indices[2])); } - public static int calculateSliceIndex(PyObject v) { - if (v.isIndex()) { - return v.asIndex(); - } - throw Py.TypeError("slice indices must be integers or None or have an __index__ method"); - } - /** * Calculates the actual indices of a slice with this slice's start, stop, step and * slicelength values for a sequence of length <code>len</code>. - * + * * @return an array with the start at index 0, stop at index 1, step at index 2 and * slicelength at index 3 */ @@ -222,12 +214,22 @@ return indices; } - @ExposedGet - public PyObject start = Py.None; + public static int calculateSliceIndex(PyObject v) { + if (v.isIndex()) { + return v.asIndex(); + } + throw Py.TypeError("slice indices must be integers or None or have an __index__ method"); + } - @ExposedGet - public PyObject stop = Py.None; + public final PyObject getStart() { + return start; + } - @ExposedGet - public PyObject step = Py.None; + public final PyObject getStop() { + return stop; + } + + public final PyObject getStep() { + return step; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-11 06:59:31
|
Revision: 5147 http://jython.svn.sourceforge.net/jython/?rev=5147&view=rev Author: pjenvey Date: 2008-08-11 06:59:28 +0000 (Mon, 11 Aug 2008) Log Message: ----------- o change PySlice.indices to work like CPython's PySlice_GetIndicesEx (include a slicelength value) o reject PySequence slice assignments with a step and mismatching slicelengths Modified Paths: -------------- branches/asm/src/org/python/core/PySequence.java branches/asm/src/org/python/core/PySlice.java Modified: branches/asm/src/org/python/core/PySequence.java =================================================================== --- branches/asm/src/org/python/core/PySequence.java 2008-08-11 05:52:43 UTC (rev 5146) +++ branches/asm/src/org/python/core/PySequence.java 2008-08-11 06:59:28 UTC (rev 5147) @@ -327,8 +327,8 @@ } final synchronized PyObject seq___getslice__(PyObject start, PyObject stop, PyObject step) { - int[] slice = new PySlice(start, stop, step).indices(__len__()); - return getslice(slice[0], slice[1], slice[2]); + int[] indices = new PySlice(start, stop, step).indicesEx(__len__()); + return getslice(indices[0], indices[1], indices[2]); } public synchronized void __setslice__(PyObject start, @@ -346,8 +346,13 @@ PyObject stop, PyObject step, PyObject value) { - int[] slice = new PySlice(start, stop, step).indices(__len__()); - setslice(slice[0], slice[1], slice[2], value); + PySlice slice = new PySlice(start, stop, step); + int[] indices = slice.indicesEx(__len__()); + if ((slice.step != Py.None) && value.__len__() != indices[3]) { + throw Py.ValueError(String.format("attempt to assign sequence of size %d to extended " + + "slice of size %d", value.__len__(), indices[3])); + } + setslice(indices[0], indices[1], indices[2], value); } public synchronized void __delslice__(PyObject start, PyObject stop, PyObject step) { @@ -355,8 +360,8 @@ } final synchronized void seq___delslice__(PyObject start, PyObject stop, PyObject step) { - int[] slice = new PySlice(start, stop, step).indices(__len__()); - delRange(slice[0], slice[1], slice[2]); + int[] indices = new PySlice(start, stop, step).indicesEx(__len__()); + delRange(indices[0], indices[1], indices[2]); } public synchronized void __setitem__(int index, PyObject value) { Modified: branches/asm/src/org/python/core/PySlice.java =================================================================== --- branches/asm/src/org/python/core/PySlice.java 2008-08-11 05:52:43 UTC (rev 5146) +++ branches/asm/src/org/python/core/PySlice.java 2008-08-11 06:59:28 UTC (rev 5147) @@ -114,12 +114,9 @@ @ExposedMethod public PyObject slice_indices(PyObject len) { - int[] slice = indices(len.asIndex(Py.OverflowError)); - PyInteger[] pyInts = new PyInteger[slice.length]; - for(int i = 0; i < pyInts.length; i++) { - pyInts[i] = Py.newInteger(slice[i]); - } - return new PyTuple(pyInts); + int[] indices = indicesEx(len.asIndex(Py.OverflowError)); + return new PyTuple(Py.newInteger(indices[0]), Py.newInteger(indices[1]), + Py.newInteger(indices[2])); } public static int calculateSliceIndex(PyObject v) { @@ -130,52 +127,66 @@ } /** - * Calculates the actual indices of a slice with this slice's start, stop - * and step values for a sequence of length <code>len</code>. + * Calculates the actual indices of a slice with this slice's start, stop, step and + * slicelength values for a sequence of length <code>len</code>. * - * @return an array with the start at index 0, stop at index 1 and step and - * index 2. + * @return an array with the start at index 0, stop at index 1, step at index 2 and + * slicelength at index 3 */ - public int[] indices(int len) { - int[] slice = new int[3]; + public int[] indicesEx(int len) { + int start; + int stop; + int step; + int slicelength; + if (getStep() == Py.None) { - slice[STEP] = 1; + step = 1; } else { - slice[STEP] = calculateSliceIndex(getStep()); - if (slice[STEP] == 0) { + step = calculateSliceIndex(getStep()); + if (step == 0) { throw Py.ValueError("slice step cannot be zero"); } } if (getStart() == Py.None) { - slice[START] = slice[STEP] < 0 ? len - 1 : 0; + start = step < 0 ? len - 1 : 0; } else { - slice[START] = calculateSliceIndex(getStart()); - if(slice[START] < 0) { - slice[START] += len; + start = calculateSliceIndex(getStart()); + if (start < 0) { + start += len; } - if(slice[START] < 0) { - slice[START] = slice[STEP] < 0 ? -1 : 0; + if (start < 0) { + start = step < 0 ? -1 : 0; } - if(slice[START] >= len) { - slice[START] = slice[STEP] < 0 ? len - 1 : len; + if (start >= len) { + start = step < 0 ? len - 1 : len; } } - if(getStop() == Py.None) { - slice[STOP] = slice[STEP] < 0 ? -1 : len; + + if (getStop() == Py.None) { + stop = step < 0 ? -1 : len; } else { - slice[STOP] = calculateSliceIndex(getStop()); - if(slice[STOP] < 0) { - slice[STOP] += len; + stop = calculateSliceIndex(getStop()); + if (stop < 0) { + stop += len; } - if(slice[STOP] < 0) { - slice[STOP] = -1; + if (stop < 0) { + stop = -1; } - if(slice[STOP] > len) { - slice[STOP] = len; + if (stop > len) { + stop = len; } } - return slice; + + if ((step < 0 && stop >= start) || (step > 0 && start >= stop)) { + slicelength = 0; + } else if (step < 0) { + slicelength = (stop - start + 1) / (step) + 1; + } else { + slicelength = (stop - start - 1) / (step) + 1; + } + + return new int[] {start, stop, step, slicelength}; } /** @@ -211,8 +222,6 @@ return indices; } - private static final int START = 0, STOP = 1, STEP = 2; - @ExposedGet public PyObject start = Py.None; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |