@contextfilter
def do_map(*args, **kwargs):
 context = args[0]
 seq = args[1]
 if ((len(args) == 2) and ('attribute' in kwargs)):
  attribute = kwargs.pop('attribute')
  if kwargs:
   raise FilterArgumentError(('Unexpected keyword argument %r' % next(iter(kwargs))))
  func = make_attrgetter(context.environment, attribute)
 else:
  try:
   name = args[2]
   args = args[3:]
  except LookupError:
   raise FilterArgumentError('map requires a filter argument')
  func = (lambda item: context.environment.call_filter(name, item, args, kwargs, context=context))
 if seq:
  for item in seq:
   (yield func(item))

@ contextfilter def do_map ( * args , ** kwargs ) : context = args [ 0 ] seq = args [ 1 ] if ( ( len ( args ) == 2 ) and ( 'attribute' in kwargs ) ) : attribute = kwargs . pop ( 'attribute' ) if kwargs : raise FilterArgumentError ( ( 'Unexpected keyword argument %r' % next ( iter ( kwargs ) ) ) ) func = make_attrgetter ( context . environment , attribute ) else : try : name = args [ 2 ] args = args [ 3 : ] except LookupError : raise FilterArgumentError ( 'map requires a filter argument' ) func = ( lambda item : context . environment . call_filter ( name , item , args , kwargs , context = context ) ) if seq : for item in seq : ( yield func ( item ) )
applies a filter on a sequence of objects or looks up an attribute .