def parse(self, inp): """""" if not inp or inp == NO_STR: value = tuple() elif isinstance(inp, (tuple, list)) or is_lazy_iterable(inp): value = make_tuple(inp) elif isinstance(inp, six.string_types): if self._brace_expand: elems = brace_expand(inp, split_csv=True, escape_csv_sep=self._escape_sep) else: # replace escaped separators if self._escape_sep: escaped_sep = "__law_escaped_csv_sep__" inp = inp.replace("\\" + self.CSV_SEP, escaped_sep) # split elems = inp.split(self.CSV_SEP) # add back escaped separators per element if self._escape_sep: elems = [elem.replace(escaped_sep, self.CSV_SEP) for elem in elems] value = tuple(map(self._inst.parse, elems)) else: value = (inp,) # apply uniqueness, sort, length and choices checks value = self._check_unique(value) value = self._check_sort(value) self._check_len(value) self._check_choices(value) return value
def _flatten_output(output, depth): if isinstance(output, (list, tuple, set)) or is_lazy_iterable(output): return [(outp, depth, "{}: ".format(i)) for i, outp in enumerate(output)] elif isinstance(output, dict): return [(outp, depth, "{}: ".format(k)) for k, outp in six.iteritems(output)] else: return [(outp, depth, "") for outp in flatten(output)]
def parse(self, inp): """""" if not inp: return () elif isinstance(inp, (tuple, list)) or is_lazy_iterable(inp): return make_tuple(inp) else: return tuple(self._inst.parse(elem) for elem in inp.split(","))
def parse(self, inp): """""" if not inp or inp == NO_STR: value = tuple() elif isinstance(inp, (tuple, list)) or is_lazy_iterable(inp): value = tuple(super(MultiRangeParameter, self).parse(v) for v in inp) elif isinstance(inp, six.string_types): elems = inp.split(self.MULTI_RANGE_SEP) value = tuple(super(MultiRangeParameter, self).parse(e) for e in elems) else: value = (super(MultiRangeParameter, self).parse(inp),) return value
def parse(self, inp): """""" if not inp: ret = tuple() elif isinstance(inp, (tuple, list)) or is_lazy_iterable(inp): ret = make_tuple(inp) else: ret = tuple(self._inst.parse(elem) for elem in inp.split(",")) # ensure uniqueness if self._unique: ret = make_unique(ret) # check min_len and max_len self._check_len(ret) return ret
def uri(self, path, *args, **kwargs): """ uri(path, base=None, *args, **kwargs) """ # get the base base = kwargs.pop("base", None) if not base: kwargs["return_index"] = False base = self.get_base(*args, **kwargs) # helper to join the path to a base b uri = lambda b: os.path.join(b, self.gfal_str(path).lstrip("/")).rstrip( "/") if isinstance(base, (list, tuple)) or is_lazy_iterable(base): return [uri(b) for b in base] else: return uri(base)
def uri(self, path, base=None, scheme=True, **kwargs): # get a base path when not given if not base: kwargs["return_index"] = False base = self.get_base(**kwargs) # helper to join the path to a base b and remove the scheme if requested def uri(b): uri = os.path.join( b, self.sanitize_path(path).lstrip("/")).rstrip("/") if not scheme: uri = remove_scheme(uri) return uri if isinstance(base, (list, tuple)) or is_lazy_iterable(base): return [uri(b) for b in base] else: return uri(base)
def parse(self, inp): """""" if not inp or inp == NO_STR: value = tuple() elif isinstance(inp, (tuple, list)) or is_lazy_iterable(inp): value = make_tuple(inp) elif isinstance(inp, six.integer_types): value = (inp,) elif isinstance(inp, six.string_types): parts = inp.split(self.RANGE_SEP) # convert integers try: value = tuple((int(p) if p else self.OPEN) for p in parts) except ValueError: raise ValueError("range '{}'' contains non-integer elements".format(inp)) else: value = (inp,) self._check(value) return value
def parse(self, inp): """""" if not inp or inp == NO_STR: value = tuple() elif isinstance(inp, (tuple, list)) or is_lazy_iterable(inp): value = tuple(super(MultiCSVParameter, self).parse(v) for v in inp) elif isinstance(inp, six.string_types): # replace escaped separators if self._escape_sep: escaped_sep = "__law_escaped_multi_csv_sep__" inp = inp.replace("\\" + self.MULTI_CSV_SEP, escaped_sep) # split elems = inp.split(self.MULTI_CSV_SEP) # add back escaped separators per element if self._escape_sep: elems = [elem.replace(escaped_sep, self.MULTI_CSV_SEP) for elem in elems] value = tuple(super(MultiCSVParameter, self).parse(e) for e in elems) else: value = (super(MultiCSVParameter, self).parse(inp),) return value