diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-11-21 21:17:27 +0100 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-11-24 22:51:27 -0500 |
commit | 31acba8ff7c123a20ae308b7f4ab6df3df264b48 (patch) | |
tree | a4c39a2123e1b95edf17995ba85bb69ee619f6e4 /lib/sqlalchemy/dialects/postgresql | |
parent | d3a4e96196cd47858de072ae589c6554088edc24 (diff) | |
download | sqlalchemy-31acba8ff7c123a20ae308b7f4ab6df3df264b48.tar.gz |
Clean up most py3k compat
Change-Id: I8172fdcc3103ff92aa049827728484c8779af6b7
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/__init__.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/array.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/asyncpg.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 38 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/dml.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/ext.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/hstore.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/json.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/pg8000.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 4 |
10 files changed, 34 insertions, 45 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py index 056de66be..08b05dc74 100644 --- a/lib/sqlalchemy/dialects/postgresql/__init__.py +++ b/lib/sqlalchemy/dialects/postgresql/__init__.py @@ -4,6 +4,7 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php +from . import asyncpg # noqa from . import base from . import pg8000 # noqa from . import psycopg2 # noqa @@ -57,9 +58,6 @@ from .ranges import TSRANGE from .ranges import TSTZRANGE from ...util import compat -if compat.py3k: - from . import asyncpg # noqa - base.dialect = dialect = psycopg2.dialect diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py index 0cb574dac..614559035 100644 --- a/lib/sqlalchemy/dialects/postgresql/array.py +++ b/lib/sqlalchemy/dialects/postgresql/array.py @@ -374,12 +374,12 @@ class ARRAY(sqltypes.ARRAY): def process(value): if value is None: return value - # isinstance(value, util.string_types) is required to handle + # isinstance(value, str) is required to handle # the case where a TypeDecorator for and Array of Enum is # used like was required in sa < 1.3.17 return super_rp( handle_raw_string(value) - if isinstance(value, util.string_types) + if isinstance(value, str) else value ) diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index fe1f9fd5a..d6cde0087 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -99,6 +99,7 @@ To disable the prepared statement cache, use a value of zero:: """ # noqa import collections +import collections.abc as collections_abc import decimal import json as _py_json import re @@ -216,8 +217,8 @@ class AsyncpgJSONStrIndexType(sqltypes.JSON.JSONStrIndexType): class AsyncpgJSONPathType(json.JSONPathType): def bind_processor(self, dialect): def process(value): - assert isinstance(value, util.collections_abc.Sequence) - tokens = [util.text_type(elem) for elem in value] + assert isinstance(value, collections_abc.Sequence) + tokens = [str(elem) for elem in value] return tokens return process diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 583d9c263..d00318fc8 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1721,7 +1721,7 @@ class UUID(sqltypes.TypeEngine): def coerce_compared_value(self, op, value): """See :meth:`.TypeEngine.coerce_compared_value` for a description.""" - if isinstance(value, util.string_types): + if isinstance(value, str): return self else: return super(UUID, self).coerce_compared_value(op, value) @@ -1731,7 +1731,7 @@ class UUID(sqltypes.TypeEngine): def process(value): if value is not None: - value = util.text_type(value) + value = str(value) return value return process @@ -2375,7 +2375,7 @@ class PGCompiler(compiler.SQLCompiler): target_text = "(%s)" % ", ".join( ( self.preparer.quote(c) - if isinstance(c, util.string_types) + if isinstance(c, str) else self.process(c, include_table=False, use_schema=False) ) for c in clause.inferred_target_elements @@ -2451,7 +2451,7 @@ class PGCompiler(compiler.SQLCompiler): for k, v in set_parameters.items(): key_text = ( self.preparer.quote(k) - if isinstance(k, util.string_types) + if isinstance(k, str) else self.process(k, use_schema=False) ) value_text = self.process( @@ -2653,9 +2653,7 @@ class PGDDLCompiler(compiler.DDLCompiler): includeclause = index.dialect_options["postgresql"]["include"] if includeclause: inclusions = [ - index.table.c[col] - if isinstance(col, util.string_types) - else col + index.table.c[col] if isinstance(col, str) else col for col in includeclause ] text += " INCLUDE (%s)" % ", ".join( @@ -3326,7 +3324,7 @@ class PGDialect(default.DefaultDialect): sql.text(query).bindparams( sql.bindparam( "schema", - util.text_type(schema.lower()), + str(schema.lower()), type_=sqltypes.Unicode, ) ) @@ -3347,7 +3345,7 @@ class PGDialect(default.DefaultDialect): ).bindparams( sql.bindparam( "name", - util.text_type(table_name), + str(table_name), type_=sqltypes.Unicode, ) ) @@ -3361,12 +3359,12 @@ class PGDialect(default.DefaultDialect): ).bindparams( sql.bindparam( "name", - util.text_type(table_name), + str(table_name), type_=sqltypes.Unicode, ), sql.bindparam( "schema", - util.text_type(schema), + str(schema), type_=sqltypes.Unicode, ), ) @@ -3384,12 +3382,12 @@ class PGDialect(default.DefaultDialect): ).bindparams( sql.bindparam( "name", - util.text_type(sequence_name), + str(sequence_name), type_=sqltypes.Unicode, ), sql.bindparam( "schema", - util.text_type(schema), + str(schema), type_=sqltypes.Unicode, ), ) @@ -3418,15 +3416,11 @@ class PGDialect(default.DefaultDialect): """ query = sql.text(query) query = query.bindparams( - sql.bindparam( - "typname", util.text_type(type_name), type_=sqltypes.Unicode - ) + sql.bindparam("typname", str(type_name), type_=sqltypes.Unicode) ) if schema is not None: query = query.bindparams( - sql.bindparam( - "nspname", util.text_type(schema), type_=sqltypes.Unicode - ) + sql.bindparam("nspname", str(schema), type_=sqltypes.Unicode) ) cursor = connection.execute(query) return bool(cursor.scalar()) @@ -3471,9 +3465,9 @@ class PGDialect(default.DefaultDialect): ) # Since we're binding to unicode, table_name and schema_name must be # unicode. - table_name = util.text_type(table_name) + table_name = str(table_name) if schema is not None: - schema = util.text_type(schema) + schema = str(schema) s = sql.text(query).bindparams(table_name=sqltypes.Unicode) s = s.columns(oid=sqltypes.Integer) if schema: @@ -3573,7 +3567,7 @@ class PGDialect(default.DefaultDialect): ).bindparams( sql.bindparam( "schema", - util.text_type(schema), + str(schema), type_=sqltypes.Unicode, ), ) diff --git a/lib/sqlalchemy/dialects/postgresql/dml.py b/lib/sqlalchemy/dialects/postgresql/dml.py index bb6345cf4..c561b73a1 100644 --- a/lib/sqlalchemy/dialects/postgresql/dml.py +++ b/lib/sqlalchemy/dialects/postgresql/dml.py @@ -185,7 +185,7 @@ class OnConflictClause(ClauseElement): def __init__(self, constraint=None, index_elements=None, index_where=None): if constraint is not None: - if not isinstance(constraint, util.string_types) and isinstance( + if not isinstance(constraint, str) and isinstance( constraint, (schema.Index, schema.Constraint, ext.ExcludeConstraint), ): @@ -197,7 +197,7 @@ class OnConflictClause(ClauseElement): "'constraint' and 'index_elements' are mutually exclusive" ) - if isinstance(constraint, util.string_types): + if isinstance(constraint, str): self.constraint_target = constraint self.inferred_target_elements = None self.inferred_target_whereclause = None diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py index f9e4c1d6c..f779a8010 100644 --- a/lib/sqlalchemy/dialects/postgresql/ext.py +++ b/lib/sqlalchemy/dialects/postgresql/ext.py @@ -4,9 +4,9 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php +from itertools import zip_longest from .array import ARRAY -from ... import util from ...sql import coercions from ...sql import elements from ...sql import expression @@ -237,7 +237,7 @@ class ExcludeConstraint(ColumnCollectionConstraint): name, operator, ) - for (expr, name, operator), colexpr in util.zip_longest( + for (expr, name, operator), colexpr in zip_longest( self._render_exprs, self.columns ) ] diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py index 85d678ef5..2ade4b7c1 100644 --- a/lib/sqlalchemy/dialects/postgresql/hstore.py +++ b/lib/sqlalchemy/dialects/postgresql/hstore.py @@ -9,7 +9,6 @@ import re from .array import ARRAY from ... import types as sqltypes -from ... import util from ...sql import functions as sqlfunc from ...sql import operators @@ -413,7 +412,7 @@ def _serialize_hstore(val): def esc(s, position): if position == "value" and s is None: return "NULL" - elif isinstance(s, util.string_types): + elif isinstance(s, str): return '"%s"' % s.replace("\\", "\\\\").replace('"', r"\"") else: raise ValueError( diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index ef046e3ae..fb7621365 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -4,10 +4,9 @@ # # This module is part of SQLAlchemy and is released under # the MIT License: https://www.opensource.org/licenses/mit-license.php -from __future__ import absolute_import +import collections.abc as collections_abc from ... import types as sqltypes -from ... import util from ...sql import operators @@ -71,8 +70,8 @@ class JSONPathType(sqltypes.JSON.JSONPathType): super_proc = self.string_bind_processor(dialect) def process(value): - assert isinstance(value, util.collections_abc.Sequence) - tokens = [util.text_type(elem) for elem in value] + assert isinstance(value, collections_abc.Sequence) + tokens = [str(elem) for elem in value] value = "{%s}" % (", ".join(tokens)) if super_proc: value = super_proc(value) @@ -84,8 +83,8 @@ class JSONPathType(sqltypes.JSON.JSONPathType): super_proc = self.string_literal_processor(dialect) def process(value): - assert isinstance(value, util.collections_abc.Sequence) - tokens = [util.text_type(elem) for elem in value] + assert isinstance(value, collections_abc.Sequence) + tokens = [str(elem) for elem in value] value = "{%s}" % (", ".join(tokens)) if super_proc: value = super_proc(value) diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py index 324007e7e..ac29b28e9 100644 --- a/lib/sqlalchemy/dialects/postgresql/pg8000.py +++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py @@ -554,7 +554,7 @@ class PGDialect_pg8000(PGDialect): fns = [] def on_connect(conn): - conn.py_types[quoted_name] = conn.py_types[util.text_type] + conn.py_types[quoted_name] = conn.py_types[str] fns.append(on_connect) diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index f62830a0d..11a5f31a3 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -441,8 +441,7 @@ place within SQLAlchemy's own marshalling logic, and not that of ``psycopg2`` which may be more performant. """ # noqa -from __future__ import absolute_import - +import collections.abc as collections_abc import decimal import logging import re @@ -466,7 +465,6 @@ from ... import processors from ... import types as sqltypes from ... import util from ...engine import cursor as _cursor -from ...util import collections_abc logger = logging.getLogger("sqlalchemy.dialects.postgresql") |