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
d02b657f
Commit
d02b657f
authored
Nov 12, 2009
by
Chris Wanstrath
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement unescape tag, make escape tag actually escape
parent
24bdeb2d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
pystache/template.py
+8
-2
No files found.
pystache/template.py
View file @
d02b657f
import
re
import
cgi
SECTION_RE
=
re
.
compile
(
r"{{\#([^\}]*)}}\s*(.+?)\s*{{/\1}}"
,
re
.
M
|
re
.
S
)
TAG_RE
=
re
.
compile
(
r"{{(#|=|!|<|>|\{)?(.+?)\1?}}+"
)
...
...
@@ -6,7 +7,8 @@ TAG_RE = re.compile(r"{{(#|=|!|<|>|\{)?(.+?)\1?}}+")
class
Template
(
object
):
tag_types
=
{
None
:
'tag'
,
'!'
:
'comment'
'!'
:
'comment'
,
'{'
:
'unescaped'
}
def
__init__
(
self
,
template
,
context
=
None
):
...
...
@@ -62,8 +64,12 @@ class Template(object):
def
render_tag
(
self
,
tag_name
,
context
):
"""Given a tag name and context, finds and renders the tag."""
return
c
ontext
.
get
(
tag_name
,
''
)
return
c
gi
.
escape
(
context
.
get
(
tag_name
,
''
)
)
def
render_comment
(
self
,
tag_name
=
None
,
context
=
None
):
"""Rendering a comment always returns nothing."""
return
''
def
render_unescaped
(
self
,
tag_name
=
None
,
context
=
None
):
"""Render a tag without escaping it."""
return
context
.
get
(
tag_name
,
''
)
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