Skip to content

Commit

Permalink
adodbapi reduce _raiseConnectionError to a single argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 2, 2024
1 parent 377a3ef commit 192cf0f
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ def connect(self, kwargs, connection_maker=make_COM_connecter):
self.connection_string = (
kwargs["connection_string"] % kwargs
) # insert keyword arguments
except Exception as e:
except Exception:
self._raiseConnectionError(
KeyError, "Python string format error in connection string->"
KeyError("Python string format error in connection string->")
)
self.timeout = kwargs.get("timeout", 30)
self.mode = kwargs.get("mode", adc.adModeUnknown)
Expand All @@ -266,8 +266,7 @@ def connect(self, kwargs, connection_maker=make_COM_connecter):
self.connector.Open() # Open the ADO connection
except api.Error:
self._raiseConnectionError(
api.DatabaseError,
"ADO error trying to Open=%s" % self.connection_string,
api.DatabaseError(f"ADO error trying to Open={self.connection_string}")
)

try: # Stefan Fuchs; support WINCCOLEDBProvider
Expand Down Expand Up @@ -298,11 +297,11 @@ def connect(self, kwargs, connection_maker=make_COM_connecter):
if verbose:
print("adodbapi New connection at %X" % id(self))

def _raiseConnectionError(self, errorclass, errorvalue):
def _raiseConnectionError(self, errorvalue: BaseException):
eh = self.errorhandler
if eh is None:
eh = api.standardErrorHandler
eh(self, None, errorclass, errorvalue)
eh(self, None, type(errorvalue), errorvalue)

def _closeAdoConnection(self): # all v2.1 Rose
"""close the underlying ADO Connection object,
Expand Down Expand Up @@ -334,7 +333,7 @@ def close(self):
try:
self._closeAdoConnection() # v2.1 Rose
except Exception as e:
self._raiseConnectionError(sys.exc_info()[0], sys.exc_info()[1])
self._raiseConnectionError(e)

self.connector = None # v2.4.2.2 fix subtle timeout bug
# per M.Hammond: "I expect the benefits of uninitializing are probably fairly small,
Expand Down Expand Up @@ -364,7 +363,7 @@ def commit(self):
# If not, we will have to start a new transaction by this command:
self.transaction_level = self.connector.BeginTrans()
except Exception as e:
self._raiseConnectionError(api.ProgrammingError, e)
self._raiseConnectionError(api.ProgrammingError(e))

def _rollback(self):
"""In case a database does provide transactions this method causes the the database to roll back to
Expand Down Expand Up @@ -395,12 +394,10 @@ def _rollback(self):
# If attributes has adXactAbortRetaining it performs retaining aborts that is,
# calling RollbackTrans automatically starts a new transaction. Not all providers support this.
# If not, we will have to start a new transaction by this command:
if (
not self.transaction_level
): # if self.transaction_level == 0 or self.transaction_level is None:
if not self.transaction_level: # if self.transaction_level == 0 or self.transaction_level is None:
self.transaction_level = self.connector.BeginTrans()
except Exception as e:
self._raiseConnectionError(api.ProgrammingError, e)
self._raiseConnectionError(api.ProgrammingError(e))

def __setattr__(self, name, value):
if name == "autocommit": # extension: allow user to turn autocommit on or off
Expand All @@ -414,8 +411,9 @@ def __setattr__(self, name, value):
elif name == "paramstyle":
if value not in api.accepted_paramstyles:
self._raiseConnectionError(
api.NotSupportedError,
f"paramstyle={value!r} not in:{api.accepted_paramstyles!r}",
api.NotSupportedError(
f"paramstyle={value!r} not in:{api.accepted_paramstyles!r}"
)
)
elif name == "variantConversions":
# make a new copy -- no changes in the default, please
Expand Down Expand Up @@ -634,9 +632,7 @@ def _makeDescriptionFromRS(self):
if self.rs.EOF or self.rs.BOF:
display_size = None
else:
display_size = (
f.ActualSize
) # TODO: Is this the correct defintion according to the DB API 2 Spec ?
display_size = f.ActualSize # TODO: Is this the correct defintion according to the DB API 2 Spec ?
null_ok = bool(f.Attributes & adc.adFldMayBeNull) # v2.1 Cole
desc.append(
(
Expand Down Expand Up @@ -774,9 +770,7 @@ def get_returned_parameters(self):
after the last recordset has been read. In that case, you must coll nextset() until it
returns None, then call this method to get your returned information."""

retLst = (
[]
) # store procedures may return altered parameters, including an added "return value" item
retLst = [] # store procedures may return altered parameters, including an added "return value" item
for p in tuple(self.cmd.Parameters):
if verbose > 2:
print(
Expand Down Expand Up @@ -907,9 +901,7 @@ def _buildADOparameterList(self, parameters, sproc=False):
)
i += 1
else: # -- build own parameter list
if (
self._parameter_names
): # we expect a dictionary of parameters, this is the list of expected names
if self._parameter_names: # we expect a dictionary of parameters, this is the list of expected names
for parm_name in self._parameter_names:
elem = parameters[parm_name]
adotype = api.pyTypeToADOType(elem)
Expand Down

0 comments on commit 192cf0f

Please sign in to comment.