various docstring changes
--HG--
branch : trunk
diff --git a/jinja2/compiler.py b/jinja2/compiler.py
index ca25304..596091e 100644
--- a/jinja2/compiler.py
+++ b/jinja2/compiler.py
@@ -424,7 +424,7 @@
raise TemplateAssertionError('It\'s not possible to set and '
'access variables derived from '
'an outer scope! (affects: %s' %
- vars, node.lineno, self.filename)
+ vars, node.lineno, self.name)
# remove variables from a closure from the frame's undeclared
# identifiers.
@@ -463,7 +463,7 @@
if block.name in self.blocks:
raise TemplateAssertionError('block %r defined twice' %
block.name, block.lineno,
- self.filename)
+ self.name)
self.blocks[block.name] = block
# generate the root render function.
@@ -545,7 +545,7 @@
if not frame.toplevel:
raise TemplateAssertionError('cannot use extend from a non '
'top-level scope', node.lineno,
- self.filename)
+ self.name)
# if the number of extends statements in general is zero so
# far, we don't have to add a check if something extended
@@ -570,7 +570,7 @@
self.writeline('parent_root = environment.get_template(', node, 1)
self.visit(node.template, frame)
- self.write(', %r).root_render_func' % self.filename)
+ self.write(', %r).root_render_func' % self.name)
# if this extends statement was in the root level we can take
# advantage of that information and simplify the generated code
diff --git a/jinja2/environment.py b/jinja2/environment.py
index 9fdfdae..4b1e70c 100644
--- a/jinja2/environment.py
+++ b/jinja2/environment.py
@@ -132,7 +132,12 @@
def compile(self, source, name=None, filename=None, raw=False,
globals=None):
- """Compile a node or source."""
+ """Compile a node or source. The name is the load name of the
+ template after it was joined using `join_path` if necessary,
+ filename is the estimated filename of the template on the file
+ system. If the template came from a database or memory this
+ can be omitted.
+ """
if isinstance(source, basestring):
source = self.parse(source, name)
if self.optimized:
@@ -141,7 +146,7 @@
if raw:
return source
if filename is None:
- filename = '<from_string>'
+ filename = '<template>'
elif isinstance(filename, unicode):
filename = filename.encode('utf-8')
return compile(source, filename, 'exec')
diff --git a/jinja2/exceptions.py b/jinja2/exceptions.py
index f07d860..024ff58 100644
--- a/jinja2/exceptions.py
+++ b/jinja2/exceptions.py
@@ -24,23 +24,23 @@
self.name = name
-class TemplateSyntaxError(SyntaxError, TemplateError):
+class TemplateSyntaxError(TemplateError):
"""
Raised to tell the user that there is a problem with the template.
"""
- def __init__(self, message, lineno, filename):
- SyntaxError.__init__(self, '%s (line %s)' % (message, lineno))
+ def __init__(self, message, lineno, name):
+ TEmplateError.__init__(self, '%s (line %s)' % (message, lineno))
self.message = message
self.lineno = lineno
- self.filename = filename
+ self.name = name
class TemplateAssertionError(AssertionError, TemplateSyntaxError):
- def __init__(self, message, lineno, filename):
+ def __init__(self, message, lineno, name):
AssertionError.__init__(self, message)
- TemplateSyntaxError.__init__(self, message, lineno, filename)
+ TemplateSyntaxError.__init__(self, message, lineno, name)
class TemplateRuntimeError(TemplateError):
diff --git a/jinja2/runtime.py b/jinja2/runtime.py
index 2b05e73..a18b7bc 100644
--- a/jinja2/runtime.py
+++ b/jinja2/runtime.py
@@ -26,11 +26,11 @@
the exported variables for example).
"""
- def __init__(self, environment, globals, filename, blocks, standalone):
+ def __init__(self, environment, globals, name, blocks, standalone):
dict.__init__(self, globals)
self.environment = environment
self.exported = set()
- self.filename = filename
+ self.name = name
self.blocks = dict((k, [v]) for k, v in blocks.iteritems())
# if the template is in standalone mode we don't copy the blocks over.
@@ -74,7 +74,7 @@
return '<%s %s of %r>' % (
self.__class__.__name__,
dict.__repr__(self),
- self.filename
+ self.name
)
@@ -103,7 +103,7 @@
template = environment.get_template(template)
gen = template.root_render_func(context, standalone=True)
context = gen.next()
- self._filename = template.name
+ self._name = template.name
self._rendered_body = u''.join(gen)
self._context = context.get_exported()
@@ -119,7 +119,7 @@
def __repr__(self):
return '<%s %r>' % (
self.__class__.__name__,
- self._filename
+ self._name
)
diff --git a/jinja2/utils.py b/jinja2/utils.py
index 2e64fe2..63394ce 100644
--- a/jinja2/utils.py
+++ b/jinja2/utils.py
@@ -16,7 +16,9 @@
def escape(obj, attribute=False):
"""HTML escape an object."""
- if hasattr(obj, '__html__'):
+ if obj is None:
+ return u''
+ elif hasattr(obj, '__html__'):
return obj.__html__()
return Markup(unicode(obj)
.replace('&', '&')