1 """CardConnectionObserver interface.
2
3 CardConnectionObserver is a base class for objects that are to be notified
4 upon CardConnection events.
5
6 __author__ = "http://www.gemalto.com"
7
8 Copyright 2001-2011 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.util import toHexString
29 from smartcard.Observer import Observer
30
31
32
34 """
35 CardConnectionObserver is a base class for objects that are to be notified
36 upon CardConnection events.
37 """
38
39 - def update(self, cardconnection, cardconnectionevent):
40 """Called upon CardConnection event.
41
42 cardconnection: the observed card connection object
43 cardconnectionevent: the CardConnectionEvent sent by the connection
44 """
45 pass
46
47
49
50 - def update(self, cardconnection, ccevent):
51
52 if 'connect' == ccevent.type:
53 print 'connecting to ' + cardconnection.getReader()
54
55 elif 'disconnect' == ccevent.type:
56 print 'disconnecting from ' + cardconnection.getReader()
57
58 elif 'command' == ccevent.type:
59 print '> ', toHexString(ccevent.args[0])
60
61 elif 'response' == ccevent.type:
62 if [] == ccevent.args[0]:
63 print '< [] ', "%-2X %-2X" % tuple(ccevent.args[-2:])
64 else:
65 print '< ', toHexString(ccevent.args[0]), "%-2X %-2X" % tuple(ccevent.args[-2:])
66