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:: ...@@ -32,6 +32,7 @@ an SFTP server::
""" """
import os
import sys import sys
import imp import imp
import marshal import marshal
...@@ -58,12 +59,14 @@ class FSImportHook(object): ...@@ -58,12 +59,14 @@ class FSImportHook(object):
# If given a string, try to open it as an FS url. # If given a string, try to open it as an FS url.
# Don't open things on the local filesystem though. # Don't open things on the local filesystem though.
if isinstance(fs_or_url,basestring): if isinstance(fs_or_url,basestring):
if ":" not in fs_or_url: if ":/" not in fs_or_url:
raise ImportError raise ImportError
try: try:
self.fs = fsopendir(fs_or_url) self.fs = fsopendir(fs_or_url)
except OpenerError: except OpenerError:
raise ImportError raise ImportError
except (CreateFailedError,ResourceNotFoundError,):
raise ImportError
self.path = fs_or_url self.path = fs_or_url
# Otherwise, it must be an FS object of some sort. # Otherwise, it must be an FS object of some sort.
else: else:
......
...@@ -84,10 +84,7 @@ def _expand_syspath(path): ...@@ -84,10 +84,7 @@ def _expand_syspath(path):
if path is None: if path is None:
return path return path
path = os.path.expanduser(os.path.expandvars(path)) path = os.path.expanduser(os.path.expandvars(path))
path = path.replace('\\', '/') path = os.path.normpath(os.path.abspath(path))
if not path.startswith('/'):
path = os.path.join(getcwd(), path)
path = normpath(path)
return path return path
def _parse_credentials(url): def _parse_credentials(url):
...@@ -208,7 +205,6 @@ class OpenerRegistry(object): ...@@ -208,7 +205,6 @@ class OpenerRegistry(object):
fs_url = '%s!%s' % (fs_url, '!'.join(paths)) fs_url = '%s!%s' % (fs_url, '!'.join(paths))
fs_name = fs_name or self.default_opener fs_name = fs_name or self.default_opener
else: else:
fs_name = default_fs_name or self.default_opener fs_name = default_fs_name or self.default_opener
fs_url = _expand_syspath(fs_url) fs_url = _expand_syspath(fs_url)
...@@ -340,11 +336,11 @@ class OSFSOpener(Opener): ...@@ -340,11 +336,11 @@ class OSFSOpener(Opener):
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir): def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir):
from fs.osfs import OSFS from fs.osfs import OSFS
path = normpath(fs_path) path = os.path.normpath(fs_path)
if create_dir and not os.path.exists(path): if create_dir and not os.path.exists(path):
from fs.osfs import _os_makedirs from fs.osfs import _os_makedirs
_os_makedirs(path) _os_makedirs(path)
dirname, resourcename = pathsplit(fs_path) dirname, resourcename = os.path.split(fs_path)
osfs = OSFS(dirname) osfs = OSFS(dirname)
return osfs, resourcename return osfs, resourcename
...@@ -862,3 +858,4 @@ opener = OpenerRegistry([OSFSOpener, ...@@ -862,3 +858,4 @@ opener = OpenerRegistry([OSFSOpener,
fsopen = opener.open fsopen = opener.open
fsopendir = opener.opendir 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