Skip to content

Commit c3ec719

Browse files
ephesc00kiemon5ter
authored andcommitted
Refactor _shelve_compat
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 1d6ea60 commit c3ec719

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/saml2/server.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"""Contains classes and functions that a SAML2.0 Identity provider (IdP)
55
or attribute authority (AA) may use to conclude its tasks.
66
"""
7-
import dbm
87
import importlib
98
import logging
109
import shelve
1110
import threading
11+
from dbm import error as DbmError
1212

1313
from saml2 import BINDING_HTTP_REDIRECT
1414
from saml2 import class_name
@@ -58,13 +58,8 @@
5858
def _shelve_compat(name, *args, **kwargs):
5959
try:
6060
return shelve.open(name, *args, **kwargs)
61-
except dbm.error[0]:
62-
# Python 3 whichdb needs to try .db to determine type
63-
if name.endswith(".db"):
64-
name = name.rsplit(".db", 1)[0]
65-
return shelve.open(name, *args, **kwargs)
66-
else:
67-
raise
61+
except DbmError:
62+
return shelve.open(name.removesuffix(".db"), *args, **kwargs)
6863

6964

7065
class Server(Entity):

0 commit comments

Comments
 (0)