From c73905d35d3fa015b14a2e81e3386dbcae25220e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 27 May 2018 11:47:57 +0200 Subject: [PATCH] More robust handling of card removed events --- platypush/backend/scard/__init__.py | 4 ++-- platypush/message/event/scard.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platypush/backend/scard/__init__.py b/platypush/backend/scard/__init__.py index 626c7790..0d9f9a28 100644 --- a/platypush/backend/scard/__init__.py +++ b/platypush/backend/scard/__init__.py @@ -3,7 +3,7 @@ import json from smartcard.CardType import AnyCardType, ATRCardType from smartcard.CardRequest import CardRequest -from smartcard.Exceptions import NoCardException +from smartcard.Exceptions import NoCardException, CardConnectionException from smartcard.util import toHexString from platypush.backend import Backend @@ -71,7 +71,7 @@ class ScardBackend(Backend): self.bus.post(SmartCardDetectedEvent(atr=atr, reader=reader)) prev_atr = atr except Exception as e: - if isinstance(e, NoCardException): + if isinstance(e, NoCardException) or isinstance(e, CardConnectionException): self.bus.post(SmartCardRemovedEvent(atr=prev_atr, reader=reader)) else: logging.exception(e) diff --git a/platypush/message/event/scard.py b/platypush/message/event/scard.py index 252d2800..29bbb5ee 100644 --- a/platypush/message/event/scard.py +++ b/platypush/message/event/scard.py @@ -8,7 +8,7 @@ class SmartCardDetectedEvent(Event): class SmartCardRemovedEvent(Event): def __init__(self, atr=None, reader=None, *args, **kwargs): - super().__init__(*args, **kwargs) + super().__init__(atr=atr, reader=reader, *args, **kwargs) # vim:sw=4:ts=4:et: