Skip to content

Commit

Permalink
adodbapi: Remove references to outdated IronPython (#2049)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam authored Mar 28, 2024
1 parent 493aba1 commit 61aa43e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 183 deletions.
93 changes: 19 additions & 74 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 2 additions & 27 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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

Expand Down
12 changes: 2 additions & 10 deletions adodbapi/is64bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions adodbapi/quick_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
<https://github.com/mhammond/pywin32/tree/master/adodbapi>
Expand Down
13 changes: 4 additions & 9 deletions adodbapi/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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: <http://sourceforge.net/projects/adodbapi>

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.:
Expand All @@ -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,
Expand Down Expand Up @@ -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
4 changes: 0 additions & 4 deletions adodbapi/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion adodbapi/remote/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down
1 change: 0 additions & 1 deletion adodbapi/setup.py
Original file line number Diff line number Diff line change
@@ -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 = """\
Expand Down
15 changes: 3 additions & 12 deletions adodbapi/test/adodbapitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions adodbapi/test/is64bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 61aa43e

Please sign in to comment.