Skip to content

Commit

Permalink
Some manual post-2to3 cleanups of adodbapi
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond committed Jul 5, 2020
1 parent e1ce885 commit 25f4d49
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 95 deletions.
18 changes: 5 additions & 13 deletions adodbapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,16 @@
import sys
import time

if sys.version_info < (3,0): # in Python 2, define all symbols, just like the bad old way
from .apibase import *
VariantConversionMap = MultiMap # old name. Should use apibase.MultiMap
from .ado_consts import *
_makeByteBuffer = buffer
else:
# but if the user is running Python 3, then keep the dictionary clean
from .apibase import apilevel, threadsafety, paramstyle
from .apibase import Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError
from .apibase import InternalError, ProgrammingError, NotSupportedError, FetchFailedError
from .apibase import NUMBER, STRING, BINARY, DATETIME, ROWID
_makeByteBuffer = bytes
from .apibase import apilevel, threadsafety, paramstyle
from .apibase import Warning, Error, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError
from .apibase import InternalError, ProgrammingError, NotSupportedError, FetchFailedError
from .apibase import NUMBER, STRING, BINARY, DATETIME, ROWID

from .adodbapi import connect, Connection, __version__, dateconverter, Cursor

def Binary(aString):
"""This function constructs an object capable of holding a binary (long) string value. """
return _makeByteBuffer(aString)
return bytes(aString)

def Date(year,month,day):
"This function constructs an object holding a date value. "
Expand Down
13 changes: 4 additions & 9 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
or, after running through 2to3.py, CPython 3.4 or later.
"""


__version__ = '2.6.2.0'
version = 'adodbapi v' + __version__

Expand Down Expand Up @@ -80,14 +79,10 @@ def getIndexedValue(obj,index):
Mapping = dict # this will handle the most common case

# --- define objects to smooth out Python3000 <-> Python 2.x differences
unicodeType = str #this line will be altered by 2to3.py to '= str'
longType = int #this line will be altered by 2to3.py to '= int'
if sys.version_info >= (3,0): #python 3.x
StringTypes = str
maxint = sys.maxsize
else: #python 2.x
StringTypes = (str,str) # will be messed up by 2to3 but never used
maxint = sys.maxint
unicodeType = str
longType = int
StringTypes = str
maxint = sys.maxsize

# ----------------- The .connect method -----------------
def make_COM_connecter():
Expand Down
35 changes: 11 additions & 24 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
NullTypes = type(None)

# --- define objects to smooth out Python3 <-> Python 2.x differences
unicodeType = str #this line will be altered by 2to3.py to '= str'
longType = int #this line will be altered by 2to3.py to '= int'
if sys.version[0] >= '3': #python 3.x
StringTypes = str
makeByteBuffer = bytes
memoryViewType = memoryview
_BaseException = Exception
else: #python 2.x
# noinspection PyUnresolvedReferences
from exceptions import Exception as _BaseException
memoryViewType = type(buffer(''))
makeByteBuffer = buffer
StringTypes = (str,str) # will be messed up by 2to3 but never used
unicodeType = str
longType = int
StringTypes = str
makeByteBuffer = bytes
memoryViewType = memoryview
_BaseException = Exception

try: #jdhardy -- handle bytes under IronPython & Py3
bytes
Expand Down Expand Up @@ -345,17 +338,11 @@ def __ne__(self, other):
typeMap = { memoryViewType : adc.adVarBinary,
float : adc.adDouble,
type(None) : adc.adEmpty,
str : adc.adBSTR, # this line will be altered by 2to3 to 'str:'
str : adc.adBSTR,
bool :adc.adBoolean, #v2.1 Cole
decimal.Decimal : adc.adDecimal }
if longType != int: #not Python 3
typeMap[longType] = adc.adBigInt #works in python 2.x
typeMap[int] = adc.adInteger
typeMap[bytes] = adc.adBSTR # 2.x string type
else: #python 3.0 integrated integers
## Should this differentiate between an int that fits in a long and one that requires 64 bit datatype?
typeMap[int] = adc.adBigInt
typeMap[bytes] = adc.adVarBinary
decimal.Decimal : adc.adDecimal,
int: adc.adBigInt,
bytes: adc.adVarBinary }

def pyTypeToADOType(d):
tp=type(d)
Expand Down Expand Up @@ -418,7 +405,7 @@ def cvtBuffer(variant):
return bytes(variant)

def cvtUnicode(variant):
return str(variant) # will be altered by 2to3 to 'str(variant)'
return str(variant)

def identity(x): return x

Expand Down
3 changes: 1 addition & 2 deletions adodbapi/examples/db_print.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" db_print.py -- a simple demo for ADO database reads."""
#needed for Python 2.5

import sys
import adodbapi.ado_consts as adc
Expand All @@ -15,7 +14,7 @@
if len(s) > 1:
if s[0] in cmd_args:
kw_args[s[0]] = s[1]

