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
ba04172d
Commit
ba04172d
authored
Apr 07, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added module pystache.common with a read(path) function.
parent
75030e7d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
7 deletions
+29
-7
pystache/common.py
+26
-0
pystache/loader.py
+3
-7
No files found.
pystache/common.py
0 → 100644
View file @
ba04172d
# coding: utf-8
"""
Exposes common functions.
"""
# This function was designed to be portable across Python versions -- both
# with older versions and with Python 3 after applying 2to3.
def
read
(
path
):
"""
Return the contents of a text file as a byte string.
"""
# Opening in binary mode is necessary for compatibility across Python
# 2 and 3. In both Python 2 and 3, open() defaults to opening files in
# text mode. However, in Python 2, open() returns file objects whose
# read() method returns byte strings (strings of type `str` in Python 2),
# whereas in Python 3, the file object returns unicode strings (strings
# of type `str` in Python 3).
f
=
open
(
path
,
'rb'
)
# We avoid use of the with keyword for Python 2.4 support.
try
:
return
f
.
read
()
finally
:
f
.
close
()
pystache/loader.py
View file @
ba04172d
...
...
@@ -8,6 +8,7 @@ This module provides a Loader class for locating and reading templates.
import
os
import
sys
from
pystache
import
common
from
pystache
import
defaults
from
pystache.locator
import
Locator
...
...
@@ -106,17 +107,12 @@ class Loader(object):
Read the template at the given path, and return it as a unicode string.
"""
# We avoid use of the with keyword for Python 2.4 support.
f
=
open
(
path
,
'r'
)
try
:
text
=
f
.
read
()
finally
:
f
.
close
()
b
=
common
.
read
(
path
)
if
encoding
is
None
:
encoding
=
self
.
file_encoding
return
self
.
unicode
(
text
,
encoding
)
return
self
.
unicode
(
b
,
encoding
)
# TODO: unit-test this method.
def
load_name
(
self
,
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