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
abfba610
Commit
abfba610
authored
Jan 17, 2010
by
Eric Naeseth
Committed by
Chris Wanstrath
Feb 09, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding template file encoding awareness.
parent
db1b35cc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
0 deletions
+21
-0
examples/unicode_input.mustache
+2
-0
examples/unicode_input.py
+8
-0
pystache/view.py
+6
-0
tests/test_examples.py
+5
-0
No files found.
examples/unicode_input.mustache
0 → 100644
View file @
abfba610
<p>
If alive today, Henri Poincaré would be
{{
age
}}
years old.
</p>
\ No newline at end of file
examples/unicode_input.py
0 → 100644
View file @
abfba610
import
pystache
class
UnicodeInput
(
pystache
.
View
):
template_path
=
'examples'
template_encoding
=
'utf8'
def
age
(
self
):
return
156
pystache/view.py
View file @
abfba610
...
@@ -19,6 +19,10 @@ class View(object):
...
@@ -19,6 +19,10 @@ class View(object):
# Contents of the template.
# Contents of the template.
template
=
None
template
=
None
# Character encoding of the template file. If None, Pystache will not
# do any decoding of the template.
template_encoding
=
None
def
__init__
(
self
,
template
=
None
,
context
=
None
,
**
kwargs
):
def
__init__
(
self
,
template
=
None
,
context
=
None
,
**
kwargs
):
self
.
template
=
template
self
.
template
=
template
...
@@ -57,6 +61,8 @@ class View(object):
...
@@ -57,6 +61,8 @@ class View(object):
f
=
open
(
self
.
template_file
,
'r'
)
f
=
open
(
self
.
template_file
,
'r'
)
try
:
try
:
template
=
f
.
read
()
template
=
f
.
read
()
if
self
.
template_encoding
:
template
=
unicode
(
template
,
self
.
template_encoding
)
finally
:
finally
:
f
.
close
()
f
.
close
()
return
template
return
template
...
...
tests/test_examples.py
View file @
abfba610
...
@@ -10,6 +10,7 @@ from examples.unescaped import Unescaped
...
@@ -10,6 +10,7 @@ from examples.unescaped import Unescaped
from
examples.template_partial
import
TemplatePartial
from
examples.template_partial
import
TemplatePartial
from
examples.delimiters
import
Delimiters
from
examples.delimiters
import
Delimiters
from
examples.unicode_output
import
UnicodeOutput
from
examples.unicode_output
import
UnicodeOutput
from
examples.unicode_input
import
UnicodeInput
class
TestView
(
unittest
.
TestCase
):
class
TestView
(
unittest
.
TestCase
):
def
test_comments
(
self
):
def
test_comments
(
self
):
...
@@ -27,6 +28,10 @@ class TestView(unittest.TestCase):
...
@@ -27,6 +28,10 @@ class TestView(unittest.TestCase):
def
test_encoded_output
(
self
):
def
test_encoded_output
(
self
):
self
.
assertEquals
(
UnicodeOutput
()
.
render
(
'utf8'
),
'<p>Name: Henri Poincar
\xc3\xa9
</p>'
)
self
.
assertEquals
(
UnicodeOutput
()
.
render
(
'utf8'
),
'<p>Name: Henri Poincar
\xc3\xa9
</p>'
)
def
test_unicode_input
(
self
):
self
.
assertEquals
(
UnicodeInput
()
.
render
(),
u'<p>If alive today, Henri Poincaré would be 156 years old.</p>'
)
def
test_escaped
(
self
):
def
test_escaped
(
self
):
self
.
assertEquals
(
Escaped
()
.
render
(),
"<h1>Bear > Shark</h1>"
)
self
.
assertEquals
(
Escaped
()
.
render
(),
"<h1>Bear > Shark</h1>"
)
...
...
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