AMBARI-7138. Ambari RPM deals with jinja2 dependency incorrectly (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/658360a5 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/658360a5 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/658360a5 Branch: refs/heads/trunk Commit: 658360a5a334b79f8012fd6e07b5017a3bf2b1e7 Parents: a537b8e Author: Andrew Onishuk <aonis...@hortonworks.com> Authored: Thu Sep 4 16:06:32 2014 +0300 Committer: Andrew Onishuk <aonis...@hortonworks.com> Committed: Thu Sep 4 16:06:32 2014 +0300 ---------------------------------------------------------------------- ambari-agent/pom.xml | 12 +- .../resource_management/TestContentSources.py | 2 +- .../src/main/python/ambari_jinja2/AUTHORS | 31 + .../src/main/python/ambari_jinja2/CHANGES | 235 +++ .../src/main/python/ambari_jinja2/LICENSE | 31 + .../src/main/python/ambari_jinja2/MANIFEST.in | 12 + .../src/main/python/ambari_jinja2/Makefile | 4 + .../ambari_jinja2/ambari_jinja2/__init__.py | 73 + .../ambari_jinja2/ambari_jinja2/_debugsupport.c | 78 + .../ambari_jinja2/_markupsafe/__init__.py | 225 +++ .../ambari_jinja2/_markupsafe/_bundle.py | 49 + .../ambari_jinja2/_markupsafe/_constants.py | 267 +++ .../ambari_jinja2/_markupsafe/_native.py | 45 + .../ambari_jinja2/_markupsafe/tests.py | 80 + .../ambari_jinja2/ambari_jinja2/_stringdefs.py | 130 ++ .../ambari_jinja2/ambari_jinja2/bccache.py | 280 +++ .../ambari_jinja2/ambari_jinja2/compiler.py | 1640 ++++++++++++++++++ .../ambari_jinja2/ambari_jinja2/constants.py | 32 + .../python/ambari_jinja2/ambari_jinja2/debug.py | 308 ++++ .../ambari_jinja2/ambari_jinja2/defaults.py | 40 + .../ambari_jinja2/ambari_jinja2/environment.py | 1118 ++++++++++++ .../ambari_jinja2/ambari_jinja2/exceptions.py | 143 ++ .../python/ambari_jinja2/ambari_jinja2/ext.py | 610 +++++++ .../ambari_jinja2/ambari_jinja2/filters.py | 719 ++++++++ .../python/ambari_jinja2/ambari_jinja2/lexer.py | 681 ++++++++ .../ambari_jinja2/ambari_jinja2/loaders.py | 449 +++++ .../python/ambari_jinja2/ambari_jinja2/meta.py | 102 ++ .../python/ambari_jinja2/ambari_jinja2/nodes.py | 901 ++++++++++ .../ambari_jinja2/ambari_jinja2/optimizer.py | 68 + .../ambari_jinja2/ambari_jinja2/parser.py | 896 ++++++++++ .../ambari_jinja2/ambari_jinja2/runtime.py | 544 ++++++ .../ambari_jinja2/ambari_jinja2/sandbox.py | 271 +++ .../python/ambari_jinja2/ambari_jinja2/tests.py | 146 ++ .../ambari_jinja2/testsuite/__init__.py | 95 + .../ambari_jinja2/testsuite/api.py | 240 +++ .../ambari_jinja2/testsuite/core_tags.py | 286 +++ .../ambari_jinja2/testsuite/debug.py | 60 + .../ambari_jinja2/testsuite/doctests.py | 29 + .../ambari_jinja2/testsuite/ext.py | 455 +++++ .../ambari_jinja2/testsuite/filters.py | 291 ++++ .../ambari_jinja2/testsuite/imports.py | 144 ++ .../ambari_jinja2/testsuite/inheritance.py | 208 +++ .../ambari_jinja2/testsuite/lexnparse.py | 390 +++++ .../ambari_jinja2/testsuite/loader.py | 191 ++ .../ambari_jinja2/testsuite/regression.py | 258 +++ .../testsuite/res/templates/broken.html | 3 + .../testsuite/res/templates/foo/test.html | 1 + .../testsuite/res/templates/syntaxerror.html | 4 + .../testsuite/res/templates/test.html | 1 + .../ambari_jinja2/testsuite/security.py | 134 ++ .../ambari_jinja2/testsuite/tests.py | 87 + .../ambari_jinja2/testsuite/utils.py | 85 + .../python/ambari_jinja2/ambari_jinja2/utils.py | 601 +++++++ .../ambari_jinja2/ambari_jinja2/visitor.py | 87 + .../python/ambari_jinja2/artwork/jinjalogo.svg | 132 ++ .../custom_fixers/fix_alt_unicode.py | 13 + .../custom_fixers/fix_broken_reraising.py | 21 + .../ambari_jinja2/custom_fixers/fix_xrange2.py | 11 + .../src/main/python/ambari_jinja2/docs/Makefile | 75 + .../python/ambari_jinja2/docs/_static/jinja.js | 26 + .../python/ambari_jinja2/docs/_static/print.css | 5 + .../python/ambari_jinja2/docs/_static/style.css | 390 +++++ .../ambari_jinja2/docs/_templates/genindex.html | 36 + .../ambari_jinja2/docs/_templates/layout.html | 77 + .../docs/_templates/opensearch.xml | 9 + .../ambari_jinja2/docs/_templates/page.html | 4 + .../ambari_jinja2/docs/_templates/search.html | 35 + .../src/main/python/ambari_jinja2/docs/api.rst | 787 +++++++++ .../ambari_jinja2/docs/cache_extension.py | 56 + .../python/ambari_jinja2/docs/changelog.rst | 3 + .../src/main/python/ambari_jinja2/docs/conf.py | 141 ++ .../python/ambari_jinja2/docs/extensions.rst | 347 ++++ .../src/main/python/ambari_jinja2/docs/faq.rst | 191 ++ .../main/python/ambari_jinja2/docs/index.rst | 27 + .../python/ambari_jinja2/docs/integration.rst | 88 + .../main/python/ambari_jinja2/docs/intro.rst | 168 ++ .../main/python/ambari_jinja2/docs/jinjaext.py | 192 ++ .../main/python/ambari_jinja2/docs/sandbox.rst | 46 + .../python/ambari_jinja2/docs/switching.rst | 242 +++ .../python/ambari_jinja2/docs/templates.rst | 1365 +++++++++++++++ .../main/python/ambari_jinja2/docs/tricks.rst | 100 ++ .../ambari_jinja2/examples/basic/cycle.py | 13 + .../ambari_jinja2/examples/basic/debugger.py | 7 + .../ambari_jinja2/examples/basic/inheritance.py | 12 + .../examples/basic/templates/broken.html | 6 + .../examples/basic/templates/subbroken.html | 3 + .../python/ambari_jinja2/examples/basic/test.py | 27 + .../basic/test_filter_and_linestatements.py | 25 + .../examples/basic/test_loop_filter.py | 12 + .../ambari_jinja2/examples/basic/translate.py | 6 + .../main/python/ambari_jinja2/examples/bench.py | 433 +++++ .../python/ambari_jinja2/examples/profile.py | 52 + .../examples/rwbench/django/_form.html | 1 + .../examples/rwbench/django/_input_field.html | 1 + .../examples/rwbench/django/_textarea.html | 1 + .../examples/rwbench/django/index.html | 29 + .../examples/rwbench/django/layout.html | 29 + .../ambari_jinja2/examples/rwbench/djangoext.py | 135 ++ .../examples/rwbench/genshi/helpers.html | 12 + .../examples/rwbench/genshi/index.html | 41 + .../examples/rwbench/genshi/layout.html | 30 + .../examples/rwbench/jinja/helpers.html | 12 + .../examples/rwbench/jinja/index.html | 29 + .../examples/rwbench/jinja/layout.html | 29 + .../examples/rwbench/mako/helpers.html | 11 + .../examples/rwbench/mako/index.html | 31 + .../examples/rwbench/mako/layout.html | 30 + .../ambari_jinja2/examples/rwbench/rwbench.py | 112 ++ .../python/ambari_jinja2/ext/Vim/htmljinja.vim | 27 + .../main/python/ambari_jinja2/ext/Vim/jinja.vim | 113 ++ .../ext/django2jinja/django2jinja.py | 768 ++++++++ .../ambari_jinja2/ext/django2jinja/example.py | 7 + .../ext/django2jinja/templates/index.html | 58 + .../ext/django2jinja/templates/layout.html | 4 + .../ext/django2jinja/templates/subtemplate.html | 1 + .../python/ambari_jinja2/ext/djangojinja2.py | 86 + .../python/ambari_jinja2/ext/inlinegettext.py | 78 + .../src/main/python/ambari_jinja2/ext/jinja.el | 213 +++ .../main/python/ambari_jinja2/jinja2-debug.py | 40 + .../main/python/ambari_jinja2/scripts/pylintrc | 301 ++++ .../src/main/python/ambari_jinja2/setup.cfg | 6 + .../src/main/python/ambari_jinja2/setup.py | 110 ++ ambari-common/src/main/python/jinja2/AUTHORS | 31 - ambari-common/src/main/python/jinja2/CHANGES | 235 --- ambari-common/src/main/python/jinja2/LICENSE | 31 - .../src/main/python/jinja2/MANIFEST.in | 12 - ambari-common/src/main/python/jinja2/Makefile | 4 - .../main/python/jinja2/artwork/jinjalogo.svg | 132 -- .../python/jinja2/custom_fixers/__init__.py | 0 .../jinja2/custom_fixers/fix_alt_unicode.py | 13 - .../custom_fixers/fix_broken_reraising.py | 21 - .../python/jinja2/custom_fixers/fix_xrange2.py | 11 - .../src/main/python/jinja2/docs/Makefile | 75 - .../src/main/python/jinja2/docs/_build/.ignore | 0 .../src/main/python/jinja2/docs/_static/.ignore | 0 .../main/python/jinja2/docs/_static/jinja.js | 26 - .../main/python/jinja2/docs/_static/print.css | 5 - .../main/python/jinja2/docs/_static/style.css | 390 ----- .../main/python/jinja2/docs/_templates/.ignore | 0 .../python/jinja2/docs/_templates/genindex.html | 36 - .../python/jinja2/docs/_templates/layout.html | 77 - .../jinja2/docs/_templates/opensearch.xml | 9 - .../python/jinja2/docs/_templates/page.html | 4 - .../python/jinja2/docs/_templates/search.html | 35 - .../src/main/python/jinja2/docs/api.rst | 787 --------- .../main/python/jinja2/docs/cache_extension.py | 56 - .../src/main/python/jinja2/docs/changelog.rst | 3 - .../src/main/python/jinja2/docs/conf.py | 141 -- .../src/main/python/jinja2/docs/extensions.rst | 347 ---- .../src/main/python/jinja2/docs/faq.rst | 191 -- .../src/main/python/jinja2/docs/index.rst | 27 - .../src/main/python/jinja2/docs/integration.rst | 88 - .../src/main/python/jinja2/docs/intro.rst | 168 -- .../src/main/python/jinja2/docs/jinjaext.py | 192 -- .../src/main/python/jinja2/docs/sandbox.rst | 46 - .../src/main/python/jinja2/docs/switching.rst | 242 --- .../src/main/python/jinja2/docs/templates.rst | 1365 --------------- .../src/main/python/jinja2/docs/tricks.rst | 100 -- .../main/python/jinja2/examples/basic/cycle.py | 13 - .../python/jinja2/examples/basic/debugger.py | 7 - .../python/jinja2/examples/basic/inheritance.py | 12 - .../jinja2/examples/basic/templates/broken.html | 6 - .../examples/basic/templates/subbroken.html | 3 - .../main/python/jinja2/examples/basic/test.py | 27 - .../basic/test_filter_and_linestatements.py | 25 - .../jinja2/examples/basic/test_loop_filter.py | 12 - .../python/jinja2/examples/basic/translate.py | 6 - .../src/main/python/jinja2/examples/bench.py | 433 ----- .../src/main/python/jinja2/examples/profile.py | 52 - .../jinja2/examples/rwbench/django/_form.html | 1 - .../examples/rwbench/django/_input_field.html | 1 - .../examples/rwbench/django/_textarea.html | 1 - .../jinja2/examples/rwbench/django/index.html | 29 - .../jinja2/examples/rwbench/django/layout.html | 29 - .../python/jinja2/examples/rwbench/djangoext.py | 135 -- .../jinja2/examples/rwbench/genshi/helpers.html | 12 - .../jinja2/examples/rwbench/genshi/index.html | 41 - .../jinja2/examples/rwbench/genshi/layout.html | 30 - .../jinja2/examples/rwbench/jinja/helpers.html | 12 - .../jinja2/examples/rwbench/jinja/index.html | 29 - .../jinja2/examples/rwbench/jinja/layout.html | 29 - .../jinja2/examples/rwbench/mako/helpers.html | 11 - .../jinja2/examples/rwbench/mako/index.html | 31 - .../jinja2/examples/rwbench/mako/layout.html | 30 - .../python/jinja2/examples/rwbench/rwbench.py | 112 -- .../main/python/jinja2/ext/Vim/htmljinja.vim | 27 - .../src/main/python/jinja2/ext/Vim/jinja.vim | 113 -- .../jinja2/ext/django2jinja/django2jinja.py | 768 -------- .../python/jinja2/ext/django2jinja/example.py | 7 - .../ext/django2jinja/templates/index.html | 58 - .../ext/django2jinja/templates/layout.html | 4 - .../ext/django2jinja/templates/subtemplate.html | 1 - .../src/main/python/jinja2/ext/djangojinja2.py | 86 - .../src/main/python/jinja2/ext/inlinegettext.py | 78 - .../src/main/python/jinja2/ext/jinja.el | 213 --- .../src/main/python/jinja2/jinja2-debug.py | 40 - .../src/main/python/jinja2/jinja2/__init__.py | 73 - .../main/python/jinja2/jinja2/_debugsupport.c | 78 - .../jinja2/jinja2/_markupsafe/__init__.py | 225 --- .../python/jinja2/jinja2/_markupsafe/_bundle.py | 49 - .../jinja2/jinja2/_markupsafe/_constants.py | 267 --- .../python/jinja2/jinja2/_markupsafe/_native.py | 45 - .../python/jinja2/jinja2/_markupsafe/tests.py | 80 - .../main/python/jinja2/jinja2/_stringdefs.py | 130 -- .../src/main/python/jinja2/jinja2/bccache.py | 280 --- .../src/main/python/jinja2/jinja2/compiler.py | 1640 ------------------ .../src/main/python/jinja2/jinja2/constants.py | 32 - .../src/main/python/jinja2/jinja2/debug.py | 308 ---- .../src/main/python/jinja2/jinja2/defaults.py | 40 - .../main/python/jinja2/jinja2/environment.py | 1118 ------------ .../src/main/python/jinja2/jinja2/exceptions.py | 143 -- .../src/main/python/jinja2/jinja2/ext.py | 610 ------- .../src/main/python/jinja2/jinja2/filters.py | 719 -------- .../src/main/python/jinja2/jinja2/lexer.py | 681 -------- .../src/main/python/jinja2/jinja2/loaders.py | 449 ----- .../src/main/python/jinja2/jinja2/meta.py | 102 -- .../src/main/python/jinja2/jinja2/nodes.py | 901 ---------- .../src/main/python/jinja2/jinja2/optimizer.py | 68 - .../src/main/python/jinja2/jinja2/parser.py | 896 ---------- .../src/main/python/jinja2/jinja2/runtime.py | 544 ------ .../src/main/python/jinja2/jinja2/sandbox.py | 271 --- .../src/main/python/jinja2/jinja2/tests.py | 146 -- .../python/jinja2/jinja2/testsuite/__init__.py | 95 - .../main/python/jinja2/jinja2/testsuite/api.py | 240 --- .../python/jinja2/jinja2/testsuite/core_tags.py | 286 --- .../python/jinja2/jinja2/testsuite/debug.py | 60 - .../python/jinja2/jinja2/testsuite/doctests.py | 29 - .../main/python/jinja2/jinja2/testsuite/ext.py | 455 ----- .../python/jinja2/jinja2/testsuite/filters.py | 291 ---- .../python/jinja2/jinja2/testsuite/imports.py | 144 -- .../jinja2/jinja2/testsuite/inheritance.py | 208 --- .../python/jinja2/jinja2/testsuite/lexnparse.py | 390 ----- .../python/jinja2/jinja2/testsuite/loader.py | 191 -- .../jinja2/jinja2/testsuite/regression.py | 258 --- .../jinja2/jinja2/testsuite/res/__init__.py | 0 .../jinja2/testsuite/res/templates/broken.html | 3 - .../testsuite/res/templates/foo/test.html | 1 - .../testsuite/res/templates/syntaxerror.html | 4 - .../jinja2/testsuite/res/templates/test.html | 1 - .../python/jinja2/jinja2/testsuite/security.py | 134 -- .../python/jinja2/jinja2/testsuite/tests.py | 87 - .../python/jinja2/jinja2/testsuite/utils.py | 85 - .../src/main/python/jinja2/jinja2/utils.py | 601 ------- .../src/main/python/jinja2/jinja2/visitor.py | 87 - .../src/main/python/jinja2/scripts/pylintrc | 301 ---- ambari-common/src/main/python/jinja2/setup.cfg | 6 - ambari-common/src/main/python/jinja2/setup.py | 110 -- .../python/resource_management/core/source.py | 2 +- ambari-server/pom.xml | 2 +- ambari-server/src/test/python/unitTests.py | 2 +- pom.xml | 2 + 251 files changed, 21398 insertions(+), 21396 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-agent/pom.xml ---------------------------------------------------------------------- diff --git a/ambari-agent/pom.xml b/ambari-agent/pom.xml index a487aa7..f4cec91 100644 --- a/ambari-agent/pom.xml +++ b/ambari-agent/pom.xml @@ -40,7 +40,7 @@ <agent.install.dir>/usr/lib/python2.6/site-packages/ambari_agent</agent.install.dir> <ambari_commons.install.dir>/usr/lib/ambari-agent/lib/ambari_commons</ambari_commons.install.dir> <resource_management.install.dir>/usr/lib/ambari-agent/lib/resource_management</resource_management.install.dir> - <jinja.install.dir>/usr/lib/python2.6/site-packages/jinja2</jinja.install.dir> + <jinja.install.dir>/usr/lib/python2.6/site-packages/ambari_jinja2</jinja.install.dir> <lib.dir>/usr/lib/ambari-agent/lib</lib.dir> <python.ver>python >= 2.6</python.ver> <deb.python.ver>python (>= 2.6)</deb.python.ver> @@ -115,7 +115,7 @@ <argument>unitTests.py</argument> </arguments> <environmentVariables> - <PYTHONPATH>${project.basedir}/../ambari-common/src/main/python/jinja2:${project.basedir}/../ambari-common/src/main/python/ambari_commons:${project.basedir}/../ambari-common/src/main/python/resource_management:${project.basedir}/../ambari-common/src/test/python:${project.basedir}/../ambari-common/src/main/python:${project.basedir}/src/main/python/ambari_agent:${project.basedir}/src/test/python/ambari_agent:${project.basedir}/src/test/python/resource_management:${project.basedir}/src/main/python:${project.basedir}/../ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/package/files:${project.basedir}/../ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HDFS/package/files:$PYTHONPATH</PYTHONPATH> + <PYTHONPATH>${project.basedir}/../ambari-common/src/main/python/ambari_jinja2:${project.basedir}/../ambari-common/src/main/python/ambari_commons:${project.basedir}/../ambari-common/src/main/python/resource_management:${project.basedir}/../ambari-common/src/test/python:${project.basedir}/../ambari-common/src/main/python:${project.basedir}/src/main/python/ambari_agent:${project.basedir}/src/test/python/ambari_agent:${project.basedir}/src/test/python/resource_management:${project.basedir}/src/main/python:${project.basedir}/../ambari-server/src/main/resources/stacks/HDP/2.0.6/services/HDFS/package/files:${project.basedir}/../ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HDFS/package/files:$PYTHONPATH</PYTHONPATH> </environmentVariables> <skip>${skipTests}</skip> </configuration> @@ -255,9 +255,9 @@ <groupname>root</groupname> <sources> <source> - <location>${project.basedir}/../ambari-common/src/main/python/jinja2/jinja2</location> + <location>${project.basedir}/../ambari-common/src/main/python/ambari_jinja2/ambari_jinja2</location> <excludes> - <exclude>${project.basedir}/../ambari-common/src/main/python/jinja2/jinja2/testsuite</exclude> + <exclude>${project.basedir}/../ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/testsuite</exclude> </excludes> </source> </sources> @@ -413,8 +413,8 @@ </mapper> </data> <data> - <src>${project.basedir}/../ambari-common/src/main/python/jinja2/jinja2</src> - <excludes>${project.basedir}/../ambari-common/src/main/python/jinja2/jinja2/testsuite</excludes> + <src>${project.basedir}/../ambari-common/src/main/python/ambari_jinja2/ambari_jinja2</src> + <excludes>${project.basedir}/../ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/testsuite</excludes> <type>directory</type> <mapper> <type>perm</type> http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-agent/src/test/python/resource_management/TestContentSources.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestContentSources.py b/ambari-agent/src/test/python/resource_management/TestContentSources.py index 2527f30..1c5e8a8 100644 --- a/ambari-agent/src/test/python/resource_management/TestContentSources.py +++ b/ambari-agent/src/test/python/resource_management/TestContentSources.py @@ -27,7 +27,7 @@ from resource_management.core.source import DownloadSource from resource_management.core.source import Template from resource_management.core.source import InlineTemplate -from jinja2 import UndefinedError, TemplateNotFound +from ambari_jinja2 import UndefinedError, TemplateNotFound import urllib2 import os http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/AUTHORS ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/AUTHORS b/ambari-common/src/main/python/ambari_jinja2/AUTHORS new file mode 100644 index 0000000..c6cd9ba --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/AUTHORS @@ -0,0 +1,31 @@ +Jinja is written and maintained by the Jinja Team and various +contributors: + +Lead Developer: + +- Armin Ronacher <armin.ronac...@active-4.com> + +Developers: + +- Christoph Hack +- Georg Brandl + +Contributors: + +- Bryan McLemore +- Mickaël Guérin <k...@crocobox.org> +- Cameron Knight +- Lawrence Journal-World. +- David Cramer + +Patches and suggestions: + +- Ronny Pfannschmidt +- Axel Böhm +- Alexey Melchakov +- Bryan McLemore +- Clovis Fabricio (nosklo) +- Cameron Knight +- Peter van Dijk (Habbie) +- Stefan Ebner +- Rene Leonhardt http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/CHANGES ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/CHANGES b/ambari-common/src/main/python/ambari_jinja2/CHANGES new file mode 100644 index 0000000..25b8aa4 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/CHANGES @@ -0,0 +1,235 @@ +Jinja2 Changelog +================ + +Version 2.5.5 +------------- +(re-release of 2.5.4 with built documentation removed for filesize. + Released on October 18th 2010) + +- built documentation is no longer part of release. + +Version 2.5.4 +------------- +(bugfix release, released on October 17th 2010) + +- Fixed extensions not loading properly with overlays. +- Work around a bug in cpython for the debugger that causes segfaults + on 64bit big-endian architectures. + +Version 2.5.3 +------------- +(bugfix release, released on October 17th 2010) + +- fixed an operator precedence error introduced in 2.5.2. Statements + like "-foo.bar" had their implicit parentheses applied around the + first part of the expression ("(-foo).bar") instead of the more + correct "-(foo.bar)". + +Version 2.5.2 +------------- +(bugfix release, released on August 18th 2010) + +- improved setup.py script to better work with assumptions people + might still have from it (``--with-speedups``). +- fixed a packaging error that excluded the new debug support. + +Version 2.5.1 +------------- +(bugfix release, released on August 17th 2010) + +- StopIteration exceptions raised by functions called from templates + are now intercepted and converted to undefineds. This solves a + lot of debugging grief. (StopIteration is used internally to + abort template execution) +- improved performance of macro calls slightly. +- babel extraction can now properly extract newstyle gettext calls. +- using the variable `num` in newstyle gettext for something else + than the pluralize count will no longer raise a :exc:`KeyError`. +- removed builtin markup class and switched to markupsafe. For backwards + compatibility the pure Python implementation still exists but is + pulled from markupsafe by the Jinja2 developers. The debug support + went into a separate feature called "debugsupport" and is disabled + by default because it is only relevant for Python 2.4 +- fixed an issue with unary operators having the wrong precendence. + +Version 2.5 +----------- +(codename Incoherence, relased on May 29th 2010) + +- improved the sort filter (should have worked like this for a + long time) by adding support for case insensitive searches. +- fixed a bug for getattribute constant folding. +- support for newstyle gettext translations which result in a + nicer in-template user interface and more consistent + catalogs. (:ref:`newstyle-gettext`) +- it's now possible to register extensions after an environment + was created. + +Version 2.4.1 +------------- +(bugfix release, released on April 20th 2010) + +- fixed an error reporting bug for undefineds. + +Version 2.4 +----------- +(codename Correlation, released on April 13th 2010) + +- the environment template loading functions now transparently + pass through a template object if it was passed to it. This + makes it possible to import or extend from a template object + that was passed to the template. +- added a :class:`ModuleLoader` that can load templates from + precompiled sources. The environment now features a method + to compile the templates from a configured loader into a zip + file or folder. +- the _speedups C extension now supports Python 3. +- added support for autoescaping toggling sections and support + for evaluation contexts (:ref:`eval-context`). +- extensions have a priority now. + +Version 2.3.1 +------------- +(bugfix release, released on February 19th 2010) + +- fixed an error reporting bug on all python versions +- fixed an error reporting bug on Python 2.4 + +Version 2.3 +----------- +(3000 Pythons, released on February 10th 2010) + +- fixes issue with code generator that causes unbound variables + to be generated if set was used in if-blocks and other small + identifier problems. +- include tags are now able to select between multiple templates + and take the first that exists, if a list of templates is + given. +- fixed a problem with having call blocks in outer scopes that + have an argument that is also used as local variable in an + inner frame (#360). +- greatly improved error message reporting (#339) +- implicit tuple expressions can no longer be totally empty. + This change makes ``{% if %}...{% endif %}`` a syntax error + now. (#364) +- added support for translator comments if extracted via babel. +- added with-statement extension. +- experimental Python 3 support. + +Version 2.2.1 +------------- +(bugfix release, released on September 14th 2009) + +- fixes some smaller problems for Jinja2 on Jython. + +Version 2.2 +----------- +(codename Kong, released on September 13th 2009) + +- Include statements can now be marked with ``ignore missing`` to skip + non existing templates. +- Priority of `not` raised. It's now possible to write `not foo in bar` + as an alias to `foo not in bar` like in python. Previously the grammar + required parentheses (`not (foo in bar)`) which was odd. +- Fixed a bug that caused syntax errors when defining macros or using the + `{% call %}` tag inside loops. +- Fixed a bug in the parser that made ``{{ foo[1, 2] }}`` impossible. +- Made it possible to refer to names from outer scopes in included templates + that were unused in the callers frame (#327) +- Fixed a bug that caused internal errors if names where used as iteration + variable and regular variable *after* the loop if that variable was unused + *before* the loop. (#331) +- Added support for optional `scoped` modifier to blocks. +- Added support for line-comments. +- Added the `meta` module. +- Renamed (undocumented) attribute "overlay" to "overlayed" on the + environment because it was clashing with a method of the same name. +- speedup extension is now disabled by default. + +Version 2.1.1 +------------- +(Bugfix release) + +- Fixed a translation error caused by looping over empty recursive loops. + +Version 2.1 +----------- +(codename YasuzÅ, released on November 23rd 2008) + +- fixed a bug with nested loops and the special loop variable. Before the + change an inner loop overwrote the loop variable from the outer one after + iteration. + +- fixed a bug with the i18n extension that caused the explicit pluralization + block to look up the wrong variable. + +- fixed a limitation in the lexer that made ``{{ foo.0.0 }}`` impossible. + +- index based subscribing of variables with a constant value returns an + undefined object now instead of raising an index error. This was a bug + caused by eager optimizing. + +- the i18n extension looks up `foo.ugettext` now followed by `foo.gettext` + if an translations object is installed. This makes dealing with custom + translations classes easier. + +- fixed a confusing behavior with conditional extending. loops were partially + executed under some conditions even though they were not part of a visible + area. + +- added `sort` filter that works like `dictsort` but for arbitrary sequences. + +- fixed a bug with empty statements in macros. + +- implemented a bytecode cache system. (:ref:`bytecode-cache`) + +- the template context is now weakref-able + +- inclusions and imports "with context" forward all variables now, not only + the initial context. + +- added a cycle helper called `cycler`. + +- added a joining helper called `joiner`. + +- added a `compile_expression` method to the environment that allows compiling + of Jinja expressions into callable Python objects. + +- fixed an escaping bug in urlize + +Version 2.0 +----------- +(codename jinjavitus, released on July 17th 2008) + +- the subscribing of objects (looking up attributes and items) changed from + slightly. It's now possible to give attributes or items a higher priority + by either using dot-notation lookup or the bracket syntax. This also + changed the AST slightly. `Subscript` is gone and was replaced with + :class:`~ambari_jinja2.nodes.Getitem` and :class:`~ambari_jinja2.nodes.Getattr`. + + For more information see :ref:`the implementation details <notes-on-subscriptions>`. + +- added support for preprocessing and token stream filtering for extensions. + This would allow extensions to allow simplified gettext calls in template + data and something similar. + +- added :meth:`ambari_jinja2.environment.TemplateStream.dump`. + +- added missing support for implicit string literal concatenation. + ``{{ "foo" "bar" }}`` is equivalent to ``{{ "foobar" }}`` + +- `else` is optional for conditional expressions. If not given it evaluates + to `false`. + +- improved error reporting for undefined values by providing a position. + +- `filesizeformat` filter uses decimal prefixes now per default and can be + set to binary mode with the second parameter. + +- fixed bug in finalizer + +Version 2.0rc1 +-------------- +(no codename, released on June 9th 2008) + +- first release of Jinja2 http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/LICENSE ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/LICENSE b/ambari-common/src/main/python/ambari_jinja2/LICENSE new file mode 100644 index 0000000..31bf900 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/LICENSE @@ -0,0 +1,31 @@ +Copyright (c) 2009 by the Jinja Team, see AUTHORS for more details. + +Some rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * The names of the contributors may not be used to endorse or + promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in b/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in new file mode 100644 index 0000000..17ef0bd --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/MANIFEST.in @@ -0,0 +1,12 @@ +include MANIFEST.in Makefile CHANGES LICENSE AUTHORS ambari_jinja2/_debugsupport.c +recursive-include docs * +recursive-include custom_fixers * +recursive-include ext * +recursive-include artwork * +recursive-include examples * +recursive-include ambari_jinja2/testsuite/res * +recursive-exclude docs/_build * +recursive-exclude ambari_jinja2 *.pyc +recursive-exclude docs *.pyc +recursive-exclude ambari_jinja2 *.pyo +recursive-exclude docs *.pyo http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/Makefile ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/Makefile b/ambari-common/src/main/python/ambari_jinja2/Makefile new file mode 100644 index 0000000..60ca1d7 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/Makefile @@ -0,0 +1,4 @@ +test: + python setup.py test + +.PHONY: test http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py new file mode 100644 index 0000000..d02aab2 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/__init__.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +""" + ambari_jinja2 + ~~~~~~ + + Jinja2 is a template engine written in pure Python. It provides a + Django inspired non-XML syntax but supports inline expressions and + an optional sandboxed environment. + + Nutshell + -------- + + Here a small example of a Jinja2 template:: + + {% extends 'base.html' %} + {% block title %}Memberlist{% endblock %} + {% block content %} + <ul> + {% for user in users %} + <li><a href="{{ user.url }}">{{ user.username }}</a></li> + {% endfor %} + </ul> + {% endblock %} + + + :copyright: (c) 2010 by the Jinja Team. + :license: BSD, see LICENSE for more details. +""" +__docformat__ = 'restructuredtext en' +try: + __version__ = __import__('pkg_resources') \ + .get_distribution('Jinja2').version +except: + __version__ = 'unknown' + +# high level interface +from ambari_jinja2.environment import Environment, Template + +# loaders +from ambari_jinja2.loaders import BaseLoader, FileSystemLoader, PackageLoader, \ + DictLoader, FunctionLoader, PrefixLoader, ChoiceLoader, \ + ModuleLoader + +# bytecode caches +from ambari_jinja2.bccache import BytecodeCache, FileSystemBytecodeCache, \ + MemcachedBytecodeCache + +# undefined types +from ambari_jinja2.runtime import Undefined, DebugUndefined, StrictUndefined + +# exceptions +from ambari_jinja2.exceptions import TemplateError, UndefinedError, \ + TemplateNotFound, TemplatesNotFound, TemplateSyntaxError, \ + TemplateAssertionError + +# decorators and public utilities +from ambari_jinja2.filters import environmentfilter, contextfilter, \ + evalcontextfilter +from ambari_jinja2.utils import Markup, escape, clear_caches, \ + environmentfunction, evalcontextfunction, contextfunction, \ + is_undefined + +__all__ = [ + 'Environment', 'Template', 'BaseLoader', 'FileSystemLoader', + 'PackageLoader', 'DictLoader', 'FunctionLoader', 'PrefixLoader', + 'ChoiceLoader', 'BytecodeCache', 'FileSystemBytecodeCache', + 'MemcachedBytecodeCache', 'Undefined', 'DebugUndefined', + 'StrictUndefined', 'TemplateError', 'UndefinedError', 'TemplateNotFound', + 'TemplatesNotFound', 'TemplateSyntaxError', 'TemplateAssertionError', + 'ModuleLoader', 'environmentfilter', 'contextfilter', 'Markup', 'escape', + 'environmentfunction', 'contextfunction', 'clear_caches', 'is_undefined', + 'evalcontextfilter', 'evalcontextfunction' +] http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c new file mode 100644 index 0000000..041c94f --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_debugsupport.c @@ -0,0 +1,78 @@ +/** + * ambari_jinja2._debugsupport + * ~~~~~~~~~~~~~~~~~~~~ + * + * C implementation of `tb_set_next`. + * + * :copyright: (c) 2010 by the Jinja Team. + * :license: BSD. + */ + +#include <Python.h> + + +static PyObject* +tb_set_next(PyObject *self, PyObject *args) +{ + PyTracebackObject *tb, *old; + PyObject *next; + + if (!PyArg_ParseTuple(args, "O!O:tb_set_next", &PyTraceBack_Type, &tb, &next)) + return NULL; + if (next == Py_None) + next = NULL; + else if (!PyTraceBack_Check(next)) { + PyErr_SetString(PyExc_TypeError, + "tb_set_next arg 2 must be traceback or None"); + return NULL; + } + else + Py_INCREF(next); + + old = tb->tb_next; + tb->tb_next = (PyTracebackObject*)next; + Py_XDECREF(old); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef module_methods[] = { + {"tb_set_next", (PyCFunction)tb_set_next, METH_VARARGS, + "Set the tb_next member of a traceback object."}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + + +#if PY_MAJOR_VERSION < 3 + +#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ +#define PyMODINIT_FUNC void +#endif +PyMODINIT_FUNC +init_debugsupport(void) +{ + Py_InitModule3("ambari_jinja2._debugsupport", module_methods, ""); +} + +#else /* Python 3.x module initialization */ + +static struct PyModuleDef module_definition = { + PyModuleDef_HEAD_INIT, + "ambari_jinja2._debugsupport", + NULL, + -1, + module_methods, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC +PyInit__debugsupport(void) +{ + return PyModule_Create(&module_definition); +} + +#endif http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py new file mode 100644 index 0000000..74d0fe3 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/__init__.py @@ -0,0 +1,225 @@ +# -*- coding: utf-8 -*- +""" + markupsafe + ~~~~~~~~~~ + + Implements a Markup string. + + :copyright: (c) 2010 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" +import re +from itertools import imap + + +__all__ = ['Markup', 'soft_unicode', 'escape', 'escape_silent'] + + +_striptags_re = re.compile(r'(<!--.*?-->|<[^>]*>)') +_entity_re = re.compile(r'&([^;]+);') + + +class Markup(unicode): + r"""Marks a string as being safe for inclusion in HTML/XML output without + needing to be escaped. This implements the `__html__` interface a couple + of frameworks and web applications use. :class:`Markup` is a direct + subclass of `unicode` and provides all the methods of `unicode` just that + it escapes arguments passed and always returns `Markup`. + + The `escape` function returns markup objects so that double escaping can't + happen. + + The constructor of the :class:`Markup` class can be used for three + different things: When passed an unicode object it's assumed to be safe, + when passed an object with an HTML representation (has an `__html__` + method) that representation is used, otherwise the object passed is + converted into a unicode string and then assumed to be safe: + + >>> Markup("Hello <em>World</em>!") + Markup(u'Hello <em>World</em>!') + >>> class Foo(object): + ... def __html__(self): + ... return '<a href="#">foo</a>' + ... + >>> Markup(Foo()) + Markup(u'<a href="#">foo</a>') + + If you want object passed being always treated as unsafe you can use the + :meth:`escape` classmethod to create a :class:`Markup` object: + + >>> Markup.escape("Hello <em>World</em>!") + Markup(u'Hello <em>World</em>!') + + Operations on a markup string are markup aware which means that all + arguments are passed through the :func:`escape` function: + + >>> em = Markup("<em>%s</em>") + >>> em % "foo & bar" + Markup(u'<em>foo & bar</em>') + >>> strong = Markup("<strong>%(text)s</strong>") + >>> strong % {'text': '<blink>hacker here</blink>'} + Markup(u'<strong><blink>hacker here</blink></strong>') + >>> Markup("<em>Hello</em> ") + "<foo>" + Markup(u'<em>Hello</em> <foo>') + """ + __slots__ = () + + def __new__(cls, base=u'', encoding=None, errors='strict'): + if hasattr(base, '__html__'): + base = base.__html__() + if encoding is None: + return unicode.__new__(cls, base) + return unicode.__new__(cls, base, encoding, errors) + + def __html__(self): + return self + + def __add__(self, other): + if hasattr(other, '__html__') or isinstance(other, basestring): + return self.__class__(unicode(self) + unicode(escape(other))) + return NotImplemented + + def __radd__(self, other): + if hasattr(other, '__html__') or isinstance(other, basestring): + return self.__class__(unicode(escape(other)) + unicode(self)) + return NotImplemented + + def __mul__(self, num): + if isinstance(num, (int, long)): + return self.__class__(unicode.__mul__(self, num)) + return NotImplemented + __rmul__ = __mul__ + + def __mod__(self, arg): + if isinstance(arg, tuple): + arg = tuple(imap(_MarkupEscapeHelper, arg)) + else: + arg = _MarkupEscapeHelper(arg) + return self.__class__(unicode.__mod__(self, arg)) + + def __repr__(self): + return '%s(%s)' % ( + self.__class__.__name__, + unicode.__repr__(self) + ) + + def join(self, seq): + return self.__class__(unicode.join(self, imap(escape, seq))) + join.__doc__ = unicode.join.__doc__ + + def split(self, *args, **kwargs): + return map(self.__class__, unicode.split(self, *args, **kwargs)) + split.__doc__ = unicode.split.__doc__ + + def rsplit(self, *args, **kwargs): + return map(self.__class__, unicode.rsplit(self, *args, **kwargs)) + rsplit.__doc__ = unicode.rsplit.__doc__ + + def splitlines(self, *args, **kwargs): + return map(self.__class__, unicode.splitlines(self, *args, **kwargs)) + splitlines.__doc__ = unicode.splitlines.__doc__ + + def unescape(self): + r"""Unescape markup again into an unicode string. This also resolves + known HTML4 and XHTML entities: + + >>> Markup("Main » <em>About</em>").unescape() + u'Main \xbb <em>About</em>' + """ + from ambari_jinja2._markupsafe._constants import HTML_ENTITIES + def handle_match(m): + name = m.group(1) + if name in HTML_ENTITIES: + return unichr(HTML_ENTITIES[name]) + try: + if name[:2] in ('#x', '#X'): + return unichr(int(name[2:], 16)) + elif name.startswith('#'): + return unichr(int(name[1:])) + except ValueError: + pass + return u'' + return _entity_re.sub(handle_match, unicode(self)) + + def striptags(self): + r"""Unescape markup into an unicode string and strip all tags. This + also resolves known HTML4 and XHTML entities. Whitespace is + normalized to one: + + >>> Markup("Main » <em>About</em>").striptags() + u'Main \xbb About' + """ + stripped = u' '.join(_striptags_re.sub('', self).split()) + return Markup(stripped).unescape() + + @classmethod + def escape(cls, s): + """Escape the string. Works like :func:`escape` with the difference + that for subclasses of :class:`Markup` this function would return the + correct subclass. + """ + rv = escape(s) + if rv.__class__ is not cls: + return cls(rv) + return rv + + def make_wrapper(name): + orig = getattr(unicode, name) + def func(self, *args, **kwargs): + args = _escape_argspec(list(args), enumerate(args)) + _escape_argspec(kwargs, kwargs.iteritems()) + return self.__class__(orig(self, *args, **kwargs)) + func.__name__ = orig.__name__ + func.__doc__ = orig.__doc__ + return func + + for method in '__getitem__', 'capitalize', \ + 'title', 'lower', 'upper', 'replace', 'ljust', \ + 'rjust', 'lstrip', 'rstrip', 'center', 'strip', \ + 'translate', 'expandtabs', 'swapcase', 'zfill': + locals()[method] = make_wrapper(method) + + # new in python 2.5 + if hasattr(unicode, 'partition'): + partition = make_wrapper('partition'), + rpartition = make_wrapper('rpartition') + + # new in python 2.6 + if hasattr(unicode, 'format'): + format = make_wrapper('format') + + # not in python 3 + if hasattr(unicode, '__getslice__'): + __getslice__ = make_wrapper('__getslice__') + + del method, make_wrapper + + +def _escape_argspec(obj, iterable): + """Helper for various string-wrapped functions.""" + for key, value in iterable: + if hasattr(value, '__html__') or isinstance(value, basestring): + obj[key] = escape(value) + return obj + + +class _MarkupEscapeHelper(object): + """Helper for Markup.__mod__""" + + def __init__(self, obj): + self.obj = obj + + __getitem__ = lambda s, x: _MarkupEscapeHelper(s.obj[x]) + __str__ = lambda s: str(escape(s.obj)) + __unicode__ = lambda s: unicode(escape(s.obj)) + __repr__ = lambda s: str(escape(repr(s.obj))) + __int__ = lambda s: int(s.obj) + __float__ = lambda s: float(s.obj) + + +# we have to import it down here as the speedups and native +# modules imports the markup type which is define above. +try: + from ambari_jinja2._markupsafe._speedups import escape, escape_silent, soft_unicode +except ImportError: + from ambari_jinja2._markupsafe._native import escape, escape_silent, soft_unicode http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py new file mode 100644 index 0000000..de5d15e --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_bundle.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +""" + ambari_jinja2._markupsafe._bundle + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + This script pulls in markupsafe from a source folder and + bundles it with Jinja2. It does not pull in the speedups + module though. + + :copyright: Copyright 2010 by the Jinja team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +import sys +import os +import re + + +def rewrite_imports(lines): + for idx, line in enumerate(lines): + new_line = re.sub(r'(import|from)\s+markupsafe\b', + r'\1 ambari_jinja2._markupsafe', line) + if new_line != line: + lines[idx] = new_line + + +def main(): + if len(sys.argv) != 2: + print 'error: only argument is path to markupsafe' + sys.exit(1) + basedir = os.path.dirname(__file__) + markupdir = sys.argv[1] + for filename in os.listdir(markupdir): + if filename.endswith('.py'): + f = open(os.path.join(markupdir, filename)) + try: + lines = list(f) + finally: + f.close() + rewrite_imports(lines) + f = open(os.path.join(basedir, filename), 'w') + try: + for line in lines: + f.write(line) + finally: + f.close() + + +if __name__ == '__main__': + main() http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py new file mode 100644 index 0000000..919bf03 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_constants.py @@ -0,0 +1,267 @@ +# -*- coding: utf-8 -*- +""" + markupsafe._constants + ~~~~~~~~~~~~~~~~~~~~~ + + Highlevel implementation of the Markup string. + + :copyright: (c) 2010 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" + + +HTML_ENTITIES = { + 'AElig': 198, + 'Aacute': 193, + 'Acirc': 194, + 'Agrave': 192, + 'Alpha': 913, + 'Aring': 197, + 'Atilde': 195, + 'Auml': 196, + 'Beta': 914, + 'Ccedil': 199, + 'Chi': 935, + 'Dagger': 8225, + 'Delta': 916, + 'ETH': 208, + 'Eacute': 201, + 'Ecirc': 202, + 'Egrave': 200, + 'Epsilon': 917, + 'Eta': 919, + 'Euml': 203, + 'Gamma': 915, + 'Iacute': 205, + 'Icirc': 206, + 'Igrave': 204, + 'Iota': 921, + 'Iuml': 207, + 'Kappa': 922, + 'Lambda': 923, + 'Mu': 924, + 'Ntilde': 209, + 'Nu': 925, + 'OElig': 338, + 'Oacute': 211, + 'Ocirc': 212, + 'Ograve': 210, + 'Omega': 937, + 'Omicron': 927, + 'Oslash': 216, + 'Otilde': 213, + 'Ouml': 214, + 'Phi': 934, + 'Pi': 928, + 'Prime': 8243, + 'Psi': 936, + 'Rho': 929, + 'Scaron': 352, + 'Sigma': 931, + 'THORN': 222, + 'Tau': 932, + 'Theta': 920, + 'Uacute': 218, + 'Ucirc': 219, + 'Ugrave': 217, + 'Upsilon': 933, + 'Uuml': 220, + 'Xi': 926, + 'Yacute': 221, + 'Yuml': 376, + 'Zeta': 918, + 'aacute': 225, + 'acirc': 226, + 'acute': 180, + 'aelig': 230, + 'agrave': 224, + 'alefsym': 8501, + 'alpha': 945, + 'amp': 38, + 'and': 8743, + 'ang': 8736, + 'apos': 39, + 'aring': 229, + 'asymp': 8776, + 'atilde': 227, + 'auml': 228, + 'bdquo': 8222, + 'beta': 946, + 'brvbar': 166, + 'bull': 8226, + 'cap': 8745, + 'ccedil': 231, + 'cedil': 184, + 'cent': 162, + 'chi': 967, + 'circ': 710, + 'clubs': 9827, + 'cong': 8773, + 'copy': 169, + 'crarr': 8629, + 'cup': 8746, + 'curren': 164, + 'dArr': 8659, + 'dagger': 8224, + 'darr': 8595, + 'deg': 176, + 'delta': 948, + 'diams': 9830, + 'divide': 247, + 'eacute': 233, + 'ecirc': 234, + 'egrave': 232, + 'empty': 8709, + 'emsp': 8195, + 'ensp': 8194, + 'epsilon': 949, + 'equiv': 8801, + 'eta': 951, + 'eth': 240, + 'euml': 235, + 'euro': 8364, + 'exist': 8707, + 'fnof': 402, + 'forall': 8704, + 'frac12': 189, + 'frac14': 188, + 'frac34': 190, + 'frasl': 8260, + 'gamma': 947, + 'ge': 8805, + 'gt': 62, + 'hArr': 8660, + 'harr': 8596, + 'hearts': 9829, + 'hellip': 8230, + 'iacute': 237, + 'icirc': 238, + 'iexcl': 161, + 'igrave': 236, + 'image': 8465, + 'infin': 8734, + 'int': 8747, + 'iota': 953, + 'iquest': 191, + 'isin': 8712, + 'iuml': 239, + 'kappa': 954, + 'lArr': 8656, + 'lambda': 955, + 'lang': 9001, + 'laquo': 171, + 'larr': 8592, + 'lceil': 8968, + 'ldquo': 8220, + 'le': 8804, + 'lfloor': 8970, + 'lowast': 8727, + 'loz': 9674, + 'lrm': 8206, + 'lsaquo': 8249, + 'lsquo': 8216, + 'lt': 60, + 'macr': 175, + 'mdash': 8212, + 'micro': 181, + 'middot': 183, + 'minus': 8722, + 'mu': 956, + 'nabla': 8711, + 'nbsp': 160, + 'ndash': 8211, + 'ne': 8800, + 'ni': 8715, + 'not': 172, + 'notin': 8713, + 'nsub': 8836, + 'ntilde': 241, + 'nu': 957, + 'oacute': 243, + 'ocirc': 244, + 'oelig': 339, + 'ograve': 242, + 'oline': 8254, + 'omega': 969, + 'omicron': 959, + 'oplus': 8853, + 'or': 8744, + 'ordf': 170, + 'ordm': 186, + 'oslash': 248, + 'otilde': 245, + 'otimes': 8855, + 'ouml': 246, + 'para': 182, + 'part': 8706, + 'permil': 8240, + 'perp': 8869, + 'phi': 966, + 'pi': 960, + 'piv': 982, + 'plusmn': 177, + 'pound': 163, + 'prime': 8242, + 'prod': 8719, + 'prop': 8733, + 'psi': 968, + 'quot': 34, + 'rArr': 8658, + 'radic': 8730, + 'rang': 9002, + 'raquo': 187, + 'rarr': 8594, + 'rceil': 8969, + 'rdquo': 8221, + 'real': 8476, + 'reg': 174, + 'rfloor': 8971, + 'rho': 961, + 'rlm': 8207, + 'rsaquo': 8250, + 'rsquo': 8217, + 'sbquo': 8218, + 'scaron': 353, + 'sdot': 8901, + 'sect': 167, + 'shy': 173, + 'sigma': 963, + 'sigmaf': 962, + 'sim': 8764, + 'spades': 9824, + 'sub': 8834, + 'sube': 8838, + 'sum': 8721, + 'sup': 8835, + 'sup1': 185, + 'sup2': 178, + 'sup3': 179, + 'supe': 8839, + 'szlig': 223, + 'tau': 964, + 'there4': 8756, + 'theta': 952, + 'thetasym': 977, + 'thinsp': 8201, + 'thorn': 254, + 'tilde': 732, + 'times': 215, + 'trade': 8482, + 'uArr': 8657, + 'uacute': 250, + 'uarr': 8593, + 'ucirc': 251, + 'ugrave': 249, + 'uml': 168, + 'upsih': 978, + 'upsilon': 965, + 'uuml': 252, + 'weierp': 8472, + 'xi': 958, + 'yacute': 253, + 'yen': 165, + 'yuml': 255, + 'zeta': 950, + 'zwj': 8205, + 'zwnj': 8204 +} http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py new file mode 100644 index 0000000..97c8d35 --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/_native.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +""" + markupsafe._native + ~~~~~~~~~~~~~~~~~~ + + Native Python implementation the C module is not compiled. + + :copyright: (c) 2010 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" +from ambari_jinja2._markupsafe import Markup + + +def escape(s): + """Convert the characters &, <, >, ' and " in string s to HTML-safe + sequences. Use this if you need to display text that might contain + such characters in HTML. Marks return value as markup string. + """ + if hasattr(s, '__html__'): + return s.__html__() + return Markup(unicode(s) + .replace('&', '&') + .replace('>', '>') + .replace('<', '<') + .replace("'", ''') + .replace('"', '"') + ) + + +def escape_silent(s): + """Like :func:`escape` but converts `None` into an empty + markup string. + """ + if s is None: + return Markup() + return escape(s) + + +def soft_unicode(s): + """Make a string unicode if it isn't already. That way a markup + string is not converted back to unicode. + """ + if not isinstance(s, unicode): + s = unicode(s) + return s http://git-wip-us.apache.org/repos/asf/ambari/blob/658360a5/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py new file mode 100644 index 0000000..8e88bfe --- /dev/null +++ b/ambari-common/src/main/python/ambari_jinja2/ambari_jinja2/_markupsafe/tests.py @@ -0,0 +1,80 @@ +import gc +import unittest +from ambari_jinja2._markupsafe import Markup, escape, escape_silent + + +class MarkupTestCase(unittest.TestCase): + + def test_markup_operations(self): + # adding two strings should escape the unsafe one + unsafe = '<script type="application/x-some-script">alert("foo");</script>' + safe = Markup('<em>username</em>') + assert unsafe + safe == unicode(escape(unsafe)) + unicode(safe) + + # string interpolations are safe to use too + assert Markup('<em>%s</em>') % '<bad user>' == \ + '<em><bad user></em>' + assert Markup('<em>%(username)s</em>') % { + 'username': '<bad user>' + } == '<em><bad user></em>' + + # an escaped object is markup too + assert type(Markup('foo') + 'bar') is Markup + + # and it implements __html__ by returning itself + x = Markup("foo") + assert x.__html__() is x + + # it also knows how to treat __html__ objects + class Foo(object): + def __html__(self): + return '<em>awesome</em>' + def __unicode__(self): + return 'awesome' + assert Markup(Foo()) == '<em>awesome</em>' + assert Markup('<strong>%s</strong>') % Foo() == \ + '<strong><em>awesome</em></strong>' + + # escaping and unescaping + assert escape('"<>&\'') == '"<>&'' + assert Markup("<em>Foo & Bar</em>").striptags() == "Foo & Bar" + assert Markup("<test>").unescape() == "<test>" + + def test_all_set(self): + import ambari_jinja2._markupsafe as markup + for item in markup.__all__: + getattr(markup, item) + + def test_escape_silent(self): + assert escape_silent(None) == Markup() + assert escape(None) == Markup(None) + assert escape_silent('<foo>') == Markup(u'<foo>') + + +class MarkupLeakTestCase(unittest.TestCase): + + def test_markup_leaks(self): + counts = set() + for count in xrange(20): + for item in xrange(1000): + escape("foo") + escape("<foo>") + escape(u"foo") + escape(u"<foo>") + counts.add(len(gc.get_objects())) + assert len(counts) == 1, 'ouch, c extension seems to leak objects' + + +def suite(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(MarkupTestCase)) + + # this test only tests the c extension + if not hasattr(escape, 'func_code'): + suite.addTest(unittest.makeSuite(MarkupLeakTestCase)) + + return suite + + +if __name__ == '__main__': + unittest.main(defaultTest='suite')