summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/postgresql
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-11-02 20:51:28 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-11-02 20:51:28 +0000
commit72780bae3377c45abb03cb62b638b84ed04375e2 (patch)
treebf09b8f26fae7e797a2aeb9fc67babd1dd91da7e /lib/sqlalchemy/dialects/postgresql
parentfc5c54fcd4d868c2a4c7ac19668d72f506fe821e (diff)
parent36e7aebd8d6faac77570403e99f9aa7b2330fa59 (diff)
downloadsqlalchemy-72780bae3377c45abb03cb62b638b84ed04375e2.tar.gz
Merge "First round of removal of python 2" into main
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-rw-r--r--lib/sqlalchemy/dialects/postgresql/hstore.py42
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2.py42
2 files changed, 11 insertions, 73 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py
index a4090f1ac..85d678ef5 100644
--- a/lib/sqlalchemy/dialects/postgresql/hstore.py
+++ b/lib/sqlalchemy/dialects/postgresql/hstore.py
@@ -228,42 +228,20 @@ class HSTORE(sqltypes.Indexable, sqltypes.Concatenable, sqltypes.TypeEngine):
comparator_factory = Comparator
def bind_processor(self, dialect):
- if util.py2k:
- encoding = dialect.encoding
-
- def process(value):
- if isinstance(value, dict):
- return _serialize_hstore(value).encode(encoding)
- else:
- return value
-
- else:
-
- def process(value):
- if isinstance(value, dict):
- return _serialize_hstore(value)
- else:
- return value
+ def process(value):
+ if isinstance(value, dict):
+ return _serialize_hstore(value)
+ else:
+ return value
return process
def result_processor(self, dialect, coltype):
- if util.py2k:
- encoding = dialect.encoding
-
- def process(value):
- if value is not None:
- return _parse_hstore(value.decode(encoding))
- else:
- return value
-
- else:
-
- def process(value):
- if value is not None:
- return _parse_hstore(value)
- else:
- return value
+ def process(value):
+ if value is not None:
+ return _parse_hstore(value)
+ else:
+ return value
return process
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
index 7512ab9b5..162ddde94 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
@@ -478,7 +478,6 @@ from .base import _ColonCast
from .base import _DECIMAL_TYPES
from .base import _FLOAT_TYPES
from .base import _INT_TYPES
-from .base import ENUM
from .base import PGCompiler
from .base import PGDialect
from .base import PGExecutionContext
@@ -527,22 +526,6 @@ class _PGNumeric(sqltypes.Numeric):
)
-class _PGEnum(ENUM):
- def result_processor(self, dialect, coltype):
- if util.py2k and self._expect_unicode is True:
- # for py2k, if the enum type needs unicode data (which is set up as
- # part of the Enum() constructor based on values passed as py2k
- # unicode objects) we have to use our own converters since
- # psycopg2's don't work, a rare exception to the "modern DBAPIs
- # support unicode everywhere" theme of deprecating
- # convert_unicode=True. Use the special "force_nocheck" directive
- # which forces unicode conversion to happen on the Python side
- # without an isinstance() check. in py3k psycopg2 does the right
- # thing automatically.
- self._expect_unicode = "force_nocheck"
- return super(_PGEnum, self).result_processor(dialect, coltype)
-
-
class _PGHStore(HSTORE):
def bind_processor(self, dialect):
if dialect._has_native_hstore:
@@ -664,16 +647,6 @@ class PGDialect_psycopg2(PGDialect):
driver = "psycopg2"
supports_statement_cache = True
-
- if util.py2k:
- # turn off supports_unicode_statements for Python 2. psycopg2 supports
- # unicode statements in Py2K. But! it does not support unicode *bound
- # parameter names* because it uses the Python "%" operator to
- # interpolate these into the string, and this fails. So for Py2K, we
- # have to use full-on encoding for statements and parameters before
- # passing to cursor.execute().
- supports_unicode_statements = False
-
supports_server_side_cursors = True
default_paramstyle = "pyformat"
@@ -694,8 +667,6 @@ class PGDialect_psycopg2(PGDialect):
PGDialect.colspecs,
{
sqltypes.Numeric: _PGNumeric,
- ENUM: _PGEnum, # needs force_unicode
- sqltypes.Enum: _PGEnum, # needs force_unicode
HSTORE: _PGHStore,
JSON: _PGJSON,
sqltypes.JSON: _PGJSON,
@@ -718,7 +689,7 @@ class PGDialect_psycopg2(PGDialect):
):
PGDialect.__init__(self, **kwargs)
self.use_native_unicode = use_native_unicode
- if not use_native_unicode and not util.py2k:
+ if not use_native_unicode:
raise exc.ArgumentError(
"psycopg2 native_unicode mode is required under Python 3"
)
@@ -854,7 +825,6 @@ class PGDialect_psycopg2(PGDialect):
def on_connect(self):
extras = self._psycopg2_extras
- extensions = self._psycopg2_extensions
fns = []
if self.client_encoding is not None:
@@ -878,14 +848,6 @@ class PGDialect_psycopg2(PGDialect):
fns.append(on_connect)
- if util.py2k and self.dbapi and self.use_native_unicode:
-
- def on_connect(conn):
- extensions.register_type(extensions.UNICODE, conn)
- extensions.register_type(extensions.UNICODEARRAY, conn)
-
- fns.append(on_connect)
-
if self.dbapi and self.use_native_hstore:
def on_connect(conn):
@@ -893,8 +855,6 @@ class PGDialect_psycopg2(PGDialect):
if hstore_oids is not None:
oid, array_oid = hstore_oids
kw = {"oid": oid}
- if util.py2k:
- kw["unicode"] = True
kw["array_oid"] = array_oid
extras.register_hstore(conn, **kw)