From cf9fda165fa5e2734db201edf88333bf9a765e62 Mon Sep 17 00:00:00 2001 From: Martin Sekera Date: Thu, 18 Apr 2019 02:08:20 +0200 Subject: [PATCH] changed the over.callback.path API a bit --- over/callback.py | 13 +++++++++---- over/version.py | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/over/callback.py b/over/callback.py index 43c0146..252dd8b 100644 --- a/over/callback.py +++ b/over/callback.py @@ -53,11 +53,11 @@ def strings(*args): return out -def path(exists=False, writable=False, validators=[]): +def path(exists=False, permissions=None, validators=None): """ Returns a path callback that takes a path (str) and verifies if it: - exists iff `exists` is True - - is writable iff `writable` is True + - its permissions match those in `permissions` ("rwx" or any subset, e.g. "r--", "-w-", dashes are optional) - goes through each (function, message) pair in `validators`, in order A validator is a function that takes a str argument and returns True or False. @@ -78,8 +78,13 @@ def path(exists=False, writable=False, validators=[]): if exists and not os.path.exists(path): raise FileNotFoundError("%s does not exist" %(arg)) - if writable and not os.access(path, os.W_OK): - raise PermissionError("%s exists but is not writable" %(arg)) + if permissions: + if "r" in permissions and not os.access(path, os.R_OK): + raise PermissionError("%s is not readable" %(arg)) + if "w" in permissions and not os.access(path, os.W_OK): + raise PermissionError("%s is not writable" %(arg)) + if "x" in permissions and not os.access(path, os.X_OK): + raise PermissionError("%s is not executable" %(arg)) if validators: for fn, msg_tpl in validators: diff --git a/over/version.py b/over/version.py index 26e8c61..14cbadc 100644 --- a/over/version.py +++ b/over/version.py @@ -4,5 +4,5 @@ major = 2 # VERSION_MAJOR_IDENTIFIER minor = 1 # VERSION_MINOR_IDENTIFIER # VERSION_LAST_MM 2.1 -patch = 2 # VERSION_PATCH_IDENTIFIER -str = "2.1.2" # VERSION_STRING_IDENTIFIER +patch = 3 # VERSION_PATCH_IDENTIFIER +str = "2.1.3" # VERSION_STRING_IDENTIFIER