Skip to content

Commit

Permalink
Turn iterables into lists for in operator.
Browse files Browse the repository at this point in the history
The implementation is currently written in a way that would try
to consume the iterator multiple times and cannot deal with new
memoryviews like those returned by dict.keys().
  • Loading branch information
hannosch committed May 16, 2017
1 parent bdc26a8 commit 5716eb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/DocumentTemplate/DT_In.py
Expand Up @@ -465,6 +465,11 @@ def renderwb(self, md):
raise ValueError(
'Strings are not allowed as input to the in tag.')

# Turn iterable like dict.keys() into a list.
sequence = list(sequence)
if cache is not None:
cache[name] = sequence

section = self.section
params = self.args

Expand Down Expand Up @@ -668,6 +673,11 @@ def renderwob(self, md):
raise ValueError(
'Strings are not allowed as input to the in tag.')

# Turn iterable like dict.keys() into a list.
sequence = list(sequence)
if cache is not None:
cache[name] = sequence

section = self.section
mapping = self.mapping
no_push_item = self.no_push_item
Expand Down
3 changes: 3 additions & 0 deletions src/DocumentTemplate/DT_InSV.py
Expand Up @@ -31,6 +31,9 @@ class sequence_variables(object):

def __init__(self, items=None, query_string='', start_name_re=None,
alt_prefix=''):
if items is not None:
# Turn iterable into a list, to support key lookup
items = list(items)
self.items = items
self.query_string = query_string
self.start_name_re = start_name_re
Expand Down

0 comments on commit 5716eb8

Please sign in to comment.