nicer status word printing
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@47 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
parent
a2d6c6a624
commit
7d3953d48d
|
@ -123,21 +123,29 @@ class Card:
|
|||
if self.last_sw is None:
|
||||
return "No command executed so far"
|
||||
else:
|
||||
retval = None
|
||||
|
||||
desc = self.STATUS_WORDS.get(self.last_sw)
|
||||
if desc is not None:
|
||||
return desc
|
||||
retval = desc
|
||||
else:
|
||||
target = binascii.b2a_hex(self.last_sw).upper()
|
||||
for (key, value) in self.STATUS_WORDS.items():
|
||||
if fnmatch.fnmatch(target, key):
|
||||
if isinstance(value, str):
|
||||
return value % { "SW1": ord(self.last_sw[0]),
|
||||
retval = value % { "SW1": ord(self.last_sw[0]),
|
||||
"SW2": ord(self.last_sw[1]) }
|
||||
elif callable(value):
|
||||
return value( ord(self.last_sw[0]),
|
||||
ord(self.last_sw[1]) )
|
||||
break
|
||||
|
||||
return "Unknown SW: %s" % binascii.b2a_hex(self.last_sw)
|
||||
elif callable(value):
|
||||
retval = value( ord(self.last_sw[0]),
|
||||
ord(self.last_sw[1]) )
|
||||
break
|
||||
|
||||
if retval is None:
|
||||
return "%s: Unknown SW" % binascii.b2a_hex(self.last_sw)
|
||||
else:
|
||||
return "%s: %s" % (binascii.b2a_hex(self.last_sw), retval)
|
||||
|
||||
def get_protocol(self):
|
||||
return ((self.card.status()["Protocol"] == pycsc.SCARD_PROTOCOL_T0) and (0,) or (1,))[0]
|
||||
|
|
|
@ -92,13 +92,15 @@ if __name__ == "__main__":
|
|||
apdu_binary = binascii.a2b_hex("".join(apdu_string.split()))
|
||||
apdu = utils.APDU(apdu_binary)
|
||||
response = card.send_apdu(apdu)
|
||||
print utils.hexdump(response)
|
||||
|
||||
if len(response) > 2: ## The SW is already printed by _print_sw as a post_hook
|
||||
print utils.hexdump(response[:-2])
|
||||
|
||||
shell.fallback = do_raw_apdu
|
||||
|
||||
def _print_sw():
|
||||
if card.sw_changed:
|
||||
print card.decode_statusword()
|
||||
print "\n", card.decode_statusword()
|
||||
shell.register_post_hook(_print_sw)
|
||||
|
||||
shell.run()
|
||||
|
|
Loading…
Reference in New Issue