Skip to content

Commit 3f02259

Browse files
SCardGetAttrib.py: modernize code
1 parent b2ba655 commit 3f02259

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

UnitaryTests/SCardGetAttrib.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
# SCARD_ATTR_VENDOR_IFD_SERIAL_NO support has been added in ccid 1.3.13
2222
# SCARD_ATTR_ATR_STRING support has been added in ccid 0.9.0
2323

24+
from struct import unpack
2425
from smartcard.scard import *
2526
from smartcard.pcsc.PCSCExceptions import *
2627
from smartcard.util import toHexString, toASCIIString
27-
from struct import unpack
2828

2929
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
3030
if hresult != SCARD_S_SUCCESS:
@@ -33,19 +33,23 @@
3333
hresult, readers = SCardListReaders(hcontext, [])
3434
if hresult != SCARD_S_SUCCESS:
3535
raise ListReadersException(hresult)
36-
print('PC/SC Readers:', readers)
36+
print("PC/SC Readers:", readers)
3737

3838
for reader in readers:
39-
hresult, hcard, dwActiveProtocol = SCardConnect(hcontext, reader,
40-
SCARD_SHARE_DIRECT, SCARD_PROTOCOL_ANY)
39+
hresult, hcard, dwActiveProtocol = SCardConnect(
40+
hcontext, reader, SCARD_SHARE_DIRECT, SCARD_PROTOCOL_ANY
41+
)
4142
if hresult != SCARD_S_SUCCESS:
4243
raise BaseSCardException(hresult)
4344

4445
print("reader:", reader)
45-
for attribute in (SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
46-
SCARD_ATTR_ATR_STRING, SCARD_ATTR_CHANNEL_ID):
46+
for attribute in (
47+
SCARD_ATTR_VENDOR_IFD_SERIAL_NO,
48+
SCARD_ATTR_ATR_STRING,
49+
SCARD_ATTR_CHANNEL_ID,
50+
):
4751
hresult, attrib = SCardGetAttrib(hcard, attribute)
48-
print(hex(attribute), end=' ')
52+
print(hex(attribute), end=" ")
4953
if hresult != SCARD_S_SUCCESS:
5054
print(SCardGetErrorMessage(hresult))
5155
else:
@@ -57,8 +61,7 @@
5761
if DDDD == 0x0020:
5862
bus = (DDDDCCCC & 0xFF00) >> 8
5963
addr = DDDDCCCC & 0xFF
60-
print(" USB: bus: {}, addr: {}".format(bus, addr))
61-
64+
print(f" USB: bus: {bus}, addr: {addr}")
6265

6366
hresult = SCardDisconnect(hcard, SCARD_LEAVE_CARD)
6467
if hresult != SCARD_S_SUCCESS:

0 commit comments

Comments
 (0)