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