text stringlengths 0 828 |
|---|
else: |
up = ['..'] * (len(orig_list) - i - 1) |
return self.__class__(*up)" |
4111,"def lies_under(self, prefix): |
""""""Indicates if the `prefix` is a parent of this path. |
"""""" |
orig_list = self.norm_case()._components() |
pref_list = self.__class__(prefix).norm_case()._components() |
return (len(orig_list) >= len(pref_list) and |
orig_list[:len(pref_list)] == pref_list)" |
4112,"def tempfile(cls, suffix='', prefix=None, dir=None, text=False): |
""""""Returns a new temporary file. |
The return value is a pair (fd, path) where fd is the file descriptor |
returned by :func:`os.open`, and path is a :class:`~rpaths.Path` to it. |
:param suffix: If specified, the file name will end with that suffix, |
otherwise there will be no suffix. |
:param prefix: Is specified, the file name will begin with that prefix, |
otherwise a default prefix is used. |
:param dir: If specified, the file will be created in that directory, |
otherwise a default directory is used. |
:param text: If true, the file is opened in text mode. Else (the |
default) the file is opened in binary mode. On some operating |
systems, this makes no difference. |
The file is readable and writable only by the creating user ID. |
If the operating system uses permission bits to indicate whether a |
file is executable, the file is executable by no one. The file |
descriptor is not inherited by children of this process. |
The caller is responsible for deleting the file when done with it. |
"""""" |
if prefix is None: |
prefix = tempfile.template |
if dir is not None: |
# Note that this is not safe on Python 2 |
# There is no work around, apart from not using the tempfile module |
dir = str(Path(dir)) |
fd, filename = tempfile.mkstemp(suffix, prefix, dir, text) |
return fd, cls(filename).absolute()" |
4113,"def tempdir(cls, suffix='', prefix=None, dir=None): |
""""""Returns a new temporary directory. |
Arguments are as for :meth:`~rpaths.Path.tempfile`, except that the |
`text` argument is not accepted. |
The directory is readable, writable, and searchable only by the |
creating user. |
The caller is responsible for deleting the directory when done with it. |
"""""" |
if prefix is None: |
prefix = tempfile.template |
if dir is not None: |
# Note that this is not safe on Python 2 |
# There is no work around, apart from not using the tempfile module |
dir = str(Path(dir)) |
dirname = tempfile.mkdtemp(suffix, prefix, dir) |
return cls(dirname).absolute()" |
4114,"def rel_path_to(self, dest): |
""""""Builds a relative path leading from this one to another. |
Note that these paths might be both relative, in which case they'll be |
assumed to be considered starting from the same directory. |
Contrary to :class:`~rpaths.AbstractPath`'s version, this will also |
work if one path is relative and the other absolute. |
"""""" |
return super(Path, self.absolute()).rel_path_to(Path(dest).absolute())" |
4115,"def listdir(self, pattern=None): |
""""""Returns a list of all the files in this directory. |
The special entries ``'.'`` and ``'..'`` will not be returned. |
:param pattern: A pattern to match directory entries against. |
:type pattern: NoneType | Callable | Pattern | unicode | bytes |
"""""" |
files = [self / self.__class__(p) for p in os.listdir(self.path)] |
if pattern is None: |
pass |
elif callable(pattern): |
files = filter(pattern, files) |
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 = pattern.start_dir, pattern.full_regex |
else: |
raise TypeError(""listdir() expects pattern to be a callable, "" |
""a regular expression or a string pattern, "" |
""got %r"" % type(pattern)) |
# If pattern contains slashes (other than first and last chars), |
# listdir() will never match anything |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.