From: <pj...@us...> - 2009-05-09 21:07:07
|
Revision: 6319 http://jython.svn.sourceforge.net/jython/?rev=6319&view=rev Author: pjenvey Date: 2009-05-09 21:06:49 +0000 (Sat, 09 May 2009) Log Message: ----------- coding standards Modified Paths: -------------- trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2009-05-08 06:41:51 UTC (rev 6318) +++ trunk/jython/src/org/python/util/jython.java 2009-05-09 21:06:49 UTC (rev 6319) @@ -2,8 +2,9 @@ package org.python.util; import java.io.File; -import java.io.IOException; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.List; @@ -29,8 +30,7 @@ import org.python.modules._systemrestart; import org.python.modules.thread.thread; -public class jython -{ +public class jython { private static final String COPYRIGHT = "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information."; @@ -64,32 +64,32 @@ "- : program read from stdin (default; interactive mode if a tty)\n" + "arg ... : arguments passed to program in sys.argv[1:]\n" + "Other environment variables:\n" + - "JYTHONPATH: '" + java.io.File.pathSeparator + "'-separated list of directories prefixed to the default module\n" + + "JYTHONPATH: '" + File.pathSeparator + + "'-separated list of directories prefixed to the default module\n" + " search path. The result is sys.path."; public static boolean shouldRestart; public static void runJar(String filename) { - // TBD: this is kind of gross because a local called `zipfile' just - // magically shows up in the module's globals. Either `zipfile' - // should be called `__zipfile__' or (preferrably, IMO), __run__.py - // should be imported and a main() function extracted. This - // function should be called passing zipfile in as an argument. + // TBD: this is kind of gross because a local called `zipfile' just magically + // shows up in the module's globals. Either `zipfile' should be called + // `__zipfile__' or (preferrably, IMO), __run__.py should be imported and a main() + // function extracted. This function should be called passing zipfile in as an + // argument. // - // Probably have to keep this code around for backwards - // compatibility (?) + // Probably have to keep this code around for backwards compatibility (?) try { ZipFile zip = new ZipFile(filename); ZipEntry runit = zip.getEntry("__run__.py"); - if (runit == null) + if (runit == null) { throw Py.ValueError("jar file missing '__run__.py'"); + } PyStringMap locals = new PyStringMap(); - // Stripping the stuff before the last File.separator fixes Bug - // #931129 by keeping illegal characters out of the generated - // proxy class name + // Stripping the stuff before the last File.separator fixes Bug #931129 by + // keeping illegal characters out of the generated proxy class name int beginIndex; if ((beginIndex = filename.lastIndexOf(File.separator)) != -1) { filename = filename.substring(beginIndex + 1); @@ -151,7 +151,7 @@ opts.interactive = ((PyFile)Py.defaultSystemState.stdin).isatty(); if (!opts.interactive) { PySystemState systemState = Py.getSystemState(); - systemState.ps1 = systemState.ps2 = new PyString(); + systemState.ps1 = systemState.ps2 = Py.EmptyString; } } @@ -176,13 +176,13 @@ } if (opts.division != null) { - if ("old".equals(opts.division)) + if ("old".equals(opts.division)) { Options.divisionWarning = 0; - else if ("warn".equals(opts.division)) + } else if ("warn".equals(opts.division)) { Options.divisionWarning = 1; - else if ("warnall".equals(opts.division)) + } else if ("warnall".equals(opts.division)) { Options.divisionWarning = 2; - else if ("new".equals(opts.division)) { + } else if ("new".equals(opts.division)) { Options.Qnew = true; interp.cflags.setFlag(CodeFlag.CO_FUTURE_DIVISION); } @@ -204,8 +204,7 @@ runJar(opts.filename); } else if (opts.filename.equals("-")) { try { - interp.locals.__setitem__(new PyString("__file__"), - new PyString("<stdin>")); + interp.locals.__setitem__(new PyString("__file__"), new PyString("<stdin>")); interp.execfile(System.in, "<stdin>"); } catch (Throwable t) { Py.printException(t); @@ -217,8 +216,8 @@ FileInputStream file; try { - file = new java.io.FileInputStream(new RelativeFile(opts.filename)); - } catch (java.io.FileNotFoundException e) { + file = new FileInputStream(new RelativeFile(opts.filename)); + } catch (FileNotFoundException e) { throw Py.IOError(e); } if (FileUtil.isatty(file.getFD())) { @@ -228,9 +227,9 @@ } else { interp.execfile(file, opts.filename); } - } catch(Throwable t) { - if (t instanceof PyException && - ((PyException)t).match(_systemrestart.SystemRestart)) { + } catch (Throwable t) { + if (t instanceof PyException + && ((PyException)t).match(_systemrestart.SystemRestart)) { // Shutdown this instance... shouldRestart = true; shutdownInterpreter(); @@ -248,12 +247,11 @@ } } else { - // if there was no file name on the command line, then "" is - // the first element on sys.path. This is here because if - // there /was/ a filename on the c.l., and say the -i option - // was given, sys.path[0] will have gotten filled in with the - // dir of the argument filename. - Py.getSystemState().path.insert(0, new PyString("")); + // if there was no file name on the command line, then "" is the first element + // on sys.path. This is here because if there /was/ a filename on the c.l., + // and say the -i option was given, sys.path[0] will have gotten filled in + // with the dir of the argument filename. + Py.getSystemState().path.insert(0, Py.EmptyString); if (opts.command != null) { try { @@ -285,10 +283,11 @@ opts.encoding = PySystemState.registry.getProperty( "python.console.encoding", null); } - if(opts.encoding != null) { - if(!Charset.isSupported(opts.encoding)) { + if (opts.encoding != null) { + if (!Charset.isSupported(opts.encoding)) { System.err.println(opts.encoding - + " is not a supported encoding on this JVM, so it can't be used in python.console.encoding."); + + " is not a supported encoding on this JVM, so it can't " + + "be used in python.console.encoding."); System.exit(1); } interp.cflags.encoding = opts.encoding; @@ -311,8 +310,9 @@ */ private static InteractiveConsole newInterpreter() { try { - String interpClass = PySystemState.registry.getProperty("python.console", - "org.python.util.InteractiveConsole"); + String interpClass = + PySystemState.registry.getProperty("python.console", + "org.python.util.InteractiveConsole"); return (InteractiveConsole)Class.forName(interpClass).newInstance(); } catch (Throwable t) { return new InteractiveConsole(); @@ -335,8 +335,7 @@ } } -class CommandLineOptions -{ +class CommandLineOptions { public String filename; public boolean jar, interactive, notice; public boolean runCommand, runModule; @@ -363,57 +362,50 @@ properties.put(key, value); try { System.setProperty(key, value); + } catch (SecurityException e) { + // continue } - catch (SecurityException e) {} } public boolean parse(String[] args) { - int index=0; + int index = 0; + while (index < args.length && args[index].startsWith("-")) { String arg = args[index]; if (arg.equals("-h") || arg.equals("-?") || arg.equals("--help")) { help = true; return false; - } - else if (arg.equals("-V") || arg.equals("--version")) { + } else if (arg.equals("-V") || arg.equals("--version")) { version = true; return false; - } - else if (arg.equals("-")) { - if (!fixInteractive) + } else if (arg.equals("-")) { + if (!fixInteractive) { interactive = false; + } filename = "-"; - } - else if (arg.equals("-i")) { + } else if (arg.equals("-i")) { fixInteractive = true; interactive = true; - } - else if (arg.equals("-jar")) { + } else if (arg.equals("-jar")) { jar = true; - if (!fixInteractive) + if (!fixInteractive) { interactive = false; - } - else if (arg.equals("-u")) { + } + } else if (arg.equals("-u")) { Options.unbuffered = true; - } - else if (arg.equals("-v")) { + } else if (arg.equals("-v")) { Options.verbose++; - } - else if (arg.equals("-vv")) { + } else if (arg.equals("-vv")) { Options.verbose += 2; - } - else if (arg.equals("-vvv")) { + } else if (arg.equals("-vvv")) { Options.verbose +=3 ; - } - else if (arg.equals("-S")) { + } else if (arg.equals("-S")) { Options.importSite = false; - } - else if (arg.equals("-c")) { + } else if (arg.equals("-c")) { runCommand = true; if (arg.length() > 2) { command = arg.substring(2); - } - else if ((index + 1) < args.length) { + } else if ((index + 1) < args.length) { command = args[++index]; } else { System.err.println("Argument expected for the -c option"); @@ -426,19 +418,14 @@ } index++; break; - } - else if (arg.equals("-W")) { + } else if (arg.equals("-W")) { warnoptions.add(args[++index]); - } - else if (arg.equals("-C")) { + } else if (arg.equals("-C")) { encoding = args[++index]; - } - else if (arg.equals("-E")) { - // XXX: accept -E (ignore environment variables) to be - // compatiable with CPython. do nothing for now (we - // could ignore the registry) - } - else if (arg.startsWith("-D")) { + } else if (arg.equals("-E")) { + // XXX: accept -E (ignore environment variables) to be compatiable with + // CPython. do nothing for now (we could ignore the registry) + } else if (arg.startsWith("-D")) { String key = null; String value = null; int equals = arg.indexOf("="); @@ -446,25 +433,22 @@ String arg2 = args[++index]; key = arg.substring(2, arg.length()); value = arg2; - } - else { + } else { key = arg.substring(2, equals); - value = arg.substring(equals+1, arg.length()); + value = arg.substring(equals + 1, arg.length()); } setProperty(key, value); - } - else if (arg.startsWith("-Q")) { - if (arg.length() > 2) + } else if (arg.startsWith("-Q")) { + if (arg.length() > 2) { division = arg.substring(2); - else + } else { division = args[++index]; - } - else if (arg.startsWith("-m")) { + } + } else if (arg.startsWith("-m")) { runModule = true; if (arg.length() > 2) { moduleName = arg.substring(2); - } - else if ((index + 1) < args.length) { + } else if ((index + 1) < args.length) { moduleName = args[++index]; } else { System.err.println("Argument expected for the -m option"); @@ -477,20 +461,20 @@ } index++; - int n = args.length-index+1; + int n = args.length - index + 1; argv = new String[n]; argv[0] = moduleName; for (int i = 1; index < args.length; i++, index++) { argv[i] = args[index]; } return true; - } - else { + } else { String opt = args[index]; - if (opt.startsWith("--")) + if (opt.startsWith("--")) { opt = opt.substring(2); - else if (opt.startsWith("-")) + } else if (opt.startsWith("-")) { opt = opt.substring(1); + } System.err.println("Unknown option: " + opt); return false; } @@ -499,24 +483,26 @@ notice = interactive; if (filename == null && index < args.length && command == null) { filename = args[index++]; - if (!fixInteractive) + if (!fixInteractive) { interactive = false; + } notice = false; } - if (command != null) + if (command != null) { notice = false; + } - int n = args.length-index+1; + int n = args.length - index + 1; argv = new String[n]; - //new String[args.length-index+1]; - if (filename != null) + if (filename != null) { argv[0] = filename; - else if (command != null) + } else if (command != null) { argv[0] = "-c"; - else + } else { argv[0] = ""; + } - for(int i=1; i<n; i++, index++) { + for (int i = 1; i < n; i++, index++) { argv[i] = args[index]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |