From jython-checkins at python.org Sun Jan 1 23:00:01 2012 From: jython-checkins at python.org (frank.wierzbicki) Date: Sun, 01 Jan 2012 23:00:01 +0100 Subject: [Jython-checkins] =?utf8?q?jython_=282=2E5=29=3A_Use_finally_for_?= =?utf8?q?resource_closings=2E?= Message-ID: http://hg.python.org/jython/rev/abcb98e5b619 changeset: 6293:abcb98e5b619 branch: 2.5 parent: 6291:958ecf3eb8f0 user: Frank Wierzbicki date: Sun Jan 01 13:32:26 2012 -0800 summary: Use finally for resource closings. files: src/org/python/core/packagecache/CachedJarsPackageManager.java | 76 +++++++-- 1 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/org/python/core/packagecache/CachedJarsPackageManager.java b/src/org/python/core/packagecache/CachedJarsPackageManager.java --- a/src/org/python/core/packagecache/CachedJarsPackageManager.java +++ b/src/org/python/core/packagecache/CachedJarsPackageManager.java @@ -308,17 +308,22 @@ entry.mtime = mtime; } - InputStream jarin; - if (jarconn == null) { - jarin = new BufferedInputStream( - new FileInputStream(jarfile)); - } else { - jarin = jarconn.getInputStream(); + InputStream jarin = null; + try { + if (jarconn == null) { + jarin = new BufferedInputStream( + new FileInputStream(jarfile)); + } else { + jarin = jarconn.getInputStream(); + } + + zipPackages = getZipPackages(jarin); + } finally { + if (jarin != null) { + jarin.close(); + } } - zipPackages = getZipPackages(jarin); - jarin.close(); - if (caching) { writeCacheFile(entry, jarcanon, zipPackages, brandNew); } @@ -357,8 +362,9 @@ debug("reading cache, '" + jarcanon + "'"); + DataInputStream istream = null; try { - DataInputStream istream = inOpenCacheFile(cachefile); + istream = inOpenCacheFile(cachefile); String old_jarcanon = istream.readUTF(); long old_mtime = istream.readLong(); if ((!old_jarcanon.equals(jarcanon)) || (old_mtime != mtime)) { @@ -383,22 +389,30 @@ packs.put(packageName, classes); } } catch (EOFException eof) { - ; + //ignore } - istream.close(); return packs; } catch (IOException ioe) { // if (cachefile.exists()) cachefile.delete(); return null; + } finally { + if (istream != null) { + try { + istream.close(); + } catch (IOException ignore) { + //ignore + } + } } } // Write a cache file storing package info for a single .jar private void writeCacheFile(JarXEntry entry, String jarcanon, Map zipPackages, boolean brandNew) { + DataOutputStream ostream = null; try { - DataOutputStream ostream = outCreateCacheFile(entry, brandNew); + ostream = outCreateCacheFile(entry, brandNew); ostream.writeUTF(jarcanon); ostream.writeLong(entry.mtime); comment("rewriting cachefile for '" + jarcanon + "'"); @@ -412,9 +426,16 @@ ostream.writeUTF(part); } } - ostream.close(); } catch (IOException ioe) { warning("can't write cache file for '" + jarcanon + "'"); + } finally { + if (ostream != null) { + try { + ostream.close(); + } catch (IOException ignore) { + //ignore + } + } } } @@ -455,8 +476,9 @@ this.indexModified = false; this.jarfiles = Generic.map(); + DataInputStream istream = null; try { - DataInputStream istream = inOpenIndex(); + istream = inOpenIndex(); if (istream == null) { return; } @@ -469,13 +491,19 @@ this.jarfiles.put(jarcanon, new JarXEntry(cachefile, mtime)); } } catch (EOFException eof) { - ; + //ignore } - istream.close(); } catch (IOException ioe) { warning("invalid index file"); + } finally { + if (istream != null) { + try { + istream.close(); + } catch (IOException ignore) { + //ignore + } + } } - } /** @@ -491,8 +519,9 @@ comment("writing modified index file"); + DataOutputStream ostream = null; try { - DataOutputStream ostream = outOpenIndex(); + ostream = outOpenIndex(); for (Entry entry : jarfiles.entrySet()) { String jarcanon = entry.getKey(); JarXEntry xentry = entry.getValue(); @@ -500,9 +529,16 @@ ostream.writeUTF(xentry.cachefile); ostream.writeLong(xentry.mtime); } - ostream.close(); } catch (IOException ioe) { warning("can't write index file"); + } finally { + if (ostream != null) { + try { + ostream.close(); + } catch (IOException ignore) { + //ignore + } + } } } -- Repository URL: http://hg.python.org/jython From jython-checkins at python.org Sun Jan 1 23:00:02 2012 From: jython-checkins at python.org (frank.wierzbicki) Date: Sun, 01 Jan 2012 23:00:02 +0100 Subject: [Jython-checkins] =?utf8?q?jython_=28merge_2=2E5_-=3E_default=29?= =?utf8?q?=3A_Merge_w/_2=2E5?= Message-ID: http://hg.python.org/jython/rev/f575ec2f6e96 changeset: 6294:f575ec2f6e96 parent: 6292:b3007362260c parent: 6293:abcb98e5b619 user: Frank Wierzbicki date: Sun Jan 01 13:59:53 2012 -0800 summary: Merge w/ 2.5 files: src/org/python/core/packagecache/CachedJarsPackageManager.java | 76 +++++++-- 1 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/org/python/core/packagecache/CachedJarsPackageManager.java b/src/org/python/core/packagecache/CachedJarsPackageManager.java --- a/src/org/python/core/packagecache/CachedJarsPackageManager.java +++ b/src/org/python/core/packagecache/CachedJarsPackageManager.java @@ -308,17 +308,22 @@ entry.mtime = mtime; } - InputStream jarin; - if (jarconn == null) { - jarin = new BufferedInputStream( - new FileInputStream(jarfile)); - } else { - jarin = jarconn.getInputStream(); + InputStream jarin = null; + try { + if (jarconn == null) { + jarin = new BufferedInputStream( + new FileInputStream(jarfile)); + } else { + jarin = jarconn.getInputStream(); + } + + zipPackages = getZipPackages(jarin); + } finally { + if (jarin != null) { + jarin.close(); + } } - zipPackages = getZipPackages(jarin); - jarin.close(); - if (caching) { writeCacheFile(entry, jarcanon, zipPackages, brandNew); } @@ -357,8 +362,9 @@ debug("reading cache, '" + jarcanon + "'"); + DataInputStream istream = null; try { - DataInputStream istream = inOpenCacheFile(cachefile); + istream = inOpenCacheFile(cachefile); String old_jarcanon = istream.readUTF(); long old_mtime = istream.readLong(); if ((!old_jarcanon.equals(jarcanon)) || (old_mtime != mtime)) { @@ -383,22 +389,30 @@ packs.put(packageName, classes); } } catch (EOFException eof) { - ; + //ignore } - istream.close(); return packs; } catch (IOException ioe) { // if (cachefile.exists()) cachefile.delete(); return null; + } finally { + if (istream != null) { + try { + istream.close(); + } catch (IOException ignore) { + //ignore + } + } } } // Write a cache file storing package info for a single .jar private void writeCacheFile(JarXEntry entry, String jarcanon, Map zipPackages, boolean brandNew) { + DataOutputStream ostream = null; try { - DataOutputStream ostream = outCreateCacheFile(entry, brandNew); + ostream = outCreateCacheFile(entry, brandNew); ostream.writeUTF(jarcanon); ostream.writeLong(entry.mtime); comment("rewriting cachefile for '" + jarcanon + "'"); @@ -412,9 +426,16 @@ ostream.writeUTF(part); } } - ostream.close(); } catch (IOException ioe) { warning("can't write cache file for '" + jarcanon + "'"); + } finally { + if (ostream != null) { + try { + ostream.close(); + } catch (IOException ignore) { + //ignore + } + } } } @@ -455,8 +476,9 @@ this.indexModified = false; this.jarfiles = Generic.map(); + DataInputStream istream = null; try { - DataInputStream istream = inOpenIndex(); + istream = inOpenIndex(); if (istream == null) { return; } @@ -469,13 +491,19 @@ this.jarfiles.put(jarcanon, new JarXEntry(cachefile, mtime)); } } catch (EOFException eof) { - ; + //ignore } - istream.close(); } catch (IOException ioe) { warning("invalid index file"); + } finally { + if (istream != null) { + try { + istream.close(); + } catch (IOException ignore) { + //ignore + } + } } - } /** @@ -491,8 +519,9 @@ comment("writing modified index file"); + DataOutputStream ostream = null; try { - DataOutputStream ostream = outOpenIndex(); + ostream = outOpenIndex(); for (Entry entry : jarfiles.entrySet()) { String jarcanon = entry.getKey(); JarXEntry xentry = entry.getValue(); @@ -500,9 +529,16 @@ ostream.writeUTF(xentry.cachefile); ostream.writeLong(xentry.mtime); } - ostream.close(); } catch (IOException ioe) { warning("can't write index file"); + } finally { + if (ostream != null) { + try { + ostream.close(); + } catch (IOException ignore) { + //ignore + } + } } } -- Repository URL: http://hg.python.org/jython From jython-checkins at python.org Mon Jan 2 23:00:58 2012 From: jython-checkins at python.org (frank.wierzbicki) Date: Mon, 02 Jan 2012 23:00:58 +0100 Subject: [Jython-checkins] =?utf8?q?jython_=282=2E5=29=3A_Expose_task_shou?= =?utf8?q?ld_depend_on_compile_task=2E?= Message-ID: http://hg.python.org/jython/rev/10aaf610d148 changeset: 6295:10aaf610d148 branch: 2.5 parent: 6293:abcb98e5b619 user: Frank Wierzbicki date: Mon Jan 02 11:33:22 2012 -0800 summary: Expose task should depend on compile task. files: build.xml | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/build.xml b/build.xml --- a/build.xml +++ b/build.xml @@ -593,7 +593,7 @@ - + -- Repository URL: http://hg.python.org/jython From jython-checkins at python.org Mon Jan 2 23:00:58 2012 From: jython-checkins at python.org (frank.wierzbicki) Date: Mon, 02 Jan 2012 23:00:58 +0100 Subject: [Jython-checkins] =?utf8?q?jython_=28merge_2=2E5_-=3E_default=29?= =?utf8?q?=3A_Merge_w/_2=2E5?= Message-ID: http://hg.python.org/jython/rev/401faa658035 changeset: 6296:401faa658035 parent: 6294:f575ec2f6e96 parent: 6295:10aaf610d148 user: Frank Wierzbicki date: Mon Jan 02 11:33:59 2012 -0800 summary: Merge w/ 2.5 files: build.xml | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/build.xml b/build.xml --- a/build.xml +++ b/build.xml @@ -595,7 +595,7 @@ - + -- Repository URL: http://hg.python.org/jython From jython-checkins at python.org Thu Jan 5 05:36:26 2012 From: jython-checkins at python.org (frank.wierzbicki) Date: Thu, 05 Jan 2012 05:36:26 +0100 Subject: [Jython-checkins] =?utf8?q?jython_=282=2E5=29=3A_Remove_commented?= =?utf8?q?_code=2C_tabs-=3Espaces=2E?= Message-ID: http://hg.python.org/jython/rev/edadd4f115f1 changeset: 6297:edadd4f115f1 branch: 2.5 parent: 6295:10aaf610d148 user: Frank Wierzbicki date: Tue Jan 03 09:26:00 2012 -0800 summary: Remove commented code, tabs->spaces. files: src/org/python/core/PyString.java | 75 +++++++----------- 1 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/org/python/core/PyString.java b/src/org/python/core/PyString.java --- a/src/org/python/core/PyString.java +++ b/src/org/python/core/PyString.java @@ -587,21 +587,6 @@ return str___hash__(); } -// @Override -// public boolean equals(Object obj) { -// if (obj == null) { -// return false; -// } -// if (getClass() != obj.getClass()) { -// return false; -// } -// final PyString other = (PyString) obj; -// if ((this.string == null) ? (other.string != null) : !this.string.equals(other.string)) { -// return false; -// } -// return true; -// } - @ExposedMethod(doc = BuiltinDocs.str___hash___doc) final int str___hash__() { return getString().hashCode(); @@ -876,7 +861,7 @@ int end = endDouble(getString(),s); z = Double.valueOf(getString().substring(s, end)).doubleValue(); if (z == Double.POSITIVE_INFINITY) { - throw Py.ValueError(String.format("float() out of range: %.150s", getString())); + throw Py.ValueError(String.format("float() out of range: %.150s", getString())); } s=end; @@ -2025,28 +2010,28 @@ int[] indices = translateIndices(start, end); if (prefix instanceof PyString) { - String strPrefix = ((PyString) prefix).getString(); + String strPrefix = ((PyString) prefix).getString(); if (indices[1] - indices[0] < strPrefix.length()) return false; - return getString().startsWith(strPrefix, indices[0]); + return getString().startsWith(strPrefix, indices[0]); } else if (prefix instanceof PyTuple) { - PyObject[] prefixes = ((PyTuple)prefix).getArray(); - - for (int i = 0 ; i < prefixes.length ; i++) { - if (!(prefixes[i] instanceof PyString)) - throw Py.TypeError("expected a character buffer object"); - - String strPrefix = ((PyString) prefixes[i]).getString(); + PyObject[] prefixes = ((PyTuple)prefix).getArray(); + + for (int i = 0 ; i < prefixes.length ; i++) { + if (!(prefixes[i] instanceof PyString)) + throw Py.TypeError("expected a character buffer object"); + + String strPrefix = ((PyString) prefixes[i]).getString(); if (indices[1] - indices[0] < strPrefix.length()) - continue; + continue; - if (getString().startsWith(strPrefix, indices[0])) - return true; - } - return false; + if (getString().startsWith(strPrefix, indices[0])) + return true; + } + return false; } else { - throw Py.TypeError("expected a character buffer object or tuple"); + throw Py.TypeError("expected a character buffer object or tuple"); } } @@ -2068,20 +2053,20 @@ String substr = getString().substring(indices[0], indices[1]); if (suffix instanceof PyString) { - return substr.endsWith(((PyString) suffix).getString()); + return substr.endsWith(((PyString) suffix).getString()); } else if (suffix instanceof PyTuple) { - PyObject[] suffixes = ((PyTuple)suffix).getArray(); - - for (int i = 0 ; i < suffixes.length ; i++) { - if (!(suffixes[i] instanceof PyString)) - throw Py.TypeError("expected a character buffer object"); - - if (substr.endsWith(((PyString) suffixes[i]).getString())) - return true; - } - return false; + PyObject[] suffixes = ((PyTuple)suffix).getArray(); + + for (int i = 0 ; i < suffixes.length ; i++) { + if (!(suffixes[i] instanceof PyString)) + throw Py.TypeError("expected a character buffer object"); + + if (substr.endsWith(((PyString) suffixes[i]).getString())) + return true; + } + return false; } else { - throw Py.TypeError("expected a character buffer object or tuple"); + throw Py.TypeError("expected a character buffer object or tuple"); } } @@ -2785,10 +2770,6 @@ numberFormat.setGroupingUsed(false); String ret = numberFormat.format(v); -// System.err.println("formatFloat: "+v+", prec="+prec+", ret="+ret); -// if (ret.indexOf('.') == -1) { -// return ret+'.'; -// } return ret; } -- Repository URL: http://hg.python.org/jython From jython-checkins at python.org Thu Jan 5 05:36:26 2012 From: jython-checkins at python.org (frank.wierzbicki) Date: Thu, 05 Jan 2012 05:36:26 +0100 Subject: [Jython-checkins] =?utf8?q?jython_=28merge_2=2E5_-=3E_default=29?= =?utf8?q?=3A_merge_w/_2=2E5?= Message-ID: http://hg.python.org/jython/rev/2b4f725d4d29 changeset: 6298:2b4f725d4d29 parent: 6296:401faa658035 parent: 6297:edadd4f115f1 user: Frank Wierzbicki date: Tue Jan 03 09:34:18 2012 -0800 summary: merge w/ 2.5 files: src/org/python/core/PyString.java | 75 +++++++----------- 1 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/org/python/core/PyString.java b/src/org/python/core/PyString.java --- a/src/org/python/core/PyString.java +++ b/src/org/python/core/PyString.java @@ -591,21 +591,6 @@ return str___hash__(); } -// @Override -// public boolean equals(Object obj) { -// if (obj == null) { -// return false; -// } -// if (getClass() != obj.getClass()) { -// return false; -// } -// final PyString other = (PyString) obj; -// if ((this.string == null) ? (other.string != null) : !this.string.equals(other.string)) { -// return false; -// } -// return true; -// } - @ExposedMethod(doc = BuiltinDocs.str___hash___doc) final int str___hash__() { return getString().hashCode(); @@ -880,7 +865,7 @@ int end = endDouble(getString(),s); z = Double.valueOf(getString().substring(s, end)).doubleValue(); if (z == Double.POSITIVE_INFINITY) { - throw Py.ValueError(String.format("float() out of range: %.150s", getString())); + throw Py.ValueError(String.format("float() out of range: %.150s", getString())); } s=end; @@ -2049,28 +2034,28 @@ int[] indices = translateIndices(start, end); if (prefix instanceof PyString) { - String strPrefix = ((PyString) prefix).getString(); + String strPrefix = ((PyString) prefix).getString(); if (indices[1] - indices[0] < strPrefix.length()) return false; - return getString().startsWith(strPrefix, indices[0]); + return getString().startsWith(strPrefix, indices[0]); } else if (prefix instanceof PyTuple) { - PyObject[] prefixes = ((PyTuple)prefix).getArray(); - - for (int i = 0 ; i < prefixes.length ; i++) { - if (!(prefixes[i] instanceof PyString)) - throw Py.TypeError("expected a character buffer object"); - - String strPrefix = ((PyString) prefixes[i]).getString(); + PyObject[] prefixes = ((PyTuple)prefix).getArray(); + + for (int i = 0 ; i < prefixes.length ; i++) { + if (!(prefixes[i] instanceof PyString)) + throw Py.TypeError("expected a character buffer object"); + + String strPrefix = ((PyString) prefixes[i]).getString(); if (indices[1] - indices[0] < strPrefix.length()) - continue; + continue; - if (getString().startsWith(strPrefix, indices[0])) - return true; - } - return false; + if (getString().startsWith(strPrefix, indices[0])) + return true; + } + return false; } else { - throw Py.TypeError("expected a character buffer object or tuple"); + throw Py.TypeError("expected a character buffer object or tuple"); } } @@ -2092,20 +2077,20 @@ String substr = getString().substring(indices[0], indices[1]); if (suffix instanceof PyString) { - return substr.endsWith(((PyString) suffix).getString()); + return substr.endsWith(((PyString) suffix).getString()); } else if (suffix instanceof PyTuple) { - PyObject[] suffixes = ((PyTuple)suffix).getArray(); - - for (int i = 0 ; i < suffixes.length ; i++) { - if (!(suffixes[i] instanceof PyString)) - throw Py.TypeError("expected a character buffer object"); - - if (substr.endsWith(((PyString) suffixes[i]).getString())) - return true; - } - return false; + PyObject[] suffixes = ((PyTuple)suffix).getArray(); + + for (int i = 0 ; i < suffixes.length ; i++) { + if (!(suffixes[i] instanceof PyString)) + throw Py.TypeError("expected a character buffer object"); + + if (substr.endsWith(((PyString) suffixes[i]).getString())) + return true; + } + return false; } else { - throw Py.TypeError("expected a character buffer object or tuple"); + throw Py.TypeError("expected a character buffer object or tuple"); } } @@ -2956,10 +2941,6 @@ numberFormat.setGroupingUsed(false); String ret = numberFormat.format(v); -// System.err.println("formatFloat: "+v+", prec="+prec+", ret="+ret); -// if (ret.indexOf('.') == -1) { -// return ret+'.'; -// } return ret; } -- Repository URL: http://hg.python.org/jython