You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <pj...@us...> - 2008-07-29 22:40:08
|
Revision: 5021 http://jython.svn.sourceforge.net/jython/?rev=5021&view=rev Author: pjenvey Date: 2008-07-29 22:40:05 +0000 (Tue, 29 Jul 2008) Log Message: ----------- fix readChunk reading more than CHUNK_SIZE, which'll blow up packReadahead Modified Paths: -------------- branches/asm/Lib/test/test_file_newlines.py branches/asm/src/org/python/core/io/TextIOBase.java Modified: branches/asm/Lib/test/test_file_newlines.py =================================================================== --- branches/asm/Lib/test/test_file_newlines.py 2008-07-29 22:33:56 UTC (rev 5020) +++ branches/asm/Lib/test/test_file_newlines.py 2008-07-29 22:40:05 UTC (rev 5021) @@ -27,13 +27,14 @@ data = CRLF_TEST write_mode = 'wb' mode = 'r' + bufsize = -1 def setUp(self): self.filename = tempfile.mktemp() - self.write_fp = open(self.filename, self.write_mode) + self.write_fp = open(self.filename, self.write_mode, self.bufsize) self.write_fp.write(self.data) self.write_fp.flush() - self.fp = open(self.filename, self.mode) + self.fp = open(self.filename, self.mode, self.bufsize) def tearDown(self): if self.write_fp: @@ -259,6 +260,17 @@ read_data = data +class UniversalCRAtReadaheadBoundaryTestCase(BaseTestCase): + + mode = 'U' + bufsize = 0 + data = ('-' * 1023) + '\r\n' + ('-' * 10233) + + def test_read_cr_at_boundary(self): + # Used to raise a BufferOverflowException w/ bufsize of 0 + read(self.fp, ('-' * 1023) + '\n', 1024) + + class WriteTextNewlinesTestCase(BaseTestCase): write_mode = 'w' @@ -344,6 +356,7 @@ UniversalReadaheadBoundary3TestCase, UniversalReadaheadBoundary4TestCase, UniversalReadaheadBoundary5TestCase, + UniversalCRAtReadaheadBoundaryTestCase, WriteTextNewlinesTestCase, ReadUniversalNewlinesTestCase, WriteUniversalNewlinesTestCase] Modified: branches/asm/src/org/python/core/io/TextIOBase.java =================================================================== --- branches/asm/src/org/python/core/io/TextIOBase.java 2008-07-29 22:33:56 UTC (rev 5020) +++ branches/asm/src/org/python/core/io/TextIOBase.java 2008-07-29 22:40:05 UTC (rev 5021) @@ -227,6 +227,10 @@ // Prepare the readahead for reading readahead.clear(); + if (readahead.remaining() > CHUNK_SIZE) { + // Limit potential full reads on a resized readahead to CHUNK_SIZE + readahead.limit(readahead.position() + CHUNK_SIZE); + } bufferedIO.read1(readahead); readahead.flip(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-29 22:33:59
|
Revision: 5020 http://jython.svn.sourceforge.net/jython/?rev=5020&view=rev Author: zyasoft Date: 2008-07-29 22:33:56 +0000 (Tue, 29 Jul 2008) Log Message: ----------- cStringIO.tell needs to return an int for it to be used by __len__ (perhaps that should be relaxed instead?). Found by testing against PyAMF which uses cStringIO as a backing store for its BufferedByteStream objs. Modified Paths: -------------- branches/asm/src/org/python/modules/cStringIO.java Modified: branches/asm/src/org/python/modules/cStringIO.java =================================================================== --- branches/asm/src/org/python/modules/cStringIO.java 2008-07-29 20:29:08 UTC (rev 5019) +++ branches/asm/src/org/python/modules/cStringIO.java 2008-07-29 22:33:56 UTC (rev 5020) @@ -160,7 +160,7 @@ * Return the file position. * @returns the position in the file. */ - public long tell() { + public int tell() { _complain_ifclosed(); return pos; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-29 20:29:10
|
Revision: 5019 http://jython.svn.sourceforge.net/jython/?rev=5019&view=rev Author: pjenvey Date: 2008-07-29 20:29:08 +0000 (Tue, 29 Jul 2008) Log Message: ----------- add an InputStream tie-in to TextIOBases, for parsing in universal newlines mode fixes #1082 Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java branches/asm/src/org/python/core/imp.java Added Paths: ----------- branches/asm/src/org/python/core/io/TextIOInputStream.java Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-07-29 12:31:46 UTC (rev 5018) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-07-29 20:29:08 UTC (rev 5019) @@ -15,6 +15,7 @@ import org.antlr.runtime.ANTLRReaderStream; import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonTokenStream; + import org.python.antlr.ExpressionParser; import org.python.antlr.InteractiveParser; import org.python.antlr.LeadingSpaceSkippingStream; @@ -23,12 +24,15 @@ import org.python.antlr.NoCloseReaderStream; import org.python.antlr.PythonParser; import org.python.antlr.PythonTree; -import org.python.core.util.StringUtil; import org.python.antlr.PythonTree; import org.python.antlr.PythonPartialLexer; import org.python.antlr.PythonPartialParser; import org.python.antlr.PythonPartialTokenSource; import org.python.antlr.ast.modType; +import org.python.core.io.StreamIO; +import org.python.core.io.TextIOInputStream; +import org.python.core.io.UniversalIOWrapper; +import org.python.core.util.StringUtil; /** * Facade for the classes in the org.python.antlr package. @@ -187,6 +191,13 @@ encoding = cflags.encoding; } + // Enable universal newlines mode on the input + StreamIO rawIO = new StreamIO(istream, true); + org.python.core.io.BufferedReader bufferedIO = + new org.python.core.io.BufferedReader(rawIO, 0); + UniversalIOWrapper textIO = new UniversalIOWrapper(bufferedIO); + istream = new TextIOInputStream(textIO); + Reader reader; if(encoding != null) { try { Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-07-29 12:31:46 UTC (rev 5018) +++ branches/asm/src/org/python/core/imp.java 2008-07-29 20:29:08 UTC (rev 5019) @@ -22,7 +22,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 13; + public static final int APIVersion = 14; /** A non-empty fromlist for __import__'ing sub-modules. */ private static final PyObject nonEmptyFromlist = new PyTuple(Py.newString("__doc__")); Added: branches/asm/src/org/python/core/io/TextIOInputStream.java =================================================================== --- branches/asm/src/org/python/core/io/TextIOInputStream.java (rev 0) +++ branches/asm/src/org/python/core/io/TextIOInputStream.java 2008-07-29 20:29:08 UTC (rev 5019) @@ -0,0 +1,60 @@ +/* Copyright (c) Jython Developers */ +package org.python.core.io; + +import java.io.InputStream; +import java.io.IOException; + +/** + * An InputStream tie-in to a TextIOBase. + */ +public class TextIOInputStream extends InputStream { + + private TextIOBase textIO; + + /** + * Creates an InputStream wrapper to a given TextIOBase. + * + * @param textIO a TextIOBase + */ + public TextIOInputStream(TextIOBase textIO) { + this.textIO = textIO; + } + + @Override + public int read() throws IOException { + String result = textIO.read(1); + if (result.length() == 0) { + return -1; + } + return (int)result.charAt(0); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (b == null) { + throw new NullPointerException(); + } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) + || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return 0; + } + + String result = textIO.read(len); + len = result.length(); + for (int i = 0; i < len; i++) { + b[off + i] = (byte)result.charAt(i); + } + return len == 0 ? -1 : len; + } + + @Override + public void close() throws IOException { + textIO.close(); + } + + @Override + public long skip(long n) throws IOException { + return textIO.seek(n, 1); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-29 12:31:50
|
Revision: 5018 http://jython.svn.sourceforge.net/jython/?rev=5018&view=rev Author: fwierzbicki Date: 2008-07-29 12:31:46 +0000 (Tue, 29 Jul 2008) Log Message: ----------- Move testing classes out of main code. Added Paths: ----------- branches/asm/tests/java/org/python/antlr/ branches/asm/tests/java/org/python/antlr/GrammarTester.java branches/asm/tests/java/org/python/antlr/PythonPartialTester.java branches/asm/tests/java/org/python/antlr/PythonTreeTester.java branches/asm/tests/java/org/python/antlr/WalkerTester.java Removed Paths: ------------- branches/asm/src/org/python/antlr/GrammarTester.java branches/asm/src/org/python/antlr/PythonPartialTester.java branches/asm/src/org/python/antlr/PythonTreeTester.java branches/asm/src/org/python/antlr/WalkerTester.java Deleted: branches/asm/src/org/python/antlr/GrammarTester.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/GrammarTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,11 +0,0 @@ -package org.python.antlr; - -public class GrammarTester { - - public static void main(String[] args) throws Exception { - PythonTreeTester walker = new PythonTreeTester(); - walker.setParseOnly(true); - walker.parse(args); - } - -} Deleted: branches/asm/src/org/python/antlr/PythonPartialTester.java =================================================================== --- branches/asm/src/org/python/antlr/PythonPartialTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/PythonPartialTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,47 +0,0 @@ -package org.python.antlr; - -import org.antlr.runtime.ANTLRFileStream; -import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.Token; - -/** - * A walker producing a <code>PythonTree</code> AST. - */ -public class PythonPartialTester { - - public static class PPLexer extends PythonPartialLexer { - public PPLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - - public void parse(String[] args) throws Exception { - try { - PythonTree result = null; - CharStream input = new ANTLRFileStream(args[0]); - PythonPartialLexer lexer = new PPLexer(input); - CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); - //PythonTokenSource indentedSource = new PythonTokenSource(tokens); - PythonPartialTokenSource indentedSource = new PythonPartialTokenSource(tokens); - tokens = new CommonTokenStream(indentedSource); - PythonPartialParser parser = new PythonPartialParser(tokens); - parser.single_input(); - System.out.println("SUCCEED"); - } catch (ParseException e) { - System.out.println("FAIL:" + e); - } - } - - public static void main(String[] args) throws Exception { - PythonPartialTester p = new PythonPartialTester(); - p.parse(args); - } - -} Deleted: branches/asm/src/org/python/antlr/PythonTreeTester.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTreeTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/PythonTreeTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,98 +0,0 @@ -package org.python.antlr; - -import org.antlr.runtime.ANTLRFileStream; -import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.Token; -import org.antlr.runtime.tree.CommonTreeAdaptor; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.antlr.runtime.tree.TreeAdaptor; - -/** - * A walker producing a <code>PythonTree</code> AST. - */ -public class PythonTreeTester { - - public enum Block { MODULE, INTERACTIVE, EXPRESSION }; - - private boolean _parseOnly; - private Block _block; - - public PythonTreeTester() { - setParseOnly(false); - setBlock(Block.MODULE); - } - - public PythonTree parse(String[] args) throws Exception { - PythonTree result = null; - CharStream input = new ANTLRFileStream(args[0]); - PythonLexer lexer = new ModuleParser.PyLexer(input); - CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); - PythonTokenSource indentedSource = new PythonTokenSource(tokens); - tokens = new CommonTokenStream(indentedSource); - PythonParser parser = new PythonParser(tokens); - parser.setTreeAdaptor(new PythonTreeAdaptor()); - Tree r = null; - switch (_block) { - case MODULE : - r = (Tree)parser.file_input().tree; - break; - case INTERACTIVE : - r = (Tree)parser.single_input().tree; - break; - case EXPRESSION : - r = (Tree)parser.eval_input().tree; - break; - } - if (args.length > 1) { - System.out.println((r).toStringTree()); - } - if (!isParseOnly()) { - CommonTreeNodeStream nodes = new CommonTreeNodeStream(r); - nodes.setTokenStream(tokens); - PythonWalker walker = new PythonWalker(nodes); - switch (_block) { - case MODULE : - result = walker.module(); - break; - case INTERACTIVE : - result = walker.interactive(); - break; - case EXPRESSION : - result = walker.expression(); - break; - } - - if (args.length > 1) { - System.out.println(result.toStringTree()); - } - } - return result; - } - - /** - * If set to <code>true</code>, only <code>PythonParser</code> is - * called. - * - * @param parseOnly - */ - public void setParseOnly(boolean parseOnly) { - _parseOnly = parseOnly; - } - - public boolean isParseOnly() { - return _parseOnly; - } - - public void setBlock(Block block) { - _block = block; - } - - public Block getBlock() { - return _block; - } - -} Deleted: branches/asm/src/org/python/antlr/WalkerTester.java =================================================================== --- branches/asm/src/org/python/antlr/WalkerTester.java 2008-07-29 01:40:32 UTC (rev 5017) +++ branches/asm/src/org/python/antlr/WalkerTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -1,11 +0,0 @@ -package org.python.antlr; - -public class WalkerTester extends PythonTreeTester { - - public static void main(String[] args) throws Exception { - PythonTreeTester walker = new PythonTreeTester(); - walker.setParseOnly(false); - walker.parse(args); - } - -} Copied: branches/asm/tests/java/org/python/antlr/GrammarTester.java (from rev 5013, branches/asm/src/org/python/antlr/GrammarTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/GrammarTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/GrammarTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,11 @@ +package org.python.antlr; + +public class GrammarTester { + + public static void main(String[] args) throws Exception { + PythonTreeTester walker = new PythonTreeTester(); + walker.setParseOnly(true); + walker.parse(args); + } + +} Copied: branches/asm/tests/java/org/python/antlr/PythonPartialTester.java (from rev 5013, branches/asm/src/org/python/antlr/PythonPartialTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonPartialTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/PythonPartialTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,47 @@ +package org.python.antlr; + +import org.antlr.runtime.ANTLRFileStream; +import org.antlr.runtime.CharStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.Token; + +/** + * A walker producing a <code>PythonTree</code> AST. + */ +public class PythonPartialTester { + + public static class PPLexer extends PythonPartialLexer { + public PPLexer(CharStream lexer) { + super(lexer); + } + + public Token nextToken() { + startPos = getCharPositionInLine(); + return super.nextToken(); + } + } + + public void parse(String[] args) throws Exception { + try { + PythonTree result = null; + CharStream input = new ANTLRFileStream(args[0]); + PythonPartialLexer lexer = new PPLexer(input); + CommonTokenStream tokens = new CommonTokenStream(lexer); + tokens.discardOffChannelTokens(true); + //PythonTokenSource indentedSource = new PythonTokenSource(tokens); + PythonPartialTokenSource indentedSource = new PythonPartialTokenSource(tokens); + tokens = new CommonTokenStream(indentedSource); + PythonPartialParser parser = new PythonPartialParser(tokens); + parser.single_input(); + System.out.println("SUCCEED"); + } catch (ParseException e) { + System.out.println("FAIL:" + e); + } + } + + public static void main(String[] args) throws Exception { + PythonPartialTester p = new PythonPartialTester(); + p.parse(args); + } + +} Copied: branches/asm/tests/java/org/python/antlr/PythonTreeTester.java (from rev 5013, branches/asm/src/org/python/antlr/PythonTreeTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonTreeTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/PythonTreeTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,98 @@ +package org.python.antlr; + +import org.antlr.runtime.ANTLRFileStream; +import org.antlr.runtime.CharStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; +import org.antlr.runtime.tree.CommonTreeAdaptor; +import org.antlr.runtime.tree.CommonTreeNodeStream; +import org.antlr.runtime.tree.Tree; +import org.antlr.runtime.tree.TreeAdaptor; + +/** + * A walker producing a <code>PythonTree</code> AST. + */ +public class PythonTreeTester { + + public enum Block { MODULE, INTERACTIVE, EXPRESSION }; + + private boolean _parseOnly; + private Block _block; + + public PythonTreeTester() { + setParseOnly(false); + setBlock(Block.MODULE); + } + + public PythonTree parse(String[] args) throws Exception { + PythonTree result = null; + CharStream input = new ANTLRFileStream(args[0]); + PythonLexer lexer = new ModuleParser.PyLexer(input); + CommonTokenStream tokens = new CommonTokenStream(lexer); + tokens.discardOffChannelTokens(true); + PythonTokenSource indentedSource = new PythonTokenSource(tokens); + tokens = new CommonTokenStream(indentedSource); + PythonParser parser = new PythonParser(tokens); + parser.setTreeAdaptor(new PythonTreeAdaptor()); + Tree r = null; + switch (_block) { + case MODULE : + r = (Tree)parser.file_input().tree; + break; + case INTERACTIVE : + r = (Tree)parser.single_input().tree; + break; + case EXPRESSION : + r = (Tree)parser.eval_input().tree; + break; + } + if (args.length > 1) { + System.out.println((r).toStringTree()); + } + if (!isParseOnly()) { + CommonTreeNodeStream nodes = new CommonTreeNodeStream(r); + nodes.setTokenStream(tokens); + PythonWalker walker = new PythonWalker(nodes); + switch (_block) { + case MODULE : + result = walker.module(); + break; + case INTERACTIVE : + result = walker.interactive(); + break; + case EXPRESSION : + result = walker.expression(); + break; + } + + if (args.length > 1) { + System.out.println(result.toStringTree()); + } + } + return result; + } + + /** + * If set to <code>true</code>, only <code>PythonParser</code> is + * called. + * + * @param parseOnly + */ + public void setParseOnly(boolean parseOnly) { + _parseOnly = parseOnly; + } + + public boolean isParseOnly() { + return _parseOnly; + } + + public void setBlock(Block block) { + _block = block; + } + + public Block getBlock() { + return _block; + } + +} Copied: branches/asm/tests/java/org/python/antlr/WalkerTester.java (from rev 5013, branches/asm/src/org/python/antlr/WalkerTester.java) =================================================================== --- branches/asm/tests/java/org/python/antlr/WalkerTester.java (rev 0) +++ branches/asm/tests/java/org/python/antlr/WalkerTester.java 2008-07-29 12:31:46 UTC (rev 5018) @@ -0,0 +1,11 @@ +package org.python.antlr; + +public class WalkerTester extends PythonTreeTester { + + public static void main(String[] args) throws Exception { + PythonTreeTester walker = new PythonTreeTester(); + walker.setParseOnly(false); + walker.parse(args); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-29 01:40:34
|
Revision: 5017 http://jython.svn.sourceforge.net/jython/?rev=5017&view=rev Author: fwierzbicki Date: 2008-07-29 01:40:32 +0000 (Tue, 29 Jul 2008) Log Message: ----------- IParserHost is no longer used. Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java Removed Paths: ------------- branches/asm/src/org/python/antlr/IParserHost.java Deleted: branches/asm/src/org/python/antlr/IParserHost.java =================================================================== --- branches/asm/src/org/python/antlr/IParserHost.java 2008-07-28 23:13:21 UTC (rev 5016) +++ branches/asm/src/org/python/antlr/IParserHost.java 2008-07-29 01:40:32 UTC (rev 5017) @@ -1,23 +0,0 @@ -package org.python.antlr; - -/** - * - * literal creation callbacks from the parser to the its host - * - **/ - -public interface IParserHost { - - public Object newLong(String s); - - public Object newLong(java.math.BigInteger i); - - public Object newFloat(double v); - - public Object newImaginary(double v); - - public Object newInteger(int i); - - public String decode_UnicodeEscape(String str, int start, int end, - String errors, boolean unicode); -} Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-07-28 23:13:21 UTC (rev 5016) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-07-29 01:40:32 UTC (rev 5017) @@ -24,7 +24,6 @@ import org.python.antlr.PythonParser; import org.python.antlr.PythonTree; import org.python.core.util.StringUtil; -import org.python.antlr.IParserHost; import org.python.antlr.PythonTree; import org.python.antlr.PythonPartialLexer; import org.python.antlr.PythonPartialParser; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-28 23:13:23
|
Revision: 5016 http://jython.svn.sourceforge.net/jython/?rev=5016&view=rev Author: pjenvey Date: 2008-07-28 23:13:21 +0000 (Mon, 28 Jul 2008) Log Message: ----------- fix chdir('/') on windows Modified Paths: -------------- branches/asm/Lib/os.py Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-28 22:56:55 UTC (rev 5015) +++ branches/asm/Lib/os.py 2008-07-28 23:13:21 UTC (rev 5016) @@ -243,11 +243,12 @@ Change the current working directory to the specified path. """ - if not _path.exists(path): + realpath = _path.realpath(path) + if not _path.exists(realpath): raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) - if not _path.isdir(path): + if not _path.isdir(realpath): raise OSError(errno.ENOTDIR, errno.strerror(errno.ENOTDIR), path) - sys.setCurrentWorkingDir(_path.realpath(path)) + sys.setCurrentWorkingDir(realpath) def listdir(path): """listdir(path) -> list_of_strings This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-28 22:56:57
|
Revision: 5015 http://jython.svn.sourceforge.net/jython/?rev=5015&view=rev Author: nriley Date: 2008-07-28 22:56:55 +0000 (Mon, 28 Jul 2008) Log Message: ----------- pwd, grp; test_posix no longer skipped Modified Paths: -------------- branches/asm/Lib/test/regrtest.py Added Paths: ----------- branches/asm/Lib/grp.py branches/asm/Lib/pwd.py Added: branches/asm/Lib/grp.py =================================================================== --- branches/asm/Lib/grp.py (rev 0) +++ branches/asm/Lib/grp.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -0,0 +1,77 @@ +""" +"Access to the Unix group database. + +Group entries are reported as 4-tuples containing the following fields +from the group database, in order: + + name - name of the group + passwd - group password (encrypted); often empty + gid - numeric ID of the group + mem - list of members + +The gid is an integer, name and password are strings. (Note that most +users are not explicitly listed as members of the groups they are in +according to the password database. Check both databases to get +complete membership information.) +""" + +__all__ = ['getgrgid', 'getgrnam', 'getgrall'] + +from os import _posix +from java.lang import NullPointerException + +class struct_group(tuple): + """ + grp.struct_group: Results from getgr*() routines. + + This object may be accessed either as a tuple of + (gr_name,gr_passwd,gr_gid,gr_mem) + or via the object attributes as named in the above tuple. + """ + + attrs = ['gr_name', 'gr_passwd', 'gr_gid', 'gr_mem'] + + def __new__(cls, grp): + return tuple.__new__(cls, (grp.gr_name, grp.gr_passwd, grp.gr_gid, + list(grp.getMembers()))) + + def __getattr__(self, attr): + try: + return self[self.attrs.index(attr)] + except ValueError: + raise AttributeError + +def getgrgid(uid): + """ + getgrgid(id) -> tuple + Return the group database entry for the given numeric group ID. If + id is not valid, raise KeyError."}, + """ + try: + return struct_group(_posix.getgrgid(uid)) + except NullPointerException: + raise KeyError, uid + +def getgrnam(name): + """ + getgrnam(name) -> tuple + Return the group database entry for the given group name. If + name is not valid, raise KeyError. + """ + try: + return struct_group(_posix.getgrnam(name)) + except NullPointerException: + raise KeyError, name + +def getgrall(): + """ + getgrall() -> list of tuples + Return a list of all available group database entries, + in arbitrary order. + """ + groups = [] + try: + while True: + groups.append(struct_group(_posix.getgrent())) + except NullPointerException: + return groups Added: branches/asm/Lib/pwd.py =================================================================== --- branches/asm/Lib/pwd.py (rev 0) +++ branches/asm/Lib/pwd.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -0,0 +1,73 @@ +""" +This module provides access to the Unix password database. + +Password database entries are reported as 7-tuples containing the +following items from the password database (see `<pwd.h>'), in order: +pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell. The +uid and gid items are integers, all others are strings. An exception +is raised if the entry asked for cannot be found. +""" + +__all__ = ['getpwuid', 'getpwnam', 'getpwall'] + +from os import _posix +from java.lang import NullPointerException + +class struct_passwd(tuple): + """ + pwd.struct_passwd: Results from getpw*() routines. + + This object may be accessed either as a tuple of + (pw_name,pw_passwd,pw_uid,pw_gid,pw_gecos,pw_dir,pw_shell) + or via the object attributes as named in the above tuple. + """ + + attrs = ['pw_name', 'pw_passwd', 'pw_uid', 'pw_gid', 'pw_gecos', + 'pw_dir', 'pw_shell'] + + def __new__(cls, pwd): + return tuple.__new__(cls, (getattr(pwd, attr) for attr in cls.attrs)) + + def __getattr__(self, attr): + try: + return self[self.attrs.index(attr)] + except ValueError: + raise AttributeError + +def getpwuid(uid): + """ + getpwuid(uid) -> (pw_name,pw_passwd,pw_uid, + pw_gid,pw_gecos,pw_dir,pw_shell) + Return the password database entry for the given numeric user ID. + See pwd.__doc__ for more on password database entries. + """ + try: + return struct_passwd(_posix.getpwuid(uid)) + except NullPointerException: + raise KeyError, uid + +def getpwnam(name): + """ + getpwnam(name) -> (pw_name,pw_passwd,pw_uid, + pw_gid,pw_gecos,pw_dir,pw_shell) + Return the password database entry for the given user name. + See pwd.__doc__ for more on password database entries. + """ + try: + return struct_passwd(_posix.getpwnam(name)) + except NullPointerException: + raise KeyError, name + +def getpwall(): + """ + getpwall() -> list_of_entries + Return a list of all available password database entries, + in arbitrary order. + See pwd.__doc__ for more on password database entries. + """ + entries = [] + try: + while True: + entries.append(struct_passwd(_posix.getpwent())) + except NullPointerException: + return entries Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-07-28 22:55:35 UTC (rev 5014) +++ branches/asm/Lib/test/regrtest.py 2008-07-28 22:56:55 UTC (rev 5015) @@ -1406,7 +1406,6 @@ test_gdbm test_getargs2 test_gl - test_grp test_hotshot test_imageop test_imgfile @@ -1430,7 +1429,6 @@ test_poll test_profile test_pty - test_pwd test_pyexpat test_resource test_rgbimg This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-28 22:55:38
|
Revision: 5014 http://jython.svn.sourceforge.net/jython/?rev=5014&view=rev Author: nriley Date: 2008-07-28 22:55:35 +0000 (Mon, 28 Jul 2008) Log Message: ----------- jna-posix from http://svn.codehaus.org/jruby-contrib/trunk/jna-posix r210 Modified Paths: -------------- branches/asm/extlibs/jna-posix.jar This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-28 19:50:46
|
Revision: 5013 http://jython.svn.sourceforge.net/jython/?rev=5013&view=rev Author: pjenvey Date: 2008-07-28 19:50:43 +0000 (Mon, 28 Jul 2008) Log Message: ----------- include UserList Modified Paths: -------------- branches/asm/CPythonLib.includes Modified: branches/asm/CPythonLib.includes =================================================================== --- branches/asm/CPythonLib.includes 2008-07-28 19:46:39 UTC (rev 5012) +++ branches/asm/CPythonLib.includes 2008-07-28 19:50:43 UTC (rev 5013) @@ -150,6 +150,7 @@ urlparse.py user.py UserDict.py +UserList.py UserString.py uu.py uuid.py This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-28 19:46:42
|
Revision: 5012 http://jython.svn.sourceforge.net/jython/?rev=5012&view=rev Author: pjenvey Date: 2008-07-28 19:46:39 +0000 (Mon, 28 Jul 2008) Log Message: ----------- fix stock UserList/test_userlist: o handle __get/set/delslice__ start/stop as null or None in PySlice.indices2 o fix list slice assignments of the same underlying list (always copy first as CPython does) Modified Paths: -------------- branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PySlice.java Removed Paths: ------------- branches/asm/Lib/UserList.py branches/asm/Lib/test/test_userlist.py Deleted: branches/asm/Lib/UserList.py =================================================================== --- branches/asm/Lib/UserList.py 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/Lib/UserList.py 2008-07-28 19:46:39 UTC (rev 5012) @@ -1,94 +0,0 @@ -"""A more or less complete user-defined wrapper around list objects.""" - -#Imported from Python 2.3.5 and added _fixindex -class UserList: - def __init__(self, initlist=None): - self.data = [] - if initlist is not None: - # XXX should this accept an arbitrary sequence? - if type(initlist) == type(self.data): - self.data[:] = initlist - elif isinstance(initlist, UserList): - self.data[:] = initlist.data[:] - else: - self.data = list(initlist) - def __repr__(self): return repr(self.data) - def __lt__(self, other): return self.data < self.__cast(other) - def __le__(self, other): return self.data <= self.__cast(other) - def __eq__(self, other): return self.data == self.__cast(other) - def __ne__(self, other): return self.data != self.__cast(other) - def __gt__(self, other): return self.data > self.__cast(other) - def __ge__(self, other): return self.data >= self.__cast(other) - def __cast(self, other): - if isinstance(other, UserList): return other.data - else: return other - def __cmp__(self, other): - return cmp(self.data, self.__cast(other)) - def __contains__(self, item): return item in self.data - def __len__(self): return len(self.data) - def __getitem__(self, i): return self.data[i] - def __setitem__(self, i, item): self.data[i] = item - def __delitem__(self, i): del self.data[i] - def __getslice__(self, i, j): - i = self._fixindex(i); j = self._fixindex(j) - return self.__class__(self.data[i:j]) - def __setslice__(self, i, j, other): - i = self._fixindex(i); j = self._fixindex(j) - if isinstance(other, UserList): - self.data[i:j] = other.data - elif isinstance(other, type(self.data)): - self.data[i:j] = other - else: - self.data[i:j] = list(other) - def __delslice__(self, i, j): - i = self._fixindex(i); j = self._fixindex(j) - del self.data[i:j] - def __add__(self, other): - if isinstance(other, UserList): - return self.__class__(self.data + other.data) - elif isinstance(other, type(self.data)): - return self.__class__(self.data + other) - else: - return self.__class__(self.data + list(other)) - def __radd__(self, other): - if isinstance(other, UserList): - return self.__class__(other.data + self.data) - elif isinstance(other, type(self.data)): - return self.__class__(other + self.data) - else: - return self.__class__(list(other) + self.data) - def __iadd__(self, other): - if isinstance(other, UserList): - self.data += other.data - elif isinstance(other, type(self.data)): - self.data += other - else: - self.data += list(other) - return self - def __mul__(self, n): - return self.__class__(self.data*n) - __rmul__ = __mul__ - def __imul__(self, n): - self.data *= n - return self - def append(self, item): self.data.append(item) - def insert(self, i, item): self.data.insert(i, item) - def pop(self, i=-1): return self.data.pop(i) - def remove(self, item): self.data.remove(item) - def count(self, item): return self.data.count(item) - def index(self, item, *args): return self.data.index(item, *args) - def reverse(self): self.data.reverse() - def sort(self, *args): self.data.sort(*args) - def extend(self, other): - if isinstance(other, UserList): - self.data.extend(other.data) - else: - self.data.extend(other) - def _fixindex(self, index): - if index < 0: - index += len(self.data) - elif index > len(self.data): - index = len(self.data) - index = max(index, 0) - return index - Deleted: branches/asm/Lib/test/test_userlist.py =================================================================== --- branches/asm/Lib/test/test_userlist.py 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/Lib/test/test_userlist.py 2008-07-28 19:46:39 UTC (rev 5012) @@ -1,269 +0,0 @@ -# Check every path through every method of UserList - -#imported from Python 2.3.5 - -from UserList import UserList -import unittest, test.test_support - -class UserListTest(unittest.TestCase): - - def test_constructors(self): - l0 = [] - l1 = [0] - l2 = [0, 1] - - u = UserList() - u0 = UserList(l0) - u1 = UserList(l1) - u2 = UserList(l2) - - uu = UserList(u) - uu0 = UserList(u0) - uu1 = UserList(u1) - uu2 = UserList(u2) - - v = UserList(tuple(u)) - class OtherList: - def __init__(self, initlist): - self.__data = initlist - def __len__(self): - return len(self.__data) - def __getitem__(self, i): - return self.__data[i] - v0 = UserList(OtherList(u0)) - vv = UserList("this is also a sequence") - - def test_repr(self): - l0 = [] - l2 = [0, 1, 2] - u0 = UserList(l0) - u2 = UserList(l2) - - self.assertEqual(str(u0), str(l0)) - self.assertEqual(repr(u0), repr(l0)) - self.assertEqual(`u2`, `l2`) - - def test_cmplen(self): - l0 = [] - l1 = [0] - l2 = [0, 1] - - # Test constructors - - u = UserList() - u0 = UserList(l0) - u1 = UserList(l1) - u2 = UserList(l2) - - uu = UserList(u) - uu0 = UserList(u0) - uu1 = UserList(u1) - uu2 = UserList(u2) - - def mycmp(x, y): - r = cmp(x, y) - if r < 0: return -1 - if r > 0: return 1 - return r - - all = [l0, l1, l2, u, u0, u1, u2, uu, uu0, uu1, uu2] - for a in all: - for b in all: - self.assertEqual(mycmp(a, b), mycmp(len(a), len(b))) - - self.assert_(u0 <= u2) - self.assert_(u2 >= u0) - - def test_getitem(self): - u = UserList([0, 1, 2]) - for i in xrange(len(u)): - self.assertEqual(u[i], i) - - def test_setitem(self): - u = UserList([0, 1]) - u[0] = 0 - u[1] = 100 - self.assertEqual(u, [0, 100]) - self.assertRaises(IndexError, u.__setitem__, 2, 200) - - def test_delitem(self): - u = UserList([0, 1]) - del u[1] - del u[0] - self.assertRaises(IndexError, u.__delitem__, 0) - - def test_getslice(self): - l = [0, 1] - u = UserList(l) - for i in xrange(-3, 4): - self.assertEqual(u[:i], l[:i]) - self.assertEqual(u[i:], l[i:]) - for j in xrange(-3, 4): - self.assertEqual(u[i:j], l[i:j]) - - def test_setslice(self): - l = [0, 1] - u = UserList(l) - - # Test __setslice__ - for i in range(-3, 4): - u[:i] = l[:i] - self.assertEqual(u, l) - u2 = u[:] - u2[:i] = u[:i] - self.assertEqual(u2, u) - u[i:] = l[i:] - self.assertEqual(u, l) - u2 = u[:] - u2[i:] = u[i:] - self.assertEqual(u2, u) - for j in range(-3, 4): - u[i:j] = l[i:j] - self.assertEqual(u, l) - u2 = u[:] - u2[i:j] = u[i:j] - self.assertEqual(u2, u) - - uu2 = u2[:] - uu2[:0] = [-2, -1] - self.assertEqual(uu2, [-2, -1, 0, 1]) - uu2[0:] = [] - self.assertEqual(uu2, []) - - def test_contains(self): - u = UserList([0, 1, 2]) - for i in u: - self.assert_(i in u) - for i in min(u)-1, max(u)+1: - self.assert_(i not in u) - - def test_delslice(self): - u = UserList([0, 1]) - del u[1:2] - del u[0:1] - self.assertEqual(u, []) - - u = UserList([0, 1]) - del u[1:] - del u[:1] - self.assertEqual(u, []) - - def test_addmul(self): - u1 = UserList([0]) - u2 = UserList([0, 1]) - self.assertEqual(u1, u1 + []) - self.assertEqual(u1, [] + u1) - self.assertEqual(u1 + [1], u2) - self.assertEqual([-1] + u1, [-1, 0]) - self.assertEqual(u2, u2*1) - self.assertEqual(u2, 1*u2) - self.assertEqual(u2+u2, u2*2) - self.assertEqual(u2+u2, 2*u2) - self.assertEqual(u2+u2+u2, u2*3) - self.assertEqual(u2+u2+u2, 3*u2) - - def test_add_specials(self): - u = UserList("spam") - u2 = u + "eggs" - self.assertEqual(u2, list("spameggs")) - - def test_radd_specials(self): - u = UserList("eggs") - u2 = "spam" + u - self.assertEqual(u2, list("spameggs")) - u2 = u.__radd__(UserList("spam")) - self.assertEqual(u2, list("spameggs")) - - def test_append(self): - u = UserList((0, )) - u.append(1) - self.assertEqual(u, [0, 1]) - - def test_insert(self): - u = UserList((0, 1)) - u.insert(0, -1) - self.assertEqual(u, [-1, 0, 1]) - - def test_pop(self): - u = UserList((-1, 0, 1)) - u.pop() - self.assertEqual(u, [-1, 0]) - u.pop(0) - self.assertEqual(u, [0]) - - def test_remove(self): - u = UserList((0, 1)) - u.remove(1) - self.assertEqual(u, [0]) - - def test_count(self): - u = UserList((0, 1))*3 - self.assertEqual(u.count(0), 3) - self.assertEqual(u.count(1), 3) - self.assertEqual(u.count(2), 0) - - def test_index(self): - u = UserList((0, 1)) - self.assertEqual(u.index(0), 0) - self.assertEqual(u.index(1), 1) - self.assertRaises(ValueError, u.index, 2) - - u = UserList([-2,-1,0,0,1,2]) - self.assertEqual(u.count(0), 2) - self.assertEqual(u.index(0), 2) - self.assertEqual(u.index(0,2), 2) - self.assertEqual(u.index(-2,-10), 0) - self.assertEqual(u.index(0,3), 3) - self.assertEqual(u.index(0,3,4), 3) - self.assertRaises(ValueError, u.index, 2,0,-10) - - def test_reverse(self): - u = UserList((0, 1)) - u2 = u[:] - u.reverse() - self.assertEqual(u, [1, 0]) - u.reverse() - self.assertEqual(u, u2) - - def test_sort(self): - u = UserList([1, 0]) - u.sort() - self.assertEqual(u, [0, 1]) - - def test_slice(self): - u = UserList("spam") - u[:2] = "h" - self.assertEqual(u, list("ham")) - - def test_iadd(self): - u = UserList((0, 1)) - u += [0, 1] - self.assertEqual(u, [0, 1, 0, 1]) - u += UserList([0, 1]) - self.assertEqual(u, [0, 1, 0, 1, 0, 1]) - - u = UserList("spam") - u += "eggs" - self.assertEqual(u, list("spameggs")) - - def test_extend(self): - u1 = UserList((0, )) - u2 = UserList((0, 1)) - u = u1[:] - u.extend(u2) - self.assertEqual(u, u1 + u2) - - u = UserList("spam") - u.extend("eggs") - self.assertEqual(u, list("spameggs")) - - def test_imul(self): - u = UserList((0, 1)) - u *= 3 - self.assertEqual(u, [0, 1, 0, 1, 0, 1]) - -def test_main(): - test.test_support.run_unittest(UserListTest) - -if __name__ == "__main__": - test_main() Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/src/org/python/core/PyList.java 2008-07-28 19:46:39 UTC (rev 5012) @@ -190,7 +190,7 @@ protected void setsliceList(int start, int stop, int step, List value) { if(step != 1) { - throw Py.TypeError("setslice with java.util.List and step != 1 not " + "supported yet"); + throw Py.TypeError("setslice with java.util.List and step != 1 not supported yet"); } int n = value.size(); list.ensureCapacity(start + n); @@ -200,23 +200,16 @@ } protected void setsliceIterable(int start, int stop, int step, PyObject value) { - PyObject iter; + PyObject[] seq; try { - iter = value.__iter__(); - } catch(PyException pye) { - if(Py.matchException(pye, Py.TypeError)) { + seq = Py.make_array(value); + } catch (PyException pye) { + if (Py.matchException(pye, Py.TypeError)) { throw Py.TypeError("can only assign an iterable"); } throw pye; } - PyObject next; - for(int j = 0; (next = iter.__iternext__()) != null; j += step) { - if(step < 0) { - list.pyset(start + j, next); - } else { - list.add(start + j, next); - } - } + setslicePySequence(start, stop, step, new PyList(seq)); } protected PyObject repeat(int count) { Modified: branches/asm/src/org/python/core/PySlice.java =================================================================== --- branches/asm/src/org/python/core/PySlice.java 2008-07-28 13:33:50 UTC (rev 5011) +++ branches/asm/src/org/python/core/PySlice.java 2008-07-28 19:46:39 UTC (rev 5012) @@ -188,8 +188,9 @@ */ public static PyObject[] indices2(PyObject obj, PyObject start, PyObject stop) { PyObject[] indices = new PyObject[2]; - int istart = start == null ? 0 : calculateSliceIndex(start); - int istop = stop == null ? PySystemState.maxint : calculateSliceIndex(stop); + int istart = (start == null || start == Py.None) ? 0 : calculateSliceIndex(start); + int istop = (stop == null || stop == Py.None) + ? PySystemState.maxint : calculateSliceIndex(stop); if (istart < 0 || istop < 0) { try { int len = obj.__len__(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-28 13:33:53
|
Revision: 5011 http://jython.svn.sourceforge.net/jython/?rev=5011&view=rev Author: zyasoft Date: 2008-07-28 13:33:50 +0000 (Mon, 28 Jul 2008) Log Message: ----------- Excluded test cases that depend on tuple unpacking in the arg specification, since this depends on introspecing bytecode. (Perhaps we should provide a Jython-specific version where appropriate metadata is emitted in the compiled code object?) Modified Paths: -------------- branches/asm/Lib/test/test_inspect.py Modified: branches/asm/Lib/test/test_inspect.py =================================================================== --- branches/asm/Lib/test/test_inspect.py 2008-07-28 12:13:52 UTC (rev 5010) +++ branches/asm/Lib/test/test_inspect.py 2008-07-28 13:33:50 UTC (rev 5011) @@ -4,7 +4,7 @@ import inspect import datetime -from test.test_support import TESTFN, run_unittest +from test.test_support import TESTFN, run_unittest, is_jython from test import inspect_fodder as mod from test import inspect_fodder2 as mod2 @@ -29,6 +29,15 @@ git = mod.StupidGit() +def na_for_jython(fn): + if is_jython: + def do_nothing(*args, **kw): + pass + return do_nothing + else: + return fn + + class IsTestBase(unittest.TestCase): predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode, inspect.isframe, inspect.isfunction, inspect.ismethod, @@ -115,6 +124,11 @@ self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals), '(x=11, y=14)') + # TODO - test_previous_frame could be rewritten such that we could + # introspect on the previous frame but without a dependency on + # tuple unpacking + + @na_for_jython def test_previous_frame(self): args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back) self.assertEqual(args, ['a', 'b', 'c', 'd', ['e', ['f']]]) @@ -327,6 +341,7 @@ self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults), formatted) + @na_for_jython def test_getargspec(self): self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted = '(x, y)') @@ -335,12 +350,14 @@ 'g', 'h', (3, (4, (5,))), '(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)') + @na_for_jython def test_getargspec_method(self): class A(object): def m(self): pass self.assertArgSpecEquals(A.m, ['self']) + @na_for_jython def test_getargspec_sublistofone(self): def sublistOfOne((foo,)): return 1 self.assertArgSpecEquals(sublistOfOne, [['foo']]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-28 12:13:55
|
Revision: 5010 http://jython.svn.sourceforge.net/jython/?rev=5010&view=rev Author: zyasoft Date: 2008-07-28 12:13:52 +0000 (Mon, 28 Jul 2008) Log Message: ----------- Replaced test_inspect.py with rewritten version (using unittest!) from 2.5: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_inspect.py@65262 Modified Paths: -------------- branches/asm/Lib/test/test_inspect.py Modified: branches/asm/Lib/test/test_inspect.py =================================================================== --- branches/asm/Lib/test/test_inspect.py 2008-07-28 11:51:51 UTC (rev 5009) +++ branches/asm/Lib/test/test_inspect.py 2008-07-28 12:13:52 UTC (rev 5010) @@ -1,390 +1,482 @@ -source = '''# line 1 -'A module docstring.' +import sys +import types +import unittest +import inspect +import datetime -import sys, inspect -# line 5 +from test.test_support import TESTFN, run_unittest -# line 7 -def spam(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h): - eggs(b + d, c + f) +from test import inspect_fodder as mod +from test import inspect_fodder2 as mod2 -# line 11 -def eggs(x, y): - "A docstring." - global fr, st - fr = inspect.currentframe() - st = inspect.stack() - p = x - q = y / 0 +# Functions tested in this suite: +# ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, +# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule, +# getsourcefile, getcomments, getsource, getclasstree, getargspec, +# getargvalues, formatargspec, formatargvalues, currentframe, stack, trace +# isdatadescriptor -# line 20 -class StupidGit: - """A longer, +modfile = mod.__file__ +if modfile.endswith(('c', 'o')): + modfile = modfile[:-1] - indented +import __builtin__ - docstring.""" -# line 27 +try: + 1/0 +except: + tb = sys.exc_traceback - def abuse(self, a, b, c): - """Another +git = mod.StupidGit() -\tdocstring +class IsTestBase(unittest.TestCase): + predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode, + inspect.isframe, inspect.isfunction, inspect.ismethod, + inspect.ismodule, inspect.istraceback]) - containing + def istest(self, predicate, exp): + obj = eval(exp) + self.failUnless(predicate(obj), '%s(%s)' % (predicate.__name__, exp)) -\ttabs -\t - """ - self.argue(a, b, c) -# line 40 - def argue(self, a, b, c): - try: - spam(a, b, c) - except: - self.ex = sys.exc_info() - self.tr = inspect.trace() + for other in self.predicates - set([predicate]): + self.failIf(other(obj), 'not %s(%s)' % (other.__name__, exp)) -# line 48 -class MalodorousPervert(StupidGit): - pass +class TestPredicates(IsTestBase): + def test_thirteen(self): + count = len(filter(lambda x:x.startswith('is'), dir(inspect))) + # Doc/lib/libinspect.tex claims there are 13 such functions + expected = 13 + err_msg = "There are %d (not %d) is* functions" % (count, expected) + self.assertEqual(count, expected, err_msg) -class ParrotDroppings: - pass + def test_excluding_predicates(self): + self.istest(inspect.isbuiltin, 'sys.exit') + self.istest(inspect.isbuiltin, '[].append') + self.istest(inspect.isclass, 'mod.StupidGit') + self.istest(inspect.iscode, 'mod.spam.func_code') + self.istest(inspect.isframe, 'tb.tb_frame') + self.istest(inspect.isfunction, 'mod.spam') + self.istest(inspect.ismethod, 'mod.StupidGit.abuse') + self.istest(inspect.ismethod, 'git.argue') + self.istest(inspect.ismodule, 'mod') + self.istest(inspect.istraceback, 'tb') + self.istest(inspect.isdatadescriptor, '__builtin__.file.closed') + self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace') + if hasattr(types, 'GetSetDescriptorType'): + self.istest(inspect.isgetsetdescriptor, + 'type(tb.tb_frame).f_locals') + else: + self.failIf(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) + if hasattr(types, 'MemberDescriptorType'): + self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') + else: + self.failIf(inspect.ismemberdescriptor(datetime.timedelta.days)) -class FesteringGob(MalodorousPervert, ParrotDroppings): - pass -''' + def test_isroutine(self): + self.assert_(inspect.isroutine(mod.spam)) + self.assert_(inspect.isroutine([].count)) -# Functions tested in this suite: -# ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, -# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule, -# getsourcefile, getcomments, getsource, getclasstree, getargspec, -# getargvalues, formatargspec, formatargvalues, currentframe, stack, trace -# isdatadescriptor +class TestInterpreterStack(IsTestBase): + def __init__(self, *args, **kwargs): + unittest.TestCase.__init__(self, *args, **kwargs) -from test.test_support import TestFailed, TESTFN, is_jython -import sys, imp, os, string + git.abuse(7, 8, 9) -def test(assertion, message, *args): - if not assertion: - raise TestFailed, message % args + def test_abuse_done(self): + self.istest(inspect.istraceback, 'git.ex[2]') + self.istest(inspect.isframe, 'mod.fr') -import inspect + def test_stack(self): + self.assert_(len(mod.st) >= 5) + self.assertEqual(mod.st[0][1:], + (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0)) + self.assertEqual(mod.st[1][1:], + (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0)) + self.assertEqual(mod.st[2][1:], + (modfile, 43, 'argue', [' spam(a, b, c)\n'], 0)) + self.assertEqual(mod.st[3][1:], + (modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0)) -file = open(TESTFN, 'w') -file.write(source) -file.close() + def test_trace(self): + self.assertEqual(len(git.tr), 3) + self.assertEqual(git.tr[0][1:], (modfile, 43, 'argue', + [' spam(a, b, c)\n'], 0)) + self.assertEqual(git.tr[1][1:], (modfile, 9, 'spam', + [' eggs(b + d, c + f)\n'], 0)) + self.assertEqual(git.tr[2][1:], (modfile, 18, 'eggs', + [' q = y / 0\n'], 0)) -# Note that load_source creates file TESTFN+'c' or TESTFN+'o'. -mod = imp.load_source('testmod', TESTFN) -files_to_clean_up = [TESTFN, TESTFN + 'c', TESTFN + 'o'] + def test_frame(self): + args, varargs, varkw, locals = inspect.getargvalues(mod.fr) + self.assertEqual(args, ['x', 'y']) + self.assertEqual(varargs, None) + self.assertEqual(varkw, None) + self.assertEqual(locals, {'x': 11, 'p': 11, 'y': 14}) + self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals), + '(x=11, y=14)') -def istest(func, exp): - obj = eval(exp) - test(func(obj), '%s(%s)' % (func.__name__, exp)) - for other in [inspect.isbuiltin, inspect.isclass, inspect.iscode, - inspect.isframe, inspect.isfunction, inspect.ismethod, - inspect.ismodule, inspect.istraceback]: - if other is not func: - test(not other(obj), 'not %s(%s)' % (other.__name__, exp)) + def test_previous_frame(self): + args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back) + self.assertEqual(args, ['a', 'b', 'c', 'd', ['e', ['f']]]) + self.assertEqual(varargs, 'g') + self.assertEqual(varkw, 'h') + self.assertEqual(inspect.formatargvalues(args, varargs, varkw, locals), + '(a=7, b=8, c=9, d=3, (e=4, (f=5,)), *g=(), **h={})') -git = mod.StupidGit() -try: - 1/0 -except: - tb = sys.exc_traceback +class GetSourceBase(unittest.TestCase): + # Subclasses must override. + fodderFile = None -istest(inspect.isbuiltin, 'ord') -istest(inspect.isbuiltin, '[].append') -istest(inspect.isclass, 'mod.StupidGit') -istest(inspect.iscode, 'mod.spam.func_code') -istest(inspect.isframe, 'tb.tb_frame') -istest(inspect.isfunction, 'mod.spam') -istest(inspect.ismethod, 'mod.StupidGit.abuse') -istest(inspect.ismethod, 'git.argue') -istest(inspect.ismodule, 'mod') -istest(inspect.istraceback, 'tb') -import __builtin__ -istest(inspect.isdatadescriptor, '__builtin__.file.closed') -istest(inspect.isdatadescriptor, '__builtin__.file.softspace') -test(inspect.isroutine(mod.spam), 'isroutine(mod.spam)') -test(inspect.isroutine([].count), 'isroutine([].count)') + def __init__(self, *args, **kwargs): + unittest.TestCase.__init__(self, *args, **kwargs) -classes = inspect.getmembers(mod, inspect.isclass) -test(classes == - [('FesteringGob', mod.FesteringGob), - ('MalodorousPervert', mod.MalodorousPervert), - ('ParrotDroppings', mod.ParrotDroppings), - ('StupidGit', mod.StupidGit)], 'class list') -tree = inspect.getclasstree(map(lambda x: x[1], classes), 1) -test(tree == - [(mod.ParrotDroppings, ()), - (mod.StupidGit, ()), - [(mod.MalodorousPervert, (mod.StupidGit,)), - [(mod.FesteringGob, (mod.MalodorousPervert, mod.ParrotDroppings)) - ] - ] - ], 'class tree') + self.source = file(inspect.getsourcefile(self.fodderFile)).read() -functions = inspect.getmembers(mod, inspect.isfunction) -test(functions == [('eggs', mod.eggs), ('spam', mod.spam)], 'function list') + def sourcerange(self, top, bottom): + lines = self.source.split("\n") + return "\n".join(lines[top-1:bottom]) + "\n" -test(inspect.getdoc(mod) == 'A module docstring.', 'getdoc(mod)') -test(inspect.getcomments(mod) == '# line 1\n', 'getcomments(mod)') -test(inspect.getmodule(mod.StupidGit) == mod, 'getmodule(mod.StupidGit)') -test(inspect.getfile(mod.StupidGit) == TESTFN, 'getfile(mod.StupidGit)') -test(inspect.getsourcefile(mod.spam) == TESTFN, 'getsourcefile(mod.spam)') -test(inspect.getsourcefile(git.abuse) == TESTFN, 'getsourcefile(git.abuse)') + def assertSourceEqual(self, obj, top, bottom): + self.assertEqual(inspect.getsource(obj), + self.sourcerange(top, bottom)) -def sourcerange(top, bottom): - lines = string.split(source, '\n') - return string.join(lines[top-1:bottom], '\n') + '\n' +class TestRetrievingSourceCode(GetSourceBase): + fodderFile = mod -test(inspect.getsource(git.abuse) == sourcerange(29, 39), - 'getsource(git.abuse)') -test(inspect.getsource(mod.StupidGit) == sourcerange(21, 46), - 'getsource(mod.StupidGit)') -test(inspect.getdoc(mod.StupidGit) == - 'A longer,\n\nindented\n\ndocstring.', 'getdoc(mod.StupidGit)') -test(inspect.getdoc(git.abuse) == - 'Another\n\ndocstring\n\ncontaining\n\ntabs', 'getdoc(git.abuse)') -test(inspect.getcomments(mod.StupidGit) == '# line 20\n', - 'getcomments(mod.StupidGit)') + def test_getclasses(self): + classes = inspect.getmembers(mod, inspect.isclass) + self.assertEqual(classes, + [('FesteringGob', mod.FesteringGob), + ('MalodorousPervert', mod.MalodorousPervert), + ('ParrotDroppings', mod.ParrotDroppings), + ('StupidGit', mod.StupidGit)]) + tree = inspect.getclasstree([cls[1] for cls in classes], 1) + self.assertEqual(tree, + [(mod.ParrotDroppings, ()), + (mod.StupidGit, ()), + [(mod.MalodorousPervert, (mod.StupidGit,)), + [(mod.FesteringGob, (mod.MalodorousPervert, + mod.ParrotDroppings)) + ] + ] + ]) -git.abuse(7, 8, 9) + def test_getfunctions(self): + functions = inspect.getmembers(mod, inspect.isfunction) + self.assertEqual(functions, [('eggs', mod.eggs), + ('spam', mod.spam)]) -istest(inspect.istraceback, 'git.ex[2]') -istest(inspect.isframe, 'mod.fr') + def test_getdoc(self): + self.assertEqual(inspect.getdoc(mod), 'A module docstring.') + self.assertEqual(inspect.getdoc(mod.StupidGit), + 'A longer,\n\nindented\n\ndocstring.') + self.assertEqual(inspect.getdoc(git.abuse), + 'Another\n\ndocstring\n\ncontaining\n\ntabs') -test(len(git.tr) == 3, 'trace() length') -test(git.tr[0][1:] == (TESTFN, 43, 'argue', - [' spam(a, b, c)\n'], 0), - 'trace() row 2') -test(git.tr[1][1:] == (TESTFN, 9, 'spam', [' eggs(b + d, c + f)\n'], 0), - 'trace() row 2') -test(git.tr[2][1:] == (TESTFN, 18, 'eggs', [' q = y / 0\n'], 0), - 'trace() row 3') + def test_getcomments(self): + self.assertEqual(inspect.getcomments(mod), '# line 1\n') + self.assertEqual(inspect.getcomments(mod.StupidGit), '# line 20\n') -test(len(mod.st) >= 5, 'stack() length') -test(mod.st[0][1:] == - (TESTFN, 16, 'eggs', [' st = inspect.stack()\n'], 0), - 'stack() row 1') -test(mod.st[1][1:] == - (TESTFN, 9, 'spam', [' eggs(b + d, c + f)\n'], 0), - 'stack() row 2') -test(mod.st[2][1:] == - (TESTFN, 43, 'argue', [' spam(a, b, c)\n'], 0), - 'stack() row 3') -test(mod.st[3][1:] == - (TESTFN, 39, 'abuse', [' self.argue(a, b, c)\n'], 0), - 'stack() row 4') + def test_getmodule(self): + # Check actual module + self.assertEqual(inspect.getmodule(mod), mod) + # Check class (uses __module__ attribute) + self.assertEqual(inspect.getmodule(mod.StupidGit), mod) + # Check a method (no __module__ attribute, falls back to filename) + self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod) + # Do it again (check the caching isn't broken) + self.assertEqual(inspect.getmodule(mod.StupidGit.abuse), mod) + # Check a builtin + self.assertEqual(inspect.getmodule(str), sys.modules["__builtin__"]) + # Check filename override + self.assertEqual(inspect.getmodule(None, modfile), mod) -args, varargs, varkw, locals = inspect.getargvalues(mod.fr) -test(args == ['x', 'y'], 'mod.fr args') -test(varargs == None, 'mod.fr varargs') -test(varkw == None, 'mod.fr varkw') -test(locals == {'x': 11, 'p': 11, 'y': 14}, 'mod.fr locals') -test(inspect.formatargvalues(args, varargs, varkw, locals) == - '(x=11, y=14)', 'mod.fr formatted argvalues') + def test_getsource(self): + self.assertSourceEqual(git.abuse, 29, 39) + self.assertSourceEqual(mod.StupidGit, 21, 46) -if not is_jython: - # Jython can't handle this without co_code - args, varargs, varkw, locals = inspect.getargvalues(mod.fr.f_back) - test(args == ['a', 'b', 'c', 'd', ['e', ['f']]], 'mod.fr.f_back args') - test(varargs == 'g', 'mod.fr.f_back varargs') - test(varkw == 'h', 'mod.fr.f_back varkw') - test(inspect.formatargvalues(args, varargs, varkw, locals) == - '(a=7, b=8, c=9, d=3, (e=4, (f=5,)), *g=(), **h={})', - 'mod.fr.f_back formatted argvalues') + def test_getsourcefile(self): + self.assertEqual(inspect.getsourcefile(mod.spam), modfile) + self.assertEqual(inspect.getsourcefile(git.abuse), modfile) -for fname in files_to_clean_up: - try: - os.unlink(fname) - except: - pass + def test_getfile(self): + self.assertEqual(inspect.getfile(mod.StupidGit), mod.__file__) -# Test classic-class method resolution order. -class A: pass -class B(A): pass -class C(A): pass -class D(B, C): pass + def test_getmodule_recursion(self): + from new import module + name = '__inspect_dummy' + m = sys.modules[name] = module(name) + m.__file__ = "<string>" # hopefully not a real filename... + m.__loader__ = "dummy" # pretend the filename is understood by a loader + exec "def x(): pass" in m.__dict__ + self.assertEqual(inspect.getsourcefile(m.x.func_code), '<string>') + del sys.modules[name] + inspect.getmodule(compile('a=10','','single')) -expected = (D, B, A, C) -got = inspect.getmro(D) -test(expected == got, "expected %r mro, got %r", expected, got) +class TestDecorators(GetSourceBase): + fodderFile = mod2 -# The same w/ new-class MRO. -class A(object): pass -class B(A): pass -class C(A): pass -class D(B, C): pass + def test_wrapped_decorator(self): + self.assertSourceEqual(mod2.wrapped, 14, 17) -expected = (D, B, C, A, object) -got = inspect.getmro(D) -test(expected == got, "expected %r mro, got %r", expected, got) + def test_replacing_decorator(self): + self.assertSourceEqual(mod2.gone, 9, 10) -# Test classify_class_attrs. +class TestOneliners(GetSourceBase): + fodderFile = mod2 + def test_oneline_lambda(self): + # Test inspect.getsource with a one-line lambda function. + self.assertSourceEqual(mod2.oll, 25, 25) + + def test_threeline_lambda(self): + # Test inspect.getsource with a three-line lambda function, + # where the second and third lines are _not_ indented. + self.assertSourceEqual(mod2.tll, 28, 30) + + def test_twoline_indented_lambda(self): + # Test inspect.getsource with a two-line lambda function, + # where the second line _is_ indented. + self.assertSourceEqual(mod2.tlli, 33, 34) + + def test_onelinefunc(self): + # Test inspect.getsource with a regular one-line function. + self.assertSourceEqual(mod2.onelinefunc, 37, 37) + + def test_manyargs(self): + # Test inspect.getsource with a regular function where + # the arguments are on two lines and _not_ indented and + # the body on the second line with the last arguments. + self.assertSourceEqual(mod2.manyargs, 40, 41) + + def test_twolinefunc(self): + # Test inspect.getsource with a regular function where + # the body is on two lines, following the argument list and + # continued on the next line by a \\. + self.assertSourceEqual(mod2.twolinefunc, 44, 45) + + def test_lambda_in_list(self): + # Test inspect.getsource with a one-line lambda function + # defined in a list, indented. + self.assertSourceEqual(mod2.a[1], 49, 49) + + def test_anonymous(self): + # Test inspect.getsource with a lambda function defined + # as argument to another function. + self.assertSourceEqual(mod2.anonymous, 55, 55) + +class TestBuggyCases(GetSourceBase): + fodderFile = mod2 + + def test_with_comment(self): + self.assertSourceEqual(mod2.with_comment, 58, 59) + + def test_multiline_sig(self): + self.assertSourceEqual(mod2.multiline_sig[0], 63, 64) + + def test_nested_class(self): + self.assertSourceEqual(mod2.func69().func71, 71, 72) + + def test_one_liner_followed_by_non_name(self): + self.assertSourceEqual(mod2.func77, 77, 77) + + def test_one_liner_dedent_non_name(self): + self.assertSourceEqual(mod2.cls82.func83, 83, 83) + + def test_with_comment_instead_of_docstring(self): + self.assertSourceEqual(mod2.func88, 88, 90) + + def test_method_in_dynamic_class(self): + self.assertSourceEqual(mod2.method_in_dynamic_class, 95, 97) + +# Helper for testing classify_class_attrs. def attrs_wo_objs(cls): return [t[:3] for t in inspect.classify_class_attrs(cls)] -class A: - def s(): pass - s = staticmethod(s) +class TestClassesAndFunctions(unittest.TestCase): + def test_classic_mro(self): + # Test classic-class method resolution order. + class A: pass + class B(A): pass + class C(A): pass + class D(B, C): pass - def c(cls): pass - c = classmethod(c) + expected = (D, B, A, C) + got = inspect.getmro(D) + self.assertEqual(expected, got) - def getp(self): pass - p = property(getp) + def test_newstyle_mro(self): + # The same w/ new-class MRO. + class A(object): pass + class B(A): pass + class C(A): pass + class D(B, C): pass - def m(self): pass + expected = (D, B, C, A, object) + got = inspect.getmro(D) + self.assertEqual(expected, got) - def m1(self): pass + def assertArgSpecEquals(self, routine, args_e, varargs_e = None, + varkw_e = None, defaults_e = None, + formatted = None): + args, varargs, varkw, defaults = inspect.getargspec(routine) + self.assertEqual(args, args_e) + self.assertEqual(varargs, varargs_e) + self.assertEqual(varkw, varkw_e) + self.assertEqual(defaults, defaults_e) + if formatted is not None: + self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults), + formatted) - datablob = '1' + def test_getargspec(self): + self.assertArgSpecEquals(mod.eggs, ['x', 'y'], formatted = '(x, y)') -attrs = attrs_wo_objs(A) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'class method', A) in attrs, 'missing class method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', A) in attrs, 'missing plain method') -test(('m1', 'method', A) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + self.assertArgSpecEquals(mod.spam, + ['a', 'b', 'c', 'd', ['e', ['f']]], + 'g', 'h', (3, (4, (5,))), + '(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)') -class B(A): - def m(self): pass + def test_getargspec_method(self): + class A(object): + def m(self): + pass + self.assertArgSpecEquals(A.m, ['self']) -attrs = attrs_wo_objs(B) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'class method', A) in attrs, 'missing class method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', B) in attrs, 'missing plain method') -test(('m1', 'method', A) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + def test_getargspec_sublistofone(self): + def sublistOfOne((foo,)): return 1 + self.assertArgSpecEquals(sublistOfOne, [['foo']]) + def fakeSublistOfOne((foo)): return 1 + self.assertArgSpecEquals(fakeSublistOfOne, ['foo']) -class C(A): - def m(self): pass - def c(self): pass + def test_classify_oldstyle(self): + class A: + def s(): pass + s = staticmethod(s) -attrs = attrs_wo_objs(C) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'method', C) in attrs, 'missing plain method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', C) in attrs, 'missing plain method') -test(('m1', 'method', A) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + def c(cls): pass + c = classmethod(c) -class D(B, C): - def m1(self): pass + def getp(self): pass + p = property(getp) -attrs = attrs_wo_objs(D) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'class method', A) in attrs, 'missing class method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', B) in attrs, 'missing plain method') -test(('m1', 'method', D) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + def m(self): pass -# Repeat all that, but w/ new-style classes. + def m1(self): pass -class A(object): + datablob = '1' - def s(): pass - s = staticmethod(s) + attrs = attrs_wo_objs(A) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'class method', A) in attrs, 'missing class method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', A) in attrs, 'missing plain method') + self.assert_(('m1', 'method', A) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') - def c(cls): pass - c = classmethod(c) + class B(A): + def m(self): pass - def getp(self): pass - p = property(getp) + attrs = attrs_wo_objs(B) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'class method', A) in attrs, 'missing class method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', B) in attrs, 'missing plain method') + self.assert_(('m1', 'method', A) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') - def m(self): pass - def m1(self): pass + class C(A): + def m(self): pass + def c(self): pass - datablob = '1' + attrs = attrs_wo_objs(C) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'method', C) in attrs, 'missing plain method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', C) in attrs, 'missing plain method') + self.assert_(('m1', 'method', A) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') -attrs = attrs_wo_objs(A) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'class method', A) in attrs, 'missing class method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', A) in attrs, 'missing plain method') -test(('m1', 'method', A) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + class D(B, C): + def m1(self): pass -class B(A): + attrs = attrs_wo_objs(D) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'class method', A) in attrs, 'missing class method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', B) in attrs, 'missing plain method') + self.assert_(('m1', 'method', D) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') - def m(self): pass + # Repeat all that, but w/ new-style classes. + def test_classify_newstyle(self): + class A(object): -attrs = attrs_wo_objs(B) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'class method', A) in attrs, 'missing class method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', B) in attrs, 'missing plain method') -test(('m1', 'method', A) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + def s(): pass + s = staticmethod(s) + def c(cls): pass + c = classmethod(c) -class C(A): + def getp(self): pass + p = property(getp) - def m(self): pass - def c(self): pass + def m(self): pass -attrs = attrs_wo_objs(C) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'method', C) in attrs, 'missing plain method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', C) in attrs, 'missing plain method') -test(('m1', 'method', A) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + def m1(self): pass -class D(B, C): + datablob = '1' - def m1(self): pass + attrs = attrs_wo_objs(A) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'class method', A) in attrs, 'missing class method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', A) in attrs, 'missing plain method') + self.assert_(('m1', 'method', A) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') -attrs = attrs_wo_objs(D) -test(('s', 'static method', A) in attrs, 'missing static method') -test(('c', 'method', C) in attrs, 'missing plain method') -test(('p', 'property', A) in attrs, 'missing property') -test(('m', 'method', B) in attrs, 'missing plain method') -test(('m1', 'method', D) in attrs, 'missing plain method') -test(('datablob', 'data', A) in attrs, 'missing data') + class B(A): -args, varargs, varkw, defaults = inspect.getargspec(mod.eggs) -test(args == ['x', 'y'], 'mod.eggs args') -test(varargs == None, 'mod.eggs varargs') -test(varkw == None, 'mod.eggs varkw') -test(defaults == None, 'mod.eggs defaults') -test(inspect.formatargspec(args, varargs, varkw, defaults) == - '(x, y)', 'mod.eggs formatted argspec') -if not is_jython: - # Jython can't handle this without co_code - args, varargs, varkw, defaults = inspect.getargspec(mod.spam) - test(args == ['a', 'b', 'c', 'd', ['e', ['f']]], 'mod.spam args') - test(varargs == 'g', 'mod.spam varargs') - test(varkw == 'h', 'mod.spam varkw') - test(defaults == (3, (4, (5,))), 'mod.spam defaults') - test(inspect.formatargspec(args, varargs, varkw, defaults) == - '(a, b, c, d=3, (e, (f,))=(4, (5,)), *g, **h)', - 'mod.spam formatted argspec') -args, varargs, varkw, defaults = inspect.getargspec(A.m) -test(args == ['self'], 'A.m args') -test(varargs is None, 'A.m varargs') -test(varkw is None, 'A.m varkw') -test(defaults is None, 'A.m defaults') + def m(self): pass -# Doc/lib/libinspect.tex claims there are 11 such functions -count = len(filter(lambda x:x.startswith('is'), dir(inspect))) -test(count == 11, "There are %d (not 11) is* functions", count) + attrs = attrs_wo_objs(B) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'class method', A) in attrs, 'missing class method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', B) in attrs, 'missing plain method') + self.assert_(('m1', 'method', A) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') -def sublistOfOne((foo)): return 1 -args, varargs, varkw, defaults = inspect.getargspec(sublistOfOne) -if not is_jython: - # Jython can't handle this without co_code - test(args == [['foo']], 'sublistOfOne args') -test(varargs is None, 'sublistOfOne varargs') -test(varkw is None, 'sublistOfOne varkw') -test(defaults is None, 'sublistOfOn defaults') + class C(A): + + def m(self): pass + def c(self): pass + + attrs = attrs_wo_objs(C) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'method', C) in attrs, 'missing plain method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', C) in attrs, 'missing plain method') + self.assert_(('m1', 'method', A) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') + + class D(B, C): + + def m1(self): pass + + attrs = attrs_wo_objs(D) + self.assert_(('s', 'static method', A) in attrs, 'missing static method') + self.assert_(('c', 'method', C) in attrs, 'missing plain method') + self.assert_(('p', 'property', A) in attrs, 'missing property') + self.assert_(('m', 'method', B) in attrs, 'missing plain method') + self.assert_(('m1', 'method', D) in attrs, 'missing plain method') + self.assert_(('datablob', 'data', A) in attrs, 'missing data') + +def test_main(): + run_unittest(TestDecorators, TestRetrievingSourceCode, TestOneliners, + TestBuggyCases, + TestInterpreterStack, TestClassesAndFunctions, TestPredicates) + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-07-28 11:51:53
|
Revision: 5009 http://jython.svn.sourceforge.net/jython/?rev=5009&view=rev Author: zyasoft Date: 2008-07-28 11:51:51 +0000 (Mon, 28 Jul 2008) Log Message: ----------- test__rawffi will now skip if it cannot load ctypes_test, a test dynamic library that we do not yet have an ant task to create. Modified Paths: -------------- branches/asm/Lib/test/test__rawffi.py Modified: branches/asm/Lib/test/test__rawffi.py =================================================================== --- branches/asm/Lib/test/test__rawffi.py 2008-07-28 06:40:09 UTC (rev 5008) +++ branches/asm/Lib/test/test__rawffi.py 2008-07-28 11:51:51 UTC (rev 5009) @@ -1,6 +1,14 @@ import unittest from test import test_support +# xxx - forces a skip in the case we haven't built ctypes_test module in ant (which is not yet a task as of now) + +try: + import _rawffi + _rawffi.CDLL("ctypes_test") +except: + raise ImportError + class RawFFITestCase(unittest.TestCase): def setUp(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-28 06:40:14
|
Revision: 5008 http://jython.svn.sourceforge.net/jython/?rev=5008&view=rev Author: pjenvey Date: 2008-07-28 06:40:09 +0000 (Mon, 28 Jul 2008) Log Message: ----------- deriveds changes for __index__ Modified Paths: -------------- branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBaseExceptionDerived.java branches/asm/src/org/python/core/PyBooleanDerived.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/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyModuleDerived.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/PySuperDerived.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.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/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyBaseExceptionDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyBaseExceptionDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom @@ -867,29 +881,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1029,6 +1057,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -881,29 +881,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1043,6 +1057,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PySetDerived.java =================================================================== --- branches/asm/src/org/python/core/PySetDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PySetDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PySliceDerived.java =================================================================== --- branches/asm/src/org/python/core/PySliceDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PySliceDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PyStringDerived.java =================================================================== --- branches/asm/src/org/python/core/PyStringDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PyStringDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); return; } super.__delslice__(start,stop,step); @@ -1067,6 +1081,19 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the Modified: branches/asm/src/org/python/core/PySuperDerived.java =================================================================== --- branches/asm/src/org/python/core/PySuperDerived.java 2008-07-28 06:38:44 UTC (rev 5007) +++ branches/asm/src/org/python/core/PySuperDerived.java 2008-07-28 06:40:09 UTC (rev 5008) @@ -905,29 +905,43 @@ } public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } PyType self_type=getType(); PyObject impl=self_type.lookup("__getslice__"); if (impl!=null) { - return impl.__get__(this,self_type).__call__(start,stop); + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); } return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__setslice__"); if (impl!=null) { - impl.__get__(this,self_type).__call__(start,stop,value); + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); return; } super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } PyType self_type=getType(); PyObject impl=self_type.lookup("__delslice__"); if (impl!=null) { - impl.__get_... [truncated message content] |
From: <pj...@us...> - 2008-07-28 06:38:48
|
Revision: 5007 http://jython.svn.sourceforge.net/jython/?rev=5007&view=rev Author: pjenvey Date: 2008-07-28 06:38:44 +0000 (Mon, 28 Jul 2008) Log Message: ----------- PEP 357 (__index__), adds: o PyObject.isIndex - true if int, long or implements __index__ o PyObject.asIndex - like asInt for indexes o also fixed a dispatching to __get/set/delitem__ vs __get/set/delslice__ bug and __get/set/delitem__ indices weren't utilizing __len__ when available (fixes test_userstring) Modified Paths: -------------- branches/asm/src/org/python/core/PyArray.java branches/asm/src/org/python/core/PyInstance.java branches/asm/src/org/python/core/PyInteger.java branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PyLong.java branches/asm/src/org/python/core/PyObject.java branches/asm/src/org/python/core/PySequence.java branches/asm/src/org/python/core/PySlice.java branches/asm/src/org/python/core/PyString.java branches/asm/src/org/python/core/PyTuple.java branches/asm/src/org/python/modules/collections/PyDeque.java branches/asm/src/org/python/modules/operator.java branches/asm/src/templates/object.derived Modified: branches/asm/src/org/python/core/PyArray.java =================================================================== --- branches/asm/src/org/python/core/PyArray.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyArray.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -252,11 +252,11 @@ @ExposedMethod(type = MethodType.BINARY) final PyObject array___imul__(PyObject o) { - if(!(o instanceof PyInteger || o instanceof PyLong)) { + if (!o.isIndex()) { return null; } if (delegate.getSize() > 0) { - int count = o.asInt(); + int count = o.asIndex(Py.OverflowError); if (count <= 0) { delegate.clear(); return this; @@ -276,10 +276,10 @@ @ExposedMethod(type = MethodType.BINARY) final PyObject array___mul__(PyObject o) { - if(!(o instanceof PyInteger || o instanceof PyLong)) { + if (!o.isIndex()) { return null; } - return repeat(o.asInt()); + return repeat(o.asIndex(Py.OverflowError)); } public PyObject __rmul__(PyObject o) { @@ -288,10 +288,10 @@ @ExposedMethod(type = MethodType.BINARY) final PyObject array___rmul__(PyObject o) { - if(!(o instanceof PyInteger || o instanceof PyLong)) { + if (!o.isIndex()) { return null; } - return repeat(o.asInt()); + return repeat(o.asIndex(Py.OverflowError)); } public PyObject __iadd__(PyObject other) { Modified: branches/asm/src/org/python/core/PyInstance.java =================================================================== --- branches/asm/src/org/python/core/PyInstance.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyInstance.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -246,6 +246,11 @@ return __findattr__("__call__") != null; } + @Override + public boolean isIndex() { + return __findattr__("__index__") != null; + } + public PyObject invoke(String name) { PyObject f = ifindlocal(name); if (f == null) { @@ -582,34 +587,20 @@ return __finditem__(new PyInteger(key)); } - private PyObject trySlice(PyObject key, String name, PyObject extraArg) { - if (!(key instanceof PySlice)) - return null; + private PyObject trySlice(String name, PyObject start, PyObject stop) { + return trySlice(name, start, stop, null); + } - PySlice slice = (PySlice)key; - - if (slice.getStep() != Py.None && slice.getStep() != Py.One) { - if (slice.getStep() instanceof PyInteger) { - if (((PyInteger)slice.getStep()).getValue() != 1) { - return null; - } - } else { - return null; - } - } - + private PyObject trySlice(String name, PyObject start, PyObject stop, PyObject extraArg) { PyObject func = __findattr__(name); - if (func == null) + if (func == null) { return null; + } - PyObject start = slice.start; - PyObject stop = slice.stop; + PyObject[] indices = PySlice.indices2(this, start, stop); + start = indices[0]; + stop = indices[1]; - if (start == Py.None) - start = Py.Zero; - if (stop == Py.None) - stop = new PyInteger(PySystemState.maxint); - if (extraArg == null) { return func.__call__(start, stop); } else { @@ -624,10 +615,6 @@ } try { - PyObject ret = trySlice(key, "__getslice__", null); - if (ret != null) - return ret; - return invoke("__getitem__", key); } catch (PyException e) { if (Py.matchException(e, Py.IndexError)) @@ -647,11 +634,6 @@ } return ret; } - - PyObject ret = trySlice(key, "__getslice__", null); - if (ret != null) - return ret; - return invoke("__getitem__", key); } @@ -661,9 +643,6 @@ proxy.__setitem__(key, value); return; } - if (trySlice(key, "__setslice__", value) != null) - return; - invoke("__setitem__", key, value); } @@ -673,11 +652,36 @@ proxy.__delitem__(key); return; } - if (trySlice(key, "__delslice__", null) != null) - return; invoke("__delitem__", key); } + public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) { + if (step != null) { + return __getitem__(new PySlice(start, stop, step)); + } + PyObject ret = trySlice("__getslice__", start, stop); + if (ret != null) { + return ret; + } + return super.__getslice__(start, stop, step); + } + + public void __setslice__(PyObject start, PyObject stop, PyObject step, PyObject value) { + if (step != null) { + __setitem__(new PySlice(start, stop, step), value); + } else if (trySlice("__setslice__", start, stop, value) == null) { + super.__setslice__(start, stop, step, value); + } + } + + public void __delslice__(PyObject start, PyObject stop, PyObject step) { + if (step != null) { + __delitem__(new PySlice(start, stop, step)); + } else if (trySlice("__delslice__", start, stop) == null) { + super.__delslice__(start, stop, step); + } + } + public PyObject __iter__() { PyObject iter = getCollectionIter(); if (iter != null) { @@ -858,6 +862,27 @@ return invoke("__invert__"); } + /** + * Implements the __index__ method by looking it up + * in the instance's dictionary and calling it if it is found. + **/ + public PyObject __index__() { + PyObject ret; + try { + ret = invoke("__index__"); + } catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) { + throw pye; + } + throw Py.TypeError("object cannot be interpreted as an index"); + } + if (ret instanceof PyInteger || ret instanceof PyLong) { + return ret; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)", + ret.getType().fastGetName())); + } + // Binary ops /** Modified: branches/asm/src/org/python/core/PyInteger.java =================================================================== --- branches/asm/src/org/python/core/PyInteger.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyInteger.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -805,6 +805,26 @@ return int___getnewargs__(); } + @Override + public PyObject __index__() { + return int___index__(); + } + + @ExposedMethod + final PyObject int___index__() { + return this; + } + + @Override + public boolean isIndex() { + return true; + } + + @Override + public int asIndex(PyObject err) { + return getValue(); + } + public boolean isMappingType() { return false; } public boolean isSequenceType() { return false; } Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyList.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -267,11 +267,12 @@ @ExposedMethod(type = MethodType.BINARY) final PyObject list___imul__(PyObject o) { - if(!(o instanceof PyInteger || o instanceof PyLong)) { + if (!o.isIndex()) { return null; } + int count = o.asIndex(Py.OverflowError); int l = size(); - int count = ((PyInteger)o.__int__()).getValue(); + int newSize = l * count; list.setSize(newSize); PyObject[] array = getArray(); @@ -282,22 +283,30 @@ return this; } + @Override + public PyObject __mul__(PyObject o) { + return list___mul__(o); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject list___mul__(PyObject o) { - if(!(o instanceof PyInteger || o instanceof PyLong)) { + if (!o.isIndex()) { return null; } - int count = ((PyInteger)o.__int__()).getValue(); - return repeat(count); + return repeat(o.asIndex(Py.OverflowError)); } + @Override + public PyObject __rmul__(PyObject o) { + return list___rmul__(o); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject list___rmul__(PyObject o) { - if(!(o instanceof PyInteger || o instanceof PyLong)) { + if (!o.isIndex()) { return null; } - int count = ((PyInteger)o.__int__()).getValue(); - return repeat(count); + return repeat(o.asIndex(Py.OverflowError)); } public PyObject __add__(PyObject o) { Modified: branches/asm/src/org/python/core/PyLong.java =================================================================== --- branches/asm/src/org/python/core/PyLong.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyLong.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -836,7 +836,34 @@ return long___getnewargs__(); } + @Override + public PyObject __index__() { + return long___index__(); + } + @ExposedMethod + final PyObject long___index__() { + return this; + } + + @Override + public boolean isIndex() { + return true; + } + + @Override + public int asIndex(PyObject err) { + boolean tooLow = value.compareTo(PyInteger.minInt) < 0; + boolean tooHigh = value.compareTo(PyInteger.maxInt) > 0; + if (tooLow || tooHigh) { + if (err != null) { + throw new PyException(err, "cannot fit 'long' into an index-sized integer"); + } + return tooLow ? Integer.MIN_VALUE : Integer.MAX_VALUE; + } + return (int)value.longValue(); + } + public boolean isMappingType() { return false; } public boolean isSequenceType() { return false; } Modified: branches/asm/src/org/python/core/PyObject.java =================================================================== --- branches/asm/src/org/python/core/PyObject.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyObject.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -418,6 +418,15 @@ return true; } + /** + * Determine if this object can act as an index (implements __index__). + * + * @return true if the object can act as an index + */ + public boolean isIndex() { + return getType().lookup("__index__") != null; + } + /* The basic functions to implement a mapping */ /** @@ -1588,6 +1597,17 @@ public PyObject __invert__() { throw Py.AttributeError("__invert__"); } + + /** + * Equivalent to the standard Python __index__ method. + * + * @return a PyInteger or PyLong + * @throws a Py.TypeError if not supported + **/ + public PyObject __index__() { + throw Py.TypeError(String.format("'%.200s' object cannot be interpreted as an index", + getType().fastGetName())); + } /** * @param op the String form of the op (e.g. "+") @@ -3775,7 +3795,29 @@ public long asLong(int index) throws ConversionException { throw new ConversionException(index); } - + + /** + * Coerce this object into an index-sized integer. + * + * @return an index-sized int + */ + public int asIndex() { + return asIndex(null); + } + + /** + * Coerce this object into an index-sized integer. + * + * Throws a Python exception on Overflow if specified an exception type for err. + * + * @param err the Python exception to raise on OverflowErrors + * @return an index-sized int + */ + public int asIndex(PyObject err) { + // OverflowErrors are handled in PyLong.asIndex + return __index__().asInt(); + } + static { for (Class unbootstrapped : Py.BOOTSTRAP_TYPES) { Py.writeWarning("init", "Bootstrap type wasn't encountered in bootstrapping[class=" Modified: branches/asm/src/org/python/core/PySequence.java =================================================================== --- branches/asm/src/org/python/core/PySequence.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PySequence.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -288,11 +288,11 @@ } final PyObject seq___finditem__(PyObject index) { - if(index instanceof PyInteger || index instanceof PyLong) { - return seq___finditem__(index.asInt()); - } else if(index instanceof PySlice) { + if (index.isIndex()) { + return seq___finditem__(index.asIndex(Py.IndexError)); + } else if (index instanceof PySlice) { PySlice s = (PySlice)index; - return __getslice__(s.start, s.stop, s.step); + return seq___getslice__(s.start, s.stop, s.step); } else { throw Py.TypeError(getType().fastGetName() + " indices must be integers"); } @@ -360,6 +360,10 @@ } public synchronized void __setitem__(int index, PyObject value) { + seq___setitem__(index, value); + } + + final synchronized void seq___setitem__(int index, PyObject value) { int i = fixindex(index); if(i == -1) { throw Py.IndexError(getType().fastGetName() + " assignment index out of range"); @@ -372,11 +376,11 @@ } final void seq___setitem__(PyObject index, PyObject value) { - if(index instanceof PyInteger || index instanceof PyLong) { - __setitem__(index.asInt(), value); - } else if(index instanceof PySlice) { + if (index.isIndex()) { + seq___setitem__(index.asIndex(Py.IndexError), value); + } else if (index instanceof PySlice) { PySlice s = (PySlice)index; - __setslice__(s.start, s.stop, s.step, value); + seq___setslice__(s.start, s.stop, s.step, value); } else { throw Py.TypeError(getType().fastGetName() + " indices must be integers"); } @@ -387,15 +391,15 @@ } final synchronized void seq___delitem__(PyObject index) { - if(index instanceof PyInteger || index instanceof PyLong) { - int i = fixindex(index.asInt()); - if(i == -1) { + if (index.isIndex()) { + int i = fixindex(index.asIndex(Py.IndexError)); + if (i == -1) { throw Py.IndexError(getType().fastGetName() + " assignment index out of range"); } del(i); - } else if(index instanceof PySlice) { + } else if (index instanceof PySlice) { PySlice s = (PySlice)index; - __delslice__(s.start, s.stop, s.step); + seq___delslice__(s.start, s.stop, s.step); } else { throw Py.TypeError(getType().fastGetName() + " indices must be integers"); } Modified: branches/asm/src/org/python/core/PySlice.java =================================================================== --- branches/asm/src/org/python/core/PySlice.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PySlice.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -114,13 +114,7 @@ @ExposedMethod public PyObject slice_indices(PyObject len) { - int ilen; - try { - ilen = len.asInt(0); - } catch(ConversionException e) { - throw Py.TypeError("length must be an int"); - } - int[] slice = indices(ilen); + 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]); @@ -128,23 +122,11 @@ return new PyTuple(pyInts); } - private static int calculateSliceIndex(PyObject v) { - if(v instanceof PyInteger) { - return ((PyInteger)v).getValue(); - } else if(v instanceof PyLong) { - try { - return v.asInt(); - } catch (PyException exc) { - if (Py.matchException(exc, Py.OverflowError)) { - if (new PyLong(0L).__cmp__(v) < 0) { - return Integer.MAX_VALUE; - }else { - return 0; - } - } - } + public static int calculateSliceIndex(PyObject v) { + if (v.isIndex()) { + return v.asIndex(); } - throw Py.TypeError("slice indices must be integers or None"); + throw Py.TypeError("slice indices must be integers or None or have an __index__ method"); } /** @@ -195,6 +177,39 @@ } return slice; } + + /** + * Calculate indices for the deprecated __get/set/delslice__ methods. + * + * @param obj the object being sliced + * @param start the slice operation's start + * @param stop the slice operation's stop + * @return an array with start at index 0 and stop at index 1 + */ + public static PyObject[] indices2(PyObject obj, PyObject start, PyObject stop) { + PyObject[] indices = new PyObject[2]; + int istart = start == null ? 0 : calculateSliceIndex(start); + int istop = stop == null ? PySystemState.maxint : calculateSliceIndex(stop); + if (istart < 0 || istop < 0) { + try { + int len = obj.__len__(); + if (istart < 0) { + istart += len; + } + if (istop < 0) { + istop += len; + } + } catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) { + throw pye; + } + } + } + indices[0] = Py.newInteger(istart); + indices[1] = Py.newInteger(istop); + return indices; + } + private static final int START = 0, STOP = 1, STEP = 2; @ExposedGet Modified: branches/asm/src/org/python/core/PyString.java =================================================================== --- branches/asm/src/org/python/core/PyString.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyString.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -673,20 +673,30 @@ return createInstance(new String(new_chars), true); } + @Override + public PyObject __mul__(PyObject o) { + return str___mul__(o); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject str___mul__(PyObject o) { - if (!(o instanceof PyInteger || o instanceof PyLong)) + if (!o.isIndex()) { return null; - int count = ((PyInteger)o.__int__()).getValue(); - return repeat(count); + } + return repeat(o.asIndex(Py.OverflowError)); } + @Override + public PyObject __rmul__(PyObject o) { + return str___rmul__(o); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject str___rmul__(PyObject o) { - if (!(o instanceof PyInteger || o instanceof PyLong)) + if (!o.isIndex()) { return null; - int count = ((PyInteger)o.__int__()).getValue(); - return repeat(count); + } + return repeat(o.asIndex(Py.OverflowError)); } public PyObject __add__(PyObject generic_other) { Modified: branches/asm/src/org/python/core/PyTuple.java =================================================================== --- branches/asm/src/org/python/core/PyTuple.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/core/PyTuple.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -175,20 +175,30 @@ return sum; } + @Override + public PyObject __mul__(PyObject o) { + return tuple___mul__(o); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject tuple___mul__(PyObject o) { - if (!(o instanceof PyInteger || o instanceof PyLong)) + if (!o.isIndex()) { return null; - int count = ((PyInteger)o.__int__()).getValue(); - return repeat(count); + } + return repeat(o.asIndex(Py.OverflowError)); } + @Override + public PyObject __rmul__(PyObject o) { + return tuple___rmul__(o); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject tuple___rmul__(PyObject o) { - if (!(o instanceof PyInteger || o instanceof PyLong)) + if (!o.isIndex()) { return null; - int count = ((PyInteger)o.__int__()).getValue(); - return repeat(count); + } + return repeat(o.asIndex(Py.OverflowError)); } public PyObject __iter__() { Modified: branches/asm/src/org/python/modules/collections/PyDeque.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDeque.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/modules/collections/PyDeque.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -296,11 +296,11 @@ private Node getNode(PyObject index) { int pos = 0; - if (index instanceof PyInteger || index instanceof PyLong) { - pos = ((PyInteger)index.__int__()).getValue(); - } else { - throw Py.TypeError("an integer is required"); + if (!index.isIndex()) { + throw Py.TypeError(String.format("sequence index must be integer, not '%.200s'", + index.getType().fastGetName())); } + pos = index.asIndex(Py.IndexError); if (pos < 0) { pos += size; Modified: branches/asm/src/org/python/modules/operator.java =================================================================== --- branches/asm/src/org/python/modules/operator.java 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/org/python/modules/operator.java 2008-07-28 06:38:44 UTC (rev 5007) @@ -31,6 +31,7 @@ case 18: return Py.newBoolean(arg1.isNumberType()); case 19: return Py.newBoolean(arg1.isSequenceType()); case 32: return arg1.__invert__(); + case 52: return arg1.__index__(); default: throw info.unexpectedCall(1, false); } @@ -253,6 +254,8 @@ dict.__setitem__("itruediv", new OperatorFunctions("itruediv", 50, 2)); dict.__setitem__("__ixor__", new OperatorFunctions("__ixor__", 51, 2)); dict.__setitem__("ixor", new OperatorFunctions("ixor", 51, 2)); + dict.__setitem__("__index__", new OperatorFunctions("__ixor__", 52, 1)); + dict.__setitem__("index", new OperatorFunctions("ixor", 52, 1)); dict.__setitem__("attrgetter", PyAttrGetter.TYPE); dict.__setitem__("itemgetter", PyItemGetter.TYPE); Modified: branches/asm/src/templates/object.derived =================================================================== --- branches/asm/src/templates/object.derived 2008-07-28 04:56:03 UTC (rev 5006) +++ branches/asm/src/templates/object.derived 2008-07-28 06:38:44 UTC (rev 5007) @@ -240,32 +240,46 @@ } public PyObject __getslice__(PyObject start, PyObject stop, PyObject step) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getslice__"); - if (impl!=null) { - return impl.__get__(this,self_type).__call__(start, stop); - } - return super.__getslice__(start, stop, step); + if (step != null) { + return __getitem__(new PySlice(start, stop, step)); + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getslice__"); + if (impl!=null) { + PyObject[] indices = PySlice.indices2(this, start, stop); + return impl.__get__(this,self_type).__call__(indices[0], indices[1]); + } + return super.__getslice__(start,stop,step); } public void __setslice__(PyObject start, PyObject stop, PyObject step, PyObject value) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setslice__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(start, stop, value); - return; - } - super.__setslice__(start, stop, step, value); + if (step != null) { + __setitem__(new PySlice(start, stop, step), value); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setslice__"); + if (impl!=null) { + PyObject[] indices = PySlice.indices2(this, start, stop); + impl.__get__(this,self_type).__call__(indices[0], indices[1], value); + return; + } + super.__setslice__(start,stop,step,value); } public void __delslice__(PyObject start,PyObject stop,PyObject step) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delslice__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(start, stop); - return; - } - super.__delslice__(start, stop, step); + if (step != null) { + __delitem__(new PySlice(start, stop, step)); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delslice__"); + if (impl!=null) { + PyObject[] indices = PySlice.indices2(this, start, stop); + impl.__get__(this,self_type).__call__(indices[0], indices[1]); + return; + } + super.__delslice__(start,stop,step); } public void __delitem__(PyObject key) { // ??? @@ -400,6 +414,20 @@ } } + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger || res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)", + res.getType().fastGetName())); + } + return super.__index__(); + } + public Object __tojava__(Class c) { // If we are not being asked by the "default" conversion to java, then // we can provide this as the result, as long as it is a instance of the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-28 04:56:05
|
Revision: 5006 http://jython.svn.sourceforge.net/jython/?rev=5006&view=rev Author: pjenvey Date: 2008-07-28 04:56:03 +0000 (Mon, 28 Jul 2008) Log Message: ----------- o add os.link (fixes test_shutil) o fix test_re's test output -- it shouldn't have any now Modified Paths: -------------- branches/asm/Lib/os.py Removed Paths: ------------- branches/asm/Lib/test/output/test_re Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-28 02:41:38 UTC (rev 5005) +++ branches/asm/Lib/os.py 2008-07-28 04:56:03 UTC (rev 5006) @@ -646,6 +646,13 @@ raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) if _name == 'posix' and _native_posix: + def link(src, dst): + """link(src, dst) + + Create a hard link to a file. + """ + _posix.link(sys.getPath(src), sys.getPath(dst)) + def symlink(src, dst): """symlink(src, dst) Deleted: branches/asm/Lib/test/output/test_re =================================================================== --- branches/asm/Lib/test/output/test_re 2008-07-28 02:41:38 UTC (rev 5005) +++ branches/asm/Lib/test/output/test_re 2008-07-28 04:56:03 UTC (rev 5006) @@ -1,15 +0,0 @@ -test_re -re (test_re.py) -basic functions -search -match -sub -symbolic references -subn -split -match.groups -match.group -escape -flags -symbolic groups in regex's -perl5-compatible regex's This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-28 02:41:40
|
Revision: 5005 http://jython.svn.sourceforge.net/jython/?rev=5005&view=rev Author: fwierzbicki Date: 2008-07-28 02:41:38 +0000 (Mon, 28 Jul 2008) Log Message: ----------- Better error messages in the face of parser errors (line numbers + char column). 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-07-27 13:21:12 UTC (rev 5004) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-07-28 02:41:38 UTC (rev 5005) @@ -40,8 +40,9 @@ private ParserFacade() {} static String getLine(BufferedReader reader, int line) { - if (reader == null) + if (reader == null) { return ""; + } try { String text=null; for(int i=0; i < line; i++) { @@ -68,8 +69,8 @@ if (t instanceof ParseException) { ParseException e = (ParseException)t; PythonTree node = (PythonTree)e.node; - int line=0; - int col=0; + int line=e.line; + int col=e.charPositionInLine; if (node != null) { line = node.getLine(); col = node.getCharPositionInLine(); @@ -103,7 +104,7 @@ try { if (kind.equals("eval")) { bufreader = prepBufreader(new LeadingSpaceSkippingStream(bstream), cflags, filename); - CharStream cs = new ANTLRReaderStream(bufreader); + CharStream cs = new NoCloseReaderStream(bufreader); ExpressionParser e = new ExpressionParser(cs); node = e.parse(); } else if (kind.equals("single")) { @@ -112,7 +113,7 @@ node = i.parse(); } else if (kind.equals("exec")) { bufreader = prepBufreader(bstream, cflags, filename); - CharStream cs = new ANTLRReaderStream(bufreader); + CharStream cs = new NoCloseReaderStream(bufreader); ModuleParser g = new ModuleParser(cs); node = g.file_input(); } else { @@ -120,6 +121,14 @@ } } catch (Throwable t) { throw fixParseError(bufreader, t, filename); + } finally { + try { + if (bufreader != null) { + bufreader.close(); + } + } catch (IOException i) { + //XXX + } } return node; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-27 13:21:17
|
Revision: 5004 http://jython.svn.sourceforge.net/jython/?rev=5004&view=rev Author: fwierzbicki Date: 2008-07-27 13:21:12 +0000 (Sun, 27 Jul 2008) Log Message: ----------- comment out DEBUG.class in the repo. Modified Paths: -------------- branches/asm/src/org/python/compiler/ClassFile.java Modified: branches/asm/src/org/python/compiler/ClassFile.java =================================================================== --- branches/asm/src/org/python/compiler/ClassFile.java 2008-07-26 14:41:46 UTC (rev 5003) +++ branches/asm/src/org/python/compiler/ClassFile.java 2008-07-27 13:21:12 UTC (rev 5004) @@ -118,7 +118,7 @@ ByteArrayOutputStream baos = new ByteArrayOutputStream(ba.length); baos.write(ba, 0, ba.length); baos.writeTo(stream); - debug(baos); + //debug(baos); baos.close(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-26 14:41:48
|
Revision: 5003 http://jython.svn.sourceforge.net/jython/?rev=5003&view=rev Author: fwierzbicki Date: 2008-07-26 14:41:46 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Changing comment convention back to proper style (start with Returns). Modified Paths: -------------- branches/asm/src/org/python/core/imp.java Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-07-26 01:55:04 UTC (rev 5002) +++ branches/asm/src/org/python/core/imp.java 2008-07-26 14:41:46 UTC (rev 5003) @@ -240,12 +240,12 @@ } /** - * createFromCode returns a module with the given name whose contents are - * the results of running c. Sets __file__ on the module to be - * moduleLocation unless moduleLocation is null. If c comes from a local - * .py file or compiled $py.class class moduleLocation should be the result - * of running new File(moduleLocation).getAbsoultePath(). If c comes from a - * remote file or is a jar moduleLocation should be the full uri for c. + * Returns a module with the given name whose contents are the results of + * running c. Sets __file__ on the module to be moduleLocation unless + * moduleLocation is null. If c comes from a local .py file or compiled + * $py.class class moduleLocation should be the result of running new + * File(moduleLocation).getAbsoultePath(). If c comes from a remote file or + * is a jar moduleLocation should be the full uri for c. */ public static PyObject createFromCode(String name, PyCode c, String moduleLocation) { PyModule module = addModule(name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-26 01:55:06
|
Revision: 5002 http://jython.svn.sourceforge.net/jython/?rev=5002&view=rev Author: fwierzbicki Date: 2008-07-26 01:55:04 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Removed stray System.outs. Modified Paths: -------------- branches/asm/src/org/python/core/PyClass.java branches/asm/src/org/python/core/PyString.java Modified: branches/asm/src/org/python/core/PyClass.java =================================================================== --- branches/asm/src/org/python/core/PyClass.java 2008-07-26 01:51:48 UTC (rev 5001) +++ branches/asm/src/org/python/core/PyClass.java 2008-07-26 01:55:04 UTC (rev 5002) @@ -162,14 +162,11 @@ for (java.util.Iterator iter = super__methods.entrySet().iterator(); iter .hasNext();) { java.util.Map.Entry entry = (java.util.Map.Entry) iter.next(); - // System.out.println(entry.getKey()); // debug entry.setValue(((java.util.ArrayList) entry.getValue()) .toArray(empty_methods)); } } - // System.out.println("proxyClasses: "+proxyClasses+", "+ - // proxyClasses[0]); if (dict.__finditem__("__doc__") == null) { dict.__setitem__("__doc__", Py.None); } @@ -186,7 +183,6 @@ protected void findModule(PyObject dict) { PyObject module = dict.__finditem__("__module__"); if (module == null || module == Py.None) { - // System.out.println("in PyClass getFrame: "+__name__.string); PyFrame f = Py.getFrame(); if (f != null) { PyObject nm = f.f_globals.__finditem__("__name__"); Modified: branches/asm/src/org/python/core/PyString.java =================================================================== --- branches/asm/src/org/python/core/PyString.java 2008-07-26 01:51:48 UTC (rev 5001) +++ branches/asm/src/org/python/core/PyString.java 2008-07-26 01:55:04 UTC (rev 5002) @@ -2739,7 +2739,6 @@ } c = pop(); if (c == '(') { - //System.out.println("( found"); if (dict == null) throw Py.TypeError("format requires a mapping"); int parens = 1; @@ -2753,7 +2752,6 @@ } String tmp = format.substring(keyStart, index-1); this.args = dict.__getitem__(new PyString(tmp)); - //System.out.println("args: "+args+", "+argIndex); } else { push(); } @@ -2789,7 +2787,6 @@ continue; } PyObject arg = getarg(); - //System.out.println("args: "+args+", "+argIndex+", "+arg); char fill = ' '; String string=null; negative = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-26 01:51:50
|
Revision: 5001 http://jython.svn.sourceforge.net/jython/?rev=5001&view=rev Author: fwierzbicki Date: 2008-07-26 01:51:48 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Small cleanup in Py.java -- killing stray System.outs. Modified Paths: -------------- branches/asm/src/org/python/core/Py.java Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-26 01:34:48 UTC (rev 5000) +++ branches/asm/src/org/python/core/Py.java 2008-07-26 01:51:48 UTC (rev 5001) @@ -858,12 +858,10 @@ return; } - //System.out.println("path: "+sys.path.__str__()); PyObject mod; // ??pending: findClass or should avoid sys.path loading? Class modClass = Py.findClass(module+"$_PyInner"); if (modClass != null) { - //System.err.println("found as class: "+modClass); PyCode code=null; try { code = ((PyRunnable)modClass.newInstance()).getMain(); @@ -873,7 +871,6 @@ mod = imp.createFromCode(module, code); } else { mod = imp.importName(module.intern(), false); - //System.err.println("found as mod: "+mod); } PyClass pyc = (PyClass)mod.__getattr__(pyclass.intern()); @@ -1242,6 +1239,7 @@ ThreadState ts = getThreadState(newSystemState); PySystemState oldSystemState = ts.systemState; if (oldSystemState != newSystemState) { + //XXX: should we make this a real warning? //System.err.println("Warning: changing systemState "+ // "for same thread!"); ts.systemState = newSystemState; @@ -1256,7 +1254,6 @@ /* Get and set the current frame */ public static PyFrame getFrame() { - //System.out.println("getFrame"); ThreadState ts = getThreadState(); if (ts == null) { return null; @@ -1265,7 +1262,6 @@ } public static void setFrame(PyFrame f) { - //System.out.println("setFrame"); getThreadState().frame = f; } @@ -1965,6 +1961,8 @@ } public PyObject call(PyFrame frame, PyObject closure) { + //XXX: what the heck is this? Looks like debug code, but it's + // been here a long time... System.out.println("call #1"); return Py.None; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-26 01:34:50
|
Revision: 5000 http://jython.svn.sourceforge.net/jython/?rev=5000&view=rev Author: fwierzbicki Date: 2008-07-26 01:34:48 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Small cleanups in imp. Modified Paths: -------------- branches/asm/src/org/python/core/imp.java Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-07-26 01:27:25 UTC (rev 4999) +++ branches/asm/src/org/python/core/imp.java 2008-07-26 01:34:48 UTC (rev 5000) @@ -44,7 +44,6 @@ } private imp() { - ; } /** @@ -140,8 +139,7 @@ } public static String makeCompiledFilename(String filename) { - return filename.substring(0, filename.length() - 3) - + "$py.class"; + return filename.substring(0, filename.length() - 3) + "$py.class"; } /** @@ -241,13 +239,13 @@ return createFromCode(name, c, null); } - /* - * Returns a module with the given name whose contents are the results of - * running c. Sets __file__ on the module to be moduleLocation unless - * moduleLocation is null. If c comes from a local .py file or compiled - * $py.class class moduleLocation should be the result of running new - * File(moduleLocation).getAbsoultePath(). If c comes from a remote file or - * is a jar moduleLocation should be the full uri for c. + /** + * createFromCode returns a module with the given name whose contents are + * the results of running c. Sets __file__ on the module to be + * moduleLocation unless moduleLocation is null. If c comes from a local + * .py file or compiled $py.class class moduleLocation should be the result + * of running new File(moduleLocation).getAbsoultePath(). If c comes from a + * remote file or is a jar moduleLocation should be the full uri for c. */ public static PyObject createFromCode(String name, PyCode c, String moduleLocation) { PyModule module = addModule(name); @@ -369,8 +367,6 @@ path = path == null ? sys.path : path; for (int i = 0; i < path.__len__(); i++) { PyObject p = path.__getitem__(i); - // System.err.println("find_module (" + name + ", " + moduleName + - // ") Path: " + path); PyObject importer = getPathImporter(sys.path_importer_cache, sys.path_hooks, p); if (importer != Py.None) { @@ -427,7 +423,6 @@ } static PyObject loadFromSource(PySystemState sys, String name, String modName, String entry) { - // System.err.println("load-from-source: "+name+" "+modName+" "+entry); String sourceName = "__init__.py"; String compiledName = "__init__$py.class"; @@ -646,7 +641,6 @@ */ private static PyObject import_name(String name, boolean top, PyObject modDict, PyObject fromlist) { - // System.err.println("import_name " + name); if (name.length() == 0) { throw Py.ValueError("Empty module name"); } @@ -656,7 +650,6 @@ if (modDict != null && !(modDict instanceof PyNone)) { pkgName = getParent(modDict); pkgMod = modules.__finditem__(pkgName); - // System.err.println("GetParent: " + pkgName + " => " + pkgMod); if (pkgMod != null && !(pkgMod instanceof PyModule)) { pkgMod = null; } @@ -740,14 +733,12 @@ * executed. */ public static PyObject importOne(String mod, PyFrame frame) { - // System.out.println("importOne(" + mod + ")"); PyObject module = __builtin__.__import__(mod, frame.f_globals, frame .getLocals(), Py.EmptyTuple); /* * int dot = mod.indexOf('.'); if (dot != -1) { mod = mod.substring(0, * dot).intern(); } */ - // System.err.println("mod: "+mod+", "+dot); return module; } @@ -756,7 +747,6 @@ * foo" is executed. */ public static PyObject importOneAs(String mod, PyFrame frame) { - // System.out.println("importOne(" + mod + ")"); PyObject module = __builtin__.__import__(mod, frame.f_globals, frame .getLocals(), getStarArg()); // frame.setlocal(asname, module); @@ -810,7 +800,6 @@ * import *" is executed. */ public static void importAll(String mod, PyFrame frame) { - // System.out.println("importAll(" + mod + ")"); PyObject module = __builtin__.__import__(mod, frame.f_globals, frame .getLocals(), getStarArg()); PyObject names; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-26 01:27:27
|
Revision: 4999 http://jython.svn.sourceforge.net/jython/?rev=4999&view=rev Author: fwierzbicki Date: 2008-07-26 01:27:25 +0000 (Sat, 26 Jul 2008) Log Message: ----------- Re-enabled APIVersion checking in imp.java. Used ASM to read and write APIVersion as an annotation. Incremented APIVersion from 12 to 13. Modified Paths: -------------- branches/asm/src/org/python/compiler/APIVersion.java branches/asm/src/org/python/compiler/ClassFile.java branches/asm/src/org/python/compiler/Module.java branches/asm/src/org/python/core/imp.java Added Paths: ----------- branches/asm/src/org/python/core/APIReader.java Modified: branches/asm/src/org/python/compiler/APIVersion.java =================================================================== --- branches/asm/src/org/python/compiler/APIVersion.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/compiler/APIVersion.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -1,21 +1,13 @@ -// Copyright (c) Corporation for National Research Initiatives - +/* + * Copyright (c) 2008 Jython Developers + * Licensed to PSF under a Contributor Agreement. + */ package org.python.compiler; -import java.io.DataOutputStream; -import java.io.IOException; -public class APIVersion { - int attName; - int version; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; - public APIVersion(int version) throws IOException { - //FJW attName = pool.UTF8("org.python.APIVersion"); - //FJW this.version = version; - } - - public void write(DataOutputStream stream) throws IOException { - //FJW stream.writeShort(attName); - //FJW stream.writeInt(4); - //FJW stream.writeInt(version); - } +@Retention(RetentionPolicy.RUNTIME) +public @interface APIVersion { + int value(); } Modified: branches/asm/src/org/python/compiler/ClassFile.java =================================================================== --- branches/asm/src/org/python/compiler/ClassFile.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/compiler/ClassFile.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.List; +import org.python.objectweb.asm.AnnotationVisitor; import org.python.objectweb.asm.Attribute; import org.python.objectweb.asm.ClassWriter; import org.python.objectweb.asm.FieldVisitor; @@ -26,7 +27,6 @@ String[] interfaces; List<MethodVisitor> methodVisitors; List<FieldVisitor> fieldVisitors; - List<Attribute> attributes; public static String fixName(String n) { if (n.indexOf('.') == -1) @@ -53,7 +53,6 @@ methodVisitors = Collections.synchronizedList(new ArrayList()); fieldVisitors = Collections.synchronizedList(new ArrayList()); - attributes = Collections.synchronizedList(new ArrayList()); } public void setSource(String name) { @@ -67,7 +66,6 @@ interfaces = new_interfaces; } - //FIXME: Should really return a MethodVisitor public Code addMethod(String name, String type, int access) throws IOException { @@ -84,14 +82,6 @@ fieldVisitors.add(fv); } - public void endAttributes() - throws IOException - { - for (Attribute attr : attributes) { - cw.visitAttribute(attr); - } - } - public void endFields() throws IOException { @@ -110,17 +100,16 @@ } } - public void addAttribute(Attribute attr) throws IOException { - //FIXME: Do nothing for now. - //attributes.add(attr); - } - public void write(OutputStream stream) throws IOException { cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, this.name, null, this.superclass, interfaces); + AnnotationVisitor av = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true); + //XXX: should imp.java really house this value or should imp.java point into org.python.compiler? + av.visit("value", new Integer(org.python.core.imp.APIVersion)); + av.visitEnd(); + if (sfilename != null) { cw.visitSource(sfilename, null); } - endAttributes(); endFields(); endMethods(); Modified: branches/asm/src/org/python/compiler/Module.java =================================================================== --- branches/asm/src/org/python/compiler/Module.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/compiler/Module.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -574,8 +574,6 @@ if (sfilename != null) { classfile.setSource(sfilename); } - //FIXME: switch to asm style. - //classfile.addAttribute(new APIVersion(org.python.core.imp.APIVersion)); classfile.write(stream); } Added: branches/asm/src/org/python/core/APIReader.java =================================================================== --- branches/asm/src/org/python/core/APIReader.java (rev 0) +++ branches/asm/src/org/python/core/APIReader.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008 Jython Developers + * Licensed to PSF under a Contributor Agreement. + */ +package org.python.core; + +import org.python.objectweb.asm.AnnotationVisitor; +import org.python.objectweb.asm.ClassReader; +import org.python.objectweb.asm.commons.EmptyVisitor; + +import java.io.InputStream; +import java.io.IOException; + +/** + * This class reads a classfile from a byte array and pulls out the value of + * the class annotation for APIVersion, which can then be retrieved by a call + * to getVersion(). + * + * Hopefully the use of ClassReader in this implementation is not too + * expensive. I suspect it is not since EmptyVisitor is just a bag of empty + * methods so shouldn't cost too much. If it turns out to cost too much, we + * will want to implement a special purpose ClassReader that only reads out the + * APIVersion annotation I think. + */ +public class APIReader extends EmptyVisitor { + + private boolean nextVisitIsVersion = false; + + private int version = -1; + + public APIReader(byte[] data) throws IOException { + ClassReader r = new ClassReader(data); + r.accept(this, 0); + } + + public AnnotationVisitor visitAnnotation(String desc, boolean visible) { + nextVisitIsVersion = desc.equals("Lorg/python/compiler/APIVersion;"); + return this; + } + + public void visit(String name, Object value) { + if (nextVisitIsVersion) { + version = (Integer)value; + nextVisitIsVersion = false; + } + } + + public int getVersion() { + return version; + } +} Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-07-25 06:07:24 UTC (rev 4998) +++ branches/asm/src/org/python/core/imp.java 2008-07-26 01:27:25 UTC (rev 4999) @@ -22,7 +22,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 12; + public static final int APIVersion = 13; /** A non-empty fromlist for __import__'ing sub-modules. */ private static final PyObject nonEmptyFromlist = new PyTuple(Py.newString("__doc__")); @@ -113,11 +113,13 @@ byte[] data = readBytes(fp); int n = data.length; - //Need to find another way to check the api version -- probably using - //an Annotation instead of an Attribute makes sense. - /* - int api = (data[n - 4] << 24) + (data[n - 3] << 16) - + (data[n - 2] << 8) + data[n - 1]; + int api; + try { + APIReader ar = new APIReader(data); + api = ar.getVersion(); + } catch (IOException i) { + api = -1; + } if (api != APIVersion) { if (testing) { return null; @@ -126,7 +128,6 @@ + APIVersion + ") in: " + name); } } - */ return data; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-25 06:07:26
|
Revision: 4998 http://jython.svn.sourceforge.net/jython/?rev=4998&view=rev Author: nriley Date: 2008-07-25 06:07:24 +0000 (Fri, 25 Jul 2008) Log Message: ----------- Suppress exception truncating /dev/null when opening it for write on Linux and Solaris; should fix test_os. Modified Paths: -------------- branches/asm/src/org/python/core/io/FileIO.java Modified: branches/asm/src/org/python/core/io/FileIO.java =================================================================== --- branches/asm/src/org/python/core/io/FileIO.java 2008-07-24 23:42:09 UTC (rev 4997) +++ branches/asm/src/org/python/core/io/FileIO.java 2008-07-25 06:07:24 UTC (rev 4998) @@ -154,7 +154,18 @@ if (appending) { seek(0, 2); } else if (writable && !readable) { - truncate(0); + try { + fileChannel.truncate(0); + } catch (IOException ioe) { + // On Solaris and Linux, ftruncate(3C) returns EINVAL + // if not a regular file whereas, e.g., + // open("/dev/null", "w") works fine. Because we have + // to simulate the "w" mode in Java, we suppress the + // exception. + if (ioe.getMessage().equals("Invalid argument")) + return; + throw Py.IOError(ioe); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-24 23:42:11
|
Revision: 4997 http://jython.svn.sourceforge.net/jython/?rev=4997&view=rev Author: pjenvey Date: 2008-07-24 23:42:09 +0000 (Thu, 24 Jul 2008) Log Message: ----------- cleanup unused var Modified Paths: -------------- branches/asm/src/org/python/modules/sre/PatternObject.java Modified: branches/asm/src/org/python/modules/sre/PatternObject.java =================================================================== --- branches/asm/src/org/python/modules/sre/PatternObject.java 2008-07-24 16:58:24 UTC (rev 4996) +++ branches/asm/src/org/python/modules/sre/PatternObject.java 2008-07-24 23:42:09 UTC (rev 4997) @@ -123,7 +123,6 @@ int n = 0; int i = 0; - boolean appended = false; while (count == 0 || n < count) { state.state_reset(); state.ptr = state.start; @@ -139,7 +138,6 @@ if (i < b) { /* get segment before this match */ buf.append(string.substring(i, b)); - appended = true; } if (! (i == b && i == e && n > 0)) { PyObject item; @@ -153,7 +151,6 @@ if (item != Py.None) { buf.append(item.toString()); - appended = true; } i = e; n++; @@ -167,7 +164,6 @@ } if (i < state.endpos) { buf.append(string.substring(i, state.endpos)); - appended = true; } // Follows rules enumerated in test_re.test_bug_1140 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |