From b951fcd0c6e916a5ccf751307b8dcdf71149b38a Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Mon, 14 Apr 2025 10:41:46 +0200 Subject: [PATCH] Lock pyscard to <2.2.2 until PCSCContext removal is handled Upstream-Stauts: Backport [https://github.com/Yubico/yubikey-manager/commit/b951fcd0c6e916a5ccf751307b8dcdf71149b38a] --- ykman/pcsc/__init__.py | 13 +++++++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ykman/pcsc/__init__.py b/ykman/pcsc/__init__.py index e5bbf962f..617f2edee 100644 --- ./ykman/pcsc/__init__.py +++ ./ykman/pcsc/__init__.py @@ -34,7 +34,6 @@ from smartcard import System from smartcard.Exceptions import CardConnectionException, NoCardException from smartcard.pcsc.PCSCExceptions import ListReadersException -from smartcard.pcsc.PCSCContext import PCSCContext from smartcard.ExclusiveConnectCardConnection import ExclusiveConnectCardConnection from fido2.pcsc import CtapPcscDevice @@ -198,12 +197,18 @@ def kill_yubikey_agent(): 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 def list_devices(name_filter=None):