Commit 00090310 by Chris Jerdonek

Added a defaults module with default DECODE_ERRORS and TEMPLATE_EXTENSION values.

parent 9909ec90
# coding: utf-8
"""
This module provides a central location for defining default behavior.
"""
# How to handle encoding errors when decoding strings from str to unicode.
#
# This value is passed as the "errors" argument to Python's built-in
# unicode() function:
#
# http://docs.python.org/library/functions.html#unicode
#
DECODE_ERRORS = 'strict'
# The default template extension.
TEMPLATE_EXTENSION = 'mustache'
......@@ -10,8 +10,7 @@ from __future__ import with_statement
import os
import sys
DEFAULT_DECODE_ERRORS = 'strict'
from . import defaults
class Loader(object):
......@@ -29,12 +28,12 @@ class Loader(object):
sys.getdefaultencoding().
decode_errors: the string to pass as the errors argument to the
built-in function unicode() when converting file contents to
unicode. Defaults to "strict".
built-in function unicode() when converting str strings to
unicode. Defaults to the package default.
"""
if decode_errors is None:
decode_errors = DEFAULT_DECODE_ERRORS
decode_errors = defaults.DECODE_ERRORS
if encoding is None:
encoding = sys.getdefaultencoding()
......
......@@ -9,8 +9,7 @@ import os
import re
import sys
DEFAULT_EXTENSION = 'mustache'
from . import defaults
class Locator(object):
......@@ -21,12 +20,13 @@ class Locator(object):
Arguments:
extension: the template file extension. Defaults to "mustache".
Pass False for no extension (i.e. extensionless template files).
extension: the template file extension. Pass False for no
extension (i.e. to use extensionless template files).
Defaults to the package default.
"""
if extension is None:
extension = DEFAULT_EXTENSION
extension = defaults.TEMPLATE_EXTENSION
self.template_extension = extension
......
......@@ -9,10 +9,10 @@ import cgi
import os
import sys
from . import defaults
from .context import Context
# TODO: remove this alias.
from .loader import Loader as Reader
from .locator import DEFAULT_EXTENSION
from .locator import Locator
from .renderengine import RenderEngine
......@@ -96,8 +96,9 @@ class Renderer(object):
current working directory. If given a string, the string is
interpreted as a single directory.
file_extension: the template file extension. Defaults to "mustache".
Pass False for no extension (i.e. for extensionless files).
file_extension: the template file extension. Pass False for no
extension (i.e. to use extensionless template files).
Defaults to the package default.
"""
if default_encoding is None:
......@@ -111,7 +112,7 @@ class Renderer(object):
file_encoding = default_encoding
if file_extension is None:
file_extension = DEFAULT_EXTENSION
file_extension = defaults.TEMPLATE_EXTENSION
if search_dirs is None:
search_dirs = os.curdir # i.e. "."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment