diff options
author | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-05-17 18:50:18 +0000 |
---|---|---|
committer | hploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b> | 2006-05-17 18:50:18 +0000 |
commit | 7d3953d48d92430aa503cb6758b04ddb9c7fe71b (patch) | |
tree | 83c8942fb34dabdc9088714eb903c38c5fa47e0f /cards/generic_card.py | |
parent | a2d6c6a624c0e02fd9cf1309c87b9dfae3640541 (diff) |
nicer status word printing
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@47 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'cards/generic_card.py')
-rw-r--r-- | cards/generic_card.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/cards/generic_card.py b/cards/generic_card.py index 1c720d0..0abbfe7 100644 --- a/cards/generic_card.py +++ b/cards/generic_card.py @@ -122,22 +122,30 @@ class Card: def decode_statusword(self): if self.last_sw is None: return "No command executed so far" - else: + 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]) } + break + elif callable(value): - return value( ord(self.last_sw[0]), + retval = value( ord(self.last_sw[0]), ord(self.last_sw[1]) ) + break - return "Unknown SW: %s" % binascii.b2a_hex(self.last_sw) + 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] |