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
00fa136b
Commit
00fa136b
authored
Apr 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the search_dirs default into the defaults module.
parent
d26bdf33
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
41 deletions
+41
-41
pystache/defaults.py
+5
-0
pystache/renderer.py
+20
-25
tests/test_renderer.py
+16
-16
No files found.
pystache/defaults.py
View file @
00fa136b
...
...
@@ -9,6 +9,7 @@ does not otherwise specify a value.
"""
import
cgi
import
os
import
sys
...
...
@@ -30,6 +31,10 @@ STRING_ENCODING = sys.getdefaultencoding()
# strings that arise from files.
FILE_ENCODING
=
sys
.
getdefaultencoding
()
# The starting list of directories in which to search for templates when
# loading a template by file name.
SEARCH_DIRS
=
[
os
.
curdir
]
# i.e. ['.']
# The escape function to apply to strings that require escaping when
# rendering templates (e.g. for tags enclosed in double braces).
# Only unicode strings will be passed to this function.
...
...
pystache/renderer.py
View file @
00fa136b
...
...
@@ -5,8 +5,6 @@ This module provides a Renderer class to render templates.
"""
import
os
from
.
import
defaults
from
.context
import
Context
from
.loader
import
Loader
...
...
@@ -32,7 +30,6 @@ class Renderer(object):
"""
# 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
):
...
...
@@ -53,6 +50,10 @@ class Renderer(object):
the file system -- using relevant instance attributes like
search_dirs, file_encoding, etc.
decode_errors: the string to pass as the errors argument to the
built-in function unicode() when converting str strings to
unicode. Defaults to the package default.
escape: the function used to escape variable tag values when
rendering a template. The function should accept a unicode
string (or subclass of unicode) and return an escaped string
...
...
@@ -69,8 +70,16 @@ class Renderer(object):
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.
and converting them to unicode. Defaults to the package default.
file_extension: the template file extension. Pass False for no
extension (i.e. to use extensionless template files).
Defaults to the package default.
search_dirs: the list of directories in which to search for
templates when loading a template by name. If given a string,
the method interprets the string as a single directory.
Defaults to the package default.
string_encoding: the name of the encoding to use when converting
to unicode any strings of type str encountered during the
...
...
@@ -78,49 +87,35 @@ class Renderer(object):
argument to the built-in function unicode(). Defaults to the
package default.
decode_errors: the string to pass as the errors argument to the
built-in function unicode() when converting str strings to
unicode. Defaults to the package default.
search_dirs: the list of directories in which to search for
templates when loading a template by name. Defaults to the
current working directory. If given a string, the string is
interpreted as a single directory.
file_extension: the template file extension. Pass False for no
extension (i.e. to use extensionless template files).
Defaults to the package default.
"""
if
decode_errors
is
None
:
decode_errors
=
defaults
.
DECODE_ERRORS
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 string_encoding.
if
file_encoding
is
None
:
file_encoding
=
string_encoding
file_encoding
=
defaults
.
FILE_ENCODING
if
file_extension
is
None
:
file_extension
=
defaults
.
TEMPLATE_EXTENSION
if
search_dirs
is
None
:
search_dirs
=
os
.
curdir
# i.e. "."
search_dirs
=
defaults
.
SEARCH_DIRS
if
string_encoding
is
None
:
string_encoding
=
defaults
.
STRING_ENCODING
if
isinstance
(
search_dirs
,
basestring
):
search_dirs
=
[
search_dirs
]
self
.
decode_errors
=
decode_errors
self
.
string_encoding
=
string_encoding
self
.
escape
=
escape
self
.
file_encoding
=
file_encoding
self
.
file_extension
=
file_extension
self
.
partials
=
partials
self
.
search_dirs
=
search_dirs
self
.
string_encoding
=
string_encoding
def
_to_unicode_soft
(
self
,
s
):
"""
...
...
tests/test_renderer.py
View file @
00fa136b
...
...
@@ -54,22 +54,6 @@ class RendererInitTestCase(unittest.TestCase):
renderer
=
Renderer
(
escape
=
escape
)
self
.
assertEquals
(
renderer
.
escape
(
"bar"
),
"**bar"
)
def
test_string_encoding__default
(
self
):
"""
Check the default value.
"""
renderer
=
Renderer
()
self
.
assertEquals
(
renderer
.
string_encoding
,
sys
.
getdefaultencoding
())
def
test_string_encoding
(
self
):
"""
Check that the constructor sets the attribute correctly.
"""
renderer
=
Renderer
(
string_encoding
=
"foo"
)
self
.
assertEquals
(
renderer
.
string_encoding
,
"foo"
)
def
test_decode_errors__default
(
self
):
"""
Check the default value.
...
...
@@ -142,6 +126,22 @@ class RendererInitTestCase(unittest.TestCase):
renderer
=
Renderer
(
search_dirs
=
[
'foo'
])
self
.
assertEquals
(
renderer
.
search_dirs
,
[
'foo'
])
def
test_string_encoding__default
(
self
):
"""
Check the default value.
"""
renderer
=
Renderer
()
self
.
assertEquals
(
renderer
.
string_encoding
,
sys
.
getdefaultencoding
())
def
test_string_encoding
(
self
):
"""
Check that the constructor sets the attribute correctly.
"""
renderer
=
Renderer
(
string_encoding
=
"foo"
)
self
.
assertEquals
(
renderer
.
string_encoding
,
"foo"
)
class
RendererTestCase
(
unittest
.
TestCase
):
...
...
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