kw_args.setdefault('filename', "test.mdb") # assumes server is running from examples folder
kw_args.setdefault('table_name', 'Products') # the name of the demo table

Expand Down
1 change: 0 additions & 1 deletion adodbapi/examples/xls_write.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# needed only if running Python 2.5
import adodbapi
import datetime
try:
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/is64bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def os():
return False # is an older version of Python, assume also an older os (best we can guess)

if __name__ == "__main__":
print ("is64bit.Python() =", Python(), "is64bit.os() =", os())
print("is64bit.Python() =", Python(), "is64bit.os() =", os())
18 changes: 4 additions & 14 deletions adodbapi/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
or, after running through 2to3.py, CPython 3.0 or later.
"""


__version__ = '2.6.0.4'
version = 'adodbapi.remote v' + __version__

Expand Down Expand Up @@ -66,19 +65,10 @@
# --- define objects to smooth out Python3 <-> Python 2.x differences
unicodeType = str #this line will be altered by 2to3.py to '= str'
longType = int #this line will be altered by 2to3.py to '= int'
if sys.version[0] >= '3': #python 3.x
StringTypes = str
makeByteBuffer = bytes
memoryViewType = memoryview
else: #python 2.x
memoryViewType = type(buffer(''))
def makeByteBuffer(x): # special for remote to be pickle-able
return bytes(x)
try: #jdhardy -- handle bytes under IronPython
bytes
except NameError:
bytes = str
StringTypes = (str,str) # will be messed up by 2to3 but never used
StringTypes = str
makeByteBuffer = bytes
memoryViewType = memoryview

# -----------------------------------------------------------
# conversion functions mandated by PEP 249
Binary = makeByteBuffer # override the function from apibase.py
Expand Down
12 changes: 3 additions & 9 deletions adodbapi/remote/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
or, after running through 2to3.py, CPython 3.2 or later.
"""


__version__ = '2.6.2.0'
version = 'adodbapi.server v' + __version__

Expand All @@ -49,14 +48,9 @@
import adodbapi
import adodbapi.process_connect_string

if sys.version[0] >= '3': #python 3.x
makeByteBuffer = bytes
_BaseException = Exception
Binary = bytes
else: #python 2.x
from exceptions import Exception as _BaseException
makeByteBuffer = buffer
Binary = buffer
makeByteBuffer = bytes
_BaseException = Exception
Binary = bytes
try:
pyro_host = os.environ['PYRO_HOST']
except:
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
for line in a:
if '__version__' in line:
VERSION = line.split("'")[1]
print ('adodbapi version="%s"' % VERSION)
print('adodbapi version="%s"' % VERSION)
break
a.close()

Expand Down
23 changes: 5 additions & 18 deletions adodbapi/test/adodbapitest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Unit tests version 2.6.1.0 for adodbapi"""

"""
adodbapi - A python DB API 2.0 interface to Microsoft ADO
Expand Down Expand Up @@ -53,20 +52,9 @@
except ImportError:
from adodbapi import ado_consts

if sys.version_info >= (3,0):
def str2bytes(sval):
return sval.encode("latin1")
str = str
long = int
else:
def str2bytes(sval):
if isinstance(sval, str):
return sval
return sval.encode("latin1")
try:
bytes
except NameError:
bytes = str
def str2bytes(sval):
return sval.encode("latin1")
long = int

def randomstring(length):
return ''.join([random.choice(string.ascii_letters) for n in range(32)])
Expand All @@ -78,7 +66,7 @@ def setUp(self):

def getEngine(self):
return self.engine

def getConnection(self):
raise NotImplementedError #"This method must be overriden by a subclass"

Expand Down Expand Up @@ -276,8 +264,7 @@ def helpTestDataType(self,sqlDataTypeString,
inputs=[pyData]
if pyDataInputAlternatives:
inputs.extend(pyDataInputAlternatives)
if str is str:
inputs = set(inputs) # removes redundant string==unicode tests
inputs = set(inputs) # removes redundant string==unicode tests
fldId=1
for inParam in inputs:
fldId+=1
Expand Down
1 change: 0 additions & 1 deletion adodbapi/test/adodbapitestconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# # Skip down to the next "# #" line --
# # -- the things you need to change are below it.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import platform
import sys
import random
Expand Down
2 changes: 1 addition & 1 deletion adodbapi/test/is64bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def os():
return False # is an older version of Python, assume also an older os (best we can guess)

if __name__ == "__main__":
print ("is64bit.Python() =", Python(), "is64bit.os() =", os())
print("is64bit.Python() =", Python(), "is64bit.os() =", os())
1 change: 0 additions & 1 deletion adodbapi/test/setuptestframework.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/python2
# Configure this in order to run the testcases.
"setuptestframework.py v 2.6.0.8"

import os
import sys
import tempfile
Expand Down

0 comments on commit 25f4d49

Please sign in to comment.