Permalink
Browse files

autoescaping is separate from finalize now and Markup is completely i…

…gnored if the environment is not in autoescape mode

--HG--
branch : trunk
  • Loading branch information...
1 parent 083ae16 commit d134231de2fcfadd1e413cfec8061fa87d036694 @mitsuhiko mitsuhiko committed Apr 28, 2008
Showing with 396 additions and 146 deletions.
  1. +4 −4 docs/conf.py
  2. +4 −5 docs/index.rst
  3. +4 −0 jinja2/__init__.py
  4. +32 −15 jinja2/compiler.py
  5. +149 −69 jinja2/environment.py
  6. +3 −5 jinja2/exceptions.py
  7. +2 −2 jinja2/ext.py
  8. +19 −15 jinja2/filters.py
  9. +115 −22 jinja2/loaders.py
  10. +64 −9 jinja2/runtime.py
View
@@ -23,7 +23,7 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-#extensions = []
+extensions = ['sphinx.ext.autodoc']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -67,7 +67,7 @@
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
+pygments_style = 'autumn'
# Options for HTML output
@@ -120,7 +120,7 @@
# ------------------------
# The paper size ('letter' or 'a4').
-#latex_paper_size = 'letter'
+latex_paper_size = 'a4'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
@@ -132,7 +132,7 @@
]
# Additional stuff for the LaTeX preamble.
-#latex_preamble = ''
+latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
View
@@ -1,7 +1,3 @@
-.. Jinja2 documentation master file, created by sphinx-quickstart on Sun Apr 27 21:42:41 2008.
- You can adapt this file completely to your liking, but it should at least
- contain the root `toctree` directive.
-
Welcome to Jinja2's documentation!
==================================
@@ -10,10 +6,13 @@ Contents:
.. toctree::
:maxdepth: 2
+ intro
+ api
+ templates
+
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
-
View
@@ -43,6 +43,10 @@
# undefined types
from jinja2.runtime import Undefined, DebugUndefined, StrictUndefined
+# exceptions
+from jinja2.exceptions import TemplateError, UndefinedError, \
+ TemplateNotFound, TemplateSyntaxError, TemplateAssertionError
+
# decorators and public utilities
from jinja2.filters import environmentfilter, contextfilter
from jinja2.utils import Markup, escape, environmentfunction, contextfunction
View
@@ -843,7 +843,10 @@ def visit_Macro(self, node, frame):
self.pull_locals(macro_frame)
self.writeline('%s = []' % buf)
self.blockvisit(node.body, macro_frame)
- self.writeline("return Markup(concat(%s))" % buf)
+ if self.environment.autoescape:
+ self.writeline('return Markup(concat(%s))' % buf)
+ else:
+ self.writeline("return concat(%s)" % buf)
self.outdent()
self.newline()
if frame.toplevel:
@@ -874,7 +877,10 @@ def visit_CallBlock(self, node, frame):
self.pull_locals(call_frame)
self.writeline('%s = []' % buf)
self.blockvisit(node.body, call_frame)
- self.writeline("return Markup(concat(%s))" % buf)
+ if self.environment.autoescape:
+ self.writeline("return Markup(concat(%s))" % buf)
+ else:
+ self.writeline('return concat(%s)' % buf)
self.outdent()
arg_tuple = ', '.join(repr(x.name) for x in node.args)
if len(node.args) == 1:
@@ -927,12 +933,6 @@ def visit_Output(self, node, frame):
return
self.newline(node)
- if self.environment.finalize is unicode:
- finalizer = 'unicode'
- have_finalizer = False
- else:
- finalizer = 'environment.finalize'
- have_finalizer = True
# if we are in the toplevel scope and there was already an extends
# statement we have to add a check that disables our yield(s) here
@@ -972,9 +972,16 @@ def visit_Output(self, node, frame):
else:
if frame.buffer is None:
self.writeline('yield ')
- self.write(finalizer + '(')
+ close = 1
+ if self.environment.autoescape:
+ self.write('escape(')
+ else:
+ self.write('unicode(')
+ if self.environment.finalize is not None:
+ self.write('environment.finalize(')
+ close += 1
self.visit(item, frame)
- self.write(')')
+ self.write(')' * close)
if frame.buffer is not None:
self.write(', ')
if frame.buffer is not None:
@@ -999,12 +1006,15 @@ def visit_Output(self, node, frame):
self.indent()
for argument in arguments:
self.newline(argument)
- if have_finalizer:
- self.write(finalizer + '(')
+ close = 0
+ if self.environment.autoescape:
+ self.write('escape(')
+ close += 1
+ if self.environment.finalize is not None:
+ self.write('environment.finalize(')
+ close += 1
self.visit(argument, frame)
- if have_finalizer:
- self.write(')')
- self.write(',')
+ self.write(')' * close + ',')
self.outdent()
self.writeline(')')
if frame.buffer is not None:
@@ -1105,6 +1115,13 @@ def visitor(self, node, frame):
visit_Not = uaop('not ')
del binop, uaop
+ def visit_Concat(self, node, frame):
+ self.write('join((')
+ for arg in node.nodes:
+ self.visit(arg, frame)
+ self.write(', ')
+ self.write('))')
+
def visit_Compare(self, node, frame):
self.visit(node.expr, frame)
for op in node.ops:
Oops, something went wrong.

0 comments on commit d134231

Please sign in to comment.