various docstring changes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 5236d8c · Browse files · 5 files·+25 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+25 added−18 removed
- other:+25 added−18 removed
Provenance
- Commit
68f7767- Tree
15d2b9d- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
5236d8c
5 files changed+25 added−18 removed
modified:jinja2/compiler.py+4 added-4 removed
422 unmodified lines423 vars = ', '.join(sorted(overriden_closure_vars))424 raise TemplateAssertionError('It\'s not possible to set and '425 'access variables derived from '426 'an outer scope! (affects: %s' %427- vars, node.lineno, self.filename)427+ vars, node.lineno, self.name)428 429 # remove variables from a closure from the frame's undeclared430 # identifiers.431 func_frame.identifiers.undeclared -= (30 unmodified lines462 for block in node.find_all(nodes.Block):463 if block.name in self.blocks:464 raise TemplateAssertionError('block %r defined twice' %465 block.name, block.lineno,466- self.filename)466+ self.name)467 self.blocks[block.name] = block468 469 # generate the root render function.470 self.writeline('def root(globals, environment=environment'73 unmodified lines544 """Calls the extender."""545 if not frame.toplevel:546 raise TemplateAssertionError('cannot use extend from a non '547 'top-level scope', node.lineno,548- self.filename)548+ self.name)549 550 # if the number of extends statements in general is zero so551 # far, we don't have to add a check if something extended552 # the template before this one.16 unmodified lines569 self.outdent()570 571 self.writeline('parent_root = environment.get_template(', node, 1)572 self.visit(node.template, frame)573- self.write(', %r).root_render_func' % self.filename)573+ self.write(', %r).root_render_func' % self.name)574 575 # if this extends statement was in the root level we can take576 # advantage of that information and simplify the generated code577 # in the top level from this point onwards480 unmodified linesmodified:jinja2/environment.py+7 added-2 removed
130 unmodified lines131 return self.lexer.tokeniter(source, name)132 133 def compile(self, source, name=None, filename=None, raw=False,134 globals=None):135- """Compile a node or source."""135+ """Compile a node or source. The name is the load name of the136+ template after it was joined using `join_path` if necessary,137+ filename is the estimated filename of the template on the file138+ system. If the template came from a database or memory this139+ can be omitted.140+ """141 if isinstance(source, basestring):142 source = self.parse(source, name)143 if self.optimized:144 node = optimize(source, self, globals or {})145 source = generate(node, self, name, filename)146 if raw:147 return source148 if filename is None:144- filename = '<from_string>'149+ filename = '<template>'150 elif isinstance(filename, unicode):151 filename = filename.encode('utf-8')152 return compile(source, filename, 'exec')153 140 unmodified linesmodified:jinja2/exceptions.py+6 added-6 removed
22 unmodified lines23 IOError.__init__(self, name)24 self.name = name25 26 27-class TemplateSyntaxError(SyntaxError, TemplateError):27+class TemplateSyntaxError(TemplateError):28 """29 Raised to tell the user that there is a problem with the template.30 """31 32- def __init__(self, message, lineno, filename):33- SyntaxError.__init__(self, '%s (line %s)' % (message, lineno))32+ def __init__(self, message, lineno, name):33+ TEmplateError.__init__(self, '%s (line %s)' % (message, lineno))34 self.message = message35 self.lineno = lineno36- self.filename = filename36+ self.name = name37 38 39 class TemplateAssertionError(AssertionError, TemplateSyntaxError):40 41- def __init__(self, message, lineno, filename):41+ def __init__(self, message, lineno, name):42 AssertionError.__init__(self, message)43- TemplateSyntaxError.__init__(self, message, lineno, filename)43+ TemplateSyntaxError.__init__(self, message, lineno, name)44 45 46 class TemplateRuntimeError(TemplateError):47 """3 unmodified linesmodified:jinja2/runtime.py+5 added-5 removed
24 unmodified lines25 update and other methods will not work as they seem (they don't update26 the exported variables for example).27 """28 29- def __init__(self, environment, globals, filename, blocks, standalone):29+ def __init__(self, environment, globals, name, blocks, standalone):30 dict.__init__(self, globals)31 self.environment = environment32 self.exported = set()33- self.filename = filename33+ self.name = name34 self.blocks = dict((k, [v]) for k, v in blocks.iteritems())35 36 # if the template is in standalone mode we don't copy the blocks over.37 # this is used for includes for example but otherwise, if the globals35 unmodified lines73 def __repr__(self):74 return '<%s %s of %r>' % (75 self.__class__.__name__,76 dict.__repr__(self),77- self.filename77+ self.name78 )79 80 81 class SuperBlock(object):20 unmodified lines102 def __init__(self, environment, context, template):103 template = environment.get_template(template)104 gen = template.root_render_func(context, standalone=True)105 context = gen.next()106- self._filename = template.name106+ self._name = template.name107 self._rendered_body = u''.join(gen)108 self._context = context.get_exported()109 110 def __getitem__(self, name):7 unmodified lines118 119 def __repr__(self):120 return '<%s %r>' % (121 self.__class__.__name__,122- self._filename122+ self._name123 )124 125 126 class LoopContextBase(object):193 unmodified linesmodified:jinja2/utils.py+3 added-1 removed
14 unmodified lines15 16 17 def escape(obj, attribute=False):18 """HTML escape an object."""19+ if obj is None:20+ return u''19- if hasattr(obj, '__html__'):21+ elif hasattr(obj, '__html__'):22 return obj.__html__()23 return Markup(unicode(obj)24 .replace('&', '&')25 .replace('>', '>')173 unmodified lines