Remove old Python 2 compatibility code. Fixes #5700

This commit is contained in:
Cyril Jouve
2020-07-27 11:03:13 +01:00
committed by Dave Page
parent 7a22cff28c
commit f93cfe8c4c
197 changed files with 47 additions and 354 deletions

View File

@@ -366,13 +366,6 @@ class Driver(BaseDriver):
if len(val) == 0:
continue
if hasattr(str, 'decode') and not isinstance(val, unicode):
# Handling for python2
try:
val = str(val).encode('utf-8')
except UnicodeDecodeError:
# If already unicode, most likely coming from db
val = str(val).decode('utf-8')
value = val
if Driver.needsQuoting(val, True):
@@ -398,14 +391,6 @@ class Driver(BaseDriver):
if not hasattr(val, '__len__'):
val = str(val)
if hasattr(str, 'decode') and not isinstance(val, unicode):
# Handling for python2
try:
val = str(val).encode('utf-8')
except UnicodeDecodeError:
# If already unicode, most likely coming from db
val = str(val).decode('utf-8')
if len(val) == 0:
continue

View File

@@ -15,7 +15,6 @@ object.
import random
import select
import six
import datetime
from collections import deque
import psycopg2
@@ -628,7 +627,7 @@ WHERE
# "unicode_escape" will convert single backslash to double
# backslash, so we will have to replace/revert them again
# to store the correct value into the database.
if isinstance(val, six.string_types):
if isinstance(val, str):
modified_val = val.encode('unicode_escape')\
.decode('raw_unicode_escape')\
.replace("\\\\", "\\")

View File

@@ -175,9 +175,6 @@ class ServerManager(object):
async_=None, use_binary_placeholder=False, array_to_string=False
):
if database is not None:
if hasattr(str, 'decode') and \
not isinstance(database, unicode):
database = database.decode('utf-8')
if did is not None and did in self.db_info:
self.db_info[did]['datname'] = database
else: