Package smartcard :: Module CardConnectionObserver
[hide private]
[frames] | no frames]

Source Code for Module smartcard.CardConnectionObserver

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