From 61aa43e7805a6584481561965bc1da22cf0f4533 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 28 Mar 2024 14:16:48 -0400 Subject: [PATCH] adodbapi: Remove references to outdated IronPython (#2049) --- adodbapi/adodbapi.py | 93 ++++++----------------------- adodbapi/apibase.py | 29 +-------- adodbapi/is64bit.py | 12 +--- adodbapi/quick_reference.md | 6 +- adodbapi/readme.txt | 13 ++-- adodbapi/remote.py | 4 -- adodbapi/remote/server.py | 1 - adodbapi/setup.py | 1 - adodbapi/test/adodbapitest.py | 15 +---- adodbapi/test/is64bit.py | 12 +--- adodbapi/test/setuptestframework.py | 39 +++--------- 11 files changed, 42 insertions(+), 183 deletions(-) diff --git a/adodbapi/adodbapi.py b/adodbapi/adodbapi.py index 1dcca42c1f..7d38754db1 100644 --- a/adodbapi/adodbapi.py +++ b/adodbapi/adodbapi.py @@ -24,8 +24,7 @@ DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/ This module source should run correctly in CPython versions 2.7 and later, -or IronPython version 2.7 and later, -or, after running through 2to3.py, CPython 3.4 or later. +or CPython 3.4 or later. """ __version__ = "2.6.2.0" @@ -46,47 +45,18 @@ if verbose: print(version) -# --- define objects to smooth out IronPython <-> CPython differences -onWin32 = False # assume the worst -if api.onIronPython: - from clr import Reference - from System import ( - Activator, - Array, - Byte, - DateTime, - DBNull, - Decimal as SystemDecimal, - Type, - ) - - def Dispatch(dispatch): - type = Type.GetTypeFromProgID(dispatch) - return Activator.CreateInstance(type) - - def getIndexedValue(obj, index): - return obj.Item[index] - -else: # try pywin32 - try: - import pythoncom - import pywintypes - import win32com.client - - onWin32 = True +try: + import pythoncom + import pywintypes + from win32com.client import Dispatch +except ImportError: + import warnings - def Dispatch(dispatch): - return win32com.client.Dispatch(dispatch) + warnings.warn("pywin32 package required for adodbapi.", ImportWarning) - except ImportError: - import warnings - warnings.warn( - "pywin32 package (or IronPython) required for adodbapi.", ImportWarning - ) - - def getIndexedValue(obj, index): - return obj(index) +def getIndexedValue(obj, index): + return obj(index) from collections.abc import Mapping @@ -101,8 +71,7 @@ def getIndexedValue(obj, index): # ----------------- The .connect method ----------------- def make_COM_connecter(): try: - if onWin32: - pythoncom.CoInitialize() # v2.1 Paj + pythoncom.CoInitialize() # v2.1 Paj c = Dispatch("ADODB.Connection") # connect _after_ CoIninialize v2.1.1 adamvan except: raise api.InterfaceError( @@ -210,12 +179,7 @@ def _configure_parameter(p, value, adotype, settings_known): p.Size = L # v2.1 Jevon elif isinstance(value, decimal.Decimal): - if api.onIronPython: - s = str(value) - p.Value = s - p.Size = len(s) - else: - p.Value = value + p.Value = value exponent = value.as_tuple()[2] digit_count = len(value.as_tuple()[1]) p.Precision = digit_count @@ -238,10 +202,6 @@ def _configure_parameter(p, value, adotype, settings_known): p.Value = s p.Size = len(s) - elif api.onIronPython and isinstance(value, longType): # Iron Python Long - s = str(value) # feature workaround for IPy 2.0 - p.Value = s - elif adotype == adc.adEmpty: # ADO will not let you specify a null column p.Type = ( adc.adInteger @@ -653,7 +613,7 @@ def build_column_info(self, recordset): self.numberOfColumns = 0 return self.rs = recordset # v2.1.1 bkline - self.recordset_format = api.RS_ARRAY if api.onIronPython else api.RS_WIN_32 + self.recordset_format = api.RS_WIN_32 self.numberOfColumns = recordset.Fields.Count try: varCon = self.connection.variantConversions @@ -790,12 +750,7 @@ def _execute_command(self): print('Executing command="%s"' % self.commandText) try: # ----- the actual SQL is executed here --- - if api.onIronPython: - ra = Reference[int]() - recordset = self.cmd.Execute(ra) - count = ra.Value - else: # pywin32 - recordset, count = self.cmd.Execute() + recordset, count = self.cmd.Execute() # ----- ------------------------------- --- except Exception as e: _message = "" @@ -1180,21 +1135,11 @@ def nextset(self): ) return None - if api.onIronPython: - try: - recordset = self.rs.NextRecordset() - except TypeError: - recordset = None - except api.Error as exc: - self._raiseCursorError(api.NotSupportedError, exc.args) - else: # pywin32 - try: # [begin 2.1 ekelund] - rsTuple = self.rs.NextRecordset() # - except pywintypes.com_error as exc: # return appropriate error - self._raiseCursorError( - api.NotSupportedError, exc.args - ) # [end 2.1 ekelund] - recordset = rsTuple[0] + try: # [begin 2.1 ekelund] + rsTuple = self.rs.NextRecordset() # + except pywintypes.com_error as exc: # return appropriate error + self._raiseCursorError(api.NotSupportedError, exc.args) # [end 2.1 ekelund] + recordset = rsTuple[0] if recordset is None: return None self.build_column_info(recordset) diff --git a/adodbapi/apibase.py b/adodbapi/apibase.py index 19ae54814e..e663631e58 100644 --- a/adodbapi/apibase.py +++ b/adodbapi/apibase.py @@ -16,16 +16,6 @@ verbose = False # debugging flag -onIronPython = sys.platform == "cli" -if onIronPython: # we need type definitions for odd data we may need to convert - # noinspection PyUnresolvedReferences - from System import DateTime, DBNull - - NullTypes = (type(None), DBNull) -else: - DateTime = type(NotImplemented) # should never be seen on win32 - NullTypes = type(None) - # --- define objects to smooth out Python3 <-> Python 2 differences unicodeType = str longType = int @@ -34,7 +24,7 @@ memoryViewType = memoryview _BaseException = Exception -try: # jdhardy -- handle bytes under IronPython & Py3 +try: # jdhardy -- handle bytes under Py3 bytes except NameError: bytes = str # define it for old Pythons @@ -284,8 +274,6 @@ def DateObjectFromCOMDate(self, comDate): new = datetime.datetime.combine(datetime.datetime.fromordinal(odn), tim) return new # return comDate.replace(tzinfo=None) # make non aware - elif isinstance(comDate, DateTime): - fComDate = comDate.ToOADate() # ironPython clr Date/Time else: fComDate = float(comDate) # ComDate is number of days since 1899-12-31 integerPart = int(fComDate) @@ -317,8 +305,6 @@ def DateObjectFromCOMDate(self, comDate): "Returns ticks since 1970" if isinstance(comDate, datetime.datetime): return comDate.timetuple() - elif isinstance(comDate, DateTime): # ironPython clr date/time - fcomDate = comDate.ToOADate() else: fcomDate = float(comDate) secondsperday = 86400 # 24*60*60 @@ -469,11 +455,6 @@ def variantConvertDate(v): def cvtString(variant): # use to get old action of adodbapi v1 if desired - if onIronPython: - try: - return variant.ToString() - except: - pass return str(variant) @@ -523,17 +504,11 @@ def identity(x): def cvtUnusual(variant): if verbose > 1: sys.stderr.write("Conversion called for Unusual data=%s\n" % repr(variant)) - if isinstance(variant, DateTime): # COMdate or System.Date - from .adodbapi import ( # this will only be called when adodbapi is in use, and very rarely - dateconverter, - ) - - return dateconverter.DateObjectFromCOMDate(variant) return variant # cannot find conversion function -- just give the data to the user def convert_to_python(variant, func): # convert DB value into Python value - if isinstance(variant, NullTypes): # IronPython Null or None + if variant is None: return None return func(variant) # call the appropriate conversion function diff --git a/adodbapi/is64bit.py b/adodbapi/is64bit.py index 36a8c63e48..dd061ef555 100644 --- a/adodbapi/is64bit.py +++ b/adodbapi/is64bit.py @@ -4,22 +4,14 @@ def Python(): - if sys.platform == "cli": # IronPython - import System - - return System.IntPtr.Size == 8 - else: - try: - return sys.maxsize > 2147483647 - except AttributeError: - return sys.maxint > 2147483647 + return sys.maxsize > 2147483647 def os(): import platform pm = platform.machine() - if pm != ".." and pm.endswith("64"): # recent Python (not Iron) + if pm != ".." and pm.endswith("64"): # recent 64 bit Python return True else: import os diff --git a/adodbapi/quick_reference.md b/adodbapi/quick_reference.md index 7c9d471075..25952bfde9 100644 --- a/adodbapi/quick_reference.md +++ b/adodbapi/quick_reference.md @@ -2,10 +2,8 @@ Adodbapi quick reference ======================== -Adodbapi is a Python DB-API 2.0 module that makes it easy to use -Microsoft ADO -for connecting with databases and other data sources -using either CPython or IronPython. +Adodbapi is a Python DB-API 2.0 module that makes it easy to use Microsoft ADO +for connecting with databases and other data sources using CPython. Source home page: diff --git a/adodbapi/readme.txt b/adodbapi/readme.txt index 02bb620f4d..9044d7a8f1 100644 --- a/adodbapi/readme.txt +++ b/adodbapi/readme.txt @@ -3,15 +3,14 @@ Project adodbapi A Python DB-API 2.0 (PEP-249) module that makes it easy to use Microsoft ADO -for connecting with databases and other data sources -using either CPython or IronPython. +for connecting with databases and other data sources using CPython. Home page: Features: * 100% DB-API 2.0 (PEP-249) compliant (including most extensions and recommendations). * Includes pyunit testcases that describe how to use the module. -* Fully implemented in Python. -- runs in Python 2.5+ Python 3.0+ and IronPython 2.6+ +* Fully implemented in Python. -- runs in current versions of Python 3 * Licensed under the LGPL license, which means that it can be used freely even in commercial programs subject to certain restrictions. * The user can choose between paramstyles: 'qmark' 'named' 'format' 'pyformat' 'dynamic' * Supports data retrieval by column name e.g.: @@ -20,16 +19,12 @@ Features: * Supports user-definable system-to-Python data conversion functions (selected by ADO data type, or by column) Prerequisites: -* C Python 2.7 or 3.5 or higher +* C Python 3.6 or higher and pywin32 (Mark Hammond's python for windows extensions.) -or - Iron Python 2.7 or higher. (works in IPy2.0 for all data types except BUFFER) Installation: * (C-Python on Windows): Install pywin32 ("pip install pywin32") which includes adodbapi. * (IronPython on Windows): Download adodbapi from http://sf.net/projects/adodbapi. Unpack the zip. - Open a command window as an administrator. CD to the folder containing the unzipped files. - Run "setup.py install" using the IronPython of your choice. NOTE: ........... If you do not like the new default operation of returning Numeric columns as decimal.Decimal, @@ -87,6 +82,6 @@ and look at the test cases in adodbapi/test directory. Mailing lists ------------- The adodbapi mailing lists have been deactivated. Submit comments to the -pywin32 or IronPython mailing lists. +pywin32 mailing lists. -- the bug tracker on sourceforge.net/projects/adodbapi may be checked, (infrequently). -- please use: https://github.com/mhammond/pywin32/issues diff --git a/adodbapi/remote.py b/adodbapi/remote.py index 910c6b49a6..bf6ab13a54 100644 --- a/adodbapi/remote.py +++ b/adodbapi/remote.py @@ -21,10 +21,6 @@ django adaptations and refactoring thanks to Adam Vandenberg DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/ - -This module source should run correctly in CPython versions 2.5 and later, -or IronPython version 2.7 and later, -or, after running through 2to3.py, CPython 3.0 or later. """ __version__ = "2.6.0.4" diff --git a/adodbapi/remote/server.py b/adodbapi/remote/server.py index bfba3a7473..9ac532d629 100644 --- a/adodbapi/remote/server.py +++ b/adodbapi/remote/server.py @@ -20,7 +20,6 @@ DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/ This module source should run correctly in CPython versions 2.6 and later, -or IronPython version 2.6 and later, or, after running through 2to3.py, CPython 3.2 or later. """ diff --git a/adodbapi/setup.py b/adodbapi/setup.py index 51c999e5b4..7d08a22a4c 100644 --- a/adodbapi/setup.py +++ b/adodbapi/setup.py @@ -1,7 +1,6 @@ """adodbapi -- a pure Python PEP 249 DB-API package using Microsoft ADO Adodbapi can be run on CPython 3.5 and later. -or IronPython version 2.6 and later (in theory, possibly no longer in practice!) """ CLASSIFIERS = """\ diff --git a/adodbapi/test/adodbapitest.py b/adodbapi/test/adodbapitest.py index a5d4fce867..d049e173ea 100644 --- a/adodbapi/test/adodbapitest.py +++ b/adodbapi/test/adodbapitest.py @@ -30,18 +30,9 @@ import sys import unittest -try: - import win32com.client - - win32 = True -except ImportError: - win32 = False - -# run the configuration module. -import adodbapitestconfig as config # will set sys.path to find correct version of adodbapi - -# in our code below, all our switches are from config.whatever -import tryconnection +import adodbapitestconfig as config # run the configuration module. # will set sys.path to find correct version of adodbapi +import tryconnection # in our code below, all our switches are from config.whatever +import win32com.client import adodbapi import adodbapi.apibase as api diff --git a/adodbapi/test/is64bit.py b/adodbapi/test/is64bit.py index 33d0244302..16a53e2e5b 100644 --- a/adodbapi/test/is64bit.py +++ b/adodbapi/test/is64bit.py @@ -4,22 +4,14 @@ def Python(): - if sys.platform == "cli": # IronPython - import System - - return System.IntPtr.Size == 8 - else: - try: - return sys.maxsize > 2147483647 - except AttributeError: - return sys.maxint > 2147483647 + return sys.maxsize > 2147483647 def os(): import platform pm = platform.machine() - if pm != ".." and pm.endswith("64"): # recent Python (not Iron) + if pm != ".." and pm.endswith("64"): # recent 64 bit Python return True else: import os diff --git a/adodbapi/test/setuptestframework.py b/adodbapi/test/setuptestframework.py index 83fe5ca9db..91c46e0889 100644 --- a/adodbapi/test/setuptestframework.py +++ b/adodbapi/test/setuptestframework.py @@ -6,11 +6,6 @@ import sys import tempfile -try: - OSErrors = (WindowsError, OSError) -except NameError: # not running on Windows - OSErrors = OSError - def maketemp(): temphome = tempfile.gettempdir() @@ -52,7 +47,7 @@ def makeadopackage(testfolder): newpackage = os.path.join(testfolder, "adodbapi") try: os.mkdir(newpackage) - except OSErrors: + except (WindowsError, OSError): print( "*Note: temporary adodbapi package already exists: may be two versions running?" ) @@ -80,41 +75,23 @@ def makemdb(testfolder, mdb_name): if os.path.isfile(_accessdatasource): print("using JET database=", _accessdatasource) else: - try: - from win32com.client import constants - from win32com.client.gencache import EnsureDispatch - - win32 = True - except ImportError: # perhaps we are running IronPython - win32 = False # iron Python - try: - from System import Activator, Type - except: - pass + from win32com.client import constants + from win32com.client.gencache import EnsureDispatch # Create a brand-new database - what is the story with these? dbe = None for suffix in (".36", ".35", ".30"): try: - if win32: - dbe = EnsureDispatch("DAO.DBEngine" + suffix) - else: - type = Type.GetTypeFromProgID("DAO.DBEngine" + suffix) - dbe = Activator.CreateInstance(type) + dbe = EnsureDispatch("DAO.DBEngine" + suffix) break except: pass if dbe: print(" ...Creating ACCESS db at " + _accessdatasource) - if win32: - workspace = dbe.Workspaces(0) - newdb = workspace.CreateDatabase( - _accessdatasource, constants.dbLangGeneral, constants.dbVersion40 - ) - else: - newdb = dbe.CreateDatabase( - _accessdatasource, ";LANGID=0x0409;CP=1252;COUNTRY=0" - ) + workspace = dbe.Workspaces(0) + newdb = workspace.CreateDatabase( + _accessdatasource, constants.dbLangGeneral, constants.dbVersion40 + ) newdb.Close() else: print(" ...copying test ACCESS db to " + _accessdatasource)