Permalink
Browse files

Wrap os.path functions in method calls

Some functions from os.path are now references to C functions (e.g. isdir on Windows). This breaks the path module, because compiled functions do not get bound to an object instance. All os.path functions have been wrapped in method calls, out of general caution.

Closes gh-737
  • Loading branch information...
1 parent a4f1e5b commit fc05f375e3603e698df43aa31baec28f00d169be @takluyver committed Sep 16, 2011
Showing with 16 additions and 13 deletions.
  1. +16 −13 IPython/external/path/_path.py
@@ -10,7 +10,7 @@
This module requires Python 2.5 or later.
-URL: http://www.jorendorff.com/articles/python/path
+URL: http://pypi.python.org/pypi/path.py
Author: Jason Orendorff <jason.orendorff\x40gmail\x2ecom> (and others - see the url!)
Date: 9 Mar 2007
"""
@@ -99,15 +99,15 @@ def getcwd(cls):
# --- Operations on path strings.
- isabs = os.path.isabs
+ def isabs(s): return os.path.isabs(s)
def abspath(self): return self.__class__(os.path.abspath(self))
def normcase(self): return self.__class__(os.path.normcase(self))
def normpath(self): return self.__class__(os.path.normpath(self))
def realpath(self): return self.__class__(os.path.realpath(self))
def expanduser(self): return self.__class__(os.path.expanduser(self))
def expandvars(self): return self.__class__(os.path.expandvars(self))
def dirname(self): return self.__class__(os.path.dirname(self))
- basename = os.path.basename
+ def basename(s): return os.path.basename(s)
def expand(self):
""" Clean up a filename by calling expandvars(),
@@ -752,33 +752,36 @@ def read_md5(self):
return m.digest()
# --- Methods for querying the filesystem.
+ # N.B. We can't assign the functions directly, because they may on some
+ # platforms be implemented in C, and compiled functions don't get bound.
+ # See gh-737 for discussion of this.
- exists = os.path.exists
- isdir = os.path.isdir
- isfile = os.path.isfile
- islink = os.path.islink
- ismount = os.path.ismount
+ def exists(s): return os.path.exists(s)
+ def isdir(s): return os.path.isdir(s)
+ def isfile(s): return os.path.isfile(s)
+ def islink(s): return os.path.islink(s)
+ def ismount(s): return os.path.ismount(s)
if hasattr(os.path, 'samefile'):
- samefile = os.path.samefile
+ def samefile(s, o): return os.path.samefile(s, o)
- getatime = os.path.getatime
+ def getatime(s): return os.path.getatime(s)
atime = property(
getatime, None, None,
""" Last access time of the file. """)
- getmtime = os.path.getmtime
+ def getmtime(s): return os.path.getmtime(s)
mtime = property(
getmtime, None, None,
""" Last-modified time of the file. """)
if hasattr(os.path, 'getctime'):
- getctime = os.path.getctime
+ def getctime(s): return os.path.getctime(s)
ctime = property(
getctime, None, None,
""" Creation time of the file. """)
- getsize = os.path.getsize
+ def getsize(s): return os.path.getsize(s)
size = property(
getsize, None, None,
""" Size of the file, in bytes. """)

0 comments on commit fc05f37

Please sign in to comment.