# 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"
def _save(self, config, **kwargs):
raise NotImplementedError()
+ def clear(self):
+ raise NotImplementedError()
+
class FileStorage (Storage):
"`Config` storage backend by a single file"
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)