transport: Change transport api to allow for wait_for_card/connect/disconnect

This way, we can re-use the same transport parameters for several
cards for a future batch mode

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
Sylvain Munaut
2010-12-09 13:31:58 +01:00
parent 9c8729a2d1
commit bdca252fb0
4 changed files with 93 additions and 11 deletions

View File

@@ -22,7 +22,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from smartcard.Exceptions import NoCardException
from smartcard.CardRequest import CardRequest
from smartcard.Exceptions import NoCardException, CardRequestTimeoutException
from smartcard.System import readers
from pySim.exceptions import NoCardError
@@ -34,16 +35,30 @@ class PcscSimLink(LinkBase):
def __init__(self, reader_number=0):
r = readers();
try:
self._con = r[reader_number].createConnection()
self._con.connect()
except NoCardException:
raise NoCardError()
self._reader = r[reader_number]
self._con = self._reader.createConnection()
def __del__(self):
self._con.disconnect()
return
def wait_for_card(self, timeout=None, newcardonly=False):
cr = CardRequest(readers=[self._reader], timeout=timeout, newcardonly=newcardonly)
try:
cr.waitforcard()
except CardRequestTimeoutException:
raise NoCardError()
self.connect()
def connect(self):
try:
self._con.connect()
except NoCardException:
raise NoCardError()
def disconnect(self):
self._con.disconnect()
def reset_card(self):
self._con.disconnect()
try: