diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 8431c29c1d6516..768d4c8e7a6618 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -1,16 +1,13 @@ -import fnmatch import functools import io import ntpath import os import posixpath -import re import sys from _collections_abc import Sequence from errno import EINVAL, ENOENT, ENOTDIR from operator import attrgetter from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO -from urllib.parse import quote_from_bytes as urlquote_from_bytes supports_symlinks = True @@ -226,15 +223,16 @@ def is_reserved(self, parts): def make_uri(self, path): # Under Windows, file URIs use the UTF-8 encoding. + from urllib.parse import quote_from_bytes drive = path.drive if len(drive) == 2 and drive[1] == ':': # It's a path on a local drive => 'file:///c:/a/b' rest = path.as_posix()[2:].lstrip('/') return 'file:///%s/%s' % ( - drive, urlquote_from_bytes(rest.encode('utf-8'))) + drive, quote_from_bytes(rest.encode('utf-8'))) else: # It's a path on a network drive => 'file://host/share/a/b' - return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8')) + return 'file:' + quote_from_bytes(path.as_posix().encode('utf-8')) def gethomedir(self, username): if 'HOME' in os.environ: @@ -347,8 +345,9 @@ def is_reserved(self, parts): def make_uri(self, path): # We represent the path using the local filesystem encoding, # for portability to other applications. + from urllib.parse import quote_from_bytes bpath = bytes(path) - return 'file://' + urlquote_from_bytes(bpath) + return 'file://' + quote_from_bytes(bpath) def gethomedir(self, username): if not username: @@ -498,6 +497,8 @@ def _select_from(self, parent_path, is_dir, exists, scandir): class _WildcardSelector(_Selector): def __init__(self, pat, child_parts): + import fnmatch + import re self.pat = re.compile(fnmatch.translate(pat)) _Selector.__init__(self, child_parts) @@ -914,6 +915,7 @@ def match(self, path_pattern): """ Return True if this path matches the given pattern. """ + import fnmatch cf = self._flavour.casefold path_pattern = cf(path_pattern) drv, root, pat_parts = self._flavour.parse_parts((path_pattern,))