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 ...@@ -10,8 +10,7 @@ from __future__ import with_statement
import os import os
import sys import sys
from . import defaults
DEFAULT_DECODE_ERRORS = 'strict'
class Loader(object): class Loader(object):
...@@ -29,12 +28,12 @@ class Loader(object): ...@@ -29,12 +28,12 @@ class Loader(object):
sys.getdefaultencoding(). sys.getdefaultencoding().
decode_errors: the string to pass as the errors argument to the decode_errors: the string to pass as the errors argument to the
built-in function unicode() when converting file contents to built-in function unicode() when converting str strings to
unicode. Defaults to "strict". unicode. Defaults to the package default.
""" """
if decode_errors is None: if decode_errors is None:
decode_errors = DEFAULT_DECODE_ERRORS decode_errors = defaults.DECODE_ERRORS
if encoding is None: if encoding is None:
encoding = sys.getdefaultencoding() encoding = sys.getdefaultencoding()
......
...@@ -9,8 +9,7 @@ import os ...@@ -9,8 +9,7 @@ import os
import re import re
import sys import sys
from . import defaults
DEFAULT_EXTENSION = 'mustache'
class Locator(object): class Locator(object):
...@@ -21,12 +20,13 @@ class Locator(object): ...@@ -21,12 +20,13 @@ class Locator(object):
Arguments: Arguments:
extension: the template file extension. Defaults to "mustache". extension: the template file extension. Pass False for no
Pass False for no extension (i.e. extensionless template files). extension (i.e. to use extensionless template files).
Defaults to the package default.
""" """
if extension is None: if extension is None:
extension = DEFAULT_EXTENSION extension = defaults.TEMPLATE_EXTENSION
self.template_extension = extension self.template_extension = extension
......
...@@ -9,10 +9,10 @@ import cgi ...@@ -9,10 +9,10 @@ import cgi
import os import os
import sys import sys
from . import defaults
from .context import Context from .context import Context
# TODO: remove this alias. # TODO: remove this alias.
from .loader import Loader as Reader from .loader import Loader as Reader
from .locator import DEFAULT_EXTENSION
from .locator import Locator from .locator import Locator
from .renderengine import RenderEngine from .renderengine import RenderEngine
...@@ -96,8 +96,9 @@ class Renderer(object): ...@@ -96,8 +96,9 @@ class Renderer(object):
current working directory. If given a string, the string is current working directory. If given a string, the string is
interpreted as a single directory. interpreted as a single directory.
file_extension: the template file extension. Defaults to "mustache". file_extension: the template file extension. Pass False for no
Pass False for no extension (i.e. for extensionless files). extension (i.e. to use extensionless template files).
Defaults to the package default.
""" """
if default_encoding is None: if default_encoding is None:
...@@ -111,7 +112,7 @@ class Renderer(object): ...@@ -111,7 +112,7 @@ class Renderer(object):
file_encoding = default_encoding file_encoding = default_encoding
if file_extension is None: if file_extension is None:
file_extension = DEFAULT_EXTENSION file_extension = defaults.TEMPLATE_EXTENSION
if search_dirs is None: if search_dirs is None:
search_dirs = os.curdir # i.e. "." 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