Package smartcard :: Class Session
[hide private]
[frames] | no frames]

Class Session

source code


The Session object enables programmers to transmit APDU to smartcards.

This is an example of use of the Session object:

import smartcard reader=smartcard.listReaders() s = smartcard.Session(reader[0]) SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] data, sw1, sw2 = s.sendCommandAPDU(SELECT+DF_TELECOM) print(data, sw1, sw2) s.close() print(`s`)

Instance Methods [hide private]
 
__init__(self, readerName=None, cardServiceClass=None)
Session constructor.
source code
 
__repr__(self)
Returns a string representation of the session.
source code
 
close(self)
Close the smartcard session.
source code
 
getATR(self)
Returns the ATR of the connected card.
source code
 
sendCommandAPDU(self, command)
Send an APDU command to the connected smartcard.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, readerName=None, cardServiceClass=None)
(Constructor)

source code 

Session constructor. Initializes a smart card session and connect to the card.

Parameters:
  • readerName - reader to connect to; default is first PCSC reader
  • cardServiceClass - card service to bind the session to; default is None
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

Returns a string representation of the session.

Overrides: object.__repr__

close(self)

source code 

Close the smartcard session.

Closing a session will disconnect from the card.

sendCommandAPDU(self, command)

source code 

Send an APDU command to the connected smartcard.

Parameters:
  • command - list of APDU bytes, e.g. [0xA0, 0xA4, 0x00, 0x00, 0x02]
Returns:
a tuple (response, sw1, sw2) where response is the APDU response sw1, sw2 are the two status words