text
stringlengths
0
828
if start:
return []
files = [f for f in files if full_re.search(f.unicodename)]
return files"
4116,"def recursedir(self, pattern=None, top_down=True, follow_links=False,
handle_errors=None):
""""""Recursively lists all files under this directory.
:param pattern: An extended patterns, where:
* a slash '/' always represents the path separator
* a backslash '\' escapes other special characters
* an initial slash '/' anchors the match at the beginning of the
(relative) path
* a trailing '/' suffix is removed
* an asterisk '*' matches a sequence of any length (including 0)
of any characters (except the path separator)
* a '?' matches exactly one character (except the path separator)
* '[abc]' matches characters 'a', 'b' or 'c'
* two asterisks '**' matches one or more path components (might
match '/' characters)
:type pattern: NoneType | Callable | Pattern | unicode | bytes
:param follow_links: If False, symbolic links will not be followed (the
default). Else, they will be followed, but directories reached
through different names will *not* be listed multiple times.
:param handle_errors: Can be set to a callback that will be called when
an error is encountered while accessing the filesystem (such as a
permission issue). If set to None (the default), exceptions will be
propagated.
""""""
if not self.is_dir():
raise ValueError(""recursedir() called on non-directory %s"" % self)
start = ''
int_pattern = None
if pattern is None:
pattern = lambda p: True
elif callable(pattern):
pass
else:
if isinstance(pattern, backend_types):
if isinstance(pattern, bytes):
pattern = pattern.decode(self._encoding, 'replace')
start, full_re, int_re = pattern2re(pattern)
elif isinstance(pattern, Pattern):
start, full_re, int_re = \
pattern.start_dir, pattern.full_regex, pattern.int_regex
else:
raise TypeError(""recursedir() expects pattern to be a ""
""callable, a regular expression or a string ""
""pattern, got %r"" % type(pattern))
if self._lib.sep != '/':
pattern = lambda p: full_re.search(
unicode(p).replace(self._lib.sep, '/'))
if int_re is not None:
int_pattern = lambda p: int_re.search(
unicode(p).replace(self._lib.sep, '/'))
else:
pattern = lambda p: full_re.search(unicode(p))
if int_re is not None:
int_pattern = lambda p: int_re.search(unicode(p))
if not start:
path = self
else:
path = self / start
if not path.exists():
return []
elif not path.is_dir():
return [path]
return path._recursedir(pattern=pattern, int_pattern=int_pattern,
top_down=top_down, seen=set(),
path=self.__class__(start),
follow_links=follow_links,
handle_errors=handle_errors)"
4117,"def mkdir(self, name=None, parents=False, mode=0o777):
""""""Creates that directory, or a directory under this one.
``path.mkdir(name)`` is a shortcut for ``(path/name).mkdir()``.
:param name: Path component to append to this path before creating the
directory.
:param parents: If True, missing directories leading to the path will
be created too, recursively. If False (the default), the parent of
that path needs to exist already.
:param mode: Permissions associated with the directory on creation,
without race conditions.
""""""
if name is not None:
return (self / name).mkdir(parents=parents, mode=mode)
if self.exists():
return
if parents:
os.makedirs(self.path, mode)
else:
os.mkdir(self.path, mode)
return self"