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
d570f70a
Commit
d570f70a
authored
May 02, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed item to context in the context module's _get_value().
parent
384475a5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
pystache/context.py
+8
-9
No files found.
pystache/context.py
View file @
d570f70a
...
...
@@ -27,25 +27,24 @@ def _is_callable(obj):
return
hasattr
(
obj
,
'__call__'
)
# TODO: rename item to context (now that we have a separate notion of context stack).
# TODO: document what a "context" is as opposed to a context stack.
def
_get_value
(
item
,
key
):
def
_get_value
(
context
,
key
):
"""
Retrieve a key's value from a
n
item.
Retrieve a key's value from a
context
item.
Returns _NOT_FOUND if the key does not exist.
The ContextStack.get() docstring documents this function's intended behavior.
"""
if
isinstance
(
item
,
dict
):
if
isinstance
(
context
,
dict
):
# Then we consider the argument a "hash" for the purposes of the spec.
#
# We do a membership test to avoid using exceptions for flow control
# (e.g. catching KeyError).
if
key
in
item
:
return
item
[
key
]
elif
type
(
item
)
.
__module__
!=
_BUILTIN_MODULE
:
if
key
in
context
:
return
context
[
key
]
elif
type
(
context
)
.
__module__
!=
_BUILTIN_MODULE
:
# Then we consider the argument an "object" for the purposes of
# the spec.
#
...
...
@@ -53,8 +52,8 @@ def _get_value(item, key):
# types like integers and strings as objects (cf. issue #81).
# Instances of user-defined classes on the other hand, for example,
# are considered objects by the test above.
if
hasattr
(
item
,
key
):
attr
=
getattr
(
item
,
key
)
if
hasattr
(
context
,
key
):
attr
=
getattr
(
context
,
key
)
if
_is_callable
(
attr
):
return
attr
()
return
attr
...
...
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