• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LudovicRousseau / pyscard / 14366221765

09 Apr 2025 12:51PM UTC coverage: 66.092% (-0.04%) from 66.13%
14366221765

push

github

LudovicRousseau
sample_TransmitCardObserver: use explicit .disconnect() & .release()

104 of 482 branches covered (21.58%)

4448 of 6730 relevant lines covered (66.09%)

4.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/smartcard/CardConnectionObserver.py
1
"""CardConnectionObserver interface.
2

3
CardConnectionObserver is a base class for objects that are to be notified
4
upon CardConnection events.
5

6
__author__ = "https://www.gemalto.com/"
7

8
Copyright 2001-2012 gemalto
9
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
10

11
This file is part of pyscard.
12

13
pyscard is free software; you can redistribute it and/or modify
14
it under the terms of the GNU Lesser General Public License as published by
15
the Free Software Foundation; either version 2.1 of the License, or
16
(at your option) any later version.
17

18
pyscard is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
GNU Lesser General Public License for more details.
22

23
You should have received a copy of the GNU Lesser General Public License
24
along with pyscard; if not, write to the Free Software
25
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26
"""
27

28
from smartcard.Observer import Observer
×
29
from smartcard.util import toHexString
×
30

31

32
# ReaderObserver interface
33
class CardConnectionObserver(Observer):
×
34
    """
35
    CardConnectionObserver is a base class for objects that are to be notified
36
    upon L{CardConnection} events.
37
    """
38

39
    def update(self, cardconnection, cardconnectionevent):
×
40
        """Called upon CardConnection event.
41

42
        @param cardconnection:         the observed card connection object
43
        @param cardconnectionevent:    the CardConnectionEvent sent by the connection
44
        """
45
        pass
×
46

47

48
class ConsoleCardConnectionObserver(CardConnectionObserver):
×
49

50
    def update(self, cardconnection, ccevent):
×
51

52
        if "connect" == ccevent.type:
×
53
            print("connecting to " + cardconnection.getReader())
×
54

55
        elif "reconnect" == ccevent.type:
×
56
            print("reconnecting to " + cardconnection.getReader())
×
57

58
        elif "disconnect" == ccevent.type:
×
59
            print("disconnecting from " + cardconnection.getReader())
×
60

61
        elif "release" == ccevent.type:
×
62
            print("release from " + cardconnection.getReader())
×
63

64
        elif "command" == ccevent.type:
×
65
            print("> " + toHexString(ccevent.args[0]))
×
66

67
        elif "response" == ccevent.type:
×
68
            if [] == ccevent.args[0]:
×
69
                print("<  [] %02X %02X" % tuple(ccevent.args[-2:]))
×
70
            else:
71
                print(
×
72
                    "< "
73
                    + toHexString(ccevent.args[0])
74
                    + " "
75
                    + "%02X %02X" % tuple(ccevent.args[-2:])
76
                )
77
        else:
78
            print("unknown event:", ccevent.type)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc