Commit c64ad448 by rfkelly0

OSFSOpener: use os.path functions instead of fs.path functions.

The fs.path functions break UNC paths in a variety of intersting ways.
This fixes issue #76.
parent 54e9526d
......@@ -32,6 +32,7 @@ an SFTP server::
"""
import os
import sys
import imp
import marshal
......@@ -58,12 +59,14 @@ class FSImportHook(object):
# If given a string, try to open it as an FS url.
# Don't open things on the local filesystem though.
if isinstance(fs_or_url,basestring):
if ":" not in fs_or_url:
if ":/" not in fs_or_url:
raise ImportError
try:
self.fs = fsopendir(fs_or_url)
except OpenerError:
raise ImportError
except (CreateFailedError,ResourceNotFoundError,):
raise ImportError
self.path = fs_or_url
# Otherwise, it must be an FS object of some sort.
else:
......
......@@ -84,10 +84,7 @@ def _expand_syspath(path):
if path is None:
return path
path = os.path.expanduser(os.path.expandvars(path))
path = path.replace('\\', '/')
if not path.startswith('/'):
path = os.path.join(getcwd(), path)
path = normpath(path)
path = os.path.normpath(os.path.abspath(path))
return path
def _parse_credentials(url):
......@@ -208,7 +205,6 @@ class OpenerRegistry(object):
fs_url = '%s!%s' % (fs_url, '!'.join(paths))
fs_name = fs_name or self.default_opener
else:
fs_name = default_fs_name or self.default_opener
fs_url = _expand_syspath(fs_url)
......@@ -340,11 +336,11 @@ class OSFSOpener(Opener):
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir):
from fs.osfs import OSFS
path = normpath(fs_path)
path = os.path.normpath(fs_path)
if create_dir and not os.path.exists(path):
from fs.osfs import _os_makedirs
_os_makedirs(path)
dirname, resourcename = pathsplit(fs_path)
dirname, resourcename = os.path.split(fs_path)
osfs = OSFS(dirname)
return osfs, resourcename
......@@ -862,3 +858,4 @@ opener = OpenerRegistry([OSFSOpener,
fsopen = opener.open
fsopendir = opener.opendir
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment