def get_virtual_file_path(self): """Returns a virtual file path corresponding to this URL The result is a :class:`pyslet.vfs.FilePath` instance. The host component of the URL is used to determine which virtual file system the file belongs to. If there is no virtual file system matching the URL's host and the default virtual file system support UNC paths (i.e., is Windows) the host will be placed in the machine portion of the UNC path. Path parameters e.g., /dir/file;lang=en in the URL are ignored.""" decode = lambda s: unicode(unescape_data(s), 'utf-8') if self.host: fs = vfs.get_file_system_by_name(self.host) if fs is None: if vfs.defaultFS.supports_unc: fs = vfs.defaultNS unc_root = decode('\\\\%s' % self.host) else: raise ValueError( "Unrecognized host in file URL: %s" % self.host) else: unc_root = decode('') else: fs = vfs.defaultFS unc_root = decode('') segments = split_abs_path(self.abs_path) # ignore parameters in file system path = string.join(map(decode, segments), fs.sep) if unc_root: # If we have a UNC root then we will have an absolute path vpath = fs(string.join((unc_root, path), fs.sep)) else: vpath = fs(path) if not vpath.isabs(): # Prepend the sep if we're not absolute (most likely # UNIX) because it is only drive designations that do # not need a prefix vpath = fs(string.join(('', path), fs.sep)) return vpath
def test_default_fs(self): self.assertTrue(issubclass(vfs.defaultFS, vfs.VirtualFilePath)) self.assertTrue( vfs.defaultFS is vfs.OSFilePath, "Default should be OS file path") self.assertTrue(vfs.defaultFS.fs_name == "") self.assertTrue(vfs.get_file_system_by_name('') is vfs.defaultFS)