1 """Smartcard CardRequest.
2
3 __author__ = "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.pcsc.PCSCCardRequest import PCSCCardRequest
26
27
29 """A CardRequest is used for waitForCard() invocations and specifies what
30 kind of smart card an application is waited for.
31 """
32
33 - def __init__(self, newcardonly=False, readers=None, cardType=None,
34 cardServiceClass=None, timeout=1):
35 """Construct new CardRequest.
36
37 newcardonly: if True, request a new card
38 default is False, i.e. accepts cards already
39 inserted
40
41 readers: the list of readers to consider for
42 requesting a card default is to consider all
43 readers
44
45 cardType: the smartcard.CardType.CardType to wait for;
46 default is smartcard.CardType.AnyCardType,
47 i.e. the request will succeed with any card
48
49 cardServiceClass: the specific card service class to create
50 and bind to the card default is to create
51 and bind a smartcard.PassThruCardService
52
53 timeout: the time in seconds we are ready to wait for
54 connecting to the requested card. default
55 is to wait one second to wait forever, set
56 timeout to None
57 """
58 self.pcsccardrequest = PCSCCardRequest(newcardonly, readers,
59 cardType, cardServiceClass, timeout)
60
62 """Returns the list or readers on which to wait for cards."""
63 return self.pcsccardrequest.getReaders()
64
66 """Wait for card insertion and returns a card service."""
67 return self.pcsccardrequest.waitforcard()
68
70 """Wait for card insertion or removal."""
71 return self.pcsccardrequest.waitforcardevent()
72
73
74 if __name__ == '__main__':
75 """Small sample illustrating the use of CardRequest.py."""
76
77 from smartcard.util import toHexString
78 print 'Insert a new card within 10 seconds'
79 cr = CardRequest(timeout=10, newcardonly=True)
80 cs = cr.waitforcard()
81 cs.connection.connect()
82 print cs.connection.getReader(), toHexString(cs.connection.getATR())
83 cs.connection.disconnect()
84