def mkFieldMap(fields, args=[], kwargs={}, default=None): base = dict(zip(fields, repeat(default))) if isinstance(args, Mapping): args = [args] if args: if len(args) == 1: first = args[0] if isinstance(first, Mapping): return merge(base, kwargs, first) elif isinstance(first, basestring): args = first.strip().split() else: args = first base.update(zip(fields, args)[:len(args)]) return merge(base, kwargs)
def mkFieldMap(fields, args=[], kwargs={}, default=None): base = dict(zip(fields, repeat(default))) if isinstance(args, Mapping): args = [args] if args: if len(args) == 1: first = args[0] if isinstance(first, Mapping): return merge(base, kwargs, first) elif isinstance(first, basestring): args = first.strip().split() else: args = first base.update( zip(fields, args)[:len(args)] ) return merge(base, kwargs)
def format(self, args=[], kwargs={}, maxlens=0, default=None): maxlens = self.mkMaxLens(maxlens) values = self.mkFieldMap(args, kwargs, default) return self.fmt.format(**merge(maxlens, values))