def Split(param, delimiter): if param: if not is_seq(param): param = str(param).split(delimiter) return param else: return []
def insert(self, files): """Insert the contents of a file without parsing.""" # TODO: Clean this up; unify the way "files" is passed to this routine. files = unscalar(files) if is_seq(files): files = unscalar_list(files) else: files = [unscalar(files)] prefix = providers = text = None output = cStringIO.StringIO() for file in files: prefix, name = split_prefix(file) if prefix: providers = self.__prefix_map.get(prefix) if not providers: self.throw(ERROR_FILE, "no providers for file prefix '%s'" % prefix) else: providers = self.__prefix_map.get("default") or self.__load_templates for provider in providers: try: text = provider.load(name, prefix) except Exception, e: self.throw(ERROR_FILE, str(e)) if text is not None: output.write(text) break else: self.throw(ERROR_FILE, "%s: not found" % file)
def list_splice(seq, start=0, length=None, *replace): start = util.numify(start) if start < 0: start = len(seq) + start if length is not None: stop = start + length else: stop = len(seq) if len(replace) == 1 and util.is_seq(replace[0]): replace = replace[0] s = slice(start, stop) removed = seq[s] seq[s] = replace return removed
def getref(self, ident, args=None): """Returns a "reference" to a particular item. This is represented as a function which will return the actual stash item when called. WARNING: still experimental! """ root = self if util.is_seq(ident): chopped = list(util.chop(ident, 2)) for i, (item, args) in enumerate(chopped): if i == len(chopped) - 1: break root = self.__dotop(root, item, args) if root is None: break else: item = ident if root is not None: return lambda *x: self.__dotop(root, item, tuple(args or ()) + x) else: return lambda *x: ""
def Args(key, val): key = escape(key) if not util.is_seq(val): val = [val] return ["%s=%s" % (key, escape(v)) for v in val]