def format_field(self, value, spec): if ':' not in spec: return super(RenderingFormatter, self).format_field( self.render(value), spec ) ind, sep, fmt = spec.split(':') if sep == '\\n': sep = '\n' if not ind: ind = 0 mult = 0 elif '*' in ind: ind, mult = ind.split('*') else: mult = 4 ind = int(ind) mult = int(mult) if not fmt: fmt = '%s' if isiter(value): return indent(sep.join(fmt % self.render(v) for v in value), ind, mult) else: return indent(fmt % self.render(value), ind, mult)
def render(item, join='', **fields): """ Render the given item """ if item is None: return '' elif isinstance(item, strtype): return item elif isinstance(item, Renderer): return item.render(join=join, **fields) elif isiter(item): return join.join(render(e, **fields) for e in iter(item) if e is not None) elif isinstance(item, (int, float)): return item else: return ustr(item)