Package smartcard :: Package pyro :: Module PyroReader
[hide private]
[frames] | no frames]

Source Code for Module smartcard.pyro.PyroReader

 1  """PyroReaderClient: concrete reader class for Remote Readers 
 2   
 3  __author__ = "gemalto http://www.gemalto.com" 
 4   
 5  Copyright 2001-2012 gemalto 
 6  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com 
 7   
 8  This file is part of pyscard. 
 9   
10  pyscard is free software; you can redistribute it and/or modify 
11  it under the terms of the GNU Lesser General Public License as published by 
12  the Free Software Foundation; either version 2.1 of the License, or 
13  (at your option) any later version. 
14   
15  pyscard is distributed in the hope that it will be useful, 
16  but WITHOUT ANY WARRANTY; without even the implied warranty of 
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18  GNU Lesser General Public License for more details. 
19   
20  You should have received a copy of the GNU Lesser General Public License 
21  along with pyscard; if not, write to the Free Software 
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
23  """ 
24   
25  from __future__ import print_function 
26  import Pyro.core 
27  import Pyro.naming 
28   
29  from smartcard.Exceptions import NoCardException 
30  from smartcard.reader.Reader import Reader 
31   
32   
33 -class PyroReader(Reader):
34 """Remote reader class."""
35 - def __init__(self, readername):
36 """Constructs a new Remote Reader client implementation from a 37 Pyro URI.""" 38 ns = Pyro.naming.NameServerLocator().getNS() 39 self.uri = ns.resolve(':pyscard.smartcard.readers.' + readername) 40 self.reader = Pyro.core.getAttrProxyForURI(self.uri) 41 self.name = self.reader.name
42
43 - def addtoreadergroup(self, groupname):
44 """Add reader to a reader group.""" 45 self.reader.addtoreadergroup(groupname)
46
47 - def removefromreadergroup(self, groupname):
48 """Remove a reader from a reader group""" 49 self.reader.removefromreadergroup(groupname)
50
51 - def createConnection(self):
52 """Return a card connection thru a remote reader.""" 53 uri = self.reader.createConnection() 54 return Pyro.core.getAttrProxyForURI(uri)
55
56 - class Factory:
57 - def create(readername):
58 return PyroReader(readername)
59 create = staticmethod(create)
60
61 - def readers(groups=[]):
62 readernames = [] 63 try: 64 ns = Pyro.naming.NameServerLocator().getNS() 65 readernames = ns.list(':pyscard.smartcard.readers') 66 except Pyro.errors.NamingError: 67 print('Warning: pyro name server not found') 68 69 remotereaders = [] 70 for readername in readernames: 71 remotereaders.append(PyroReader.Factory.create(readername[0])) 72 73 return remotereaders
74 readers = staticmethod(readers)
75 76 if __name__ == '__main__': 77 SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] 78 DF_TELECOM = [0x7F, 0x10] 79 from smartcard.util import * 80 81 remotereaders = PyroReader.readers() 82 for reader in remotereaders: 83 try: 84 print(reader.name, ', uri: ', reader.uri) 85 connection = reader.createConnection() 86 connection.connect() 87 print(toHexString(connection.getATR())) 88 data, sw1, sw2 = connection.transmit(SELECT + DF_TELECOM) 89 print("%X %X" % (sw1, sw2)) 90 except NoCardException as x: 91 print('no card in reader') 92