Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on use_2to3 #661

Merged
merged 3 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 44 additions & 38 deletions IBM_DB/ibm_db/ibm_db_dbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@
import types, string, time, datetime, decimal, sys
import weakref

if sys.version_info >= (3, ):
PY2 = sys.version_info < (3, )

if not PY2:
buffer = memoryview
if sys.version_info < (3, ):
if PY2:
import exceptions
exception = exceptions.StandardError
exception = exceptions.Exception
else:
exception = Exception

try:
basestring # Python 2
long
except NameError:
basestring = str # Python 3
long = int
if PY2:
import __builtin__
string_types = __builtin__.unicode, bytes
int_types = __builtin__.long, int
else:
string_types = str
int_types = int

import ibm_db
__version__ = ibm_db.__version__
Expand Down Expand Up @@ -453,10 +456,10 @@ def _server_connect(dsn, user='', password='', host=''):
if dsn is None:
raise InterfaceError("dsn value should not be None")

if (not isinstance(dsn, basestring)) | \
(not isinstance(user, basestring)) | \
(not isinstance(password, basestring)) | \
(not isinstance(host, basestring)):
if (not isinstance(dsn, string_types)) | \
(not isinstance(user, string_types)) | \
(not isinstance(password, string_types)) | \
(not isinstance(host, string_types)):
raise InterfaceError("Arguments should be of type string or unicode")

# If the dsn does not contain port and protocal adding database
Expand Down Expand Up @@ -491,9 +494,9 @@ def createdb(database, dsn, user='', password='', host='', codeset='', mode=''):

if database is None:
raise InterfaceError("createdb expects a not None database name value")
if (not isinstance(database, basestring)) | \
(not isinstance(codeset, basestring)) | \
(not isinstance(mode, basestring)):
if (not isinstance(database, string_types)) | \
(not isinstance(codeset, string_types)) | \
(not isinstance(mode, string_types)):
raise InterfaceError("Arguments sould be string or unicode")

conn = _server_connect(dsn, user=user, password=password, host=host)
Expand All @@ -515,7 +518,7 @@ def dropdb(database, dsn, user='', password='', host=''):

if database is None:
raise InterfaceError("dropdb expects a not None database name value")
if (not isinstance(database, basestring)):
if (not isinstance(database, string_types)):
raise InterfaceError("Arguments sould be string or unicode")

