From 8a6dcdbf5f57c27dbbbdb684235ccc2203394e3b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 27 May 2018 11:11:05 +0200 Subject: [PATCH] Generating SmartCardRemoveEvent as well when a scard is removed --- platypush/backend/scard/__init__.py | 5 ++++- platypush/message/event/scard.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/platypush/backend/scard/__init__.py b/platypush/backend/scard/__init__.py index 039eebfa..f5b944a9 100644 --- a/platypush/backend/scard/__init__.py +++ b/platypush/backend/scard/__init__.py @@ -3,6 +3,7 @@ import json from smartcard.CardType import AnyCardType, ATRCardType from smartcard.CardRequest import CardRequest +from smartcard.Exceptions import NoCardException from smartcard.util import toHexString from platypush.backend import Backend @@ -68,8 +69,10 @@ class ScardBackend(Backend): self.bus.post(SmartCardDetectedEvent(atr=atr, reader=reader)) prev_atr = atr except Exception as e: + if isinstance(e, NoCardException): + prev_atr = None + self.bus.post(SmartCardRemovedEvent()) logging.exception(e) - prev_atr = None # vim:sw=4:ts=4:et: diff --git a/platypush/message/event/scard.py b/platypush/message/event/scard.py index 4bf1809d..9b887b72 100644 --- a/platypush/message/event/scard.py +++ b/platypush/message/event/scard.py @@ -6,5 +6,10 @@ class SmartCardDetectedEvent(Event): super().__init__(atr=atr, reader=reader, *args, **kwargs) +class SmartCardRemovedEvent(Event): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # vim:sw=4:ts=4:et: