From e2eb7d4a52a762795c1a8aa9804f184b11b5e64d Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Mon, 14 Apr 2025 13:20:17 +0200 Subject: [PATCH] Support pyscard >=2.2.2 Upstream-Status: Backport [https://github.com/Yubico/python-fido2/commit/e2eb7d4a52a762795c1a8aa9804f184b11b5e64d] --- fido2/pcsc.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fido2/pcsc.py b/fido2/pcsc.py index 894c56b..4ce1f64 100644 --- ./fido2/pcsc.py +++ ./fido2/pcsc.py @@ -34,7 +34,6 @@ from smartcard import System from smartcard.CardConnection import CardConnection from smartcard.pcsc.PCSCExceptions import ListReadersException -from smartcard.pcsc.PCSCContext import PCSCContext from threading import Event from typing import Callable, Iterator @@ -243,9 +242,15 @@ def list_devices(cls, name: str = "") -> Iterator[CtapPcscDevice]: def _list_readers(): try: return System.readers() - except ListReadersException: + except ListReadersException as e: # If the PCSC system has restarted the context might be stale, try # forcing a new context (This happens on Windows if the last reader is # removed): - PCSCContext.instance = None - return System.readers() + try: + from smartcard.pcsc.PCSCContext import PCSCContext + + PCSCContext.instance = None + return System.readers() + except ImportError: + # As of pyscard 2.2.2 the PCSCContext singleton has been removed + raise e