diff options
Diffstat (limited to 'debug_toolbar/utils/sql.py')
| -rw-r--r-- | debug_toolbar/utils/sql.py | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/debug_toolbar/utils/sql.py b/debug_toolbar/utils/sql.py deleted file mode 100644 index 00728a3..0000000 --- a/debug_toolbar/utils/sql.py +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import unicode_literals - -import re - -from django.utils.html import escape - -import sqlparse -from sqlparse import tokens as T - - -class BoldKeywordFilter: - """sqlparse filter to bold SQL keywords""" - def process(self, stack, stream): - """Process the token stream""" - for token_type, value in stream: - is_keyword = token_type in T.Keyword - if is_keyword: - yield T.Text, '<strong>' - yield token_type, escape(value) - if is_keyword: - yield T.Text, '</strong>' - - -def reformat_sql(sql): - stack = sqlparse.engine.FilterStack() - stack.preprocess.append(BoldKeywordFilter()) # add our custom filter - stack.postprocess.append(sqlparse.filters.SerializerUnicode()) # tokens -> strings - return swap_fields(''.join(stack.run(sql))) - - -def swap_fields(sql): - expr = r'SELECT</strong> (...........*?) <strong>FROM' - subs = (r'SELECT</strong> ' - r'<a class="djDebugUncollapsed djDebugToggle" href="#">•••</a> ' - r'<a class="djDebugCollapsed djDebugToggle" href="#">\1</a> ' - r'<strong>FROM') - return re.sub(expr, subs, sql) |
