summaryrefslogtreecommitdiff
path: root/attoconf/types.py
diff options
context:
space:
mode:
Diffstat (limited to 'attoconf/types.py')
-rw-r--r--attoconf/types.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/attoconf/types.py b/attoconf/types.py
index 3e73d86..e7c8465 100644
--- a/attoconf/types.py
+++ b/attoconf/types.py
@@ -51,6 +51,18 @@ class enum(object):
raise ValueError('%r not in {%s}' % (s, ', '.join(self.args)))
+class maybe(object):
+ __slots__ = ('inferior')
+
+ def __init__(self, inferior):
+ self.inferior = inferior
+
+ def __call__(self, s):
+ if not s:
+ return s
+ return (self.inferior)(s)
+
+
class ShellList(object):
''' An argument type representing a sequence of 0 or more arguments
'''
@@ -96,9 +108,14 @@ def quoted_string(s):
def filepath(s):
s = trim_trailing_slashes(s)
- # must be absolute *and* canonical
- if s != os.path.abspath(s):
- raise ValueError('Not an absolute, canonical pathname: %s' % s)
+ # must be absolute *and* canonical, except joinable
+ a = os.path.abspath(s)
+ if a == '/':
+ # filepaths often directly cat a subpath
+ # @me@/whatever is invalid if @me@ == /
+ a = '/.'
+ if s != a:
+ raise ValueError('Not an absolute, canonical (except joinable) pathname: %r != %r' % (s, a))
return s