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
c50f77b8
Commit
c50f77b8
authored
Dec 24, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a doctest for issue #11: "View executes callables wrongly"
parent
e2305c75
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
pystache/context.py
+28
-0
No files found.
pystache/context.py
View file @
c50f77b8
...
...
@@ -125,6 +125,34 @@ class Context(object):
(3) If there is no attribute with the same name as the key, then
the key is considered not found in the item.
*Caution*:
Callables resulting from a call to __getitem__ (as in (1)
above) are handled differently from callables that are merely
attributes (as in (2) above).
The former are returned as-is, while the latter are first called
and that value returned. Here is an example:
>>> def greet():
... return "Hi Bob!"
>>>
>>> class Greeter(object):
... greet = None
>>>
>>> obj = Greeter()
>>> obj.greet = greet
>>> dct = {'greet': greet}
>>>
>>> obj.greet is dct['greet']
True
>>> Context(obj).get('greet')
'Hi Bob!'
>>> Context(dct).get('greet') #doctest: +ELLIPSIS
<function greet at 0x...>
TODO: explain the rationale for this difference in treatment.
"""
for
obj
in
reversed
(
self
.
_stack
):
val
=
_get_item
(
obj
,
key
)
...
...
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