Update of /cvsroot/jython/jython/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv3183
Modified Files:
javapath.py
Log Message:
Extra check to verify that the parameter is a string.
Fix for bug "[ #495602 ] os.path.dirname() can result in an NPE".
Index: javapath.py
===================================================================
RCS file: /cvsroot/jython/jython/Lib/javapath.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** javapath.py 2001/12/20 18:35:58 1.8
--- javapath.py 2001/12/27 15:14:27 1.9
***************
*** 21,26 ****
--- 21,34 ----
import os
+ def _tostr(s, method):
+ if isinstance(s, "".__class__):
+ return s
+ import org
+ raise TypeError, "%s() argument must be a string object, not %s" % (
+ method, org.python.core.Py.safeRepr(s))
+
def dirname(path):
"""Return the directory component of a pathname"""
+ path = _tostr(path, "dirname")
result = File(path).getParent()
if not result:
***************
*** 33,36 ****
--- 41,45 ----
def basename(path):
"""Return the final component of a pathname"""
+ path = _tostr(path, "basename")
return File(path).getName()
***************
*** 42,45 ****
--- 51,55 ----
"""
+ path = _tostr(path, "split")
return (dirname(path), basename(path))
***************
*** 76,97 ****
--- 86,113 ----
"""
+ path = _tostr(path, "exists")
return File(path).exists()
def isabs(path):
"""Test whether a path is absolute"""
+ path = _tostr(path, "isabs")
return File(path).isAbsolute()
def isfile(path):
"""Test whether a path is a regular file"""
+ path = _tostr(path, "isfile")
return File(path).isFile()
def isdir(path):
"""Test whether a path is a directory"""
+ path = _tostr(path, "isdir")
return File(path).isDirectory()
def join(path, *args):
"""Join two or more pathname components, inserting os.sep as needed"""
+ path = _tostr(path, "join")
f = File(path)
for a in args:
+ a = _tostr(a, "join")
g = File(a)
if g.isAbsolute() or len(f.getPath()) == 0:
***************
*** 107,110 ****
--- 123,127 ----
"""
+ path = _tostr(path, "normcase")
return File(path).getPath()
***************
*** 131,134 ****
--- 148,153 ----
def samefile(path, path2):
"""Test whether two pathnames reference the same actual file"""
+ path = _tostr(path, "samefile")
+ path2 = _tostr(path2, "samefile")
f = File(path)
f2 = File(path2)
***************
*** 217,224 ****
--- 236,245 ----
# Return an absolute path.
def abspath(path):
+ path = _tostr(path, "abspath")
return File(path).getAbsolutePath()
def getsize(path):
+ path = _tostr(path, "getsize")
f = File(path)
size = f.length()
***************
*** 230,233 ****
--- 251,255 ----
def getmtime(path):
+ path = _tostr(path, "getmtime")
f = File(path)
return f.lastModified() / 1000.0
***************
*** 236,239 ****
--- 258,262 ----
# We can't detect access time so we return modification time. This
# matches the behaviour in os.stat().
+ path = _tostr(path, "getatime")
f = File(path)
return f.lastModified() / 1000.0
|