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
350910b8
Commit
350910b8
authored
Apr 04, 2012
by
Rodrigo Bernardo Pimentel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing logic mistake when determining auto-invoking. Added tests for this case.
parent
3c5a6db5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
pystache/context.py
+4
-5
tests/test_context.py
+14
-2
No files found.
pystache/context.py
View file @
350910b8
...
@@ -29,6 +29,7 @@ def _get_value(item, key):
...
@@ -29,6 +29,7 @@ def _get_value(item, key):
"""
"""
parts
=
key
.
split
(
'.'
)
parts
=
key
.
split
(
'.'
)
key
=
parts
[
0
]
key
=
parts
[
0
]
rest
=
'.'
.
join
(
parts
[
1
:])
value
=
_NOT_FOUND
value
=
_NOT_FOUND
if
isinstance
(
item
,
dict
):
if
isinstance
(
item
,
dict
):
...
@@ -50,16 +51,14 @@ def _get_value(item, key):
...
@@ -50,16 +51,14 @@ def _get_value(item, key):
attr
=
getattr
(
item
,
key
)
attr
=
getattr
(
item
,
key
)
# If there are still parts to process (in a dot-notation key),
# If there are still parts to process (in a dot-notation key),
# we do not automatically invoke the object, even if it's callable.
# we do not automatically invoke the object, even if it's callable.
autocall
=
len
(
parts
)
>
1
autocall
=
len
(
rest
)
==
0
if
autocall
and
_is_callable
(
attr
):
if
autocall
and
_is_callable
(
attr
):
value
=
attr
()
value
=
attr
()
else
:
else
:
value
=
attr
value
=
attr
for
part
in
parts
[
1
:]:
if
rest
and
value
is
not
_NOT_FOUND
:
if
value
is
_NOT_FOUND
:
value
=
_get_value
(
value
,
rest
)
break
value
=
_get_value
(
value
,
part
)
return
value
return
value
...
...
tests/test_context.py
View file @
350910b8
...
@@ -432,5 +432,17 @@ class ContextTests(unittest.TestCase, AssertIsMixin):
...
@@ -432,5 +432,17 @@ class ContextTests(unittest.TestCase, AssertIsMixin):
original
=
Context
({
"foo"
:
Attachable
(
bar
=
Attachable
())})
original
=
Context
({
"foo"
:
Attachable
(
bar
=
Attachable
())})
self
.
assertEquals
(
original
.
get
(
key
),
None
)
self
.
assertEquals
(
original
.
get
(
key
),
None
)
def
test_dot_notattion__autocall
(
self
):
key
=
"foo.bar.baz"
# When the last element is callable, it should be automatically invoked
original
=
Context
({
"foo"
:
Attachable
(
bar
=
Attachable
(
baz
=
lambda
:
"Called!"
))})
self
.
assertEquals
(
original
.
get
(
key
),
"Called!"
)
# An element in the middle of the dotted path should NOT be invoked,
# even if it is callable
class
Callable
(
Attachable
):
def
__call__
(
self
):
return
'Called!'
original
=
Context
({
"foo"
:
Callable
(
bar
=
Callable
(
baz
=
'Not called!'
))})
self
.
assertEquals
(
original
.
get
(
key
),
"Not called!"
)
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