def make_uri(self, path): # Under Windows, file URIs use the UTF-8 encoding. 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"))) 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"))
def make_uri(self, path): # Under Windows, file URIs use the UTF-8 encoding. 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'))) 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'))
def make_as_uri(path): """ As URI path for Windows. Reimplementation of Path.make_as_uri to use an unicode as_posix version. """ drive = path.drive path_string = as_posix(path) if len(drive) == 2 and drive[1] == ':': # It's a path on a local drive => 'file:///c:/a/b' rest = path_string[2:].lstrip('/') return u'file:///%s/%s' % (drive, urlquote_from_bytes(rest.encode('utf-8'))) else: # It's a path on a network drive => 'file://host/share/a/b' return u'file:' + urlquote_from_bytes(path_string.encode('utf-8'))
def make_uri(self, path): # We represent the path using the local filesystem encoding, # for portability to other applications. bpath = bytes(path) return 'file://' + urlquote_from_bytes(bpath)