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-2011 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:
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 module: the python module that contains the reader class 48 @param clazz: the reader class name 49 @param readername: the reader name 50 """ 51 if not ReaderFactory.factories.has_key(clazz): 52 ReaderFactory.factories[clazz] = get_class(clazz).Factory() 53 return ReaderFactory.factories[clazz].create(readername)
54 createReader = staticmethod(createReader) 55
56 - def readers(groups=[]):
57 zreaders = [] 58 for fm in ReaderFactory.factorymethods: 59 zreaders += fm(groups) 60 return zreaders
61 readers = staticmethod(readers)
62