Skip to content

Commit c1fcef1

Browse files
committed
IdentityPython#976 use dbm.dumb for Python 3.13+
1 parent 39f352a commit c1fcef1

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/saml2/server.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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 sys
78
import dbm
89
import importlib
910
import logging
@@ -55,20 +56,14 @@
5556
}
5657

5758

58-
def _avoid_dbm_sqlite():
59-
"""
60-
Force dbm.gnu to be used instead of dbm.sqlite because of threading issues when
61-
running idp_server.py. The dbm.sqlite is the default dbm module used by Python >= 3.13
62-
"""
63-
import dbm.gnu
64-
import dbm
65-
dbm._defaultmod = dbm.gnu
66-
67-
6859
def _shelve_compat(name, *args, **kwargs):
69-
_avoid_dbm_sqlite()
7060
try:
71-
return shelve.open(name, *args, **kwargs)
61+
if sys.version_info < (3, 13):
62+
return shelve.open(name, *args, **kwargs)
63+
else:
64+
# Python 3.13 and later uses dbm.sqlite3 as default which is not compatible
65+
# with cheroot using threading. So, we need to use dbm.dumb instead.
66+
return shelve.Shelf(dbm.dumb.open(name), *args, **kwargs)
7267
except dbm.error[0]:
7368
# Python 3 whichdb needs to try .db to determine type
7469
if name.endswith(".db"):

0 commit comments

Comments
 (0)