Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
3f893994
Commit
3f893994
authored
Apr 08, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved rendering logic around list-like section values for Python 3.
parent
166f7c60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
pystache/renderengine.py
+22
-3
No files found.
pystache/renderengine.py
View file @
3f893994
...
...
@@ -167,9 +167,28 @@ class RenderEngine(object):
# TODO: should we check the arity?
template
=
data
(
template
)
parsed_template
=
self
.
_parse
(
template
,
delimiters
=
delims
)
data
=
[
data
]
elif
not
hasattr
(
data
,
'__iter__'
)
or
isinstance
(
data
,
dict
):
data
=
[
data
]
data
=
[
data
]
else
:
# The cleanest, least brittle way of determining whether
# something supports iteration is by trying to call iter() on it:
#
# http://docs.python.org/library/functions.html#iter
#
# It is not sufficient, for example, to check whether the item
# implements __iter__ () (the iteration protocol). There is
# also __getitem__() (the sequence protocol). In Python 2,
# strings do not implement __iter__(), but in Python 3 they do.
try
:
iter
(
data
)
except
TypeError
:
# Then the value does not support iteration.
data
=
[
data
]
else
:
# We treat the value as a list (but do not treat strings
# and dicts as lists).
if
isinstance
(
data
,
(
basestring
,
dict
)):
data
=
[
data
]
# Otherwise, leave it alone.
parts
=
[]
for
element
in
data
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment