MCPcopy Index your code
hub / github.com/python/cpython / as_uri

Method as_uri

Lib/pathlib/__init__.py:521–544  ·  view source on GitHub ↗

Return the path as a URI.

(self)

Source from the content-addressed store, hash-verified

519 return self.parser.isabs(self)
520
521 def as_uri(self):
522 """Return the path as a URI."""
523 import warnings
524 msg = ("pathlib.PurePath.as_uri() is deprecated and scheduled "
525 "for removal in Python 3.19. Use pathlib.Path.as_uri().")
526 warnings._deprecated("pathlib.PurePath.as_uri", msg, remove=(3, 19))
527 if not self.is_absolute():
528 raise ValueError("relative path can't be expressed as a file URI")
529
530 drive = self.drive
531 if len(drive) == 2 and drive[1] == ':':
532 # It's a path on a local drive => 'file:///c:/a/b'
533 prefix = 'file:///' + drive
534 path = self.as_posix()[2:]
535 elif drive:
536 # It's a path on a network drive => 'file://host/share/a/b'
537 prefix = 'file:'
538 path = self.as_posix()
539 else:
540 # It's a posix path => 'file:///etc/hosts'
541 prefix = 'file://'
542 path = str(self)
543 from urllib.parse import quote_from_bytes
544 return prefix + quote_from_bytes(os.fsencode(path))
545
546 def full_match(self, pattern, *, case_sensitive=None):
547 """

Callers

nothing calls this directly

Calls 4

is_absoluteMethod · 0.95
as_posixMethod · 0.95
quote_from_bytesFunction · 0.90
strFunction · 0.85

Tested by

no test coverage detected