Package smartcard :: Package reader :: Module ReaderFactory
[hide private]
[frames] | no frames]

Source Code for Module smartcard.reader.ReaderFactory

 1  """ReaderFactory: creates smartcard readers. 
 2   
 3  __author__ = "gemalto http://www.gemalto.com" 
 4   
 5  Factory pattern implementation borrowed from 
 6  Thinking in Python, Bruce Eckel, 
 7  http://mindview.net/Books/TIPython 
 8   
 9  The code to instanciate the reader Factory() has 
10  been updated to dynamically load the module with 
11  Robert Brewer ClassLoader.py. 
12   
13  Copyright 2001-2012 gemalto 
14  Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com 
15   
16  This file is part of pyscard. 
17   
18  pyscard is free software; you can redistribute it and/or modify 
19  it under the terms of the GNU Lesser General Public License as published by 
20  the Free Software Foundation; either version 2.1 of the License, or 
21  (at your option) any later version. 
22   
23  pyscard is distributed in the hope that it will be useful, 
24  but WITHOUT ANY WARRANTY; without even the implied warranty of 
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
26  GNU Lesser General Public License for more details. 
27   
28  You should have received a copy of the GNU Lesser General Public License 
29  along with pyscard; if not, write to the Free Software 
30  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
31  """ 
32   
33  from smartcard.ClassLoader import get_class 
34  from smartcard.pcsc.PCSCReader import PCSCReader 
35   
36   
37 -class ReaderFactory(object):
38 """Class to create readers from reader type id.""" 39 40 factories = {} 41 factorymethods = [PCSCReader.readers] 42 43 # A Template Method:
44 - def createReader(clazz, readername):
45 """Static method to create a reader from a reader clazz. 46 47 @param clazz: the reader class name 48 @param readername: the reader name 49 """ 50 if not clazz in ReaderFactory.factories: 51 ReaderFactory.factories[clazz] = get_class(clazz).Factory() 52 return ReaderFactory.factories[clazz].create(readername)
53 createReader = staticmethod(createReader) 54
55 - def readers(groups=[]):
56 zreaders = [] 57 for fm in ReaderFactory.factorymethods: 58 zreaders += fm(groups) 59 return zreaders
60 readers = staticmethod(readers)
61