From: <cg...@us...> - 2008-12-01 00:38:20
|
Revision: 5665 http://jython.svn.sourceforge.net/jython/?rev=5665&view=rev Author: cgroves Date: 2008-12-01 00:38:14 +0000 (Mon, 01 Dec 2008) Log Message: ----------- Merged revisions 5565,5568-5584,5593,5596,5598-5604,5606,5608-5611,5616,5618-5621,5624,5626-5627,5629-5630,5639-5640,5644-5648,5655,5661 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r5565 | fwierzbicki | 2008-11-09 19:36:31 -0800 (Sun, 09 Nov 2008) | 4 lines Just enough AST tweaking to get some of sympy working for Ondrej. On my todo list is to look at Python 2.6's ast testing and see if I can port that over to Jython. ........ r5568 | fwierzbicki | 2008-11-10 07:33:23 -0800 (Mon, 10 Nov 2008) | 2 lines remove dead code. ........ r5569 | fwierzbicki | 2008-11-10 13:12:29 -0800 (Mon, 10 Nov 2008) | 2 lines Make lineno and col_offset writable. ........ r5570 | fwierzbicki | 2008-11-11 09:48:27 -0800 (Tue, 11 Nov 2008) | 4 lines Tor Norbye found this ancient typo just by pointing NetBeans and the latest nbpython at datetime.py. Maybe there is something to be said for these "IDE"s that I keep hearing about :). ........ r5571 | otmarhumbel | 2008-11-11 15:25:25 -0800 (Tue, 11 Nov 2008) | 1 line detect JYTHON_HOME if called from the /bin directory ........ r5572 | pjenvey | 2008-11-11 17:31:02 -0800 (Tue, 11 Nov 2008) | 2 lines more java integration unicode vs str fixes ........ r5573 | fwierzbicki | 2008-11-12 11:10:54 -0800 (Wed, 12 Nov 2008) | 2 lines Upgrade to antlr-3.1.1. ........ r5574 | fwierzbicki | 2008-11-12 11:32:40 -0800 (Wed, 12 Nov 2008) | 2 lines Hopefully helping for eclipse users :). ........ r5575 | fwierzbicki | 2008-11-12 11:33:58 -0800 (Wed, 12 Nov 2008) | 3 lines Oops, try #2. That's what I get for doing this w/o having eclipse installed for verification. ........ r5576 | pjenvey | 2008-11-13 16:02:12 -0800 (Thu, 13 Nov 2008) | 2 lines fix itertools.chain stopping short with two empty iters in a row ........ r5577 | fwierzbicki | 2008-11-13 16:28:42 -0800 (Thu, 13 Nov 2008) | 2 lines Thanks to Tor Norbye for this bug fix. This was also found via NetBeans. ........ r5578 | pjenvey | 2008-11-13 23:35:53 -0800 (Thu, 13 Nov 2008) | 2 lines bring in constantine (0.3dev r80) for better errnos ........ r5579 | fwierzbicki | 2008-11-14 08:07:43 -0800 (Fri, 14 Nov 2008) | 3 lines Fix for NPE's and a weird Antlr error that can occur when Antlr is allowed to recover from parser errrors (for example, when ListErrorHandler is used). ........ r5580 | fwierzbicki | 2008-11-14 09:53:21 -0800 (Fri, 14 Nov 2008) | 2 lines Remove very old commented out code from imp.java. ........ r5581 | fwierzbicki | 2008-11-14 14:54:53 -0800 (Fri, 14 Nov 2008) | 15 lines Fix for http://bugs.jython.org/issue1141. __builtin__.__import__ had subtle differences with CPython. These differences would cause problems for those who wish to override __builtin__.__import__ statement: import hell.first_circle - CPython: ('hell.first_circle', None) - old Jython: ('hell.first_circle', ()) statement: import hell.first_circle as limbo - CPython: ('hell.first_circle', None) - old Jython: ('hell.first_circle', ('*',)) Also note that the second import statement with an "as" would return the head module instead of the tail module, the opposite of what CPython does. ........ r5582 | pjenvey | 2008-11-16 14:52:56 -0800 (Sun, 16 Nov 2008) | 3 lines fix another binop corner case -- trigger the binop 'flip' when left_type < right_type (in terms of the reversed mro) instead of left_type != right_type ........ r5583 | pjenvey | 2008-11-17 12:05:55 -0800 (Mon, 17 Nov 2008) | 4 lines o allow Socket{TCP,UDP}Test HOST/PORT to be overriden per class o use a different port than test_socket for test_select as test_socket sockopt tests don't REUSEADDR ........ r5584 | pjenvey | 2008-11-17 12:06:51 -0800 (Mon, 17 Nov 2008) | 4 lines relax the test ensuring SO_{RCV,SND}BUF matches the *exact* value we set it to after a connection was established. only for the BSDs, but we may not want to assume this anywhere ........ r5593 | pjenvey | 2008-11-20 10:52:08 -0800 (Thu, 20 Nov 2008) | 4 lines hardcode PyString encode results instead of letting java2py return unicode fixes #1177 thanks jcflack ........ r5596 | pjenvey | 2008-11-20 18:00:11 -0800 (Thu, 20 Nov 2008) | 4 lines fix handling of null prefix/exec_prefix values now that they're PyObjects fixes #1173 thanks boisgera ........ r5598 | fwierzbicki | 2008-11-22 11:18:53 -0800 (Sat, 22 Nov 2008) | 5 lines Fixes bug http://bugs.jython.org/issue1174 which reveals a corner case where CompilerFlags can come out as null. Not positive that we should be passing the "flags" value down when there is no frame, but this is probably right. Put an XXX in so it can be looked at again later. ........ r5599 | fwierzbicki | 2008-11-22 12:39:54 -0800 (Sat, 22 Nov 2008) | 3 lines Removed XXX -- looking at the code some more makes me comfortable with passing "flags" on. ........ r5600 | pjenvey | 2008-11-22 14:37:49 -0800 (Sat, 22 Nov 2008) | 3 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib/warnings.py@47273 ........ r5601 | pjenvey | 2008-11-22 15:23:48 -0800 (Sat, 22 Nov 2008) | 4 lines use the compiled filename for __file__ when appropriate. make imp responsible for setting __file__ instead of the compiler being involved fixes #1138 ........ r5602 | pjenvey | 2008-11-22 15:27:27 -0800 (Sat, 22 Nov 2008) | 3 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib/pydoc.py@54366 ........ r5603 | pjenvey | 2008-11-22 15:30:45 -0800 (Sat, 22 Nov 2008) | 3 lines o fix help -- our new isatty support confused it into using a real pager o support $py.class in ispackage ........ r5604 | cgroves | 2008-11-22 16:18:15 -0800 (Sat, 22 Nov 2008) | 1 line Assume any instance of PySequence has an accurate __len__. See http://www.nabble.com/PySequenceList-and-fastSequence-td14977175.html ........ r5606 | pjenvey | 2008-11-22 17:57:09 -0800 (Sat, 22 Nov 2008) | 5 lines o allow open({In,Out}putStream) but with a deprecation warning. make open a function o add optional bufsize args to FileUtil.wrap fixes #1171 ........ r5608 | pjenvey | 2008-11-22 20:15:40 -0800 (Sat, 22 Nov 2008) | 4 lines relax struct_time entry types to PyObject, CPython allows non ints here. mostly to get rid of __int__ calls w/ a PyInteger cast refs #1052 ........ r5609 | pjenvey | 2008-11-22 20:18:48 -0800 (Sat, 22 Nov 2008) | 6 lines ((PyInteger)obj.__int__()).getValue() -> obj.asInt() to avoid potential ClassCastException mayhem now that __int__ can return longs. as a side effect TypeErrors are raised on conversion failure rather than AttributeErrors (which is usually more appropriate anyway) fixes #1052 ........ r5610 | pjenvey | 2008-11-22 20:35:59 -0800 (Sat, 22 Nov 2008) | 4 lines zlib docs fixes #1798554, #1798556 thanks ukeshav ........ r5611 | pjenvey | 2008-11-22 22:28:45 -0800 (Sat, 22 Nov 2008) | 4 lines fix the Carlo Verre hack because open builtin classes are only cool in Ruby and JavaScript, or something like that fixes #1058 and test_descr.carloverre ........ r5616 | fwierzbicki | 2008-11-23 07:02:10 -0800 (Sun, 23 Nov 2008) | 3 lines Removed merge tracking for "svnmerge" for https://jython.svn.sourceforge.net/svnroot/jython/branches/nowalker ........ r5618 | pjenvey | 2008-11-23 11:35:19 -0800 (Sun, 23 Nov 2008) | 1 line exclude the antlr tests as they don't have any actual tests ........ r5619 | pjenvey | 2008-11-23 12:58:25 -0800 (Sun, 23 Nov 2008) | 4 lines fix bit rot in the Expose javatests: ensure we setType new descriptors, init sys when needed, fix null method docs (use "" instead) ........ r5620 | pjenvey | 2008-11-23 13:56:25 -0800 (Sun, 23 Nov 2008) | 2 lines turn on javatest/regrtest junit xml output by default, to dist/testreports ........ r5621 | pjenvey | 2008-11-23 14:22:05 -0800 (Sun, 23 Nov 2008) | 3 lines don't buffer the various popen2 helper streams in hopes to make test_cmd_line less flakey ........ r5624 | fwierzbicki | 2008-11-23 16:00:42 -0800 (Sun, 23 Nov 2008) | 3 lines Test for basic eval from a bare PythonInterpreter (was throwing an NPE) see http://bugs.jython.org/issue1174. ........ r5626 | pjenvey | 2008-11-23 18:02:47 -0800 (Sun, 23 Nov 2008) | 5 lines add an isBaseType flag to @ExposedType for toggling whether types are subclassable. disallow subclassing of builtin_function_or_method (fixes test_descr.errors). note that this requires an ant clean refs #1758319 ........ r5627 | pjenvey | 2008-11-23 18:48:33 -0800 (Sun, 23 Nov 2008) | 3 lines disallow sublcassing a number of types fixes #1758319 ........ r5629 | pjenvey | 2008-11-23 21:01:02 -0800 (Sun, 23 Nov 2008) | 4 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib/zipfile.py@60117 http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_zipfile.py@46982 ........ r5630 | pjenvey | 2008-11-23 21:02:01 -0800 (Sun, 23 Nov 2008) | 2 lines fix PyZipFile to compile to $py.class ........ r5639 | otmarhumbel | 2008-11-25 06:11:53 -0800 (Tue, 25 Nov 2008) | 2 lines to enable virtualenv again: do not hardcode JYTHON_HOME this fixes issue #1180 ........ r5640 | otmarhumbel | 2008-11-25 13:09:57 -0800 (Tue, 25 Nov 2008) | 1 line check for both jython-complete.jar and jython.jar in findRoot() ........ r5644 | pjenvey | 2008-11-26 19:30:23 -0800 (Wed, 26 Nov 2008) | 1 line update/clarify comment ........ r5645 | fwierzbicki | 2008-11-26 20:01:27 -0800 (Wed, 26 Nov 2008) | 5 lines Make PythonTree (and thus most of the ast nodes) extend PyObject instead of Antlr's CommonTree. This required pulling in much of the CommonTree code for now. Hopefully I can prune some of it out in time. Also PythonTreeAdaptor had to override more of CommonTreeAdaptor's methods. ........ r5646 | pjenvey | 2008-11-26 20:52:37 -0800 (Wed, 26 Nov 2008) | 6 lines temporarily store genexps in Java's frame instead of PyFrame. the latter could modify f_locals when cleaning up the temp slot, which causes an obscure bug if the genexp is iterating over that same f_locals (dict changed size during iteration). e.g., in a module's top level: __all__ = tuple(x for x in locals() if x.isupper()) ........ r5647 | pjenvey | 2008-11-27 12:56:10 -0800 (Thu, 27 Nov 2008) | 5 lines o explicitly convert Strings returned from ExposedGet to str (instead of unicode), just as ExposedMethod does. restores the behavior it had before the big Java integration String/unicode change o add a TypeError message for PyDataDescr.__set__ failed conversions ........ r5648 | pjenvey | 2008-11-27 12:56:40 -0800 (Thu, 27 Nov 2008) | 1 line small cleanup, match CPython's __repr__ ........ r5655 | pjenvey | 2008-11-28 13:10:39 -0800 (Fri, 28 Nov 2008) | 2 lines have exposed methods and fields convert null Strings results to Py.None ........ r5661 | pjenvey | 2008-11-28 23:43:57 -0800 (Fri, 28 Nov 2008) | 2 lines constantine-0.4 release ........ Modified Paths: -------------- branches/newstyle-java-types/.classpath branches/newstyle-java-types/Lib/datetime.py branches/newstyle-java-types/Lib/inspect.py branches/newstyle-java-types/Lib/ntpath.py branches/newstyle-java-types/Lib/os.py branches/newstyle-java-types/Lib/popen2.py branches/newstyle-java-types/Lib/posixpath.py branches/newstyle-java-types/Lib/subprocess.py branches/newstyle-java-types/Lib/test/test_bool.py branches/newstyle-java-types/Lib/test/test_chdir.py branches/newstyle-java-types/Lib/test/test_descr.py branches/newstyle-java-types/Lib/test/test_descr_jy.py branches/newstyle-java-types/Lib/test/test_fileno.py branches/newstyle-java-types/Lib/test/test_genexps.py branches/newstyle-java-types/Lib/test/test_import_jy.py branches/newstyle-java-types/Lib/test/test_inspect.py branches/newstyle-java-types/Lib/test/test_iter_jy.py branches/newstyle-java-types/Lib/test/test_select.py branches/newstyle-java-types/Lib/test/test_socket.py branches/newstyle-java-types/Lib/zlib.py branches/newstyle-java-types/ast/asdl_antlr.py branches/newstyle-java-types/build.xml branches/newstyle-java-types/grammar/Python.g branches/newstyle-java-types/src/com/ziclix/python/sql/Fetch.java branches/newstyle-java-types/src/com/ziclix/python/sql/Procedure.java branches/newstyle-java-types/src/com/ziclix/python/sql/PyCursor.java branches/newstyle-java-types/src/com/ziclix/python/sql/PyStatement.java branches/newstyle-java-types/src/org/python/antlr/AST.java branches/newstyle-java-types/src/org/python/antlr/GrammarActions.java branches/newstyle-java-types/src/org/python/antlr/ParseException.java branches/newstyle-java-types/src/org/python/antlr/PythonErrorNode.java branches/newstyle-java-types/src/org/python/antlr/PythonTree.java branches/newstyle-java-types/src/org/python/antlr/PythonTreeAdaptor.java branches/newstyle-java-types/src/org/python/antlr/ast/Assert.java branches/newstyle-java-types/src/org/python/antlr/ast/Assign.java branches/newstyle-java-types/src/org/python/antlr/ast/Attribute.java branches/newstyle-java-types/src/org/python/antlr/ast/AugAssign.java branches/newstyle-java-types/src/org/python/antlr/ast/BinOp.java branches/newstyle-java-types/src/org/python/antlr/ast/BoolOp.java branches/newstyle-java-types/src/org/python/antlr/ast/Break.java branches/newstyle-java-types/src/org/python/antlr/ast/Call.java branches/newstyle-java-types/src/org/python/antlr/ast/ClassDef.java branches/newstyle-java-types/src/org/python/antlr/ast/Compare.java branches/newstyle-java-types/src/org/python/antlr/ast/Continue.java branches/newstyle-java-types/src/org/python/antlr/ast/Delete.java branches/newstyle-java-types/src/org/python/antlr/ast/Dict.java branches/newstyle-java-types/src/org/python/antlr/ast/Ellipsis.java branches/newstyle-java-types/src/org/python/antlr/ast/ErrorExpr.java branches/newstyle-java-types/src/org/python/antlr/ast/ErrorMod.java branches/newstyle-java-types/src/org/python/antlr/ast/ErrorSlice.java branches/newstyle-java-types/src/org/python/antlr/ast/ErrorStmt.java branches/newstyle-java-types/src/org/python/antlr/ast/Exec.java branches/newstyle-java-types/src/org/python/antlr/ast/Expr.java branches/newstyle-java-types/src/org/python/antlr/ast/Expression.java branches/newstyle-java-types/src/org/python/antlr/ast/ExtSlice.java branches/newstyle-java-types/src/org/python/antlr/ast/For.java branches/newstyle-java-types/src/org/python/antlr/ast/FunctionDef.java branches/newstyle-java-types/src/org/python/antlr/ast/GeneratorExp.java branches/newstyle-java-types/src/org/python/antlr/ast/Global.java branches/newstyle-java-types/src/org/python/antlr/ast/If.java branches/newstyle-java-types/src/org/python/antlr/ast/IfExp.java branches/newstyle-java-types/src/org/python/antlr/ast/Import.java branches/newstyle-java-types/src/org/python/antlr/ast/ImportFrom.java branches/newstyle-java-types/src/org/python/antlr/ast/Index.java branches/newstyle-java-types/src/org/python/antlr/ast/Interactive.java branches/newstyle-java-types/src/org/python/antlr/ast/Lambda.java branches/newstyle-java-types/src/org/python/antlr/ast/List.java branches/newstyle-java-types/src/org/python/antlr/ast/ListComp.java branches/newstyle-java-types/src/org/python/antlr/ast/Module.java branches/newstyle-java-types/src/org/python/antlr/ast/Name.java branches/newstyle-java-types/src/org/python/antlr/ast/Num.java branches/newstyle-java-types/src/org/python/antlr/ast/Pass.java branches/newstyle-java-types/src/org/python/antlr/ast/Print.java branches/newstyle-java-types/src/org/python/antlr/ast/Raise.java branches/newstyle-java-types/src/org/python/antlr/ast/Repr.java branches/newstyle-java-types/src/org/python/antlr/ast/Return.java branches/newstyle-java-types/src/org/python/antlr/ast/Slice.java branches/newstyle-java-types/src/org/python/antlr/ast/Str.java branches/newstyle-java-types/src/org/python/antlr/ast/Subscript.java branches/newstyle-java-types/src/org/python/antlr/ast/Suite.java branches/newstyle-java-types/src/org/python/antlr/ast/TryExcept.java branches/newstyle-java-types/src/org/python/antlr/ast/TryFinally.java branches/newstyle-java-types/src/org/python/antlr/ast/Tuple.java branches/newstyle-java-types/src/org/python/antlr/ast/UnaryOp.java branches/newstyle-java-types/src/org/python/antlr/ast/While.java branches/newstyle-java-types/src/org/python/antlr/ast/With.java branches/newstyle-java-types/src/org/python/antlr/ast/Yield.java branches/newstyle-java-types/src/org/python/antlr/ast/aliasType.java branches/newstyle-java-types/src/org/python/antlr/ast/argumentsType.java branches/newstyle-java-types/src/org/python/antlr/ast/boolopType.java branches/newstyle-java-types/src/org/python/antlr/ast/cmpopType.java branches/newstyle-java-types/src/org/python/antlr/ast/comprehensionType.java branches/newstyle-java-types/src/org/python/antlr/ast/excepthandlerType.java branches/newstyle-java-types/src/org/python/antlr/ast/exprType.java branches/newstyle-java-types/src/org/python/antlr/ast/expr_contextType.java branches/newstyle-java-types/src/org/python/antlr/ast/keywordType.java branches/newstyle-java-types/src/org/python/antlr/ast/modType.java branches/newstyle-java-types/src/org/python/antlr/ast/operatorType.java branches/newstyle-java-types/src/org/python/antlr/ast/sliceType.java branches/newstyle-java-types/src/org/python/antlr/ast/stmtType.java branches/newstyle-java-types/src/org/python/antlr/ast/unaryopType.java branches/newstyle-java-types/src/org/python/compiler/CodeCompiler.java branches/newstyle-java-types/src/org/python/compiler/Module.java branches/newstyle-java-types/src/org/python/compiler/ScopesCompiler.java branches/newstyle-java-types/src/org/python/core/Py.java branches/newstyle-java-types/src/org/python/core/PyArray.java branches/newstyle-java-types/src/org/python/core/PyBoolean.java branches/newstyle-java-types/src/org/python/core/PyBuiltinCallable.java branches/newstyle-java-types/src/org/python/core/PyCell.java branches/newstyle-java-types/src/org/python/core/PyClassMethodDescr.java branches/newstyle-java-types/src/org/python/core/PyDataDescr.java branches/newstyle-java-types/src/org/python/core/PyDictProxy.java branches/newstyle-java-types/src/org/python/core/PyEllipsis.java branches/newstyle-java-types/src/org/python/core/PyFile.java branches/newstyle-java-types/src/org/python/core/PyFunction.java branches/newstyle-java-types/src/org/python/core/PyGenerator.java branches/newstyle-java-types/src/org/python/core/PyMethod.java branches/newstyle-java-types/src/org/python/core/PyMethodDescr.java branches/newstyle-java-types/src/org/python/core/PyNone.java branches/newstyle-java-types/src/org/python/core/PyNotImplemented.java branches/newstyle-java-types/src/org/python/core/PyObject.java branches/newstyle-java-types/src/org/python/core/PySequence.java branches/newstyle-java-types/src/org/python/core/PySlice.java branches/newstyle-java-types/src/org/python/core/PySlot.java branches/newstyle-java-types/src/org/python/core/PyString.java branches/newstyle-java-types/src/org/python/core/PySystemState.java branches/newstyle-java-types/src/org/python/core/PyTraceback.java branches/newstyle-java-types/src/org/python/core/PyType.java branches/newstyle-java-types/src/org/python/core/PyXRange.java branches/newstyle-java-types/src/org/python/core/__builtin__.java branches/newstyle-java-types/src/org/python/core/imp.java branches/newstyle-java-types/src/org/python/core/io/FileIO.java branches/newstyle-java-types/src/org/python/core/io/IOBase.java branches/newstyle-java-types/src/org/python/core/io/ServerSocketIO.java branches/newstyle-java-types/src/org/python/core/util/FileUtil.java branches/newstyle-java-types/src/org/python/expose/BaseTypeBuilder.java branches/newstyle-java-types/src/org/python/expose/ExposedType.java branches/newstyle-java-types/src/org/python/expose/TypeBuilder.java branches/newstyle-java-types/src/org/python/expose/generate/DescriptorExposer.java branches/newstyle-java-types/src/org/python/expose/generate/ExposedTypeProcessor.java branches/newstyle-java-types/src/org/python/expose/generate/ExposedTypeVisitor.java branches/newstyle-java-types/src/org/python/expose/generate/Exposer.java branches/newstyle-java-types/src/org/python/expose/generate/InstanceMethodExposer.java branches/newstyle-java-types/src/org/python/expose/generate/TypeExposer.java branches/newstyle-java-types/src/org/python/modules/PyTeeIterator.java branches/newstyle-java-types/src/org/python/modules/_codecs.java branches/newstyle-java-types/src/org/python/modules/_py_compile.java branches/newstyle-java-types/src/org/python/modules/_weakref/CallableProxyType.java branches/newstyle-java-types/src/org/python/modules/_weakref/ProxyType.java branches/newstyle-java-types/src/org/python/modules/errno.java branches/newstyle-java-types/src/org/python/modules/imp.java branches/newstyle-java-types/src/org/python/modules/itertools.java branches/newstyle-java-types/src/org/python/modules/operator.java branches/newstyle-java-types/src/org/python/modules/struct.java branches/newstyle-java-types/src/org/python/modules/thread/thread.java branches/newstyle-java-types/src/org/python/modules/time/PyTimeTuple.java branches/newstyle-java-types/src/org/python/modules/time/Time.java branches/newstyle-java-types/src/org/python/modules/zipimport/zipimporter.java branches/newstyle-java-types/src/shell/jython branches/newstyle-java-types/src/shell/jython.bat branches/newstyle-java-types/tests/java/org/python/expose/generate/DescriptorExposerTest.java branches/newstyle-java-types/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java branches/newstyle-java-types/tests/java/org/python/expose/generate/ExposedTypeVisitorTest.java branches/newstyle-java-types/tests/java/org/python/expose/generate/MethodExposerTest.java branches/newstyle-java-types/tests/java/org/python/expose/generate/SimpleExposed.java branches/newstyle-java-types/tests/java/org/python/expose/generate/TypeExposerTest.java Added Paths: ----------- branches/newstyle-java-types/Lib/pydoc.py branches/newstyle-java-types/Lib/test/test_genexps_jy.py branches/newstyle-java-types/Lib/test/test_zipfile.py branches/newstyle-java-types/Lib/warnings.py branches/newstyle-java-types/Lib/zipfile.py branches/newstyle-java-types/extlibs/antlr-3.1.1-runtime.jar branches/newstyle-java-types/extlibs/antlr-3.1.1.jar branches/newstyle-java-types/extlibs/constantine-0.4.jar branches/newstyle-java-types/tests/java/org/python/util/ branches/newstyle-java-types/tests/java/org/python/util/InterpreterTest.java Removed Paths: ------------- branches/newstyle-java-types/extlibs/antlr-3.1.jar branches/newstyle-java-types/extlibs/antlr-runtime-3.1.jar branches/newstyle-java-types/tests/java/org/python/util/InterpreterTest.java Property Changed: ---------------- branches/newstyle-java-types/ Property changes on: branches/newstyle-java-types ___________________________________________________________________ Modified: svnmerge-integrated - /branches/nowalker:1-5263 /trunk/jython:1-5562 + /branches/nowalker:1-5263 /trunk/jython:1-5664 Added: svn:mergeinfo + /trunk/jython:5565-5661 Modified: branches/newstyle-java-types/.classpath =================================================================== --- branches/newstyle-java-types/.classpath 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/.classpath 2008-12-01 00:38:14 UTC (rev 5665) @@ -14,6 +14,6 @@ <classpathentry kind="lib" path="extlibs/servlet-api-2.5.jar"/> <classpathentry kind="lib" path="build/jarjar"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> - <classpathentry kind="lib" path="extlibs/antlr-runtime-3.1.jar"/> + <classpathentry kind="lib" path="extlibs/antlr-3.1.1-runtime.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> Modified: branches/newstyle-java-types/Lib/datetime.py =================================================================== --- branches/newstyle-java-types/Lib/datetime.py 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/Lib/datetime.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -1574,7 +1574,7 @@ # Convert self to UTC, and attach the new time zone object. myoffset = self.utcoffset() if myoffset is None: - raise ValuError("astimezone() requires an aware datetime") + raise ValueError("astimezone() requires an aware datetime") utc = (self - myoffset).replace(tzinfo=tz) # Convert from UTC to tz's local time. Modified: branches/newstyle-java-types/Lib/inspect.py =================================================================== --- branches/newstyle-java-types/Lib/inspect.py 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/Lib/inspect.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -383,6 +383,8 @@ filename = getfile(object) if string.lower(filename[-4:]) in ('.pyc', '.pyo'): filename = filename[:-4] + '.py' + elif filename.endswith('$py.class'): + filename = filename[:-9] + '.py' for suffix, mode, kind in imp.get_suffixes(): if 'b' in mode and string.lower(filename[-len(suffix):]) == suffix: # Looks like a binary file. We want to only return a text file. Modified: branches/newstyle-java-types/Lib/ntpath.py =================================================================== --- branches/newstyle-java-types/Lib/ntpath.py 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/Lib/ntpath.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -9,6 +9,7 @@ import os import stat import sys +from org.python.core.Py import newString __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", @@ -493,7 +494,8 @@ if not splitunc(path)[0] and not splitdrive(path)[0]: # cwd lacks a UNC mount point, so it should have a drive # letter (but lacks one): determine it - drive = splitdrive(java.io.File(path).getCanonicalPath())[0] + canon_path = newString(java.io.File(path).getCanonicalPath()) + drive = splitdrive(canon_path)[0] path = join(drive, path) return normpath(path) Modified: branches/newstyle-java-types/Lib/os.py =================================================================== --- branches/newstyle-java-types/Lib/os.py 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/Lib/os.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -46,6 +46,7 @@ import stat as _stat import sys from java.io import File +from org.python.constantine.platform import Errno from org.python.core.io import FileDescriptors, FileIO, IOBase from org.python.core.Py import newString as asPyString @@ -101,7 +102,7 @@ err = getattr(errno, error.name(), None) if err is None: raise OSError('%s: %s' % (error, msg)) - raise OSError(err, errno.strerror(err), msg) + raise OSError(err, strerror(err), msg) def unimplementedError(self, method_name): raise NotImplementedError(method_name) def warn(self, warning_id, msg, rest): @@ -237,7 +238,7 @@ Return a string representing the current working directory. """ - return sys.getCurrentWorkingDir() + return asPyString(sys.getCurrentWorkingDir()) def chdir(path): """chdir(path) @@ -246,9 +247,9 @@ """ realpath = _path.realpath(path) if not _path.exists(realpath): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) if not _path.isdir(realpath): - raise OSError(errno.ENOTDIR, errno.strerror(errno.ENOTDIR), path) + raise OSError(errno.ENOTDIR, strerror(errno.ENOTDIR), path) sys.setCurrentWorkingDir(realpath) def listdir(path): @@ -275,7 +276,7 @@ # catch not found errors explicitly here, for now abs_path = sys.getPath(path) if not File(abs_path).exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) _posix.chmod(abs_path, mode) def mkdir(path, mode='ignored'): @@ -292,7 +293,7 @@ err = errno.EEXIST else: err = 0 - msg = errno.strerror(err) if err else "couldn't make directory" + msg = strerror(err) if err else "couldn't make directory" raise OSError(err, msg, path) def makedirs(path, mode='ignored'): @@ -371,9 +372,9 @@ Remove a directory.""" f = File(sys.getPath(path)) if not f.exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) elif not f.isDirectory(): - raise OSError(errno.ENOTDIR, errno.strerror(errno.ENOTDIR), path) + raise OSError(errno.ENOTDIR, strerror(errno.ENOTDIR), path) elif not f.delete(): raise OSError(0, "couldn't delete directory", path) @@ -409,10 +410,17 @@ """ if not isinstance(code, (int, long)): raise TypeError('an integer is required') - try: - return errno.strerror(code) - except KeyError: + constant = Errno.valueOf(code) + if constant is Errno.__UNKNOWN_CONSTANT__: return 'Unknown error: %d' % code + if constant.name() == constant.description(): + # XXX: have constantine handle this fallback + # Fake constant or just lacks a description, fallback to Linux's + from org.python.constantine.platform.linux import Errno as LinuxErrno + constant = getattr(LinuxErrno, constant.name(), None) + if not constant: + return 'Unknown error: %d' % code + return asPyString(constant.toString()) def access(path, mode): """access(path, mode) -> True if granted, False otherwise @@ -459,7 +467,7 @@ raise f = File(abs_path) if not f.exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) size = f.length() mtime = f.lastModified() / 1000.0 mode = 0 @@ -509,7 +517,7 @@ # Not a link, only now can we determine if it exists (because # File.exists() returns False for dead links) if not f.exists(): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), path) return stat(path) def utime(path, times): @@ -550,12 +558,12 @@ if (len(mode) and mode[0] or '') not in 'rwa': raise ValueError("invalid file mode '%s'" % mode) if rawio.closed(): - raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) + raise OSError(errno.EBADF, strerror(errno.EBADF)) try: fp = FileDescriptors.wrap(rawio, mode, bufsize) except IOError: - raise OSError(errno.EINVAL, errno.strerror(errno.EINVAL)) + raise OSError(errno.EINVAL, strerror(errno.EINVAL)) return fp def ftruncate(fd, length): @@ -567,7 +575,7 @@ try: rawio.truncate(length) except Exception, e: - raise IOError(errno.EBADF, errno.strerror(errno.EBADF)) + raise IOError(errno.EBADF, strerror(errno.EBADF)) def lseek(fd, pos, how): """lseek(fd, pos, how) -> newpos @@ -593,10 +601,10 @@ appending = flag & O_APPEND if updating and writing: - raise OSError(errno.EINVAL, errno.strerror(errno.EINVAL), filename) + raise OSError(errno.EINVAL, strerror(errno.EINVAL), filename) if not creating and not path.exists(filename): - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), filename) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) if not writing: if updating: @@ -611,7 +619,7 @@ if exclusive and creating: try: if not File(sys.getPath(filename)).createNewFile(): - raise OSError(errno.EEXIST, errno.strerror(errno.EEXIST), + raise OSError(errno.EEXIST, strerror(errno.EEXIST), filename) except java.io.IOException, ioe: raise OSError(ioe) @@ -627,8 +635,8 @@ fchannel = RandomAccessFile(sys.getPath(filename), 'rws').getChannel() except FileNotFoundException, fnfe: if path.isdir(filename): - raise OSError(errno.EISDIR, errno.strerror(errno.EISDIR)) - raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), filename) + raise OSError(errno.EISDIR, strerror(errno.EISDIR)) + raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) return FileIO(fchannel, mode) return FileIO(filename, mode) @@ -659,7 +667,7 @@ try: return func(*args, **kwargs) except: - raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) + raise OSError(errno.EBADF, strerror(errno.EBADF)) if _name == 'posix' and _native_posix: def link(src, dst): Modified: branches/newstyle-java-types/Lib/popen2.py =================================================================== --- branches/newstyle-java-types/Lib/popen2.py 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/Lib/popen2.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -44,7 +44,7 @@ the close method. """ def __init__(self, stream, process, name): - self._file = FileUtil.wrap(stream) + self._file = FileUtil.wrap(stream, 0) self._process = process def __getattr__(self, name): @@ -93,10 +93,10 @@ bufsize ) - self.tochild = FileUtil.wrap(self._tochild) - self.fromchild = FileUtil.wrap(self._fromchild) + self.tochild = FileUtil.wrap(self._tochild, 0) + self.fromchild = FileUtil.wrap(self._fromchild, 0) if self._childerr: - self.childerr = FileUtil.wrap(self._childerr) + self.childerr = FileUtil.wrap(self._childerr, 0) def _startChildWaiter(self): """Start a subthread that waits for the child process to exit.""" @@ -198,7 +198,7 @@ "%s-stderr" % self.process, self._close ) - return FileUtil.wrap(joinedStream) + return FileUtil.wrap(joinedStream, 0) def _close( self ): """Must be closed twice (once for each of the two joined pipes)""" Modified: branches/newstyle-java-types/Lib/posixpath.py =================================================================== --- branches/newstyle-java-types/Lib/posixpath.py 2008-11-30 05:37:11 UTC (rev 5664) +++ branches/newstyle-java-types/Lib/posixpath.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -14,6 +14,7 @@ import java.io.IOException import os import stat +from org.python.core.Py import newString __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", @@ -218,8 +219,8 @@ if not os._native_posix: def samefile(f1, f2): """Test whether two pathnames reference the same actual file""" - canon1 = java.io.File(_ensure_str(f1)).getCanonicalPath() - canon2 = java.io.File(_ensure_str(f2)).getCanonicalPath() + canon1 = newString(java.io.File(_ensure_str(f1)).getCanonicalPath()) + canon2 = newString(java.io.File(_ensure_str(f2)).getCanonicalPath()) return canon1 == canon2 else: def samefile(f1, f2): @@ -240,7 +241,7 @@ s2 = os.fstat(fp2) return samestat(s1, s2) - __all__append("sameopenfile") + __all__.append("sameopenfile") if os._native_posix: @@ -448,7 +449,7 @@ encounter a path we've seen before (meaning that there's a loop). """ try: - return str(java.io.File(abspath(path)).getCanonicalPath()) + return newString(java.io.File(abspath(path)).getCanonicalPath()) except java.io.IOException: return None else: Copied: branches/newstyle-java-types/Lib/pydoc.py (from rev 5661, trunk/jython/Lib/pydoc.py) =================================================================== --- branches/newstyle-java-types/Lib/pydoc.py (rev 0) +++ branches/newstyle-java-types/Lib/pydoc.py 2008-12-01 00:38:14 UTC (rev 5665) @@ -0,0 +1,2257 @@ +#!/usr/bin/env python +# -*- coding: Latin-1 -*- +"""Generate Python documentation in HTML or text for interactive use. + +In the Python interpreter, do "from pydoc import help" to provide online +help. Calling help(thing) on a Python object documents the object. + +Or, at the shell command line outside of Python: + +Run "pydoc <name>" to show documentation on something. <name> may be +the name of a function, module, package, or a dotted reference to a +class or function within a module or module in a package. If the +argument contains a path segment delimiter (e.g. slash on Unix, +backslash on Windows) it is treated as the path to a Python source file. + +Run "pydoc -k <keyword>" to search for a keyword in the synopsis lines +of all available modules. + +Run "pydoc -p <port>" to start an HTTP server on a given port on the +local machine to generate documentation web pages. + +For platforms without a command line, "pydoc -g" starts the HTTP server +and also pops up a little window for controlling it. + +Run "pydoc -w <name>" to write out the HTML documentation for a module +to a file named "<name>.html". + +Module docs for core modules are assumed to be in + + http://www.python.org/doc/current/lib/ + +This can be overridden by setting the PYTHONDOCS environment variable +to a different URL or to a local directory containing the Library +Reference Manual pages. +""" + +__author__ = "Ka-Ping Yee <pi...@lf...>" +__date__ = "26 February 2001" + +__version__ = "$Revision: 54366 $" +__credits__ = """Guido van Rossum, for an excellent programming language. +Tommy Burnette, the original creator of manpy. +Paul Prescod, for all his work on onlinehelp. +Richard Chamberlain, for the first implementation of textdoc. +""" + +# Known bugs that can't be fixed here: +# - imp.load_module() cannot be prevented from clobbering existing +# loaded modules, so calling synopsis() on a binary module file +# changes the contents of any existing module with the same name. +# - If the __file__ attribute on a module is a relative path and +# the current directory is changed with os.chdir(), an incorrect +# path will be displayed. + +import sys, imp, os, re, types, inspect, __builtin__, pkgutil +from repr import Repr +from string import expandtabs, find, join, lower, split, strip, rfind, rstrip +try: + from collections import deque +except ImportError: + # Python 2.3 compatibility + class deque(list): + def popleft(self): + return self.pop(0) + +# --------------------------------------------------------- common routines + +def pathdirs(): + """Convert sys.path into a list of absolute, existing, unique paths.""" + dirs = [] + normdirs = [] + for dir in sys.path: + dir = os.path.abspath(dir or '.') + normdir = os.path.normcase(dir) + if normdir not in normdirs and os.path.isdir(dir): + dirs.append(dir) + normdirs.append(normdir) + return dirs + +def getdoc(object): + """Get the doc string or comments for an object.""" + result = inspect.getdoc(object) or inspect.getcomments(object) + return result and re.sub('^ *\n', '', rstrip(result)) or '' + +def splitdoc(doc): + """Split a doc string into a synopsis line (if any) and the rest.""" + lines = split(strip(doc), '\n') + if len(lines) == 1: + return lines[0], '' + elif len(lines) >= 2 and not rstrip(lines[1]): + return lines[0], join(lines[2:], '\n') + return '', join(lines, '\n') + +def classname(object, modname): + """Get a class name and qualify it with a module name if necessary.""" + name = object.__name__ + if object.__module__ != modname: + name = object.__module__ + '.' + name + return name + +def isdata(object): + """Check if an object is of a type that probably means it's data.""" + return not (inspect.ismodule(object) or inspect.isclass(object) or + inspect.isroutine(object) or inspect.isframe(object) or + inspect.istraceback(object) or inspect.iscode(object)) + +def replace(text, *pairs): + """Do a series of global replacements on a string.""" + while pairs: + text = join(split(text, pairs[0]), pairs[1]) + pairs = pairs[2:] + return text + +def cram(text, maxlen): + """Omit part of a string if needed to make it fit in a maximum length.""" + if len(text) > maxlen: + pre = max(0, (maxlen-3)//2) + post = max(0, maxlen-3-pre) + return text[:pre] + '...' + text[len(text)-post:] + return text + +_re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE) +def stripid(text): + """Remove the hexadecimal id from a Python object representation.""" + # The behaviour of %p is implementation-dependent in terms of case. + if _re_stripid.search(repr(Exception)): + return _re_stripid.sub(r'\1', text) + return text + +def _is_some_method(obj): + return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj) + +def allmethods(cl): + methods = {} + for key, value in inspect.getmembers(cl, _is_some_method): + methods[key] = 1 + for base in cl.__bases__: + methods.update(allmethods(base)) # all your base are belong to us + for key in methods.keys(): + methods[key] = getattr(cl, key) + return methods + +def _split_list(s, predicate): + """Split sequence s via predicate, and return pair ([true], [false]). + + The return value is a 2-tuple of lists, + ([x for x in s if predicate(x)], + [x for x in s if not predicate(x)]) + """ + + yes = [] + no = [] + for x in s: + if predicate(x): + yes.append(x) + else: + no.append(x) + return yes, no + +def visiblename(name, all=None): + """Decide whether to show documentation on a variable.""" + # Certain special names are redundant. + if name in ('__builtins__', '__doc__', '__file__', '__path__', + '__module__', '__name__', '__slots__'): return 0 + # Private names are hidden, but special names are displayed. + if name.startswith('__') and name.endswith('__'): return 1 + if all is not None: + # only document that which the programmer exported in __all__ + return name in all + else: + return not name.startswith('_') + +def classify_class_attrs(object): + """Wrap inspect.classify_class_attrs, with fixup for data descriptors.""" + def fixup((name, kind, cls, value)): + if inspect.isdatadescriptor(value): + kind = 'data descriptor' + return name, kind, cls, value + return map(fixup, inspect.classify_class_attrs(object)) + +# ----------------------------------------------------- module manipulation + +def ispackage(path): + """Guess whether a path refers to a package directory.""" + if os.path.isdir(path): + for ext in ('.py', '.pyc', '.pyo', '$py.class'): + if os.path.isfile(os.path.join(path, '__init__' + ext)): + return True + return False + +def source_synopsis(file): + line = file.readline() + while line[:1] == '#' or not strip(line): + line = file.readline() + if not line: break + line = strip(line) + if line[:4] == 'r"""': line = line[1:] + if line[:3] == '"""': + line = line[3:] + if line[-1:] == '\\': line = line[:-1] + while not strip(line): + line = file.readline() + if not line: break + result = strip(split(line, '"""')[0]) + else: result = None + return result + +def synopsis(filename, cache={}): + """Get the one-line summary out of a module file.""" + mtime = os.stat(filename).st_mtime + lastupdate, result = cache.get(filename, (0, None)) + if lastupdate < mtime: + info = inspect.getmoduleinfo(filename) + try: + file = open(filename) + except IOError: + # module can't be opened, so skip it + return None + if info and 'b' in info[2]: # binary modules have to be imported + try: module = imp.load_module('__temp__', file, filename, info[1:]) + except: return None + result = (module.__doc__ or '').splitlines()[0] + del sys.modules['__temp__'] + else: # text modules can be directly examined + result = source_synopsis(file) + file.close() + cache[filename] = (mtime, result) + return result + +class ErrorDuringImport(Exception): + """Errors that occurred while trying to import something to document it.""" + def __init__(self, filename, (exc, value, tb)): + self.filename = filename + self.exc = exc + self.value = value + self.tb = tb + + def __str__(self): + exc = self.exc + if type(exc) is types.ClassType: + exc = exc.__name__ + return 'problem in %s - %s: %s' % (self.filename, exc, self.value) + +def importfile(path): + """Import a Python source file or compiled file given its path.""" + magic = imp.get_magic() + file = open(path, 'r') + if file.read(len(magic)) == magic: + kind = imp.PY_COMPILED + else: + kind = imp.PY_SOURCE + file.close() + filename = os.path.basename(path) + name, ext = os.path.splitext(filename) + file = open(path, 'r') + try: + module = imp.load_module(name, file, path, (ext, 'r', kind)) + except: + raise ErrorDuringImport(path, sys.exc_info()) + file.close() + return module + +def safeimport(path, forceload=0, cache={}): + """Import a module; handle errors; return None if the module isn't found. + + If the module *is* found but an exception occurs, it's wrapped in an + ErrorDuringImport exception and reraised. Unlike __import__, if a + package path is specified, the module at the end of the path is returned, + not the package at the beginning. If the optional 'forceload' argument + is 1, we reload the module from disk (unless it's a dynamic extension).""" + try: + # If forceload is 1 and the module has been previously loaded from + # disk, we always have to reload the module. Checking the file's + # mtime isn't good enough (e.g. the module could contain a class + # that inherits from another module that has changed). + if forceload and path in sys.modules: + if path not in sys.builtin_module_names: + # Avoid simply calling reload() because it leaves names in + # the currently loaded module lying around if they're not + # defined in the new source file. Instead, remove the + # module from sys.modules and re-import. Also remove any + # submodules because they won't appear in the newly loaded + # module's namespace if they're already in sys.modules. + subs = [m for m in sys.modules if m.startswith(path + '.')] + for key in [path] + subs: + # Prevent garbage collection. + cache[key] = sys.modules[key] + del sys.modules[key] + module = __import__(path) + except: + # Did the error occur before or after the module was found? + (exc, value, tb) = info = sys.exc_info() + if path in sys.modules: + # An error occurred while executing the imported module. + raise ErrorDuringImport(sys.modules[path].__file__, info) + elif exc is SyntaxError: + # A SyntaxError occurred before we could execute the module. + raise ErrorDuringImport(value.filename, info) + elif exc is ImportError and \ + split(lower(str(value)))[:2] == ['no', 'module']: + # The module was not found. + return None + else: + # Some other error occurred during the importing process. + raise ErrorDuringImport(path, sys.exc_info()) + for part in split(path, '.')[1:]: + try: module = getattr(module, part) + except AttributeError: return None + return module + +# ---------------------------------------------------- formatter base class + +class Doc: + def document(self, object, name=None, *args): + """Generate documentation for an object.""" + args = (object, name) + args + # 'try' clause is to attempt to handle the possibility that inspect + # identifies something in a way that pydoc itself has issues handling; + # think 'super' and how it is a descriptor (which raises the exception + # by lacking a __name__ attribute) and an instance. + if inspect.isgetsetdescriptor(object): return self.docdata(*args) + if inspect.ismemberdescriptor(object): return self.docdata(*args) + try: + if inspect.ismodule(object): return self.docmodule(*args) + if inspect.isclass(object): return self.docclass(*args) + if inspect.isroutine(object): return self.docroutine(*args) + except AttributeError: + pass + if isinstance(object, property): return self.docproperty(*args) + return self.docother(*args) + + def fail(self, object, name=None, *args): + """Raise an exception for unimplemented types.""" + message = "don't know how to document object%s of type %s" % ( + name and ' ' + repr(name), type(object).__name__) + raise TypeError, message + + docmodule = docclass = docroutine = docother = docproperty = docdata = fail + + def getdocloc(self, object): + """Return the location of module docs or None""" + + try: + file = inspect.getabsfile(object) + except TypeError: + file = '(built-in)' + + docloc = os.environ.get("PYTHONDOCS", + "http://www.python.org/doc/current/lib") + basedir = os.path.join(sys.exec_prefix, "lib", + "python"+sys.version[0:3]) + if (isinstance(object, type(os)) and + (object.__name__ in ('errno', 'exceptions', 'gc', 'imp', + 'marshal', 'posix', 'signal', 'sys', + 'thread', 'zipimport') or + (file.startswith(basedir) and + not file.startswith(os.path.join(basedir, 'site-packages'))))): + htmlfile = "module-%s.html" % object.__name__ + if docloc.startswith("http://"): + docloc = "%s/%s" % (docloc.rstrip("/"), htmlfile) + else: + docloc = os.path.join(docloc, htmlfile) + else: + docloc = None + return docloc + +# -------------------------------------------- HTML documentation generator + +class HTMLRepr(Repr): + """Class for safely making an HTML representation of a Python object.""" + def __init__(self): + Repr.__init__(self) + self.maxlist = self.maxtuple = 20 + self.maxdict = 10 + self.maxstring = self.maxother = 100 + + def escape(self, text): + return replace(text, '&', '&', '<', '<', '>', '>') + + def repr(self, object): + return Repr.repr(self, object) + + def repr1(self, x, level): + if hasattr(type(x), '__name__'): + methodname = 'repr_' + join(split(type(x).__name__), '_') + if hasattr(self, methodname): + return getattr(self, methodname)(x, level) + return self.escape(cram(stripid(repr(x)), self.maxother)) + + def repr_string(self, x, level): + test = cram(x, self.maxstring) + testrepr = repr(test) + if '\\' in test and '\\' not in replace(testrepr, r'\\', ''): + # Backslashes are only literal in the string and are never + # needed to make any special characters, so show a raw string. + return 'r' + testrepr[0] + self.escape(test) + testrepr[0] + return re.sub(r'((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)', + r'<font color="#c040c0">\1</font>', + self.escape(testrepr)) + + repr_str = repr_string + + def repr_instance(self, x, level): + try: + return self.escape(cram(stripid(repr(x)), self.maxstring)) + except: + return self.escape('<%s instance>' % x.__class__.__name__) + + repr_unicode = repr_string + +class HTMLDoc(Doc): + """Formatter class for HTML documentation.""" + + # ------------------------------------------- HTML formatting utilities + + _repr_instance = HTMLRepr() + repr = _repr_instance.repr + escape = _repr_instance.escape + + def page(self, title, contents): + """Format an HTML page.""" + return ''' +<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html><head><title>Python: %s</title> +</head><body bgcolor="#f0f0f8"> +%s +</body></html>''' % (title, contents) + + def heading(self, title, fgcol, bgcol, extras=''): + """Format a page heading.""" + return ''' +<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading"> +<tr bgcolor="%s"> +<td valign=bottom> <br> +<font color="%s" face="helvetica, arial"> <br>%s</font></td +><td align=right valign=bottom +><font color="%s" face="helvetica, arial">%s</font></td></tr></table> + ''' % (bgcol, fgcol, title, fgcol, extras or ' ') + + def section(self, title, fgcol, bgcol, contents, width=6, + prelude='', marginalia=None, gap=' '): + """Format a section with a heading.""" + if marginalia is None: + marginalia = '<tt>' + ' ' * width + '</tt>' + result = '''<p> +<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section"> +<tr bgcolor="%s"> +<td colspan=3 valign=bottom> <br> +<font color="%s" face="helvetica, arial">%s</font></td></tr> + ''' % (bgcol, fgcol, title) + if prelude: + result = result + ''' +<tr bgcolor="%s"><td rowspan=2>%s</td> +<td colspan=2>%s</td></tr> +<tr><td>%s</td>''' % (bgcol, marginalia, prelude, gap) + else: + result = result + ''' +<tr><td bgcolor="%s">%s</td><td>%s</td>''' % (bgcol, marginalia, gap) + + return result + '\n<td width="100%%">%s</td></tr></table>' % contents + + def bigsection(self, title, *args): + """Format a section with a big heading.""" + title = '<big><strong>%s</strong></big>' % title + return self.section(title, *args) + + def preformat(self, text): + """Format literal preformatted text.""" + text = self.escape(expandtabs(text)) + return replace(text, '\n\n', '\n \n', '\n\n', '\n \n', + ' ', ' ', '\n', '<br>\n') + + def multicolumn(self, list, format, cols=4): + """Format a list of items into a multi-column list.""" + result = '' + rows = (len(list)+cols-1)/cols + for col in range(cols): + result = result + '<td width="%d%%" valign=top>' % (100/cols) + for i in range(rows*col, rows*col+rows): + if i < len(list): + result = result + format(list[i]) + '<br>\n' + result = result + '</td>' + return '<table width="100%%" summary="list"><tr>%s</tr></table>' % result + + def grey(self, text): return '<font color="#909090">%s</font>' % text + + def namelink(self, name, *dicts): + """Make a link for an identifier, given name-to-URL mappings.""" + for dict in dicts: + if name in dict: + return '<a href="%s">%s</a>' % (dict[name], name) + return name + + def classlink(self, object, modname): + """Make a link for a class.""" + name, module = object.__name__, sys.modules.get(object.__module__) + if hasattr(module, name) and getattr(module, name) is object: + return '<a href="%s.html#%s">%s</a>' % ( + module.__name__, name, classname(object, modname)) + return classname(object, modname) + + def modulelink(self, object): + """Make a link for a module.""" + return '<a href="%s.html">%s</a>' % (object.__name__, object.__name__) + + def modpkglink(self, (name, path, ispackage, shadowed)): + """Make a link for a module or package to display in an index.""" + if shadowed: + return self.grey(name) + if path: + url = '%s.%s.html' % (path, name) + else: + url = '%s.html' % name + if ispackage: + text = '<strong>%s</strong> (package)' % name + else: + text = name + return '<a href="%s">%s</a>' % (url, text) + + def markup(self, text, escape=None, funcs={}, classes={}, methods={}): + """Mark up some plain text, given a context of symbols to look for. + Each context dictionary maps object names to anchor names.""" + escape = escape or self.escape + results = [] + here = 0 + pattern = re.compile(r'\b((http|ftp)://\S+[\w/]|' + r'RFC[- ]?(\d+)|' + r'PEP[- ]?(\d+)|' + r'(self\.)?(\w+))') + while True: + match = pattern.search(text, here) + if not match: break + start, end = match.span() + results.append(escape(text[here:start])) + + all, scheme, rfc, pep, selfdot, name = match.groups() + if scheme: + url = escape(all).replace('"', '"') + results.append('<a href="%s">%s</a>' % (url, url)) + elif rfc: + url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc) + results.append('<a href="%s">%s</a>' % (url, escape(all))) + elif pep: + url = 'http://www.python.org/peps/pep-%04d.html' % int(pep) + results.append('<a href="%s">%s</a>' % (url, escape(all))) + elif text[end:end+1] == '(': + results.append(self.namelink(name, methods, funcs, classes)) + elif selfdot: + results.append('self.<strong>%s</strong>' % name) + else: + results.append(self.namelink(name, classes)) + here = end + results.append(escape(text[here:])) + return join(results, '') + + # ---------------------------------------------- type-specific routines + + def formattree(self, tree, modname, parent=None): + """Produce HTML for a class tree as given by inspect.getclasstree().""" + result = '' + for entry in tree: + if type(entry) is type(()): + c, bases = entry + result = result + '<dt><font face="helvetica, arial">' + result = result + self.classlink(c, modname) + if bases and bases != (parent,): + parents = [] + for base in bases: + parents.append(self.classlink(base, modname)) + result = result + '(' + join(parents, ', ') + ')' + result = result + '\n</font></dt>' +... [truncated message content] |