Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring jinjasql in-line with Jinja2 3.1.2 #53

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jinjasql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from jinjasql.core import JinjaSql

__version__ = '0.1.8'
__version__ = '0.1.9'
VERSION = tuple(map(int, __version__.split('.')))

__all__ = ['JinjaSql']
11 changes: 5 additions & 6 deletions jinjasql/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from jinja2 import Template
from jinja2.ext import Extension
from jinja2.lexer import Token
from jinja2.utils import Markup
from jinja2.utils import markupsafe
from collections.abc import Iterable

try:
Expand Down Expand Up @@ -92,7 +92,7 @@ def filter_stream(self, stream):
def sql_safe(value):
"""Filter to mark the value of an expression as safe for inserting
in a SQL statement"""
return Markup(value)
return markupsafe.Markup(value)

def bind(value, name):
"""A filter that prints %s, and stores the value
Expand All @@ -101,7 +101,7 @@ def bind(value, name):
This filter is automatically applied to every {{variable}}
during the lexing stage, so developers can't forget to bind
"""
if isinstance(value, Markup):
if isinstance(value, markupsafe.Markup):
return value
else:
return _bind_param(_thread_local.bind_params, name, value)
Expand Down Expand Up @@ -150,7 +150,7 @@ def identifier_filter(raw_identifier):
raw_identifier = (raw_identifier, )
if not isinstance(raw_identifier, Iterable):
raise ValueError("identifier filter expects a string or an Iterable")
return Markup('.'.join(quote_and_escape(s) for s in raw_identifier))
return markupsafe.Markup('.'.join(quote_and_escape(s) for s in raw_identifier))

return identifier_filter

Expand All @@ -173,15 +173,14 @@ class JinjaSql(object):
def __init__(self, env=None, param_style='format', identifier_quote_character='"'):
self.param_style = param_style
if identifier_quote_character not in self.VALID_ID_QUOTE_CHARS:
raise ValueError("identifier_quote_characters must be one of " + VALID_ID_QUOTE_CHARS)
raise ValueError("identifier_quote_characters must be one of " + JinjaSql.VALID_ID_QUOTE_CHARS)
self.identifier_quote_character = identifier_quote_character
self.env = env or Environment()
self._prepare_environment()

def _prepare_environment(self):
self.env.autoescape=True
self.env.add_extension(SqlExtension)
self.env.add_extension('jinja2.ext.autoescape')
self.env.filters["bind"] = bind
self.env.filters["sqlsafe"] = sql_safe
self.env.filters["inclause"] = bind_in_clause
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jinja2>=2.5,<3.0
Jinja2>=2.8
Django>=1.7,<1.8
PyYAML>=3
testcontainers[mysql,postgresql,mssqlserver,oracle]==3.4.2
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# There are several approaches to eliminate this redundancy,
# see https://packaging.python.org/single_source_version/
# but for now, we will simply maintain it in two places
__version__ = '0.1.8'
__version__ = '0.1.9'

long_description = '''
Generate SQL Queries using a Jinja Template, without worrying about SQL Injection
Expand Down Expand Up @@ -39,7 +39,7 @@
'packages' : ['jinjasql'],
'test_suite' : 'tests.all_tests',
'install_requires': [
'Jinja2>=2.5,<3.0'
'Jinja2>=2.8'
],
'classifiers' : [
'Development Status :: 4 - Beta',
Expand Down