Skip to content

Commit 0faa6d0

Browse files
committed
Remove flavour.make_uri()
1 parent 3655d5e commit 0faa6d0

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

Lib/pathlib.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,6 @@ def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
187187
s = '\\' + s[3:]
188188
return prefix, s
189189

190-
def make_uri(self, path):
191-
# Under Windows, file URIs use the UTF-8 encoding.
192-
drive = path.drive
193-
if len(drive) == 2 and drive[1] == ':':
194-
# It's a path on a local drive => 'file:///c:/a/b'
195-
rest = path.as_posix()[2:].lstrip('/')
196-
return 'file:///%s/%s' % (
197-
drive, urlquote_from_bytes(rest.encode('utf-8')))
198-
else:
199-
# It's a path on a network drive => 'file://host/share/a/b'
200-
return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8'))
201-
202190

203191
class _PosixFlavour(_Flavour):
204192
sep = '/'
@@ -232,12 +220,6 @@ def casefold_parts(self, parts):
232220
def compile_pattern(self, pattern):
233221
return re.compile(fnmatch.translate(pattern)).fullmatch
234222

235-
def make_uri(self, path):
236-
# We represent the path using the local filesystem encoding,
237-
# for portability to other applications.
238-
bpath = bytes(path)
239-
return 'file://' + urlquote_from_bytes(bpath)
240-
241223

242224
_windows_flavour = _WindowsFlavour()
243225
_posix_flavour = _PosixFlavour()
@@ -614,9 +596,7 @@ def __repr__(self):
614596

615597
def as_uri(self):
616598
"""Return the path as a 'file' URI."""
617-
if not self.is_absolute():
618-
raise ValueError("relative path can't be expressed as a file URI")
619-
return self._flavour.make_uri(self)
599+
raise NotImplementedError
620600

621601
@property
622602
def _cparts(self):
@@ -898,6 +878,14 @@ class PurePosixPath(PurePath):
898878
def is_reserved(self):
899879
return False
900880

881+
def as_uri(self):
882+
# We represent the path using the local filesystem encoding,
883+
# for portability to other applications.
884+
if not self.is_absolute():
885+
raise ValueError("relative path can't be expressed as a file URI")
886+
bpath = bytes(self)
887+
return 'file://' + urlquote_from_bytes(bpath)
888+
901889

902890
class PureWindowsPath(PurePath):
903891
"""PurePath subclass for Windows systems.
@@ -925,6 +913,19 @@ def is_reserved(self):
925913
return False
926914
return self._parts[-1].partition('.')[0].upper() in self._reserved_names
927915

916+
def as_uri(self):
917+
if not self.is_absolute():
918+
raise ValueError("relative path can't be expressed as a file URI")
919+
# Under Windows, file URIs use the UTF-8 encoding.
920+
drive = self.drive
921+
if len(drive) == 2 and drive[1] == ':':
922+
# It's a path on a local drive => 'file:///c:/a/b'
923+
rest = self.as_posix()[2:].lstrip('/')
924+
return 'file:///%s/%s' % (
925+
drive, urlquote_from_bytes(rest.encode('utf-8')))
926+
else:
927+
# It's a path on a network drive => 'file://host/share/a/b'
928+
return 'file:' + urlquote_from_bytes(self.as_posix().encode('utf-8'))
928929

929930
# Filesystem-accessing classes
930931

0 commit comments

Comments
 (0)