From: <pj...@us...> - 2009-06-06 05:45:24
|
Revision: 6456 http://jython.svn.sourceforge.net/jython/?rev=6456&view=rev Author: pjenvey Date: 2009-06-06 05:45:22 +0000 (Sat, 06 Jun 2009) Log Message: ----------- small cleanup Modified Paths: -------------- trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-06-06 05:24:44 UTC (rev 6455) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-06-06 05:45:22 UTC (rev 6456) @@ -97,6 +97,7 @@ break; } } catch (SecurityException se) { + // continue } // back up one path element @@ -127,10 +128,6 @@ return zipimporter_find_module(fullname, null); } - public PyObject find_module(String fullname, String path) { - return zipimporter_find_module(fullname, path); - } - /** * Find the module for the fully qualified name. * @@ -139,30 +136,30 @@ * @return a loader instance if this importer can load the module, None * otherwise */ + public PyObject find_module(String fullname, String path) { + return zipimporter_find_module(fullname, path); + } + @ExposedMethod(defaults = "null") final PyObject zipimporter_find_module(String fullname, String path) { return importer_find_module(fullname, path); } - public PyObject load_module(String fullname) { - return zipimporter_load_module(fullname); - } - /** * Load a module for the fully qualified name. * * @param fullname the fully qualified name of the module * @return a loaded PyModule */ + public PyObject load_module(String fullname) { + return zipimporter_load_module(fullname); + } + @ExposedMethod final PyObject zipimporter_load_module(String fullname) { return importer_load_module(fullname); } - public String get_data(String path) { - return zipimporter_get_data(path); - } - /** * Return the uncompressed data for the file at the specified path * as a String. @@ -170,6 +167,10 @@ * @param path a String path name within the archive * @return a String of data in binary mode (no CRLF) */ + public String get_data(String path) { + return zipimporter_get_data(path); + } + @ExposedMethod final String zipimporter_get_data(String path) { int len = archive.length(); @@ -186,20 +187,14 @@ byte[] data; try { data = FileUtil.readBytes(zipBundle.inputStream); - } - catch (IOException ioe) { + } catch (IOException ioe) { throw Py.IOError(ioe); - } - finally { + } finally { zipBundle.close(); } return StringUtil.fromBytes(data); } - public boolean is_package(String fullname) { - return zipimporter_is_package(fullname); - } - /** * Return a boolean signifying whether the module is a package or * not. @@ -207,25 +202,29 @@ * @param fullname the fully qualified name of the module * @return a boolean describing if the module is a package */ + public boolean is_package(String fullname) { + return zipimporter_is_package(fullname); + } + @ExposedMethod final boolean zipimporter_is_package(String fullname) { ModuleInfo moduleInfo = getModuleInfo(fullname); if (moduleInfo == ModuleInfo.NOT_FOUND) { - throw zipimport.ZipImportError("can't find module '" + fullname + "'"); + throw zipimport.ZipImportError(String.format("can't find module '%s'", fullname)); } return moduleInfo == ModuleInfo.PACKAGE; } - public PyObject get_code(String fullname) { - return zipimporter_get_code(fullname); - } - /** * Return the code object associated with the module. * * @param fullname the fully qualified name of the module * @return the module's PyCode object or None */ + public PyObject get_code(String fullname) { + return zipimporter_get_code(fullname); + } + @ExposedMethod final PyObject zipimporter_get_code(String fullname) { ModuleCodeData moduleCodeData = getModuleCode(fullname); @@ -235,10 +234,6 @@ return Py.None; } - public String get_source(String fullname) { - return zipimporter_get_source(fullname); - } - /** * Return the source code for the module as a string (using * newline characters for line endings) @@ -246,6 +241,10 @@ * @param fullname the fully qualified name of the module * @return a String of the module's source code or null */ + public String get_source(String fullname) { + return zipimporter_get_source(fullname); + } + @ExposedMethod final String zipimporter_get_source(String fullname) { ModuleInfo moduleInfo = getModuleInfo(fullname); @@ -254,14 +253,13 @@ return null; } if (moduleInfo == ModuleInfo.NOT_FOUND) { - throw zipimport.ZipImportError("can't find module '" + fullname + "'"); + throw zipimport.ZipImportError(String.format("can't find module '%s'", fullname)); } String path = makeFilename(fullname); if (moduleInfo == ModuleInfo.PACKAGE) { path += File.separator + "__init__.py"; - } - else { + } else { path += ".py"; } @@ -282,21 +280,20 @@ * @return a ZipBundle with an InputStream to the file's * uncompressed data */ + @Override public ZipBundle makeBundle(String datapath, PyObject entry) { datapath = datapath.replace(File.separatorChar, '/'); ZipFile zipArchive; try { zipArchive = new ZipFile(new File(sys.getPath(archive))); - } - catch (IOException ioe) { + } catch (IOException ioe) { throw zipimport.ZipImportError("zipimport: can not open file: " + archive); } ZipEntry dataEntry = zipArchive.getEntry(datapath); try { return new ZipBundle(zipArchive, zipArchive.getInputStream(dataEntry)); - } - catch (IOException ioe) { + } catch (IOException ioe) { Py.writeDebug("import", "zipimporter.getDataStream exception: " + ioe.toString()); throw zipimport.ZipImportError("zipimport: can not open file: " + archive); } @@ -306,12 +303,11 @@ * Determine if the byte code at path with the specified toc entry has a modification time * greater than its accompanying source code's. * - * @param path - * a String path to the byte code - * @param tocEntry - * the byte code's PyObject toc entry + * @param path a String path to the byte code + * @param tocEntry the byte code's PyObject toc entry * @return boolean whether or not the byte code is older */ + @Override protected boolean isAcceptableBytecode(String path, PyObject tocEntry) { String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); @@ -357,16 +353,15 @@ private PyObject readDirectory(String archive) { File file = new File(sys.getPath(archive)); if (!file.canRead()) { - throw zipimport.ZipImportError("can't open Zip file: '" + archive + "'"); + throw zipimport.ZipImportError(String.format("can't open Zip file: '%s'", archive)); } ZipFile zipFile; try { zipFile = new ZipFile(file); + } catch (IOException ioe) { + throw zipimport.ZipImportError(String.format("can't read Zip file: '%s'", archive)); } - catch (IOException ioe) { - throw zipimport.ZipImportError("can't read Zip file: '" + archive + "'"); - } PyObject files = new PyDictionary(); for (Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); @@ -393,14 +388,14 @@ try { zipFile.close(); - } - catch (IOException ioe) { + } catch (IOException ioe) { throw Py.IOError(ioe); } return files; } + @Override protected String getSeparator() { return File.separator; } @@ -408,12 +403,11 @@ /** * Given a full module name, return the potential file path in the archive (without extension). * - * @param prefix - * a String value - * @param name - * a String modulename value + * @param prefix a String value + * @param name a String modulename value * @return the file path String value */ + @Override protected String makeFilename(String fullname) { return prefix + getSubname(fullname).replace('.', File.separatorChar); } @@ -497,6 +491,7 @@ return d.getTime(); } + @Override public String toString() { return zipimporter_toString(); } @@ -528,11 +523,11 @@ * * Raises an IOError if a problem occurred. */ + @Override public void close() { try { zipFile.close(); - } - catch (IOException ioe) { + } catch (IOException ioe) { throw Py.IOError(ioe); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |