More Python 3 fixes, mostly about string/byte/unicode handling.
[h5config.git] / h5config / storage / __init__.py
index 428e98ebb886b4b6358368880d36595ee1541463..48028d4bc0388c64e57d21d67d58d266decbc97d 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with h5config.  If not, see <http://www.gnu.org/licenses/>.
 
+import os as _os
+import os.path as _os_path
+import sys as _sys
+import types as _types
+
 
 class Storage (object):
     "A storage bakend for loading and saving `Config` instances"
@@ -36,6 +41,9 @@ class Storage (object):
     def _save(self, config, **kwargs):
         raise NotImplementedError()
 
+    def clear(self):
+        raise NotImplementedError()
+
 
 class FileStorage (Storage):
     "`Config` storage backend by a single file"
@@ -43,3 +51,15 @@ class FileStorage (Storage):
 
     def __init__(self, filename=None):
         self._filename = filename
+
+    def _create_basedir(self, filename):
+        dirname = _os_path.dirname(filename)
+        if dirname and not _os_path.isdir(dirname):
+            _os.makedirs(dirname)
+
+
+def is_string(x):
+    if _sys.version_info >= (3,):
+        return isinstance(x, (bytes, str))
+    else:  # Python 2 compatibility
+        return isinstance(x, _types.StringTypes)