2020from java .lang import System
2121import os
2222
23+ from org .python .core .util .StringUtil import asPyString
24+
2325
2426def _tostr (s , method ):
2527 if isinstance (s , basestring ):
@@ -40,7 +42,7 @@ def _type_name(obj):
4042def dirname (path ):
4143 """Return the directory component of a pathname"""
4244 path = _tostr (path , "dirname" )
43- result = File (path ).getParent ()
45+ result = asPyString ( File (path ).getParent () )
4446 if not result :
4547 if isabs (path ):
4648 result = path # Must be root
@@ -51,7 +53,7 @@ def dirname(path):
5153def basename (path ):
5254 """Return the final component of a pathname"""
5355 path = _tostr (path , "basename" )
54- return File (path ).getName ()
56+ return asPyString ( File (path ).getName () )
5557
5658def split (path ):
5759 """Split a pathname.
@@ -128,7 +130,7 @@ def join(path, *args):
128130 if a == "" :
129131 a = os .sep
130132 f = File (f , a )
131- return f .getPath ()
133+ return asPyString ( f .getPath () )
132134
133135def normcase (path ):
134136 """Normalize case of pathname.
@@ -137,7 +139,7 @@ def normcase(path):
137139
138140 """
139141 path = _tostr (path , "normcase" )
140- return File (path ).getPath ()
142+ return asPyString ( File (path ).getPath () )
141143
142144def commonprefix (m ):
143145 "Given a list of pathnames, return the longest common leading component"
@@ -197,7 +199,7 @@ def expanduser(path):
197199 if not c :
198200 return gethome ()
199201 if c == os .sep :
200- return File (gethome (), path [2 :]).getPath ()
202+ return asPyString ( File (gethome (), path [2 :]).getPath () )
201203 return path
202204
203205def getuser ():
@@ -252,7 +254,7 @@ def abspath(path):
252254def _abspath (path ):
253255 # Must use normpath separately because getAbsolutePath doesn't normalize
254256 # and getCanonicalPath would eliminate symlinks.
255- return normpath (File (sys .getPath (path )).getAbsolutePath ())
257+ return normpath (asPyString ( File (sys .getPath (path )).getAbsolutePath () ))
256258
257259def realpath (path ):
258260 """Return an absolute path normalized and symbolic links eliminated"""
@@ -261,7 +263,7 @@ def realpath(path):
261263
262264def _realpath (path ):
263265 try :
264- return File (sys .getPath (path )).getCanonicalPath ()
266+ return asPyString ( File (sys .getPath (path )).getCanonicalPath () )
265267 except java .io .IOException :
266268 return _abspath (path )
267269
0 commit comments