From 0ba6d551919090d079ef6667e1f228be0b79c358 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 10 Oct 2011 09:57:56 +0200 Subject: [PATCH] raise exception when given a relative path Signed-off-by: Steven Armstrong --- lib/cdist/core/property.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cdist/core/property.py b/lib/cdist/core/property.py index 30887547..e63cadcf 100644 --- a/lib/cdist/core/property.py +++ b/lib/cdist/core/property.py @@ -25,11 +25,21 @@ import collections import cdist +class AbsolutePathRequiredError(cdist.Error): + def __init__(self, path): + self.path = path + + def __str__(self): + return 'Absolute path required, got: %s' % self.path + + class FileList(collections.MutableSequence): """A list that stores it's state in a file. """ def __init__(self, path, initial=None): + if not os.path.isabs(path): + raise AbsolutePathRequiredError(path) self._path = path if initial: # delete existing file @@ -108,6 +118,8 @@ class DirectoryDict(collections.MutableMapping): """ def __init__(self, path, dict=None, **kwargs): + if not os.path.isabs(path): + raise AbsolutePathRequiredError(path) self._path = path if dict is not None: self.update(dict)