FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-33440: Defer imports in pathlib to reduce its import time. by agfor · Pull Request #6820 · python/cpython · GitHub

/ cpython Public
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 8 additions & 6 deletions Lib/pathlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,))
Expand Down

Back | FazBrowse Home | New Git URL