#NEWLINE# @ contextfilter #NEWLINE# def do_map( * args , **kwargs ) : #NEWLINE# #INDENT# "Applies a filter on a sequence of objects or looks up an attribute.\n    This is useful when dealing with lists of objects but you are really\n    only interested in a certain value of it.\n\n    The basic usage is mapping on an attribute.  Imagine you have a list\n    of users but you are only interested in a list of usernames:\n\n    .. sourcecode:: jinja\n\n        Users on this page: {{ users|map(attribute='username')|join(', ') }}\n\n    Alternatively you can let it invoke a filter by passing the name of the\n    filter and the arguments afterwards.  A good example would be applying a\n    text conversion filter on a sequence:\n\n    .. sourcecode:: jinja\n\n        Users on this page: {{ titles|map('lower')|join(', ') }}\n\n    .. versionadded:: 2.7\n    " #NEWLINE# context = args [ 0 ] #NEWLINE# seq = args [ 1 ] #NEWLINE# if ( ( len ( args ) == 2 ) and ( 'attribute' in kwargs ) ) : #NEWLINE# #INDENT# attribute = kwargs . pop ( 'attribute' ) #NEWLINE# if kwargs : #NEWLINE# #INDENT# raise FilterArgumentError ( ( 'Unexpected keyword argument %r' % next ( iter ( kwargs ) ) ) ) #NEWLINE# #UNINDENT# func = make_attrgetter ( context . environment , attribute ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# name = args [ 2 ] #NEWLINE# args = args [ 3 : ] #NEWLINE# #UNINDENT# except LookupError : #NEWLINE# #INDENT# raise FilterArgumentError ( 'map requires a filter argument' ) #NEWLINE# #UNINDENT# func = ( lambda item : context . environment . call_filter ( name , item , args , kwargs , context = context ) ) #NEWLINE# #UNINDENT# if kwargs : #NEWLINE# #INDENT# for item in seq : #NEWLINE# #INDENT# ( yield func ( item ) )