From: <lu...@us...> - 2012-09-28 16:09:07
|
Revision: 603 http://pyscard.svn.sourceforge.net/pyscard/?rev=603&view=rev Author: ludov Date: 2012-09-28 16:08:56 +0000 (Fri, 28 Sep 2012) Log Message: ----------- Use list() instead of [] Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2012-09-28 12:33:12 UTC (rev 602) +++ trunk/contrib/parseATR/parseATR.py 2012-09-28 16:08:56 UTC (rev 603) @@ -63,7 +63,7 @@ atr = atr.replace(":", "") atr = atr.replace(" ", "") - res = [] + res = list() while len(atr) >= 2: byte, atr = atr[:2], atr[2:] res.append(byte) @@ -289,7 +289,7 @@ def TCn(i, v): - text = [] + text = list() if (T == 1): text.append("Error detection code: ") if (v == 1): @@ -357,7 +357,7 @@ def data_coding(dc): # Table 87 - Second software function table (data coding byte) # ISO 7816-4:2004, page 60 - text = [] + text = list() if dc & 128: text.append(" - EF of TLV structure supported\n") @@ -381,7 +381,7 @@ def selection_methods(sm): # Table 86 - First software function table (selection methods) # ISO 7816-4:2004, page 60 - text = [] + text = list() if sm & 1: text.append(" - Record identifier supported\n") @@ -413,7 +413,7 @@ def selection_mode(sm): # Table 87 - Second software function table (data coding byte) # ISO 7816-4:2004, page 60 - text = [] + text = list() if sm & 1: text.append(" - Record identifier supported\n") @@ -445,7 +445,7 @@ def command_chaining(cc): # Table 88 - Third software function table (command chaining, length fields and logical channels) # ISO 7816-4:2004, page 61 - text = [] + text = list() if cc & 128: text.append(" - Command chaining\n") @@ -468,7 +468,7 @@ def card_service(cs): # Table 85 - Card service data byte # ISO 7816-4:2004, page 59 - text = [] + text = list() if cs & 128: text.append(" - Application selection: by full DF name\n") @@ -512,7 +512,7 @@ tag = tlv / 16 len = tlv % 16 - text = [] + text = list() text.append(" Tag: %d, Len: %d" % (tag, len)) if tag == 1: @@ -619,7 +619,7 @@ def analyse_histrorical_bytes(historical_bytes): - text = [] + text = list() # return if we have NO historical bytes if len(historical_bytes) == 0: @@ -704,7 +704,7 @@ def html_escape(text): """Produce entities within text.""" - L = [] + L = list() for c in text: L.append(html_escape_table.get(c, c)) return "".join(L) @@ -724,7 +724,7 @@ def atr_display(atr, colorize): - text = [] + text = list() TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} text.append(["TS = 0x%02X" % atr["TS"], TS.get(atr["TS"], "Invalid")]) @@ -771,7 +771,7 @@ def match_atr(atr, atr_file="smartcard_list.txt"): """ try to find card description for a given ATR """ - card = [] + card = list() atr = toHexString(normalize(atr)) file = open(atr_file) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2012-09-28 17:12:48
|
Revision: 604 http://pyscard.svn.sourceforge.net/pyscard/?rev=604&view=rev Author: ludov Date: 2012-09-28 17:12:42 +0000 (Fri, 28 Sep 2012) Log Message: ----------- Fix formatting issue Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2012-09-28 16:08:56 UTC (rev 603) +++ trunk/contrib/parseATR/parseATR.py 2012-09-28 17:12:42 UTC (rev 604) @@ -517,11 +517,11 @@ if tag == 1: text.append(" (country code, ISO 3166-1)\n") - text.append(" Country code: " + toHexString(historical_bytes[:len])) + text.append(" Country code: %s\n" % toHexString(historical_bytes[:len])) elif tag == 2: text.append(" (issuer identification number, ISO 7812-1)\n") - text.append(" Issuer identification number: " + toHexString(historical_bytes[:len])) + text.append(" Issuer identification number: %s\n" % toHexString(historical_bytes[:len])) elif tag == 3: text.append(" (card service data byte)\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2012-09-29 12:09:45
|
Revision: 605 http://pyscard.svn.sourceforge.net/pyscard/?rev=605&view=rev Author: ludov Date: 2012-09-29 12:09:39 +0000 (Sat, 29 Sep 2012) Log Message: ----------- Catch a IndexError exception Some ATR are bogus. For example: 3B EF 00 FF 81 31 00 45 65 63 is bogus. If we pad the ATR with 00 we have: ATR: 3B EF 00 FF 81 31 00 45 65 63 00 00 00 00 00 00 00 00 00 00 00 00 00 TS = 0x3B --> Direct Convention T0 = 0xEF --> Y(1): b1110, K: 15 (historical bytes) TB(1) = 0x00 --> VPP is not electrically connected TC(1) = 0xFF --> Extra guard time: 255 (special value) TD(1) = 0x81 --> Y(i+1) = b1000, Protocol T=1 ---- TD(2) = 0x31 --> Y(i+1) = b0011, Protocol T=1 ---- TA(3) = 0x00 --> IFSC: 0 TB(3) = 0x45 --> Block Waiting Integer: 4 - Character Waiting Integer: 5 ---- Historical bytes --> 65 63 00 00 00 00 00 00 00 00 00 00 00 00 00 Category indicator byte: 0x65 --> (proprietary format) equivalent ASCII string: "c............." TCK = 0x-1 --> WRONG CHECKSUM, expected 0xE3 Possibly identified card: 3B EF 00 FF 81 31 .. 45 65 63 Debit card (Germany): ec-cash, GeldKarte(DEM), Maestro, Cirrus The ATR do NOT contain 15 of history. Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2012-09-28 17:12:42 UTC (rev 604) +++ trunk/contrib/parseATR/parseATR.py 2012-09-29 12:09:39 UTC (rev 605) @@ -137,7 +137,10 @@ # Store TCK last = pointer + 1 + hb_length if "TCK" in atr: - atr["TCK"] = atr_txt[last] + try: + atr["TCK"] = atr_txt[last] + except IndexError: + atr["TCK"] = -1; last += 1 if len(atr_txt) > last: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2012-09-29 12:41:16
|
Revision: 606 http://pyscard.svn.sourceforge.net/pyscard/?rev=606&view=rev Author: ludov Date: 2012-09-29 12:41:06 +0000 (Sat, 29 Sep 2012) Log Message: ----------- Fix typo Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2012-09-29 12:09:39 UTC (rev 605) +++ trunk/contrib/parseATR/parseATR.py 2012-09-29 12:41:06 UTC (rev 606) @@ -140,7 +140,7 @@ try: atr["TCK"] = atr_txt[last] except IndexError: - atr["TCK"] = -1; + atr["TCK"] = -1 last += 1 if len(atr_txt) > last: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2012-10-06 16:44:26
|
Revision: 609 http://pyscard.svn.sourceforge.net/pyscard/?rev=609&view=rev Author: ludov Date: 2012-10-06 16:44:20 +0000 (Sat, 06 Oct 2012) Log Message: ----------- Search the smartcard_list.txt from different places Resuse the same list as present in Perl ATR_analysis Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2012-09-30 12:54:37 UTC (rev 608) +++ trunk/contrib/parseATR/parseATR.py 2012-10-06 16:44:20 UTC (rev 609) @@ -828,12 +828,35 @@ return "\n".join([colorize(t) for t in text]) -def match_atr(atr, atr_file="smartcard_list.txt"): +def match_atr(atr, atr_file=None): """ try to find card description for a given ATR """ card = list() atr = toHexString(normalize(atr)) - file = open(atr_file) + if atr_file is None: + import os + db_list = list() + + try: + cache = os.environ['XDG_CACHE_HOME'] + except KeyError: + cache = os.environ['HOME'] + "/.cache" + db_list.append(cache + "/smartcard_list.txt") + + db_list += [os.environ['HOME'] + "/.smartcard_list.txt", + "/usr/local/pcsc/smartcard_list.txt", + "/usr/share/pcsc/smartcard_list.txt", + "/usr/local/share/pcsc/smartcard_list.txt"] + for atr_file in db_list: + try: + file = open(atr_file) + print "Using:", atr_file + break + except: + pass + else: + file = open(atr_file) + # find a . * or [ in the ATR to know if we must use a RE or not re_match = re.compile("[\\.\\*\\[]") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2013-10-13 10:02:19
|
Revision: 613 http://sourceforge.net/p/pyscard/code/613 Author: ludov Date: 2013-10-13 10:02:16 +0000 (Sun, 13 Oct 2013) Log Message: ----------- Add parsing for TA5, TB5, TC5 and TD5 It may happen in particular for bogus ATR like 3BF2008065F0F80401F272D643F32323232323232323 Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2012-11-26 18:43:31 UTC (rev 612) +++ trunk/contrib/parseATR/parseATR.py 2013-10-13 10:02:16 UTC (rev 613) @@ -201,7 +201,10 @@ def TA4(v): return TAn(4, v) +def TA5(v): + return TAn(5, v) + def TAn(i, v): XI = ("not supported", "state L", "state H", "no preference") if (T == 1): @@ -254,6 +257,8 @@ def TB4(v): return TBn(4, v) +def TB5(v): + return TBn(5, v) def TBn(i, v): text = "Undocumented" @@ -298,7 +303,10 @@ def TC4(v): return TCn(4, v) +def TC5(v): + return TCn(5, v) + def TCn(i, v): text = list() args = list() @@ -329,7 +337,10 @@ def TD4(v): return TDn(4, v) +def TD5(v): + return TDn(5, v) + def TD5(v): return TDn(5, v) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2013-10-13 10:04:31
|
Revision: 614 http://sourceforge.net/p/pyscard/code/614 Author: ludov Date: 2013-10-13 10:04:26 +0000 (Sun, 13 Oct 2013) Log Message: ----------- Remove duplicate TD5 method and make PEP8 more happy Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2013-10-13 10:02:16 UTC (rev 613) +++ trunk/contrib/parseATR/parseATR.py 2013-10-13 10:04:26 UTC (rev 614) @@ -201,6 +201,7 @@ def TA4(v): return TAn(4, v) + def TA5(v): return TAn(5, v) @@ -257,9 +258,11 @@ def TB4(v): return TBn(4, v) + def TB5(v): return TBn(5, v) + def TBn(i, v): text = "Undocumented" args = list() @@ -303,6 +306,7 @@ def TC4(v): return TCn(4, v) + def TC5(v): return TCn(5, v) @@ -337,10 +341,7 @@ def TD4(v): return TDn(4, v) -def TD5(v): - return TDn(5, v) - def TD5(v): return TDn(5, v) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2013-10-13 10:06:01
|
Revision: 615 http://sourceforge.net/p/pyscard/code/615 Author: ludov Date: 2013-10-13 10:05:58 +0000 (Sun, 13 Oct 2013) Log Message: ----------- E128 continuation line under-indented for visual indent Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2013-10-13 10:04:26 UTC (rev 614) +++ trunk/contrib/parseATR/parseATR.py 2013-10-13 10:05:58 UTC (rev 615) @@ -278,11 +278,11 @@ # Smart Cards; UICC-Terminal interface; # Physical and logical characteristics (Release 8) texts = {0x00: "No additional global interface parameters supported", - 0x88: "Secure Channel supported as defined in TS 102 484", - 0x8C: "Secured APDU - Platform to Platform required as defined in TS 102 484", - 0x90: "Low Impedance drivers and protocol available on the I/O line available (see clause 7.2.1)", - 0xA0: "UICC-CLF interface supported as defined in TS 102 613", - 0xC0: "Inter-Chip USB UICC-Terminal interface supported as defined in TS 102 600"} + 0x88: "Secure Channel supported as defined in TS 102 484", + 0x8C: "Secured APDU - Platform to Platform required as defined in TS 102 484", + 0x90: "Low Impedance drivers and protocol available on the I/O line available (see clause 7.2.1)", + 0xA0: "UICC-CLF interface supported as defined in TS 102 613", + 0xC0: "Inter-Chip USB UICC-Terminal interface supported as defined in TS 102 600"} text = texts.get(v, "RFU") return [text, args] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2013-12-20 09:22:13
|
Revision: 616 http://sourceforge.net/p/pyscard/code/616 Author: ludov Date: 2013-12-20 09:22:08 +0000 (Fri, 20 Dec 2013) Log Message: ----------- Do not specify alignment inside the table You should use CSS for that Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2013-10-13 10:05:58 UTC (rev 615) +++ trunk/contrib/parseATR/parseATR.py 2013-12-20 09:22:08 UTC (rev 616) @@ -777,7 +777,7 @@ left = '<span class="data">' right = '</span>' - text = '<tr><th align="right">' + html_escape(l[0]) + '</th>' + text = '<tr><th>' + html_escape(l[0]) + '</th>' if len(l) > 1: t = "" for line in l[1:]: @@ -786,7 +786,7 @@ if '\n' in t: t = "<pre>" + t + "</pre>" - text += '<th align="left"><span class="format">' + t + '</span></th></tr>' + text += '<th><span class="format">' + t + '</span></th></tr>' return text This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2014-01-14 13:02:00
|
Revision: 617 http://sourceforge.net/p/pyscard/code/617 Author: ludov Date: 2014-01-14 13:01:53 +0000 (Tue, 14 Jan 2014) Log Message: ----------- Match only the complete RE Extra characters after the regular expression are no more ignored. 3B A7 00 40 .. 80 65 A2 08 .. .. .. will match 3B A7 00 40 18 80 65 A2 08 01 01 52 but not 3B A7 00 40 18 80 65 A2 08 01 01 52 00 Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2013-12-20 09:22:08 UTC (rev 616) +++ trunk/contrib/parseATR/parseATR.py 2014-01-14 13:01:53 UTC (rev 617) @@ -880,7 +880,7 @@ # does the ATR in the file uses a RE? if re_match.search(line): # use the RE engine (slow) - found = re.match(line, atr) + found = re.match(line + "$", atr) else: # use string compare (fast) found = line == atr This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2014-01-14 18:48:47
|
Revision: 618 http://sourceforge.net/p/pyscard/code/618 Author: ludov Date: 2014-01-14 18:48:44 +0000 (Tue, 14 Jan 2014) Log Message: ----------- match_atr(): do not add an empty line for RE If an ATR matches a regular expression add the regular expression only without an empty line. The lines can then be .join()-ed to form a text and a nice looking button for https://smartcard-atr.appspot.com/ Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2014-01-14 13:01:53 UTC (rev 617) +++ trunk/contrib/parseATR/parseATR.py 2014-01-14 18:48:44 UTC (rev 618) @@ -887,7 +887,6 @@ if found: # found the ATR if atr != line: - card.append("") card.append(line) for desc in file: if desc == "\n": @@ -911,6 +910,7 @@ card = match_atr(ATR) if card: - print "Possibly identified card:", "\n\t".join(card) + print card + print "Possibly identified card:\n\t", "\n\t".join(card) else: print "Unknown card" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-05 19:28:16
|
Revision: 660 http://sourceforge.net/p/pyscard/code/660 Author: ludov Date: 2015-02-05 19:28:13 +0000 (Thu, 05 Feb 2015) Log Message: ----------- Fix "Maximum number of logical channels" value See ISO 7816-4, 8.1.1.2.7 Card capabilities, table 88. Thanks to Kevin Su (?\232?\152?\135?\229?\152?\137?\232?\136?\136) for the bugs report. Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-01-05 09:32:49 UTC (rev 659) +++ trunk/contrib/parseATR/parseATR.py 2015-02-05 19:28:13 UTC (rev 660) @@ -486,7 +486,7 @@ t = ["No logical channel\n", "by the interface device\n", "by the card\n", "by the interface device and card\n"] text.append(" - Logical channel number assignment: " + t[v]) - text.append(" - Maximum number of logical channels: %d\n" % (cc & 7)) + text.append(" - Maximum number of logical channels: %d\n" % (1 + cc & 7)) return ''.join(text) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 17:10:34
|
Revision: 662 http://sourceforge.net/p/pyscard/code/662 Author: ludov Date: 2015-02-18 17:10:31 +0000 (Wed, 18 Feb 2015) Log Message: ----------- Update copyright date Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:07:24 UTC (rev 661) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 17:10:31 UTC (rev 662) @@ -1,7 +1,7 @@ #! /usr/bin/env python """ parseATR: convert an ATR in a human readable format - Copyright (C) 2009-2012 Ludovic Rousseau + Copyright (C) 2009-2015 Ludovic Rousseau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 17:35:53
|
Revision: 664 http://sourceforge.net/p/pyscard/code/664 Author: ludov Date: 2015-02-18 17:35:50 +0000 (Wed, 18 Feb 2015) Log Message: ----------- colorize_line(): rewrite code Avoid a long line and (try to) make the code easier to read. Fix pep8: parseATR.py:736:9: E128 continuation line under-indented for visual indent parseATR.py:737:9: E128 continuation line under-indented for visual indent Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:10:54 UTC (rev 663) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 17:35:50 UTC (rev 664) @@ -732,9 +732,9 @@ if isinstance(line, types.StringTypes): return line - template = line[0].replace("%s", left + "%s" + - right).replace("%d", left + "%d" + right).replace("%g", left - + "%g" + right) + template = line[0] + for text in ["%s", "%d", "%g"]: + template = template.replace(text, left + text + right) flattened = template % line[1] return flattened This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 17:36:49
|
Revision: 665 http://sourceforge.net/p/pyscard/code/665 Author: ludov Date: 2015-02-18 17:36:47 +0000 (Wed, 18 Feb 2015) Log Message: ----------- Reindent Fix pep8: parseATR.py:859:13: E128 continuation line under-indented for visual indent parseATR.py:860:13: E128 continuation line under-indented for visual indent parseATR.py:861:13: E128 continuation line under-indented for visual indent Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:35:50 UTC (rev 664) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 17:36:47 UTC (rev 665) @@ -856,9 +856,9 @@ db_list.append(cache + "/smartcard_list.txt") db_list += [os.environ['HOME'] + "/.smartcard_list.txt", - "/usr/local/pcsc/smartcard_list.txt", - "/usr/share/pcsc/smartcard_list.txt", - "/usr/local/share/pcsc/smartcard_list.txt"] + "/usr/local/pcsc/smartcard_list.txt", + "/usr/share/pcsc/smartcard_list.txt", + "/usr/local/share/pcsc/smartcard_list.txt"] for atr_file in db_list: try: file = open(atr_file) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 17:37:43
|
Revision: 666 http://sourceforge.net/p/pyscard/code/666 Author: ludov Date: 2015-02-18 17:37:41 +0000 (Wed, 18 Feb 2015) Log Message: ----------- Fix PEP8 parseATR.py:904:9: E265 block comment should start with '# ' Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:36:47 UTC (rev 665) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 17:37:41 UTC (rev 666) @@ -901,7 +901,7 @@ if len(sys.argv) > 1: ATR = " ".join(sys.argv[1:]) else: - #ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" + # ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" atr = parseATR(ATR) print "ATR:", toHexString(normalize(ATR)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 17:53:13
|
Revision: 668 http://sourceforge.net/p/pyscard/code/668 Author: ludov Date: 2015-02-18 17:47:21 +0000 (Wed, 18 Feb 2015) Log Message: ----------- Use from ... instead of import ... https://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Packages Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:42:05 UTC (rev 667) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 17:47:21 UTC (rev 668) @@ -24,12 +24,12 @@ ATR_MAX_PROTOCOLS = 7 T = -1 -import exceptions +from exceptions import Exception import re -import types +from types import StringTypes -class ParseAtrException(exceptions.Exception): +class ParseAtrException(Exception): """ Base class for exceptions in this module """ def __init__(self, text): @@ -736,7 +736,7 @@ def colorize_line(line, left, right): # colorize data from the format: foo: data, ... - if isinstance(line, types.StringTypes): + if isinstance(line, StringTypes): return line template = line[0] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 17:53:14
|
Revision: 667 http://sourceforge.net/p/pyscard/code/667 Author: ludov Date: 2015-02-18 17:42:05 +0000 (Wed, 18 Feb 2015) Log Message: ----------- Fix PEP8: E501 line too long Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:37:41 UTC (rev 666) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 17:42:05 UTC (rev 667) @@ -153,15 +153,19 @@ (t1, t2) = ("s", "are") else: (t1, t2) = ("", "is") - raise ParseAtrException("ERROR! ATR is truncated: %d byte%s %s missing" % (missing, t1, t2)) + raise ParseAtrException("ERROR! ATR is truncated: %d byte%s %s missing" + % (missing, t1, t2)) 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, 64, 12, 20, "RFU", "RFU", "RFU", "RFU", "RFU", "RFU") - FMax = (4, 5, 6, 8, 12, 16, 20, "RFU", "RFU", 5, 7.5, 10, 15, 20, "RFU", "RFU") + 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, 64, 12, 20, "RFU", "RFU", "RFU", "RFU", + "RFU", "RFU") + FMax = (4, 5, 6, 8, 12, 16, 20, "RFU", "RFU", 5, 7.5, 10, 15, 20, "RFU", + "RFU") F = v >> 4 D = v & 0xF @@ -469,7 +473,8 @@ def command_chaining(cc): - # Table 88 - Third software function table (command chaining, length fields and logical channels) + # Table 88 - Third software function table (command chaining, + # length fields and logical channels) # ISO 7816-4:2004, page 61 text = list() @@ -483,7 +488,8 @@ text.append(" - RFU (should not happen)\n") v = (cc >> 3) & 3 - t = ["No logical channel\n", "by the interface device\n", "by the card\n", "by the interface device and card\n"] + t = ["No logical channel\n", "by the interface device\n", "by the card\n", + "by the interface device and card\n"] text.append(" - Logical channel number assignment: " + t[v]) text.append(" - Maximum number of logical channels: %d\n" % (1 + cc & 7)) @@ -707,7 +713,8 @@ text.append(" DIR data reference: %d") args.append(data_ref) - elif hb_category in (0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F): + elif hb_category in (0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, + 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F): text.append(" (Reserved for future use)") else: @@ -801,7 +808,9 @@ Y1 = atr["T0"] >> 4 K = atr["T0"] & 0xF - text.append(["T0 = 0x%02X" % atr["T0"], ["Y(1): b%s, K: %d (historical bytes)", (int2bin(Y1, padding=4), K)]]) + text.append(["T0 = 0x%02X" % atr["T0"], + ["Y(1): b%s, K: %d (historical bytes)", + (int2bin(Y1, padding=4), K)]]) for i in (1, 2, 3, 4, 5): separator = False This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2015-02-18 19:58:45
|
Revision: 669 http://sourceforge.net/p/pyscard/code/669 Author: ludov Date: 2015-02-18 19:58:38 +0000 (Wed, 18 Feb 2015) Log Message: ----------- Add pydoc documentation Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2015-02-18 17:47:21 UTC (rev 668) +++ trunk/contrib/parseATR/parseATR.py 2015-02-18 19:58:38 UTC (rev 669) @@ -40,12 +40,31 @@ def toHexString(bytes): - """ return a hex list """ + """Returns a hex list + + Args: + bytes: list of bytes (integers) + Returns: + string representing the bytes in hexadecimal + + >>> toHexString([1,2,3, 10, 255]) + '01 02 03 0A FF' + """ return " ".join(["%02X" % b for b in bytes]) def toASCIIString(bytes): - """ return a string """ + """Returns a string. + + Args: + bytes: list of bytes (integers) + Returns: + string representing the list of bytes in ASCII. Non ASCII + characters are replaced with . + + >>> toASCIIString([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]) + 'Hello world!' + """ ascii = "" for b in bytes: if b > 31 and b < 127: @@ -56,10 +75,18 @@ def normalize(atr): - """ transform an ATR in list of integers + """Transform an ATR in list of integers. valid input formats are "3B A7 00 40 18 80 65 A2 08 01 01 52" "3B:A7:00:40:18:80:65:A2:08:01:01:52" + + Args: + atr: string + Returns: + list of bytes + + >>> normalize("3B:A7:00:40:18:80:65:A2:08:01:01:52") + [59, 167, 0, 64, 24, 128, 101, 162, 8, 1, 1, 82] """ atr = atr.replace(":", "") atr = atr.replace(" ", "") @@ -76,7 +103,19 @@ def int2bin(i, padding=8): - """ convert an integer into its binary representation """ + """Converts an integer into its binary representation + + Args: + i: integer value + padding: minimum number of digits (default value 8) + Returns: + string representation of i in binary + + >>> int2bin(2015) + '11111011111' + >>> int2bin(42) + '00101010' + """ b = "" while i > 0: b = str(i % 2) + b @@ -86,6 +125,18 @@ def parseATR(atr_txt): + """Parses an ATR + + Args: + atr_txt: ATR as a hex bytes string + Returns: + dictionary of field and values + + >>> parseATR("3B A7 00 40 18 80 65 A2 08 01 01 52") + {'hbn': 7, 'TB1': 0, 'TC2': 24, 'TS': 59, 'T0': 167, + 'atr': [59, 167, 0, 64, 24, 128, 101, 162, 8, 1, 1, 82], + 'hb': [128, 101, 162, 8, 1, 1, 82], 'TD1': 64, 'pn': 2} + """ atr_txt = normalize(atr_txt) atr = {} @@ -160,6 +211,16 @@ def TA1(v): + """Parse TA1 value + + Args: + v: TA1 + Returns: + value according to ISO 7816-4 + + >>> TA1(0x11) + ['Fi=%s, Di=%s, %g cycles/ETU (%d bits/s at 4.00 MHz, %d bits/s for fMax=%d MHz)', (372, 1, 372, 10752, 13440, 5)] + """ 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, 64, 12, 20, "RFU", "RFU", "RFU", "RFU", @@ -182,6 +243,16 @@ def TA2(v): + """Parse TA2 value + + Args: + v: TA2 + Returns: + value according to ISO 7816-4 + + >>> TA2(1) + 'Protocol to be used in spec mode: T=1 - Capable to change - defined by interface bytes' + """ F = v >> 4 D = v & 0xF text = ["Protocol to be used in spec mode: T=%s" % (D)] @@ -199,18 +270,47 @@ def TA3(v): + """Parse TA3 value + + Args: + v: TA3 + Returns: + value according to ISO 7816-4 + """ return TAn(3, v) def TA4(v): + """Parse TA4 value + + Args: + v: TA4 + Returns: + value according to ISO 7816-4 + """ return TAn(4, v) def TA5(v): + """Parse TA5 value + + Args: + v: TA5 + Returns: + value according to ISO 7816-4 + """ return TAn(5, v) def TAn(i, v): + """Parse TAi (3 <= i <= 5) + + Args: + i: i + v: value of TAi + Returns: + value according to ISO 7816-4 + """ XI = ("not supported", "state L", "state H", "no preference") if (T == 1): text = "IFSC: %s" @@ -237,6 +337,13 @@ def TB1(v): + """Parse TB1 value + + Args: + v: TB1 + Returns: + value according to ISO 7816-4 + """ I = v >> 5 PI = v & 0x1F if (PI == 0): @@ -247,6 +354,13 @@ def TB2(v): + """Parse TB2 value + + Args: + v: TB2 + Returns: + value according to ISO 7816-4 + """ text = ["Programming param PI2 (PI1 should be ignored): %d" % v, ] if ((v > 49) or (v < 251)): text.append(" (dV)") @@ -256,18 +370,47 @@ def TB3(v): + """Parse TB3 value + + Args: + v: TB3 + Returns: + value according to ISO 7816-4 + """ return TBn(3, v) def TB4(v): + """Parse TB4 value + + Args: + v: TB4 + Returns: + value according to ISO 7816-4 + """ return TBn(4, v) def TB5(v): + """Parse TB5 value + + Args: + v: TB5 + Returns: + value according to ISO 7816-4 + """ return TBn(5, v) def TBn(i, v): + """Parse TBi (3 <= i <= 5) + + Args: + i: i + v: value of TBi + Returns: + value according to ISO 7816-4 + """ text = "Undocumented" args = list() if (T == 1): @@ -292,6 +435,13 @@ def TC1(v): + """Parse TC1 value + + Args: + v: TC1 + Returns: + value according to ISO 7816-4 + """ text = "Extra guard time: %d" args = v if (v == 255): @@ -300,22 +450,58 @@ def TC2(v): + """Parse TC2 value + + Args: + v: TC2 + Returns: + value according to ISO 7816-4 + """ return "Work waiting time: 960 x %d x (Fi/F)" % v def TC3(v): + """Parse TC3 value + + Args: + v: TC3 + Returns: + value according to ISO 7816-4 + """ return TCn(3, v) def TC4(v): + """Parse TC4 value + + Args: + v: TC4 + Returns: + value according to ISO 7816-4 + """ return TCn(4, v) def TC5(v): + """Parse TC5 value + + Args: + v: TC5 + Returns: + value according to ISO 7816-4 + """ return TCn(5, v) def TCn(i, v): + """Parse TCi (3 <= i <= 5) + + Args: + i: i + v: value of TCi + Returns: + value according to ISO 7816-4 + """ text = list() args = list() if (T == 1): @@ -331,26 +517,69 @@ def TD1(v): + """Parse TD1 value + + Args: + v: TD1 + Returns: + value according to ISO 7816-4 + """ return TDn(1, v) def TD2(v): + """Parse TD2 value + + Args: + v: TD2 + Returns: + value according to ISO 7816-4 + """ return TDn(2, v) def TD3(v): + """Parse TD3 value + + Args: + v: TD3 + Returns: + value according to ISO 7816-4 + """ return TDn(3, v) def TD4(v): + """Parse TD4 value + + Args: + v: TD4 + Returns: + value according to ISO 7816-4 + """ return TDn(4, v) def TD5(v): + """Parse TD5 value + + Args: + v: TD5 + Returns: + value according to ISO 7816-4 + """ return TDn(5, v) def TDn(i, v): + """Parse TDi (1 <= i <= 5) + + Args: + i: i + v: value of TDi + Returns: + value according to ISO 7816-4 + """ global T Y = v >> 4 T = v & 0xF @@ -361,8 +590,19 @@ def life_cycle_status(lcs): + """Life Cycle Status # Table 13 - Life cycle status byte # ISO 7816-4:2004, page 21 + + Args: + lcs: Life Cycle Status + + Returns: + Text value + + >>> life_cycle_status(5) + 'Operational state (activated)' + """ text = "Unknown" if lcs > 15: @@ -385,8 +625,18 @@ def data_coding(dc): + """Data Coding + # Table 87 - Second software function table (data coding byte) # ISO 7816-4:2004, page 60 + + Args: + dc: data coding + + Returns: + Text value + + """ text = list() if dc & 128: @@ -409,8 +659,17 @@ def selection_methods(sm): + """Selection Methods + # Table 86 - First software function table (selection methods) # ISO 7816-4:2004, page 60 + + Args: + sm: Selection Methods + + Returns: + Text value + """ text = list() if sm & 1: @@ -441,8 +700,17 @@ def selection_mode(sm): + """Selection Mode + # Table 87 - Second software function table (data coding byte) # ISO 7816-4:2004, page 60 + + Args: + sm: Selection Mode + + Returns: + Text value + """ text = list() if sm & 1: @@ -473,9 +741,18 @@ def command_chaining(cc): + """Command Chaining + # Table 88 - Third software function table (command chaining, # length fields and logical channels) # ISO 7816-4:2004, page 61 + + Args: + cc: Command Chaining + + Returns: + Text value + """ text = list() if cc & 128: @@ -498,8 +775,17 @@ def card_service(cs): + """Card Service + # Table 85 - Card service data byte # ISO 7816-4:2004, page 59 + + Args: + ccs Card Service + + Returns: + Text value + """ text = list() if cs & 128: @@ -534,6 +820,17 @@ def compact_tlv(historical_bytes): + """Compact TLV + + Args: + historical_bytes + + Returns: + list of text values + + >>> compact_tlv([101, 162, 8, 1, 1, 82]) + [' Tag: 6, Len: 5 (%s)\\n Data: %s "%s"\\n', ('pre-issuing data', 'A2 08 01 01 52', '....R')] + """ text = "" tlv = historical_bytes.pop(0) @@ -665,6 +962,17 @@ def analyse_histrorical_bytes(historical_bytes): + """Analyse Historical Bytes + + Args: + historical_bytes: list of bytes + + Returns: + list + + >>> analyse_histrorical_bytes([128, 101, 162, 8, 1, 1, 82]) + [' Category indicator byte: 0x80', [' (compact TLV data object)\\n Tag: 6, Len: 5 (%s)\\n Data: %s "%s"\\n', ('pre-issuing data', 'A2 08 01 01 52', '....R')]] + """ text = list() args = list() @@ -725,6 +1033,14 @@ def compute_tck(atr): + """Computes TCK (ATR checksum) + + Args: + atr: list of bytes + + Returns: + TCK value + """ # do not include TS byte s = atr["atr"][0] for e in atr["atr"]: @@ -735,7 +1051,21 @@ def colorize_line(line, left, right): - # colorize data from the format: foo: data, ... + """Colorize a line + + Args: + line: a tuple of 2 elements with + - a line with substitution strings (%s, %d, %g) + - the values of substitution + left: string to add before the substitution + right: string to add after the substitution + + Returns: + Text + + >>> colorize_line(['foo%sbar', 1], 'a', 'b') + 'fooa1bbar' + """ if isinstance(line, StringTypes): return line @@ -747,6 +1077,14 @@ def colorize_txt(l): + """Colorize a text line using ANSI colors + + args: + l: line or 2 elements tuple + + Returns: + colorized line + """ magenta = "\033[35m" normal = "\033[0m" blue = "\033[34m" @@ -761,6 +1099,14 @@ def atr_display_txt(atr): + """Parse an ATR for a text display + + Args: + atr: ATR + + Returns: + Text + """ return atr_display(atr, colorize_txt) html_escape_table = { @@ -773,7 +1119,17 @@ def html_escape(text): - """Produce entities within text.""" + """Produce entities within text. + + Args: + text: text containing special HTML characters + + Returns: + same text with HTML character replaced by their HTML equivalent + + >>> html_escape("&") + '&' + """ L = list() for c in text: L.append(html_escape_table.get(c, c)) @@ -781,6 +1137,14 @@ def colorize_html(l): + """Colorize a text line using HTML colors + + args: + l: line or 2 elements tuple + + Returns: + colorized line + """ left = '<span class="data">' right = '</span>' @@ -798,10 +1162,27 @@ def atr_display_html(atr): + """Parse an ATR for a text display + + Args: + atr: ATR + + Returns: + Text in HTML format + """ return atr_display(atr, colorize_html) def atr_display(atr, colorize): + """Parse an ATR for a given output + + Args: + atr: ATR + colorize: colorization function + + Returns: + Text + """ text = list() TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} text.append(["TS = 0x%02X" % atr["TS"], TS.get(atr["TS"], "Invalid")]) @@ -850,7 +1231,19 @@ def match_atr(atr, atr_file=None): - """ try to find card description for a given ATR """ + """Try to find card description for a given ATR. + + Args: + atr: ATR + atr_file: file containing a list of known ATRs + + Returns: + list of card descriptions + + >>> match_atr('3B A7 00 40 18 80 65 A2 08 01 01 52') + Using: /Users/rousseau/.cache/smartcard_list.txt + ['3B A7 00 40 .. 80 65 A2 08 .. .. ..', 'Gemplus GemSAFE Smart Card (8K)', 'Gemplus GPK8000', 'GemSAFE Smart Card (8K)'] + """ card = list() atr = toHexString(normalize(atr)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |