Skip to content

Commit d91f3a1

Browse files
committed
adodbapi: Cleanup obsolete and unsupported python code
1 parent dde12b8 commit d91f3a1

9 files changed

Lines changed: 76 additions & 133 deletions

adodbapi/adodbapi.py

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,18 @@
2323
2424
DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/
2525
26-
This module source should run correctly in CPython versions 2.7 and later,
27-
or CPython 3.4 or later.
26+
This module source should run correctly in CPython 3.4 or later.
2827
"""
2928

30-
__version__ = "2.6.2.0"
31-
version = "adodbapi v" + __version__
32-
3329
import copy
3430
import decimal
3531
import os
3632
import sys
3733
import weakref
34+
from collections.abc import Mapping
3835

3936
from . import ado_consts as adc, apibase as api, process_connect_string
4037

41-
try:
42-
verbose = int(os.environ["ADODBAPI_VERBOSE"])
43-
except:
44-
verbose = False
45-
if verbose:
46-
print(version)
47-
4838
try:
4939
import pythoncom
5040
import pywintypes
@@ -54,12 +44,15 @@
5444

5545
warnings.warn("pywin32 package required for adodbapi.", ImportWarning)
5646

47+
__version__ = "3.7.0.0"
48+
version = "adodbapi v" + __version__
5749

58-
def getIndexedValue(obj, index):
59-
return obj(index)
60-
61-
62-
from collections.abc import Mapping
50+
try:
51+
verbose = int(os.environ["ADODBAPI_VERBOSE"])
52+
except:
53+
verbose = False
54+
if verbose:
55+
print(version)
6356

6457

6558
# ----------------- The .connect method -----------------
@@ -271,15 +264,13 @@ def connect(self, kwargs, connection_maker=make_COM_connecter):
271264
)
272265

273266
try: # Stefan Fuchs; support WINCCOLEDBProvider
274-
if getIndexedValue(self.connector.Properties, "Transaction DDL").Value != 0:
267+
if self.connector.Properties("Transaction DDL").Value != 0:
275268
self.supportsTransactions = True
276269
except pywintypes.com_error:
277270
pass # Stefan Fuchs
278-
self.dbms_name = getIndexedValue(self.connector.Properties, "DBMS Name").Value
271+
self.dbms_name = self.connector.Properties("DBMS Name").Value
279272
try: # Stefan Fuchs
280-
self.dbms_version = getIndexedValue(
281-
self.connector.Properties, "DBMS Version"
282-
).Value
273+
self.dbms_version = self.connector.Properties("DBMS Version").Value
283274
except pywintypes.com_error:
284275
pass # Stefan Fuchs
285276
self.connector.CursorLocation = defaultCursorLocation # v2.1 Rose
@@ -511,7 +502,7 @@ def get_table_names(self):
511502

512503
tables = []
513504
while not schema.EOF:
514-
name = getIndexedValue(schema.Fields, "TABLE_NAME").Value
505+
name = schema.Fields("TABLE_NAME").Value
515506
tables.append(name)
516507
schema.MoveNext()
517508
del schema
@@ -614,7 +605,7 @@ def build_column_info(self, recordset):
614605
except AttributeError:
615606
varCon = api.variantConversions
616607
for i in range(self.numberOfColumns):
617-
f = getIndexedValue(self.rs.Fields, i)
608+
f = self.rs.Fields(i)
618609
try:
619610
self.converters.append(
620611
varCon[f.Type]
@@ -632,7 +623,7 @@ def _makeDescriptionFromRS(self):
632623
return
633624
desc = []
634625
for i in range(self.numberOfColumns):
635-
f = getIndexedValue(self.rs.Fields, i)
626+
f = self.rs.Fields(i)
636627
if self.rs.EOF or self.rs.BOF:
637628
display_size = None
638629
else:
@@ -873,7 +864,7 @@ def _buildADOparameterList(self, parameters, sproc=False):
873864
if parameters_known: # use ado parameter list
874865
if self._parameter_names: # named parameters
875866
for i, pm_name in enumerate(self._parameter_names):
876-
p = getIndexedValue(self.cmd.Parameters, i)
867+
p = self.cmd.Parameters(i)
877868
try:
878869
_configure_parameter(
879870
p, parameters[pm_name], p.Type, parameters_known
@@ -893,12 +884,12 @@ def _buildADOparameterList(self, parameters, sproc=False):
893884
)
894885
else: # regular sequence of parameters
895886
for value in parameters:
896-
p = getIndexedValue(self.cmd.Parameters, i)
887+
p = self.cmd.Parameters(i)
897888
if (
898889
p.Direction == adc.adParamReturnValue
899890
): # this is an extra parameter added by ADO
900891
i += 1 # skip the extra
901-
p = getIndexedValue(self.cmd.Parameters, i)
892+
p = self.cmd.Parameters(i)
902893
try:
903894
_configure_parameter(p, value, p.Type, parameters_known)
904895
except Exception as e:

adodbapi/process_connect_string.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
""" a clumsy attempt at a macro language to let the programmer execute code on the server (ex: determine 64bit)"""
22

3+
import getpass
4+
import os
5+
import platform
6+
import tempfile
7+
38
from . import is64bit as is64bit
49

510

@@ -32,13 +37,9 @@ def macro_call(macro_name, args, kwargs):
3237
macro_name == "getuser"
3338
): # get the name of the user the server is logged in under
3439
if not new_key in kwargs:
35-
import getpass
36-
3740
return new_key, getpass.getuser()
3841

3942
elif macro_name == "getnode": # get the name of the computer running the server
40-
import platform
41-
4243
try:
4344
return new_key, args[1] % platform.node()
4445
except IndexError:
@@ -61,9 +62,6 @@ def macro_call(macro_name, args, kwargs):
6162
elif (
6263
macro_name == "find_temp_test_path"
6364
): # helper function for testing ado operation -- undocumented
64-
import os
65-
import tempfile
66-
6765
return new_key, os.path.join(
6866
tempfile.gettempdir(), "adodbapi_test", args[1]
6967
)

adodbapi/quick_reference.md

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,43 @@ access api specification is found at:
9999
The PEP requires several module level attributes. Older versions of
100100
adodbapi (which was once all one big file) defined a hundred or two. I
101101
hate that, but can\'t break old code, so I decided to fix the problem
102-
for Python 3. If using Python3 the programmer must take the time to pick
102+
for Python 3. The programmer must take the time to pick
103103
up the symbols she needs from apibase and ado\_consts.
104104

105105
Part of the adodbapi package\'s \_\_init\_\_.py looks something like
106106
this:
107107

108108
```python
109-
if sys.version_info < (3,0): # in Python 2, define all symbols, just like before
110-
from apibase import * # using this is bad
111-
from ado_consts import * # using this is worse
112-
else:
113-
# but if the user is running Python 3, then keep the dictionary clean
114-
from apibase import apilevel, threadsafety, paramstyle
115-
from apibase import Warning, Error, InterfaceError, DatabaseError, DataError
116-
from apibase import OperationalError, IntegrityError
117-
from apibase import InternalError, ProgrammingError, NotSupportedError
118-
from apibase import NUMBER, STRING, BINARY, DATETIME, ROWID
119-
120-
from adodbapi import connect, Connection, __version__
121-
version = 'adodbapi v' + __version__
109+
from .adodbapi import (
110+
Connection as Connection,
111+
Cursor as Cursor,
112+
__version__,
113+
connect as connect,
114+
dateconverter,
115+
)
116+
from .apibase import (
117+
BINARY as BINARY,
118+
DATETIME as DATETIME,
119+
NUMBER as NUMBER,
120+
ROWID as ROWID,
121+
STRING as STRING,
122+
DatabaseError as DatabaseError,
123+
DataError as DataError,
124+
Error as Error,
125+
FetchFailedError as FetchFailedError,
126+
IntegrityError as IntegrityError,
127+
InterfaceError as InterfaceError,
128+
InternalError as InternalError,
129+
NotSupportedError as NotSupportedError,
130+
OperationalError as OperationalError,
131+
ProgrammingError as ProgrammingError,
132+
Warning as Warning,
133+
apilevel as apilevel,
134+
paramstyle as paramstyle,
135+
threadsafety as threadsafety,
136+
)
137+
138+
version = "adodbapi v" + __version__
122139
```
123140

124141
Please, use only those last four symbols from adodbapi. All others
@@ -816,7 +833,7 @@ Running the tests
816833
The test folder contains a set of unittest programs. Setting them up can
817834
be a bit complex, because you need several database servers to do a
818835
complete test, and each one has a different configuration. Scripts in
819-
this folder try to work in Python 2.7 or Python 3.5(+)
836+
this folder try to work in Python 3.5(+)
820837

821838
- dbapi20.py
822839

@@ -846,9 +863,8 @@ the database servers are distant, this can take a while.
846863
It does some lightweight command line processing (actually the config
847864
does it).
848865

849-
"\--package" tries to build a proper Python package in a temporary
850-
location and adds it to sys.path so it can import a test version of the
851-
code. It will run 2to3 when it does this, if needed.
866+
"\--package" tries to build a proper Python package in a temporary location
867+
and adds it to sys.path so it can import a test version of the code.
852868

853869
"\--all" run as many of the 12 passes as possible.
854870

adodbapi/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242

4343
def setup_package():
44-
from setuptools.command.build_py import build_py
4544
from setuptools import setup
45+
from setuptools.command.build_py import build_py
4646

4747
setup(
4848
cmdclass={"build_py": build_py},

adodbapi/test/adodbapitest.py

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import decimal
2828
import random
2929
import string
30-
import sys
3130
import time
3231
import unittest
3332

@@ -189,49 +188,6 @@ def testUserDefinedConversions(self):
189188
pass
190189
self.helpRollbackTblTemp()
191190

192-
def testUserDefinedConversionForExactNumericTypes(self):
193-
# variantConversions is a dictionary of conversion functions
194-
# held internally in adodbapi.apibase
195-
#
196-
# !!! this test intentionally alters the value of what should be constant in the module
197-
# !!! no new code should use this example, to is only a test to see that the
198-
# !!! deprecated way of doing this still works. (use connection.variantConversions)
199-
#
200-
if sys.version_info < (3, 0): ### Py3 need different test
201-
oldconverter = adodbapi.variantConversions[
202-
ado_consts.adNumeric
203-
] # keep old function to restore later
204-
# By default decimal and "numbers" are returned as decimals.
205-
# Instead, make numbers return as floats
206-
try:
207-
adodbapi.variantConversions[ado_consts.adNumeric] = adodbapi.cvtFloat
208-
self.helpTestDataType(
209-
"decimal(18,2)", "NUMBER", 3.45, compareAlmostEqual=1
210-
)
211-
self.helpTestDataType(
212-
"numeric(18,2)", "NUMBER", 3.45, compareAlmostEqual=1
213-
)
214-
# now return strings
215-
adodbapi.variantConversions[ado_consts.adNumeric] = adodbapi.cvtString
216-
self.helpTestDataType("numeric(18,2)", "NUMBER", "3.45")
217-
# now a completly weird user defined convertion
218-
adodbapi.variantConversions[ado_consts.adNumeric] = (
219-
lambda x: "!!This function returns a funny unicode string %s!!" % x
220-
)
221-
self.helpTestDataType(
222-
"numeric(18,2)",
223-
"NUMBER",
224-
"3.45",
225-
allowedReturnValues=[
226-
"!!This function returns a funny unicode string 3.45!!"
227-
],
228-
)
229-
finally:
230-
# now reset the converter to its original function
231-
adodbapi.variantConversions[ado_consts.adNumeric] = (
232-
oldconverter # Restore the original convertion function
233-
)
234-
235191
def helpTestDataType(
236192
self,
237193
sqlDataTypeString,
@@ -432,7 +388,7 @@ def testDataTypeInt(self):
432388
"bigint",
433389
"NUMBER",
434390
3000000000,
435-
allowedReturnValues=[3000000000, int(3000000000)],
391+
allowedReturnValues=[3000000000, 3000000000],
436392
)
437393
self.helpTestDataType("int", "NUMBER", 2147483647)
438394

@@ -922,7 +878,7 @@ def testAutomaticParamstyle(self):
922878
'returned value:"%s" != test value:"%s"' % (rec[0], inParam),
923879
)
924880
self.assertEqual(rec[1], trouble)
925-
# inputs = [u'four',u'five',u'six']
881+
# inputs = ['four','five','six']
926882
fldId = 10
927883
for inParam in inputs:
928884
fldId += 1

adodbapi/test/adodbapitestconfig.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
if "--help" in sys.argv:
3333
print(
3434
"""Valid command-line switches are:
35-
--package - create a temporary test package, run 2to3 if needed.
35+
--package - create a temporary test package
3636
--all - run all possible tests
3737
--time - do time format test
3838
--nojet - do not test against an ACCESS database file
@@ -56,7 +56,7 @@
5656
testfolder = setuptestframework.maketemp()
5757

