where '%s' is replaced with filter_name. call the method parser.parse with an argument tuple with an element string 'endfilter', substitute the result for nodelist.
nodelist = parser . parse ( ( 'endfilter' , ) )