diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2020-05-24 06:44:09 -0700 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2020-08-31 17:27:38 -0700 |
commit | 3e3892f939031d58d98275ce8a237689225d299a (patch) | |
tree | 93b64d7fd8aa1cc19335db11c915dfc59376eae9 /sqlparse/sql.py | |
parent | 28a2acdd9b307c95d2111f1f831b1a5afc634691 (diff) | |
download | sqlparse-3e3892f939031d58d98275ce8a237689225d299a.tar.gz |
Remove support for end-of-life Pythons
Python 2.7 and 3.4 are end-of-life. They are no longer receiving bug
fixes, including for security issues. Python 2.7 went EOL on 2020-01-01
and 3.4 on 2019-03-18. For additional details on support Python
versions, see:
Supported: https://devguide.python.org/#status-of-python-branches
EOL: https://devguide.python.org/devcycle/#end-of-life-branches
Removing support for EOL Pythons will reduce testing and maintenance
resources while allowing the library to move towards modern Python 3.
Using pypinfo, we can show the PyPI download statistics, showing less
than 10% of users are using Python 2.7.
| python_version | percent | download_count |
| -------------- | ------: | -------------: |
| 3.7 | 45.36% | 3,056,010 |
| 3.6 | 26.46% | 1,782,778 |
| 3.8 | 12.22% | 823,213 |
| 2.7 | 9.97% | 671,459 |
| 3.5 | 5.86% | 394,846 |
| 3.4 | 0.10% | 6,700 |
| 3.9 | 0.03% | 2,346 |
| 2.6 | 0.00% | 57 |
| 3.3 | 0.00% | 21 |
| 3.10 | 0.00% | 6 |
| Total | | 6,737,436 |
Library users who continue to use Python 2.7 will still be able to
install previous versions of sqlparse.
Compatibility shims have been dropped, simplifying the code.
Using pyupgrade, the codebase has been updated to take advantage of
modern syntax <https://github.com/asottile/pyupgrade>.
The wheel is no longer marked as "universal" as it is now Python 3 only.
Diffstat (limited to 'sqlparse/sql.py')
-rw-r--r-- | sqlparse/sql.py | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py index a942bcd..a9e11da 100644 --- a/sqlparse/sql.py +++ b/sqlparse/sql.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009-2018 the sqlparse authors and contributors # <see AUTHORS file> @@ -7,12 +6,10 @@ # the BSD License: https://opensource.org/licenses/BSD-3-Clause """This module contains classes representing syntactical elements of SQL.""" -from __future__ import print_function import re from sqlparse import tokens as T -from sqlparse.compat import string_types, text_type, unicode_compatible from sqlparse.utils import imt, remove_quotes @@ -39,8 +36,7 @@ class NameAliasMixin: return self._get_first_name(reverse=True) -@unicode_compatible -class Token(object): +class Token: """Base class for all other classes in this module. It represents a single token and has two instance attributes: @@ -52,7 +48,7 @@ class Token(object): 'is_group', 'is_whitespace') def __init__(self, ttype, value): - value = text_type(value) + value = str(value) self.value = value self.ttype = ttype self.parent = None @@ -72,15 +68,15 @@ class Token(object): cls = self._get_repr_name() value = self._get_repr_value() - q = u'"' if value.startswith("'") and value.endswith("'") else u"'" - return u"<{cls} {q}{value}{q} at 0x{id:2X}>".format( + q = '"' if value.startswith("'") and value.endswith("'") else "'" + return "<{cls} {q}{value}{q} at 0x{id:2X}>".format( id=id(self), **locals()) def _get_repr_name(self): return str(self.ttype).split('.')[-1] def _get_repr_value(self): - raw = text_type(self) + raw = str(self) if len(raw) > 7: raw = raw[:6] + '...' return re.sub(r'\s+', ' ', raw) @@ -105,7 +101,7 @@ class Token(object): if not type_matched or values is None: return type_matched - if isinstance(values, string_types): + if isinstance(values, str): values = (values,) if regex: @@ -150,7 +146,6 @@ class Token(object): return False -@unicode_compatible class TokenList(Token): """A group of tokens. @@ -163,11 +158,11 @@ class TokenList(Token): def __init__(self, tokens=None): self.tokens = tokens or [] [setattr(token, 'parent', self) for token in self.tokens] - super(TokenList, self).__init__(None, text_type(self)) + super().__init__(None, str(self)) self.is_group = True def __str__(self): - return u''.join(token.value for token in self.flatten()) + return ''.join(token.value for token in self.flatten()) # weird bug # def __len__(self): @@ -190,14 +185,14 @@ class TokenList(Token): value = token._get_repr_value() last = idx == (token_count - 1) - pre = u'`- ' if last else u'|- ' + pre = '`- ' if last else '|- ' - q = u'"' if value.startswith("'") and value.endswith("'") else u"'" - print(u"{_pre}{pre}{idx} {cls} {q}{value}{q}" + q = '"' if value.startswith("'") and value.endswith("'") else "'" + print("{_pre}{pre}{idx} {cls} {q}{value}{q}" .format(**locals()), file=f) if token.is_group and (max_depth is None or depth < max_depth): - parent_pre = u' ' if last else u'| ' + parent_pre = ' ' if last else '| ' token._pprint_tree(max_depth, depth + 1, f, _pre + parent_pre) def get_token_at_offset(self, offset): @@ -216,8 +211,7 @@ class TokenList(Token): """ for token in self.tokens: if token.is_group: - for item in token.flatten(): - yield item + yield from token.flatten() else: yield token @@ -328,7 +322,7 @@ class TokenList(Token): grp = start grp.tokens.extend(subtokens) del self.tokens[start_idx + 1:end_idx] - grp.value = text_type(start) + grp.value = str(start) else: subtokens = self.tokens[start_idx:end_idx] grp = grp_cls(subtokens) |