conn = _server_connect(dsn, user=user, password=password, host=host)
Expand All @@ -537,9 +540,9 @@ def recreatedb(database, dsn, user='', password='', host='', codeset='', mode=''

if database is None:
raise InterfaceError("recreatedb expects a not None database name value")
if (not isinstance(database, basestring)) | \
(not isinstance(codeset, basestring)) | \
(not isinstance(mode, basestring)):
if (not isinstance(database, string_types)) | \
(not isinstance(codeset, string_types)) | \
(not isinstance(mode, string_types)):
raise InterfaceError("Arguments sould be string or unicode")

conn = _server_connect(dsn, user=user, password=password, host=host)
Expand All @@ -561,9 +564,9 @@ def createdbNX(database, dsn, user='', password='', host='', codeset='', mode=''

if database is None:
raise InterfaceError("createdbNX expects a not None database name value")
if (not isinstance(database, basestring)) | \
(not isinstance(codeset, basestring)) | \
(not isinstance(mode, basestring)):
if (not isinstance(database, string_types)) | \
(not isinstance(codeset, string_types)) | \
(not isinstance(mode, string_types)):
raise InterfaceError("Arguments sould be string or unicode")

conn = _server_connect(dsn, user=user, password=password, host=host)
Expand All @@ -587,11 +590,11 @@ def connect(dsn, user='', password='', host='', database='', conn_options=None):
if dsn is None:
raise InterfaceError("connect expects a not None dsn value")

if (not isinstance(dsn, basestring)) | \
(not isinstance(user, basestring)) | \
(not isinstance(password, basestring)) | \
(not isinstance(host, basestring)) | \
(not isinstance(database, basestring)):
if (not isinstance(dsn, string_types)) | \
(not isinstance(user, string_types)) | \
(not isinstance(password, string_types)) | \
(not isinstance(host, string_types)) | \
(not isinstance(database, string_types)):
raise InterfaceError("connect expects the first five arguments to"
" be of type string or unicode")
if conn_options is not None:
Expand Down Expand Up @@ -638,11 +641,11 @@ def pconnect(dsn, user='', password='', host='', database='', conn_options=None)
if dsn is None:
raise InterfaceError("connect expects a not None dsn value")

if (not isinstance(dsn, basestring)) | \
(not isinstance(user, basestring)) | \
(not isinstance(password, basestring)) | \
(not isinstance(host, basestring)) | \
(not isinstance(database, basestring)):
if (not isinstance(dsn, string_types)) | \
(not isinstance(user, string_types)) | \
(not isinstance(password, string_types)) | \
(not isinstance(host, string_types)) | \
(not isinstance(database, string_types)):
raise InterfaceError("connect expects the first five arguments to"
" be of type string or unicode")
if conn_options is not None:
Expand Down Expand Up @@ -1137,12 +1140,15 @@ def __get_rowcount( self ):
def __iter__( self ):
return self

def next( self ):
def __next__( self ):
row = self.fetchone()
if row == None:
raise StopIteration
return row

if PY2:
next = __next__

# This attribute specifies the number of rows the last executeXXX()
# produced or affected. It is a read only attribute.
rowcount = property(__get_rowcount, None, None, "")
Expand Down Expand Up @@ -1238,7 +1244,7 @@ def callproc(self, procname, parameters=None):

"""
self.messages = []
if not isinstance(procname, basestring):
if not isinstance(procname, string_types):
self.messages.append(InterfaceError("callproc expects the first argument to be of type String or Unicode."))
raise self.messages[len(self.messages) - 1]
if parameters is not None:
Expand Down Expand Up @@ -1390,7 +1396,7 @@ def execute(self, operation, parameters=None):
the SQL statement as arguments.
"""
self.messages = []
if not isinstance(operation, basestring):
if not isinstance(operation, string_types):
self.messages.append(InterfaceError("execute expects the first argument [%s] to be of type String or Unicode." % operation ))
raise self.messages[len(self.messages) - 1]
if parameters is not None:
Expand All @@ -1412,7 +1418,7 @@ def executemany(self, operation, seq_parameters):
parameter markers in the SQL statement as its argument.
"""
self.messages = []
if not isinstance(operation, basestring):
if not isinstance(operation, string_types):
self.messages.append(InterfaceError("executemany expects the first argument to be of type String or Unicode."))
raise self.messages[len(self.messages) - 1]
if seq_parameters is None:
Expand Down Expand Up @@ -1517,7 +1523,7 @@ def fetchmany(self, size=0):
It takes the number of rows to fetch as an argument. If this
is not provided it fetches self.arraysize number of rows.
"""
if not isinstance(size, (int, long)):
if not isinstance(size, int_types):
self.messages.append(InterfaceError( "fetchmany expects argument type int or long."))
raise self.messages[len(self.messages) - 1]
if size == 0:
Expand Down
3 changes: 1 addition & 2 deletions IBM_DB/ibm_db/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[build-system]
# pin to Setuptools prior to 58 for use_2to3 support
requires = ["setuptools<58"]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
7 changes: 1 addition & 6 deletions IBM_DB/ibm_db/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from io import BytesIO
else:
import urllib2 as request
from cStringIO import StringIO as BytesIO
from io import StringIO as BytesIO

from setuptools import setup, find_packages, Extension
from distutils.sysconfig import get_python_lib
Expand Down Expand Up @@ -365,10 +365,6 @@ def _setDllPath():
else:
ext_modules = _ext_modules(ibm_db_include, library, ibm_db_lib)

extra = {}
if sys.version_info >= (3, ):
extra['use_2to3'] = True

setup( name = PACKAGE,
version = VERSION,
license = LICENSE,
Expand Down Expand Up @@ -405,7 +401,6 @@ def _setDllPath():
data_files = data_files,
include_package_data = True,
cmdclass = cmd_class,
**extra
)

if license_agreement:
Expand Down
5 changes: 1 addition & 4 deletions IBM_DB/ibm_db/testfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

import ibm_db
import config
if sys.version_info >=(3,3 ):
from io import StringIO
else:
from StringIO import StringIO
from io import StringIO

class IbmDbTestFunctions(unittest.TestCase):
prepconn = ibm_db.connect(config.database, config.user, config.password)
Expand Down