def __call__(self, param_name: str, value: Sequence): if len(value) < self.minlen: raise ValidationError( f"Parameter {param_name} must have at least {self.minlen} elements." ) if len(value) < self.maxlen: raise ValidationError( f"Parameter {param_name} can have at most {self.maxlen} elements." )
def __call__(self, **kwargs): defined = len(tuple(filter(None, kwargs.values()))) if not self.cmp.fn(defined, self.n): raise ValidationError( f"Of the following parameters, the number defined must be " f"{self.cmp.symbol} {self.n}: {', '.join(kwargs.keys())}" )
def writable_path(param_name: str, value: pathlib.Path): existing = value while not existing.exists(): if existing.parent: existing = existing.parent else: break if not os.access(existing, os.W_OK): raise ValidationError( f"Parameter {param_name} value {value} is not writable.")
def __call__(self, **kwargs): args = list(kwargs.items()) groups = self.groups or range(len(args)) defined = [] for group in groups: if isinstance(group, int): group = [group] for i in group: if args[i][1] is not None: defined.append(group) break if len(defined) > self.max_defined: group_str = ",".join(f"({','.join(str(i) for i in g)})" for g in defined) raise ValidationError( f"Values specified for > {self.max_defined} mutually exclusive groups: " f"{group_str}")
def writable_dir(param_name: str, value: pathlib.Path): if value.exists() and not value.is_dir(): raise ValidationError( f"Parameter {param_name} value {value} exists and is not a directory." )
def readable_dir(param_name: str, value: pathlib.Path): if not value.is_dir(): raise ValidationError( f"Parameter {param_name} value {value} is not a directory.")
def readable_file(param_name: str, value: pathlib.Path): if not value.is_file(): raise ValidationError( f"Parameter {param_name} value {value} is not a file.")
def readable_path(param_name: str, value: pathlib.Path): if not value.exists(): raise ValidationError( f"Parameter {param_name} value {value} does not exist.")