summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-03-23 19:02:05 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-03-24 02:09:27 +0000
commitcd5413902dbdf8bffc7f74d0c0a689e9d193a4a6 (patch)
tree23ed6b53bca4fd080bfdc5ba87864921904e376d
parent9e6272fe12f9d4a17ef4e665a8e7708bff7520c1 (diff)
downloadtaskflow-cd5413902dbdf8bffc7f74d0c0a689e9d193a4a6.tar.gz
Prefer posixpath to os.path
To ensure that the memory fake filesystem works uniformly across distributions prefer to use the posixpath module which always works with '/' and friends instead of the os.path and os.path.sep and friends which may vary depending on operating system used. Since we have tested with the usage of '/' we might as well just restrict to that; and avoid the cross operating system issues that may pop up when using this fake filesystem. In general isolating one self from the operating system specifics is IMHO preferable for this; as it avoids edge cases that we don't care about. Change-Id: I3f61f380e1bcb131bc42b627adf9dfe8a7f2d992
-rw-r--r--taskflow/persistence/backends/impl_memory.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/taskflow/persistence/backends/impl_memory.py b/taskflow/persistence/backends/impl_memory.py
index a457214..bb74a40 100644
--- a/taskflow/persistence/backends/impl_memory.py
+++ b/taskflow/persistence/backends/impl_memory.py
@@ -17,7 +17,7 @@
import contextlib
import copy
-import os
+import posixpath as pp
from taskflow import exceptions as exc
from taskflow.persistence import path_based
@@ -29,14 +29,14 @@ class FakeFilesystem(object):
"""An in-memory filesystem-like structure."""
#: Root path of the in-memory filesystem.
- root_path = os.sep
+ root_path = pp.sep
@classmethod
def _normpath(cls, path):
if not path.startswith(cls.root_path):
raise ValueError("This filesystem can only normalize absolute"
" paths: '%s' is not valid" % path)
- return os.path.normpath(path)
+ return pp.normpath(path)
def __init__(self, deep_copy=True):
self._root = tree.Node(self.root_path, value=None)
@@ -98,11 +98,11 @@ class FakeFilesystem(object):
# split correctly:
#
# >>> path = "/"
- # path.split(os.sep)
+ # path.split(pp.sep)
# ['', '']
parts = []
else:
- parts = path.split(os.sep)[1:]
+ parts = path.split(pp.sep)[1:]
if include_root:
parts.insert(0, self._root.item)
for piece in parts:
@@ -120,7 +120,7 @@ class FakeFilesystem(object):
def symlink(self, src_path, dest_path):
dest_path = self._normpath(dest_path)
src_path = self._normpath(src_path)
- dirname, basename = os.path.split(dest_path)
+ dirname, basename = pp.split(dest_path)
parent_node = self._fetch_node(dirname)
child_node = parent_node.find(basename,
only_direct=True,
@@ -140,7 +140,7 @@ class FakeFilesystem(object):
item_node = self._fetch_node(path)
item_node.metadata.update(value=value)
except exc.NotFound:
- dirname, basename = os.path.split(path)
+ dirname, basename = pp.split(path)
parent_node = self._fetch_node(dirname)
parent_node.add(tree.Node(basename, value=value))
@@ -159,7 +159,7 @@ class MemoryBackend(path_based.PathBasedBackend):
def __init__(self, conf=None):
super(MemoryBackend, self).__init__(conf)
if self._path is None:
- self._path = os.sep
+ self._path = pp.sep
self.memory = FakeFilesystem(deep_copy=self._conf.get('deep_copy',
True))
self.lock = lock_utils.ReaderWriterLock()
@@ -191,7 +191,7 @@ class Connection(path_based.PathBasedConnection):
raise exc.StorageFailure("Storage backend internal error", e)
def _join_path(self, *parts):
- return os.path.join(*parts)
+ return pp.join(*parts)
def _get_item(self, path):
with self._memory_lock():