Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

various docstring changes

--HG--
branch : trunk
  • Loading branch information...
commit 68f7767541fc17d28d61b616637ab852587e8e73 1 parent 5236d8c
Armin Ronacher authored
8 jinja2/compiler.py
View
@@ -424,7 +424,7 @@ def function_scoping(self, node, frame):
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 @@ def visit_Template(self, node, frame=None):
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 @@ def visit_Extends(self, node, frame):
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 @@ def visit_Extends(self, node, frame):
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
9 jinja2/environment.py
View
@@ -132,7 +132,12 @@ def lex(self, source, name=None):
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 @@ def compile(self, source, name=None, filename=None, raw=False,
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')
12 jinja2/exceptions.py
View
@@ -24,23 +24,23 @@ def __init__(self, name):
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):
10 jinja2/runtime.py
View
@@ -26,11 +26,11 @@ class TemplateContext(dict):
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 @@ def __repr__(self):
return '<%s %s of %r>' % (
self.__class__.__name__,
dict.__repr__(self),
- self.filename
+ self.name
)
@@ -103,7 +103,7 @@ def __init__(self, environment, context, template):
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 __html__(self):
def __repr__(self):
return '<%s %r>' % (
self.__class__.__name__,
- self._filename
+ self._name
)
4 jinja2/utils.py
View
@@ -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('&', '&amp;')
Please sign in to comment.
Something went wrong with that request. Please try again.