summaryrefslogtreecommitdiff
path: root/mako/template.py
Commit message (Collapse)AuthorAgeFilesLines
* happy new year 2023HEADmainMike Bayer2023-01-031-1/+1
| | | | Change-Id: I1ae40f516c03801427063175d6b18a60556fbd29
* happy new yearMike Bayer2022-06-301-1/+1
| | | | Change-Id: I1aef208387ea7d25462b8effdfc298e89c74dadd
* update black and formatFederico Caselli2021-10-251-12/+10
| | | | | | | | Closes: #342 Pull-request: https://github.com/sqlalchemy/mako/pull/342 Pull-request-sha: 21a068103481410cf4856fb07c19146dc684d460 Change-Id: I9027433ec23ee19c9d9a47015e0327acf409e2d8
* Refactoring CodeFederico Caselli2021-10-251-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## [Setup.py](setup.py) - Use `with` when opening file to ensure closure ## [Util.py](mako/util.py) - Remove unnecessary else after guard condition - Replace if statement with if expression - Remove unnecessary else after guard condition - Replace unneeded comprehension with generator - Inline variable that is immediately returned ## [Template.py](mako/template.py) - Replace if statement with if expression, Simplify if expression by using or - Replace list(), dict() or set() with comprehension - Swap if/else branches, Merge else clause's nested if statement into elif ## [Runtime.py](mako/runtime.py) - Remove unnecessary else after guard condition ## [PyParser.py](mako/pyparser.py) - Replace yield inside for loop with yield from - Lift code into else after jump in control flow, Merge else clause's nested if statement into elif - Replace if statement with if expression ## [Pygen.py](mako/pygen.py) - Merge nested if conditions - Simplify conditional into return statement (removes comment) - Replace if statement with if expression, Simplify boolean if expression ## [Parsetree.py](mako/parsetree.py) - Replace unneeded comprehension with generator - Merge else clause's nested if statement into elif - Replace unneeded comprehension with generator ## [Lookup.py](mako/lookup.py) - Swap if/else branches, Merge else clause's nested if statement into elif - Swap if/else branches, Remove unnecessary else after guard condition ## [Lexer.py](mako/lexer.py) - Replace if statement with if expression - Merge nested if conditions - Swap if/else branches, Remove unnecessary else after guard condition, Merge else clause's nested if statement into elif - Swap if/else branches, Remove unnecessary else after guard condition ## [Exceptions.py](mako/exceptions.py) - Replace if statement with if expression, Use `with` when opening file to ensure closure ## [Ast.py](mako/ast.py) - Replace multiple comparisons of same variable with `in` operator ## [Pygmentplugin.py](mako/ext/pygmentplugin.py) - Replace if statement with if expression Closes: #335 Pull-request: https://github.com/sqlalchemy/mako/pull/335 Pull-request-sha: c6243b116441f4b14e1cff00f47ed72aee3d3133 Change-Id: I9093e2f5ca4bb59aa12536b1a0bdf2d58514aa40
* more code updatesMike Bayer2021-10-251-23/+5
| | | | | | | | | | | - 2021 copyright - remove unneeded compat functions - remove unneeded filter constructs - bytestring_passthrough mode doesn't actually do anything, as Py3k StringIO doesn't accept bytes in any case, remove this - should we call ourselves 2.0 and do semver ? Change-Id: I8a8cb5e78037b758e58c87d5d7b4f66b6c211419
* Modernize codeworkflow_test_initial_1_2Federico Caselli2021-10-231-49/+12
| | | | | | | | | | | - remove python 2 support - add github workflows - remove disable unicode - cleanup compat file - modernize setup - use pep517 Change-Id: Ic38dbf478046cec5d0815b468f0c235b4ea5e20c
* Avoid warnings under Python 3.10Petr Viktorin2021-01-141-3/+0
| | | | | | | | | | | | | | | | | | | | Fixed Python deprecation issues related to module importing, as well as file access within the Lingua plugin, for deprecated APIs that began to emit warnings under Python 3.10. Pull request courtesy Petr Viktorin. This modernizes the code to avoid `DeprecationWarning` and `ResourceWarning` encountered in the test suite under Python 3.10a4: - [load_module](https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module) is deprecated - Some files weren't being closed This changes the semantics of the `compat.load_module` function: on Python 3.5+, the module is no longer inserted in `sys.modules`. All non-test calls did `del sys.modules[self.module_id]` right after the call, anyway. On older Python, the module is inserted and then deleted. (Some additional `DeprecationWarning` come from Setuptools: https://github.com/pypa/setuptools/pull/2517) Closes: #328 Pull-request: https://github.com/sqlalchemy/mako/pull/328 Pull-request-sha: 87c1d09e5f39de7b19e749568c437928580f7553 Change-Id: I9cb3772f6812ef14297792344caf2f9aa5337adf
* happy new yearMike Bayer2020-01-051-9/+9
| | | | | | also fix one flake8 error Change-Id: Ia828267fce34d5b194898e3e301b6d463470f068
* Bump Python versions, remove conditional importsMike Bayer2019-07-271-1/+2
| | | | | | | | | | | | | | | | | | | | | | Mako 1.1 now supports Python versions: * 2.7 * 3.4 and higher This includes that setup.py no longer includes any conditionals, allowing for a pure Python wheel build, however this is not necessarily part of the Pypi release process as of yet. The test suite also raises for Python deprecation warnings. Fixes: #249 Replaced usage of ``inspect.getfullargspec()`` with the vendored version used by SQLAlchemy, Alembic to avoid future deprecation warnings. Also cleans up an additional version of the same function that's apparently been floating around for some time. Fixes: #295 Change-Id: I98274c16b6022289d1890f4daf532bab323ab112
* Include URI in traceback if filename is unknownMartin von Gagern2019-07-081-3/+6
| | | | | | | | | | | | | | | | | Using URIs as entrered will make the stack trace arguably more readable than using the module name which is the URI with non-word characters replaced by underscores. This change also fixes a mistake where a mods cache hit would not update template_filename, causing a stale filename to be displayed if the stack trace alternates between different templates. There now is a test case for this. Closes: #298 Pull-request: https://github.com/sqlalchemy/mako/pull/298 Pull-request-sha: ea35208d504932561711cdb574ec1f7def1e7060 Change-Id: Ieb606f6b6b7f4602d4d56694dd0bccf6dc287d20
* - update copyrightMike Bayer2019-05-311-1/+1
| | | | Change-Id: I258e9ff77e5a9ac687cd20d33b6d75de7c79b4dc
* Use tox / zimportsMike Bayer2019-05-311-161/+191
| | | | Change-Id: Ia047c7052a6d242c2cf1c7a83981f1e38ea4d928
* Marked some docstrings as raw strings to address the invalid escape warning ↵Yannick Gingras2017-05-101-1/+1
| | | | on Python 3.6+
* Add include_error_handler parameter.Huayi Zhang2016-11-081-1/+21
| | | | | | | | This works like error_handler but is specific to a template when included in another using the include tag. Change-Id: Ie5506a8cba42c71519c703eacc82050902b9ceba Pull-request: https://bitbucket.org/zzzeek/mako/pull-requests/22
* - happy new yearMike Bayer2016-03-101-1/+1
|
* - changelog for pr 16Mike Bayer2016-03-091-2/+6
|
* Merge branch 'feature-list_defs' of https://bitbucket.org/jvanasco/mako into ↵Mike Bayer2016-03-091-0/+4
|\ | | | | | | pr16
| * added `Template.list_defs`jonathan vanasco2015-03-111-0/+4
| |
* | - get flake8 to pass fully for mako/ (tests are a much bigger deal)Mike Bayer2015-03-251-120/+133
|/
* happy new yearrel_1_0_1Mike Bayer2015-01-221-1/+1
|
* - fix the line number scheme to be consistently 1-based, bothMike Bayer2014-05-211-11/+8
| | | | | | | for the template and the module - turn full_line_map into a list - add another start source to help with when a render callable begins
* - ensure all line numbers are integersMike Bayer2014-05-201-1/+3
|
* - add module source thing as ModuleInfo.get_module_source_metadataMike Bayer2014-04-141-0/+20
|
* - 2014Mike Bayer2014-01-091-1/+1
| | | | - move CHANGES to changelog.rst
* update copyrightMike Bayer2013-08-031-1/+1
|
* - [bug] Cleaned up all the various deprecation/Mike Bayer2013-04-131-2/+2
| | | | | | file warnings when running the tests under various Pythons with warnings turned on. [ticket:213]
* - [bug] Fixed bug whereby an exception in Python 3Mike Bayer2013-02-201-1/+1
| | | | | | against a module compiled to the filesystem would fail trying to produce a RichTraceback due to the content being in bytes. [ticket:209]
* fix doc example which illustrated "file" instead of "filename", [ticket:206]Mike Bayer2012-12-211-1/+1
|
* - [feature] Added lexer_cls argument to Template,Mike Bayer2012-11-121-6/+18
| | | | | TemplateLookup, allows alternate Lexer classes to be used.
* I'm seeing exec() as a function having the same behavior here from 2.4 to 3.3.Mike Bayer2012-11-111-1/+2
| | | | waiting on further detail what I'm missing here
* py2.5 worksMike Bayer2012-11-111-1/+4
|
* - first pass at running a py3k compatible base in py2k as well.Mike Bayer2012-11-111-11/+18
| | | | | having some weird unicode issues I can't debug; the meaning of str.encode() seems to be changing globally somehow
* Finalized future_imports feature.Benjamin Trofatter2012-11-101-4/+13
| | | | | Changed keyword argument from futures to future_imports for clarity. Added docstring describing use.
* Added futures support to makoBenjamin Trofatter2012-11-091-1/+5
| | | | | | Provide a list of names to import from __future__ to Template or TemplateLookup, and it will render the import from __future__ statement at the top of the generated code so that it actually works.
* epic trailing whitespace removalMike Bayer2012-07-071-104/+104
|
* Add paragraph-level version information markup from SphinxVincent Férotin2012-05-141-9/+22
| | | | | (``.. versionadded::``, ``.. versionchanged::`` and ``.. deprecated::``), update docs CSS to put those infos into boxes.
* Add some `reStructuredText` (or `Sphinx` related) markups:Vincent Férotin2012-05-141-46/+48
| | | | | add more litterals, systematicaly use ``.. sourcecode::`` before code samples, add some ``:func:``, ``:class:`` and so on, fix some links, etc.
* Fix some various typos in documentation:Vincent Férotin2012-05-141-48/+48
| | | | | | fix misspelled words, remove line ending spaces, change ``-`` to ``--``, add some ``'`` between subject and 'to be' verb (e.g. "it's", "i'm"), add some ending dots to sentences, change some letters "capitalness", etc.
* - add a path to disable the loop feature - enable_loop=FalseMike Bayer2012-03-291-24/+27
| | | | | - fix up links, formatting in docs - remove some repetition in the _compile logic
* - apply the #125 patchMike Bayer2012-03-241-3/+9
| | | | - changelog
* - [bug] Fixed some Py3K resource warnings dueMike Bayer2012-02-211-10/+13
| | | | | to filehandles being implicitly closed. [ticket:182]
* - [feature] Added module_writer argument to Template,Mike Bayer2012-01-161-12/+52
| | | | | | | TemplateLookup, allows a callable to be passed which takes over the writing of the template's module source file, so that special environment-specific steps can be taken. [ticket:181]
* 2012Mike Bayer2012-01-161-1/+1
|
* - Template caching has been converted into a pluginMike Bayer2011-10-011-22/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | system, whereby the usage of Beaker is just the default plugin. Template and TemplateLookup now accept a string "cache_impl" parameter which refers to the name of a cache plugin, defaulting to the name 'beaker'. New plugins can be registered as pkg_resources entrypoints under the group "mako.cache", or registered directly using mako.cache.register_plugin(). The core plugin is the mako.cache.CacheImpl class. - The <%def>, <%block> and <%page> tags now accept any argument named "cache_*", and the key minus the "cache_" prefix will be passed as keyword arguments to the CacheImpl methods. - Template and TemplateLookup now accept an argument cache_args, which refers to a dictionary containing cache parameters. The cache_dir, cache_url, cache_type, cache_timeout arguments are deprecated (will probably never be removed, however) and can be passed now as cache_args={'url':<some url>, 'type':'memcached', 'timeout':50, 'dir':'/path/to/some/directory'}
* - A Template is explicitly disallowedrel_0_5_0Mike Bayer2011-09-271-6/+12
| | | | | | | | | | | | | | | | | | | from having a url that normalizes to relative outside of the root. That is, if the Lookup is based at /home/mytemplates, an include that would place the ultimate template at /home/mytemplates/../some_other_directory, i.e. outside of /home/mytemplates, is disallowed. This usage was never intended despite the lack of an explicit check. The main issue this causes is that module files can be written outside of the module root (or raise an error, if file perms aren't set up), and can also lead to the same template being cached in the lookup under multiple, relative roots. TemplateLookup instead has always supported multiple file roots for this purpose. [ticket:174]
* - the "ascii encoding by default" approach doesn't work in Py3K,Mike Bayer2011-02-211-6/+30
| | | | | | | | | because a string and an ascii encoded string are of course different things, and we'd like render() by default to return a string. So go the other way, use FEB in all cases, add a new flag bytestring_passthrough which goes back to StringIO, to support that one guy who wanted to force a bytestring through in an expression.
* - fix uncovered bug in FastEncodingBufferMike Bayer2011-02-211-2/+2
| | | | - misc cleanup
* - use inlined getargspecMike Bayer2011-02-201-2/+5
| | | | | | | | | | | | | | | - The "output encoding" now defaults to "ascii", whereas previously it was set to None. This has the effect of FastEncodingBuffer being used internally by default when render() is called, instead of cStringIO or StringIO, which are slower, but allow bytestrings with unknown encoding to pass right through. It is of course not recommended to use bytestrings of unknown encoding. Usage of the "disable_unicode" mode also requires that output_encoding be set to None.
* - add AUTHORS fileMike Bayer2011-02-191-3/+2
| | | | - convert heading copyrights to 2006-2011, reference AUTHORS file
* - now that trailing whitespace comes up in red, need to get rid of itMike Bayer2011-01-191-64/+64
|