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
008198b5
Commit
008198b5
authored
Jan 24, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added optional encoding argument to Reader.read().
parent
78ef793b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
pystache/reader.py
+5
-2
tests/test_reader.py
+12
-1
No files found.
pystache/reader.py
View file @
008198b5
...
@@ -42,14 +42,17 @@ class Reader(object):
...
@@ -42,14 +42,17 @@ class Reader(object):
self
.
decode_errors
=
decode_errors
self
.
decode_errors
=
decode_errors
self
.
encoding
=
encoding
self
.
encoding
=
encoding
def
read
(
self
,
path
):
def
read
(
self
,
path
,
encoding
=
None
):
"""
"""
Read the template at the given path, and return it as a unicode string.
Read the template at the given path, and return it as a unicode string.
"""
"""
if
encoding
is
None
:
encoding
=
self
.
encoding
with
open
(
path
,
'r'
)
as
f
:
with
open
(
path
,
'r'
)
as
f
:
text
=
f
.
read
()
text
=
f
.
read
()
text
=
unicode
(
text
,
self
.
encoding
,
self
.
decode_errors
)
text
=
unicode
(
text
,
encoding
,
self
.
decode_errors
)
return
text
return
text
tests/test_reader.py
View file @
008198b5
...
@@ -55,7 +55,7 @@ class ReaderTestCase(unittest.TestCase):
...
@@ -55,7 +55,7 @@ class ReaderTestCase(unittest.TestCase):
contents
=
reader
.
read
(
path
)
contents
=
reader
.
read
(
path
)
self
.
assertEqual
(
type
(
contents
),
unicode
)
self
.
assertEqual
(
type
(
contents
),
unicode
)
def
test_read__encoding
(
self
):
def
test_read__encoding
__attribute
(
self
):
"""
"""
Test read(): encoding attribute respected.
Test read(): encoding attribute respected.
...
@@ -67,6 +67,17 @@ class ReaderTestCase(unittest.TestCase):
...
@@ -67,6 +67,17 @@ class ReaderTestCase(unittest.TestCase):
reader
.
encoding
=
'utf-8'
reader
.
encoding
=
'utf-8'
self
.
assertEquals
(
reader
.
read
(
path
),
u'non-ascii: é'
)
self
.
assertEquals
(
reader
.
read
(
path
),
u'non-ascii: é'
)
def
test_read__encoding__argument
(
self
):
"""
Test read(): encoding argument respected.
"""
reader
=
Reader
()
path
=
self
.
_get_path
(
'nonascii.mustache'
)
self
.
assertRaises
(
UnicodeDecodeError
,
reader
.
read
,
path
)
self
.
assertEquals
(
reader
.
read
(
path
,
encoding
=
'utf-8'
),
u'non-ascii: é'
)
def
test_get__decode_errors
(
self
):
def
test_get__decode_errors
(
self
):
"""
"""
Test get(): decode_errors attribute.
Test get(): decode_errors attribute.
...
...
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