Skip to content

Commit

Permalink
various docstring changes
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
mitsuhiko committed Apr 17, 2008
1 parent 5236d8c commit 68f7767
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions jinja2/compiler.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions jinja2/environment.py
Expand Up @@ -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:
Expand All @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions jinja2/exceptions.py
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions jinja2/runtime.py
Expand Up @@ -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.
Expand Down Expand Up @@ -74,7 +74,7 @@ def __repr__(self):
return '<%s %s of %r>' % (
self.__class__.__name__,
dict.__repr__(self),
self.filename
self.name
)


Expand Down Expand Up @@ -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()

Expand All @@ -119,7 +119,7 @@ def __html__(self):
def __repr__(self):
return '<%s %r>' % (
self.__class__.__name__,
self._filename
self._name
)


Expand Down
4 changes: 3 additions & 1 deletion jinja2/utils.py
Expand Up @@ -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;')
Expand Down

0 comments on commit 68f7767

Please sign in to comment.