Skip to content

Commit f7d6b6a

Browse files
authored
adodbapi: Remove obsolete aliases (#2088)
1 parent 3ce363e commit f7d6b6a

7 files changed

Lines changed: 68 additions & 121 deletions

File tree

adodbapi/adodbapi.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,6 @@ def getIndexedValue(obj, index):
6161

6262
from collections.abc import Mapping
6363

64-
# --- define objects to smooth out Python3000 <-> Python 2 differences
65-
unicodeType = str
66-
longType = int
67-
StringTypes = str
68-
maxint = sys.maxsize
69-
7064

7165
# ----------------- The .connect method -----------------
7266
def make_COM_connecter():
@@ -167,7 +161,7 @@ def _configure_parameter(p, value, adotype, settings_known):
167161
p.Size = len(value)
168162
p.AppendChunk(value)
169163

170-
elif isinstance(value, StringTypes): # v2.1 Jevon
164+
elif isinstance(value, str): # v2.1 Jevon
171165
L = len(value)
172166
if adotype in api.adoStringTypes: # v2.2.1 Cole
173167
if settings_known:

adodbapi/apibase.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@
1616

1717
verbose = False # debugging flag
1818

19-
# --- define objects to smooth out Python3 <-> Python 2 differences
20-
unicodeType = str
21-
longType = int
22-
StringTypes = str
23-
makeByteBuffer = bytes
24-
memoryViewType = memoryview
25-
_BaseException = Exception
26-
27-
try: # jdhardy -- handle bytes under Py3
28-
bytes
29-
except NameError:
30-
bytes = str # define it for old Pythons
31-
3219

3320
# ------- Error handlers ------
3421
def standardErrorHandler(connection, cursor, errorclass, errorvalue):
@@ -45,8 +32,7 @@ def standardErrorHandler(connection, cursor, errorclass, errorvalue):
4532
raise errorclass(errorvalue)
4633

4734

48-
# Note: _BaseException is defined differently between Python 2 and 3
49-
class Error(_BaseException):
35+
class Error(Exception):
5036
pass # Exception that is the base class of all other error
5137
# exceptions. You can use this to catch all errors with one
5238
# single 'except' statement. Warnings are not considered
@@ -55,7 +41,7 @@ class Error(_BaseException):
5541
# module exceptions).
5642

5743

58-
class Warning(_BaseException):
44+
class Warning(Exception):
5945
pass
6046

6147

@@ -153,7 +139,7 @@ class FetchFailedError(OperationalError):
153139
#
154140
# def Binary(aString):
155141
# """This function constructs an object capable of holding a binary (long) string value. """
156-
# b = makeByteBuffer(aString)
142+
# b = bytes(aString)
157143
# return b
158144
# ----- Time converters ----------------------------------------------
159145
class TimeConverter: # this is a generic time converter skeleton
@@ -375,7 +361,7 @@ def __ne__(self, other):
375361

376362
# ------- utilities for translating python data types to ADO data types ---------------------------------
377363
typeMap = {
378-
memoryViewType: adc.adVarBinary,
364+
memoryview: adc.adVarBinary,
379365
float: adc.adDouble,
380366
type(None): adc.adEmpty,
381367
str: adc.adBSTR,
@@ -397,7 +383,7 @@ def pyTypeToADOType(d):
397383
if tp in dateconverter.types:
398384
return adc.adDate
399385
# otherwise, attempt to discern the type by probing the data object itself -- to handle duck typing
400-
if isinstance(d, StringTypes):
386+
if isinstance(d, str):
401387
return adc.adBSTR
402388
if isinstance(d, numbers.Integral):
403389
return adc.adBigInt

adodbapi/remote.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import adodbapi.process_connect_string
4545
from adodbapi.apibase import ProgrammingError
4646

47-
_BaseException = api._BaseException
48-
4947
sys.excepthook = Pyro4.util.excepthook
5048
Pyro4.config.PREFER_IP_VERSION = 0 # allow system to prefer IPv6
5149
Pyro4.config.COMMTIMEOUT = 40.0 # a bit longer than the default SQL server Gtimeout
@@ -58,16 +56,12 @@
5856
if verbose:
5957
print(version)
6058

61-
# --- define objects to smooth out Python3 <-> Python 2 differences
62-
unicodeType = str # this line will be altered by 2to3.py to '= str'
63-
longType = int # this line will be altered by 2to3.py to '= int'
64-
StringTypes = str
65-
makeByteBuffer = bytes
66-
memoryViewType = memoryview
6759

6860
# -----------------------------------------------------------
6961
# conversion functions mandated by PEP 249
70-
Binary = makeByteBuffer # override the function from apibase.py
62+
def Binary(aString):
63+
"""This function constructs an object capable of holding a binary (long) string value."""
64+
return bytes(aString)
7165

7266

7367
def Date(year, month, day):
@@ -164,7 +158,7 @@ def connect(*args, **kwargs): # --> a remote db-api connection object
164158
raise api.DatabaseError(
165159
"Pyro error creating connection to/thru=%s" % repr(kwargs)
166160
)
167-
except _BaseException as e:
161+
except Exception as e:
168162
raise api.DatabaseError(
169163
"Error creating remote connection to=%s, e=%s, %s"
170164
% (repr(kwargs), repr(e), sys.exc_info()[2])
@@ -364,7 +358,7 @@ def fixpickle(x):
364358
# for 'named' paramstyle user will pass a mapping
365359
newargs = {}
366360
for arg, val in list(x.items()):
367-
if isinstance(val, memoryViewType):
361+
if isinstance(val, memoryview):
368362
newval = array.array("B")
369363
newval.fromstring(val)
370364
newargs[arg] = newval
@@ -374,7 +368,7 @@ def fixpickle(x):
374368
# if not a mapping, then a sequence
375369
newargs = []
376370
for arg in x:
377-
if isinstance(arg, memoryViewType):
371+
if isinstance(arg, memoryview):
378372
newarg = array.array("B")
379373
newarg.fromstring(arg)
380374
newargs.append(newarg)
@@ -565,7 +559,7 @@ def callproc(self, procname, parameters=None):
565559
def fetchone(self):
566560
try:
567561
f1 = self.proxy.crsr_fetchone(self.id)
568-
except _BaseException as e:
562+
except Exception as e:
569563
self._raiseCursorError(api.DatabaseError, e)
570564
else:
571565
if f1 is None:

adodbapi/remote/server.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
import adodbapi.apibase as api
4848
import adodbapi.process_connect_string
4949

50-
makeByteBuffer = bytes
51-
_BaseException = Exception
52-
Binary = bytes
5350
try:
5451
pyro_host = os.environ["PYRO_HOST"]
5552
except:
@@ -63,25 +60,25 @@
6360
if arg.lower().startswith("host"):
6461
try:
6562
pyro_host = arg.split("=")[1]
66-
except _BaseException:
63+
except Exception:
6764
raise TypeError('Must supply value for argument="%s"' % arg)
6865

6966
if arg.lower().startswith("port"):
7067
try:
7168
pyro_port = int(arg.split("=")[1])
72-
except _BaseException:
69+
except Exception:
7370
raise TypeError('Must supply numeric value for argument="%s"' % arg)
7471

7572
if arg.lower().startswith("timeout"):
7673
try:
7774
PYRO_COMMTIMEOUT = int(arg.split("=")[1])
78-
except _BaseException:
75+
except Exception:
7976
raise TypeError('Must supply numeric value for argument="%s"' % arg)
8077

8178
if arg.lower().startswith("--verbose"):
8279
try:
8380
verbose = int(arg.split("=")[1])
84-
except _BaseException:
81+
except Exception:
8582
raise TypeError('Must supply numeric value for argument="%s"' % arg)
8683
adodbapi.adodbapi.verbose = verbose
8784
else:
@@ -118,15 +115,15 @@ def unfixpickle(x):
118115
newargs = {}
119116
for arg, val in list(x.items()):
120117
if isinstance(arg, array.array):
121-
newargs[arg] = Binary(val)
118+
newargs[arg] = bytes(val)
122119
else:
123120
newargs[arg] = val
124121
return newargs
125122
# if not a mapping, then a sequence
126123
newargs = []
127124
for arg in x:
128125
if isinstance(arg, array.array):
129-
newargs.append(Binary(arg))
126+
newargs.append(bytes(arg))
130127
else:
131128
newargs.append(arg)
132129
return newargs

adodbapi/test/adodbapitest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
from adodbapi import ado_consts
4848

4949

50-
long = int
51-
52-
5350
def randomstring(length):
5451
return "".join([random.choice(string.ascii_letters) for n in range(32)])
5552

0 commit comments

Comments
 (0)