From: <pj...@us...> - 2011-03-19 20:03:26
|
Revision: 7246 http://jython.svn.sourceforge.net/jython/?rev=7246&view=rev Author: pjenvey Date: 2011-03-19 20:03:20 +0000 (Sat, 19 Mar 2011) Log Message: ----------- add -3 and Py.warnPy3k Modified Paths: -------------- trunk/jython/src/org/python/core/Options.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/core/Options.java =================================================================== --- trunk/jython/src/org/python/core/Options.java 2011-03-18 02:25:16 UTC (rev 7245) +++ trunk/jython/src/org/python/core/Options.java 2011-03-19 20:03:20 UTC (rev 7246) @@ -75,6 +75,9 @@ /** Force stdin, stdout and stderr to be unbuffered, and opened in * binary mode */ public static boolean unbuffered = false; + + /** Whether -3 (py3k warnings) were enabled via the command line. */ + public static boolean py3kwarning = false; //XXX: place holder public static int bytes_warning = 0; Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2011-03-18 02:25:16 UTC (rev 7245) +++ trunk/jython/src/org/python/core/Py.java 2011-03-19 20:03:20 UTC (rev 7246) @@ -410,6 +410,16 @@ warning(BytesWarning, message); } + public static void warnPy3k(String message) { + warnPy3k(message, 1); + } + + public static void warnPy3k(String message, int stacklevel) { + if (Options.py3kwarning) { + warning(DeprecationWarning, message, stacklevel); + } + } + private static PyObject warnings_mod; private static PyObject importWarnings() { @@ -438,6 +448,10 @@ } public static void warning(PyObject category, String message) { + warning(category, message, 1); + } + + public static void warning(PyObject category, String message, int stacklevel) { PyObject func = null; PyObject mod = importWarnings(); if (mod != null) { @@ -447,7 +461,7 @@ System.err.println(warn_hcategory(category) + ": " + message); return; } else { - func.__call__(Py.newString(message), category); + func.__call__(Py.newString(message), category, Py.newInteger(stacklevel)); } } Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2011-03-18 02:25:16 UTC (rev 7245) +++ trunk/jython/src/org/python/core/PySystemState.java 2011-03-19 20:03:20 UTC (rev 7246) @@ -70,8 +70,7 @@ // for tests that would need to pass but today would not. public final static int maxsize = Integer.MAX_VALUE; - //XXX: place holder - public final static boolean py3kwarning = false; + public static boolean py3kwarning = false; public final static Class flags = Options.class; @@ -190,6 +189,7 @@ currentWorkingDir = new File("").getAbsolutePath(); + py3kwarning = Options.py3kwarning; // Set up the initial standard ins and outs String mode = Options.unbuffered ? "b" : ""; int buffering = Options.unbuffered ? 0 : 1; Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2011-03-18 02:25:16 UTC (rev 7245) +++ trunk/jython/src/org/python/util/jython.java 2011-03-19 20:03:20 UTC (rev 7246) @@ -39,6 +39,7 @@ private static final String usage = usageHeader + "Options and arguments:\n" + //(and corresponding environment variables):\n" + + //"-B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x\n" + "-c cmd : program passed in as string (terminates option list)\n" + //"-d : debug output from parser (also PYTHONDEBUG=x)\n" + "-Dprop=v : Set the property `prop' to value `v'\n"+ @@ -52,14 +53,18 @@ //"-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n" + //"-OO : remove doc-strings in addition to the -O optimizations\n" + "-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n" + + // XXX: support -s + //"-s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n" + "-S : don't imply 'import site' on initialization\n" + //"-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n" + "-u : unbuffered binary stdout and stderr\n" + // (also PYTHONUNBUFFERED=x)\n" + //" see man page for details on internal buffering relating to '-u'\n" + "-v : verbose (trace import statements)\n" + // (also PYTHONVERBOSE=x)\n" + + " can be supplied multiple times to increase verbosity\n" + "-V : print the Python version number and exit (also --version)\n" + "-W arg : warning control (arg is action:message:category:module:lineno)\n" + //"-x : skip first line of source, allowing use of non-Unix forms of #!cmd\n" + + "-3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix\n" + "file : program read from script file\n" + "- : program read from stdin (default; interactive mode if a tty)\n" + "arg ... : arguments passed to program in sys.argv[1:]\n" + @@ -498,6 +503,8 @@ argv[i] = args[index]; } return true; + } else if (arg.startsWith("-3")) { + Options.py3kwarning = true; } else { String opt = args[index]; if (opt.startsWith("--")) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |