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

Source Code for Module smartcard.PassThruCardService

 1  """Card service abstract class. 
 2   
 3  A card service is a class providings specific smart card functionality, 
 4  e.g.  a GSM file system or an Open Platform loader.  CardService is an 
 5  abstract class from which concrete card services are derived.  A concrete 
 6  card service is almost always smart card operating system specific 
 7   
 8  __author__ = "http://www.gemalto.com" 
 9   
10  Copyright 2001-2012 gemalto 
11  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com 
12   
13  This file is part of pyscard. 
14   
15  pyscard is free software; you can redistribute it and/or modify 
16  it under the terms of the GNU Lesser General Public License as published by 
17  the Free Software Foundation; either version 2.1 of the License, or 
18  (at your option) any later version. 
19   
20  pyscard is distributed in the hope that it will be useful, 
21  but WITHOUT ANY WARRANTY; without even the implied warranty of 
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
23  GNU Lesser General Public License for more details. 
24   
25  You should have received a copy of the GNU Lesser General Public License 
26  along with pyscard; if not, write to the Free Software 
27  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
28  """ 
29   
30  from __future__ import print_function 
31  from smartcard import CardService 
32   
33   
34 -class PassThruCardService(CardService.CardService):
35 """Pass-thru card service class.""" 36
37 - def __init__(self, connection, cardname=None):
38 """Construct a pass-thru card service. 39 40 connection: the CardConnection used to access the smart card 41 """ 42 CardService.CardService.__init__(self, connection, cardname)
43
44 - def supports(cardname):
45 """Returns True if the cardname is supported by the card service. 46 The PassThruCardService supports all cardnames and always 47 returns True.""" 48 return True
49 50 supports = staticmethod(supports)
51 52 if __name__ == '__main__': 53 """Small sample illustrating the use of CardService.""" 54 SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] 55 DF_TELECOM = [0x7F, 0x10] 56 from smartcard.System import readers 57 cc = readers()[0].createConnection() 58 cs = PassThruCardService(cc) 59 cs.connection.connect() 60 data, sw1, sw2 = cs.connection.transmit(SELECT + DF_TELECOM) 61 print("%X %X" % (sw1, sw2)) 62 cs.connection.disconnect() 63