From: <lu...@us...> - 2010-02-12 08:28:58
|
Revision: 373 http://pyscard.svn.sourceforge.net/pyscard/?rev=373&view=rev Author: ludov Date: 2010-02-12 08:28:51 +0000 (Fri, 12 Feb 2010) Log Message: ----------- fix pep8 E302 expected 2 blank lines, found 1 Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2010-02-12 08:26:18 UTC (rev 372) +++ trunk/contrib/parseATR/parseATR.py 2010-02-12 08:28:51 UTC (rev 373) @@ -39,6 +39,7 @@ """ return a hex list """ return " ".join(["%02X" % b for b in bytes]) + def normalize(atr): """ transform an ATR in list of integers valid input formats are @@ -58,6 +59,7 @@ atr = map(lambda x: int(x, 16), res) return atr + def int2bin(i, padding=8): """ convert an integer into its binary representation """ b = "" @@ -67,6 +69,7 @@ b = "0" * (padding - len(b)) + b return b + def parseATR(atr_txt): atr_txt = normalize(atr_txt) atr = {} @@ -131,6 +134,7 @@ return atr + def TA1(v): Fi = (372, 372, 558, 744, 1116, 1488, 1860, "RFU", "RFU", 512, 768, 1024, 1536, 2048, "RFU", "RFU") Di = ("RFU", 1, 2, 4, 8, 16, 32, "RFU", 12, 20, "RFU", "RFU", "RFU", "RFU", "RFU", "RFU") @@ -147,6 +151,7 @@ return text + def TA2(v): F = v >> 4 D = v & 0xF @@ -163,12 +168,15 @@ return ''.join(text) + def TA3(v): return TAn(3, v) + def TA4(v): return TAn(4, v) + def TAn(i, v): XI = ("not supported", "state L", "state H", "no preference") if (T == 1): @@ -192,6 +200,7 @@ text = "Clock stop: %s - Class accepted by the card: %s" % (XI[F], ''.join(Class)) return text + def TB1(v): I = v >> 5 PI = v & 0x1F @@ -201,6 +210,7 @@ text = "Programming Param P: %d Volts, I: %d milliamperes" % (PI, I) return text + def TB2(v): text = ["Programming param PI2 (PI1 should be ignored): %d" % v, ] if ((v > 49) or (v < 251)): @@ -209,12 +219,15 @@ text.append(" is RFU") return ''.join(text) + def TB3(v): return TBn(3, v) + def TB4(v): return TBn(4, v) + def TBn(i, v): text = "Undocumented" if (T == 1): @@ -236,21 +249,26 @@ text = texts.get(v, "RFU") return text + def TC1(v): text = ["Extra guard time: %d" % v] if (v == 255): text.append(" (special value)") return ''.join(text) + def TC2(v): return "Work waiting time: 960 x %d x (Fi/F)" % v + def TC3(v): return TCn(3, v) + def TC4(v): return TCn(4, v) + def TCn(i, v): text = [] if (T == 1): @@ -264,18 +282,23 @@ text.append("RFU") return ''.join(text) + def TD1(v): return TDn(1, v) + def TD2(v): return TDn(2, v) + def TD3(v): return TDn(3, v) + def TD4(v): return TDn(4, v) + def TDn(i, v): global T Y = v >> 4 @@ -283,6 +306,7 @@ text = "Y(i+1) = b%s, Protocol T=%d" % (int2bin(Y, 4), T) return text + def life_cycle_status(lcs): # Table 13 - Life cycle status byte # ISO 7816-4:2004, page 21 @@ -306,6 +330,7 @@ return text + def data_coding(dc): # Table 87 - Second software function table (data coding byte) # ISO 7816-4:2004, page 60 @@ -329,6 +354,7 @@ return ''.join(text) + def selection_methods(sm): # Table 86 - First software function table (selection methods) # ISO 7816-4:2004, page 60 @@ -360,6 +386,7 @@ return ''.join(text) + def selection_mode(sm): # Table 87 - Second software function table (data coding byte) # ISO 7816-4:2004, page 60 @@ -391,6 +418,7 @@ return ''.join(text) + def command_chaining(cc): # Table 88 - Third software function table (command chaining, length fields and logical channels) # ISO 7816-4:2004, page 61 @@ -413,6 +441,7 @@ return ''.join(text) + def card_service(cs): # Table 85 - Card service data byte # ISO 7816-4:2004, page 59 @@ -448,6 +477,7 @@ return ''.join(text) + def compact_tlv(historical_bytes): text = "" tlv = historical_bytes.pop(0) @@ -554,6 +584,7 @@ return ''.join(text) + def analyse_histrorical_bytes(historical_bytes): text = [] @@ -602,6 +633,7 @@ return text + def compute_tck(atr): # do not include TS byte s = atr["atr"][0] @@ -611,6 +643,7 @@ s ^= atr["atr"][-1] return s + def colorize_txt(l): magenta = "\033[35m" normal = "\033[0m" @@ -619,6 +652,7 @@ text += " --> " + magenta + "".join(l[1:]) + normal return text + def atr_display_txt(atr): return atr_display(atr, colorize_txt) @@ -630,6 +664,7 @@ "<": "<", } + def html_escape(text): """Produce entities within text.""" L = [] @@ -637,6 +672,7 @@ L.append(html_escape_table.get(c, c)) return "".join(L) + def colorize_html(l): text = '<span class="left">' + html_escape(l[0]) + '</span>' if len(l) > 1: @@ -645,9 +681,11 @@ text = l[0] return text + def atr_display_html(atr): return atr_display(atr, colorize_html) + def atr_display(atr, colorize): text = [] TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} @@ -690,6 +728,7 @@ return "\n".join([colorize(t) for t in text]) + def match_atr(atr, atr_file="smartcard_list.txt"): """ try to find card description for a given ATR """ card = [] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |