text
stringlengths
0
828
else:
int_regex.append(comp)
if not start_dir_done and no_special_chars.match(pat):
start_dir.append(pat)
else:
start_dir_done = True
full_regex = re.compile(full_regex.rstrip('/') + '$')
if int_regex is not None:
n = len(int_regex)
int_regex_s = ''
for i, c in enumerate(reversed(int_regex)):
if i == n - 1: # Last iteration (first component)
int_regex_s = '^(?:%s%s)?' % (c, int_regex_s)
elif int_regex_s:
int_regex_s = '(?:/%s%s)?' % (c, int_regex_s)
else: # First iteration (last component)
int_regex_s = '(?:/%s)?' % c
int_regex = re.compile(int_regex_s + '$')
start_dir = '/'.join(start_dir)
return start_dir, full_regex, int_regex"
4106,"def _to_backend(self, p):
""""""Converts something to the correct path representation.
If given a Path, this will simply unpack it, if it's the correct type.
If given the correct backend, it will return that.
If given bytes for unicode of unicode for bytes, it will encode/decode
with a reasonable encoding. Note that these operations can raise
UnicodeError!
""""""
if isinstance(p, self._cmp_base):
return p.path
elif isinstance(p, self._backend):
return p
elif self._backend is unicode and isinstance(p, bytes):
return p.decode(self._encoding)
elif self._backend is bytes and isinstance(p, unicode):
return p.encode(self._encoding,
'surrogateescape' if PY3 else 'strict')
else:
raise TypeError(""Can't construct a %s from %r"" % (
self.__class__.__name__, type(p)))"
4107,"def parent(self):
""""""The parent directory of this path.
""""""
p = self._lib.dirname(self.path)
p = self.__class__(p)
return p"
4108,"def unicodename(self):
""""""The name of this path as unicode.
""""""
n = self._lib.basename(self.path)
if self._backend is unicode:
return n
else:
return n.decode(self._encoding, 'replace')"
4109,"def split_root(self):
""""""Splits this path into a pair (drive, location).
Note that, because all paths are normalized, a root of ``'.'`` will be
returned for relative paths.
""""""
if not PY3 and hasattr(self._lib, 'splitunc'):
root, rest = self._lib.splitunc(self.path)
if root:
if rest.startswith(self._sep):
root += self._sep
rest = rest[1:]
return self.__class__(root), self.__class__(rest)
root, rest = self._lib.splitdrive(self.path)
if root:
if rest.startswith(self._sep):
root += self._sep
rest = rest[1:]
return self.__class__(root), self.__class__(rest)
if self.path.startswith(self._sep):
return self.__class__(self._sep), self.__class__(rest[1:])
return self.__class__(''), self"
4110,"def rel_path_to(self, dest):
""""""Builds a relative path leading from this one to the given `dest`.
Note that these paths might be both relative, in which case they'll be
assumed to start from the same directory.
""""""
dest = self.__class__(dest)
orig_list = self.norm_case()._components()
dest_list = dest._components()
i = -1
for i, (orig_part, dest_part) in enumerate(zip(orig_list, dest_list)):
if orig_part != self._normcase(dest_part):
up = ['..'] * (len(orig_list) - i)
return self.__class__(*(up + dest_list[i:]))
if len(orig_list) <= len(dest_list):
if len(dest_list) > i + 1:
return self.__class__(*dest_list[i + 1:])
else:
return self.__class__('')