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