Skip to content

Commit

Permalink
Wrap os.path functions in method calls
Browse files Browse the repository at this point in the history
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 ipythongh-737
  • Loading branch information
takluyver committed Sep 16, 2011
1 parent a4f1e5b commit fc05f37
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions IPython/external/path/_path.py
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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. """)
Expand Down

0 comments on commit fc05f37

Please sign in to comment.