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
85f5ef0f
Commit
85f5ef0f
authored
Mar 30, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed Renderer.default_encoding to Renderer.string_encoding.
parent
5ba98b3d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
35 deletions
+35
-35
pystache/renderer.py
+17
-17
tests/test_renderer.py
+18
-18
No files found.
pystache/renderer.py
View file @
85f5ef0f
...
...
@@ -32,8 +32,8 @@ class Renderer(object):
"""
# TODO:
rename default_encoding to string_encoding
.
def
__init__
(
self
,
file_encoding
=
None
,
default
_encoding
=
None
,
# TODO:
file_encoding should default to the package default
.
def
__init__
(
self
,
file_encoding
=
None
,
string
_encoding
=
None
,
decode_errors
=
None
,
search_dirs
=
None
,
file_extension
=
None
,
escape
=
None
,
partials
=
None
):
"""
...
...
@@ -66,12 +66,13 @@ class Renderer(object):
escape function, for example. One may also wish to consider
using markupsafe's escape function: markupsafe.escape().
file_encoding: the name of the encoding of all template files.
This encoding is used when reading and converting any template
files to unicode. All templates are converted to unicode prior
to parsing. Defaults to the default_encoding argument.
file_encoding: the name of the default encoding to use when reading
template files. All templates are converted to unicode prior
to parsing. This encoding is used when reading template files
and converting them to unicode. Defaults to the value of the
string_encoding argument.
default
_encoding: the name of the encoding to use when converting
string
_encoding: the name of the encoding to use when converting
to unicode any strings of type str encountered during the
rendering process. The name will be passed as the encoding
argument to the built-in function unicode(). Defaults to the
...
...
@@ -94,15 +95,15 @@ class Renderer(object):
if
decode_errors
is
None
:
decode_errors
=
defaults
.
DECODE_ERRORS
if
default
_encoding
is
None
:
default
_encoding
=
defaults
.
STRING_ENCODING
if
string
_encoding
is
None
:
string
_encoding
=
defaults
.
STRING_ENCODING
if
escape
is
None
:
escape
=
defaults
.
TAG_ESCAPE
# This needs to be after we set the default
default
_encoding.
# This needs to be after we set the default
string
_encoding.
if
file_encoding
is
None
:
file_encoding
=
default
_encoding
file_encoding
=
string
_encoding
if
file_extension
is
None
:
file_extension
=
defaults
.
TEMPLATE_EXTENSION
...
...
@@ -114,8 +115,7 @@ class Renderer(object):
search_dirs
=
[
search_dirs
]
self
.
decode_errors
=
decode_errors
# TODO: rename this attribute to string_encoding.
self
.
default_encoding
=
default_encoding
self
.
string_encoding
=
string_encoding
self
.
escape
=
escape
self
.
file_encoding
=
file_encoding
self
.
file_extension
=
file_extension
...
...
@@ -148,7 +148,7 @@ class Renderer(object):
def
unicode
(
self
,
s
,
encoding
=
None
):
"""
Convert a string to unicode, using
default
_encoding and decode_errors.
Convert a string to unicode, using
string
_encoding and decode_errors.
Raises:
...
...
@@ -160,10 +160,10 @@ class Renderer(object):
"""
if
encoding
is
None
:
encoding
=
self
.
default
_encoding
encoding
=
self
.
string
_encoding
# TODO: Wrap UnicodeDecodeErrors with a message about setting
# the
default
_encoding and decode_errors attributes.
# the
string
_encoding and decode_errors attributes.
return
unicode
(
s
,
encoding
,
self
.
decode_errors
)
def
_make_loader
(
self
):
...
...
@@ -280,7 +280,7 @@ class Renderer(object):
Returns the rendering as a unicode string.
Prior to rendering, templates of type str are converted to unicode
using the
default
_encoding and decode_errors attributes. See the
using the
string
_encoding and decode_errors attributes. See the
constructor docstring for more information.
Arguments:
...
...
tests/test_renderer.py
View file @
85f5ef0f
...
...
@@ -54,21 +54,21 @@ class RendererInitTestCase(unittest.TestCase):
renderer
=
Renderer
(
escape
=
escape
)
self
.
assertEquals
(
renderer
.
escape
(
"bar"
),
"**bar"
)
def
test_
default
_encoding__default
(
self
):
def
test_
string
_encoding__default
(
self
):
"""
Check the default value.
"""
renderer
=
Renderer
()
self
.
assertEquals
(
renderer
.
default
_encoding
,
sys
.
getdefaultencoding
())
self
.
assertEquals
(
renderer
.
string
_encoding
,
sys
.
getdefaultencoding
())
def
test_
default
_encoding
(
self
):
def
test_
string
_encoding
(
self
):
"""
Check that the constructor sets the attribute correctly.
"""
renderer
=
Renderer
(
default
_encoding
=
"foo"
)
self
.
assertEquals
(
renderer
.
default
_encoding
,
"foo"
)
renderer
=
Renderer
(
string
_encoding
=
"foo"
)
self
.
assertEquals
(
renderer
.
string
_encoding
,
"foo"
)
def
test_decode_errors__default
(
self
):
"""
...
...
@@ -92,7 +92,7 @@ class RendererInitTestCase(unittest.TestCase):
"""
renderer
=
Renderer
()
self
.
assertEquals
(
renderer
.
file_encoding
,
renderer
.
default
_encoding
)
self
.
assertEquals
(
renderer
.
file_encoding
,
renderer
.
string
_encoding
)
def
test_file_encoding
(
self
):
"""
...
...
@@ -152,18 +152,18 @@ class RendererTestCase(unittest.TestCase):
## Test Renderer.unicode().
def
test_unicode__
default
_encoding
(
self
):
def
test_unicode__
string
_encoding
(
self
):
"""
Test that the
default
_encoding attribute is respected.
Test that the
string
_encoding attribute is respected.
"""
renderer
=
Renderer
()
s
=
"é"
renderer
.
default
_encoding
=
"ascii"
renderer
.
string
_encoding
=
"ascii"
self
.
assertRaises
(
UnicodeDecodeError
,
renderer
.
unicode
,
s
)
renderer
.
default
_encoding
=
"utf-8"
renderer
.
string
_encoding
=
"utf-8"
self
.
assertEquals
(
renderer
.
unicode
(
s
),
u"é"
)
def
test_unicode__decode_errors
(
self
):
...
...
@@ -172,7 +172,7 @@ class RendererTestCase(unittest.TestCase):
"""
renderer
=
Renderer
()
renderer
.
default
_encoding
=
"ascii"
renderer
.
string
_encoding
=
"ascii"
s
=
"déf"
renderer
.
decode_errors
=
"ignore"
...
...
@@ -289,12 +289,12 @@ class RendererTestCase(unittest.TestCase):
renderer
=
Renderer
()
template
=
"déf"
# Check that decode_errors and
default
_encoding are both respected.
# Check that decode_errors and
string
_encoding are both respected.
renderer
.
decode_errors
=
'ignore'
renderer
.
default
_encoding
=
'ascii'
renderer
.
string
_encoding
=
'ascii'
self
.
assertEquals
(
renderer
.
render
(
template
),
"df"
)
renderer
.
default
_encoding
=
'utf_8'
renderer
.
string
_encoding
=
'utf_8'
self
.
assertEquals
(
renderer
.
render
(
template
),
u"déf"
)
def
test_make_load_partial
(
self
):
...
...
@@ -387,7 +387,7 @@ class Renderer_MakeRenderEngineTests(unittest.TestCase):
pass
renderer
=
Renderer
()
renderer
.
default
_encoding
=
'ascii'
renderer
.
string
_encoding
=
'ascii'
renderer
.
partials
=
{
'str'
:
'foo'
,
'subclass'
:
MyUnicode
(
'abc'
)}
engine
=
renderer
.
_make_render_engine
()
...
...
@@ -439,7 +439,7 @@ class Renderer_MakeRenderEngineTests(unittest.TestCase):
"""
renderer
=
Renderer
()
renderer
.
default
_encoding
=
'ascii'
renderer
.
string
_encoding
=
'ascii'
engine
=
renderer
.
_make_render_engine
()
literal
=
engine
.
literal
...
...
@@ -452,7 +452,7 @@ class Renderer_MakeRenderEngineTests(unittest.TestCase):
"""
renderer
=
Renderer
()
renderer
.
default
_encoding
=
'ascii'
renderer
.
string
_encoding
=
'ascii'
engine
=
renderer
.
_make_render_engine
()
literal
=
engine
.
literal
...
...
@@ -520,7 +520,7 @@ class Renderer_MakeRenderEngineTests(unittest.TestCase):
"""
renderer
=
Renderer
()
renderer
.
default
_encoding
=
'ascii'
renderer
.
string
_encoding
=
'ascii'
engine
=
renderer
.
_make_render_engine
()
escape
=
engine
.
escape
...
...
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