5858
if "--package" in sys.argv:
59-
# create a new adodbapi module -- running 2to3 if needed.
59+
# create a new adodbapi module
6060
pth = setuptestframework.makeadopackage(testfolder)
6161
else:
6262
# use the adodbapi module in which this file appears
@@ -66,14 +66,9 @@
6666
sys.path.insert(1, pth)
6767

6868
# function to clean up the temporary folder -- calling program must run this function before exit.
69-
cleanup = setuptestframework.getcleanupfunction()
70-
try:
71-
import adodbapi # will (hopefully) be imported using the "pth" discovered above
72-
except SyntaxError:
73-
print(
74-
'\n* * * Are you trying to run Python2 code using Python3? Re-run this test using the "--package" switch.'
75-
)
76-
sys.exit(11)
69+
cleanup = setuptestframework.cleanup_function
70+
import adodbapi # will (hopefully) be imported using the "pth" discovered above
71+
7772
try:
7873
print(adodbapi.version) # show version
7974
except:

adodbapi/test/dbapi20.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
-- Ian Bicking
1212
"""
1313

14-
__version__ = "$Revision: 1.15.0 $"[11:-2]
14+
__version__ = "$Revision: 1.16.0 $"[11:-2]
1515
__author__ = "Stuart Bishop <stuart@stuartbishop.net>"
1616

17-
import sys
1817
import time
1918
import unittest
2019

2120
# set this to "True" to follow API 2.0 to the letter
2221
TEST_FOR_NON_IDEMPOTENT_CLOSE = False
2322

23+
# Revision 1.16 2022/12/07 22:00:00 Avasam
24+
# Drop support for EOL Python 3.6 and below
25+
2426
# Revision 1.15 2019/11/22 00:50:00 kf7xm
2527
# Make Turn off IDEMPOTENT_CLOSE a proper skipTest
2628

@@ -199,12 +201,8 @@ def test_paramstyle(self):
199201
def test_Exceptions(self):
200202
# Make sure required exceptions exist, and are in the
201203
# defined heirarchy.
202-
if sys.version[0] == "3": # under Python 3 StardardError no longer exists
203-
self.assertTrue(issubclass(self.driver.Warning, Exception))
204-
self.assertTrue(issubclass(self.driver.Error, Exception))
205-
else:
206-
self.failUnless(issubclass(self.driver.Warning, Exception))
207-
self.failUnless(issubclass(self.driver.Error, Exception))
204+
self.assertTrue(issubclass(self.driver.Warning, Exception))
205+
self.assertTrue(issubclass(self.driver.Error, Exception))
208206

209207
self.assertTrue(issubclass(self.driver.InterfaceError, self.driver.Error))
210208
self.assertTrue(issubclass(self.driver.DatabaseError, self.driver.Error))

0 commit comments

Comments
 (0)