youtube / spitfire

A high-performance Python template language
BSD 3-Clause "New" or "Revised" License
403 stars 59 forks source link

Fix cheetah_cheats mode to resolve local placeholders #54

Closed nicksay closed 8 years ago

nicksay commented 8 years ago

When compiled with -Xcheetah-cheats (or when options.cheetah_cheats is True) and no optimizations are applied, the template source

  #set $a = 'foo'
  #set $b = $a

produces the template code

  _self_search_list = self.search_list + [_globals]
  a = u'foo'
  b = resolve_placeholder(_self_search_list, 'a')

which causes a runtime error.

Fix this by adding locals() to the search list during placeholder resolution. Also fix a bug where a runtime error occurs if self.search_list is None by conditionally adding it to the search list. After, the template code is

  if self.search_list:
    _self_search_list = self.search_list + [_globals]
  else:
    _self_search_list = [_globals]
  a = u'foo'
  b = resolve_placeholder([locals()] + _self_search_list, 'a')

Closes #6

awbraunstein commented 8 years ago

lgtm