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

Source Code for Module smartcard.reader.ReaderGroups

  1  """ReaderGroups manages smart card reader in groups. 
  2   
  3  __author__ = "gemalto http://www.gemalto.com" 
  4   
  5  Copyright 2001-2011 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 smartcard.Exceptions import SmartcardException 
 26  from smartcard.ulist import ulist 
 27   
 28   
29 -class BadReaderGroupException(SmartcardException):
30 """Raised when trying to add an invalid reader group.""" 31
32 - def __init__(self):
33 SmartcardException.__init__(self, 'Invalid reader group')
34 35
36 -class DeleteSCardDefaultReaderGroupException(SmartcardException):
37 """Raised when trying to delete SCard$DefaultReaders reader group.""" 38
39 - def __init__(self):
40 SmartcardException.__init__(self, 'SCard$DefaultReaders cannot be deleted')
41 42
43 -class innerreadergroups(ulist):
44 """Smartcard readers groups private class. 45 46 The readergroups singleton manages the creation of the unique 47 instance of this class. 48 """ 49
50 - def __init__(self, initlist=None):
51 """Retrieve and store list of reader groups""" 52 if None == initlist: 53 initlist = self.getreadergroups() 54 if None != initlist: 55 ulist.__init__(self, initlist) 56 self.unremovablegroups = []
57
58 - def __onadditem__(self, item):
59 """Called when a reader group is added.""" 60 self.addreadergroup(item)
61
62 - def __onremoveitem__(self, item):
63 """Called when a reader group is added.""" 64 self.removereadergroup(item)
65 66 # 67 # abstract methods implemented in subclasses 68 # 69
70 - def getreadergroups(self):
71 """Returns the list of smartcard reader groups.""" 72 return []
73
74 - def addreadergroup(self, newgroup):
75 """Add a reader group""" 76 if not isinstance(newgroup, type("")): 77 raise BadReaderGroupException
78
79 - def removereadergroup(self, group):
80 """Remove a reader group""" 81 if not isinstance(group, type("")): 82 raise BadReaderGroupException
83
84 - def addreadertogroup(self, readername, groupname):
85 """Add a reader to a reader group""" 86 pass
87
88 - def removereaderfromgroup(self, readername, groupname):
89 """Remove a reader from a reader group""" 90 pass
91 92
93 -class readergroups:
94 """ReadersGroups organizes smart card reader as groups.""" 95 96 """The single instance of __readergroups""" 97 instance = None 98 99 """Constructor: create a single instance of __readergroups on first call""" 100
101 - def __init__(self, initlist=None):
104 105 """All operators redirected to inner class.""" 106
107 - def __getattr__(self, name):
108 return getattr(self.instance, name)
109 110 111 if __name__ == '__main__': 112 print readergroups() 113