Coverage for .tox/testcoverage/lib/python2.7/site-packages/py/_path/common : 57%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" """
# Moved from local.py.
raise NotImplementedError
raise NotImplementedError
return self.path.basename.startswith('.')
if not arg.startswith('.'): arg = '.' + arg return self.path.ext == arg
raise NotImplementedError
return self.path.basename == arg
return self.path.basename.startswith(arg)
return self.path.relto(arg)
return str(self.path).endswith(arg)
except AttributeError: if name[:3] == 'not': invert = True try: meth = getattr(self, name[3:]) except AttributeError: pass raise TypeError( "no %r checker available for %r" % (name, self.path)) else: if bool(value) ^ bool(meth()) ^ invert: return False except (py.error.ENOENT, py.error.ENOTDIR, py.error.EBUSY): # EBUSY feels not entirely correct, # but its kind of necessary since ENOMEDIUM # is not accessible in python for name in self._depend_on_existence: if name in kw: if kw.get(name): return False name = 'not' + name if name in kw: if not kw.get(name): return False return True
""" shared implementation for filesystem path objects."""
return self.join(str(other))
""" basename part of path. """
""" dirname part of path. """
""" pure base name of the path.""" return self._getbyspec('purebasename')[0]
""" extension of the path (including the '.')."""
""" return the directory path joined with any given path arguments. """ return self.new(basename='').join(*args, **kwargs)
""" read and return a bytestring from reading the path. """ with self.open('rb') as f: return f.read()
""" read and return a Unicode string from reading the path. """ with self.open("r", encoding=encoding) as f: return f.read()
""" read and return a bytestring from reading the path. """ with self.open(mode) as f: return f.read()
""" read and return a list of lines from the path. if cr is False, the newline will be removed from the end of each line. """ if not cr: content = self.read('rU') return content.split('\n') else: f = self.open('rU') try: return f.readlines() finally: f.close()
""" (deprecated) return object unpickled from self.read() """ f = self.open('rb') try: return py.error.checked_call(py.std.pickle.load, f) finally: f.close()
""" move this path to target. """ if target.relto(self): raise py.error.EINVAL(target, "cannot move path into a subdirectory of itself") try: self.rename(target) except py.error.EXDEV: # invalid cross-device link self.copy(target) self.remove()
""" return a string representation of this path. """ return repr(str(self))
""" check a path for existence and properties.
Without arguments, return True if the path exists, otherwise False.
valid checkers::
file=1 # is a file file=0 # is not a file (may not even exist) dir=1 # is a dir link=1 # is a link exists=1 # exists
You can specify multiple checker definitions, for example::
path.check(file=1, link=1) # a link pointing to a file """ kw = {'exists' : 1}
"""return true if the basename/fullname matches the glob-'pattern'.
valid pattern characters::
* matches everything ? matches any single character [seq] matches any character in seq [!seq] matches any char not in seq
If the pattern contains a path-separator then the full path is used for pattern matching and a '*' is prepended to the pattern.
if the pattern doesn't contain a path-separator the pattern is only matched against the basename. """
""" return a string which is the relative part of the path to the given 'relpath'. """ raise TypeError("%r: not a string or path object" %(relpath,)) #assert strrelpath[-1] == self.sep #assert strrelpath[-2] != self.sep if os.path.normcase(strself).startswith( os.path.normcase(strrelpath)): return strself[len(strrelpath):]
""" ensure the path joined with args is a directory. """
""" return a string which is a relative path from self (assumed to be a directory) to dest such that self.join(bestrelpath) == dest and if not such path can be determined return dest. """ return os.curdir return str(dest) n = self2base.count(self.sep) + 1 else: except AttributeError: return str(dest)
""" return a root-first list of all ancestor directories plus the path itself. """
""" return the common part shared with the other path or None if there is no common part. """ return last
""" return new path object with 'other' added to the basename""" return self.new(basename=self.basename+str(other))
""" return sort value (-1, 0, +1). """ try: return cmp(self.strpath, other.strpath) except AttributeError: return cmp(str(self), str(other)) # self.path, other.path)
try: return self.strpath < other.strpath except AttributeError: return str(self) < str(other)
""" yields all paths below the current one
fil is a filter (glob pattern or callable), if not matching the path will not be yielded, defaulting to None (everything is returned)
rec is a filter (glob pattern or callable) that controls whether a node is descended, defaulting to None
ignore is an Exception class that is ignoredwhen calling dirlist() on any of the paths (by default, all exceptions are reported)
bf if True will cause a breadthfirst search instead of the default depthfirst. Default: False
sort if True will sort entries within each directory level. """
if hasattr(sort, '__call__'): res.sort(sort) else: res.sort()
""" return True if other refers to the same stat object as self. """ return self.strpath == str(other)
fil = FNMatcher(fil) self.rec = FNMatcher(rec) self.rec = lambda path: True else:
except self.ignore: return if p.check(dir=1) and (rec is None or rec(p))]) for subdir in dirs: for p in self.gen(subdir): yield p
iswin32 and pattern.find(posixpath.sep) != -1): # Running on Windows, the pattern has no Windows path separators, # and the pattern has one or more Posix path separators. Replace # the Posix path separators with the Windows path separator. pattern = pattern.replace(posixpath.sep, path.sep)
else: name = str(path) # path.strpath # XXX svn? if not os.path.isabs(pattern): pattern = '*' + path.sep + pattern
|