From: <lu...@us...> - 2009-01-27 09:00:46
|
Revision: 261 http://pyscard.svn.sourceforge.net/pyscard/?rev=261&view=rev Author: ludov Date: 2009-01-27 09:00:44 +0000 (Tue, 27 Jan 2009) Log Message: ----------- use smartcard.util.toHexString() instead of a for loop Modified Paths: -------------- trunk/pyscard/src/smartcard/Examples/scard-api/sample_getATR.py trunk/pyscard/src/smartcard/Examples/scard-api/sample_getAttrib.py trunk/pyscard/src/smartcard/Examples/scard-api/sample_getStatusChange.py trunk/pyscard/src/smartcard/Examples/scard-api/sample_selectDFTelecom.py Modified: trunk/pyscard/src/smartcard/Examples/scard-api/sample_getATR.py =================================================================== --- trunk/pyscard/src/smartcard/Examples/scard-api/sample_getATR.py 2009-01-20 13:47:48 UTC (rev 260) +++ trunk/pyscard/src/smartcard/Examples/scard-api/sample_getATR.py 2009-01-27 09:00:44 UTC (rev 261) @@ -25,6 +25,7 @@ """ from smartcard.scard import * +import smartcard.util try: hresult, hcontext = SCardEstablishContext( SCARD_SCOPE_USER ) @@ -58,10 +59,7 @@ print 'Reader:', reader print 'State:', state print 'Protocol:', protocol - print 'ATR:', - for i in xrange(len(atr)): - print "0x%.2X" % atr[i], - print "" + print 'ATR:', smartcard.util.toHexString(atr, smartcard.util.HEX) finally: hresult = SCardDisconnect( hcard, SCARD_UNPOWER_CARD ) Modified: trunk/pyscard/src/smartcard/Examples/scard-api/sample_getAttrib.py =================================================================== --- trunk/pyscard/src/smartcard/Examples/scard-api/sample_getAttrib.py 2009-01-20 13:47:48 UTC (rev 260) +++ trunk/pyscard/src/smartcard/Examples/scard-api/sample_getAttrib.py 2009-01-27 09:00:44 UTC (rev 261) @@ -26,6 +26,7 @@ import struct from smartcard.scard import * +import smartcard.util if 'winscard'==resourceManager: attributes = { @@ -126,9 +127,7 @@ def printAttribute( attrib, value ): print '-----------------', attributes[attrib], '-----------------' print value - for j in xrange(len(value)): - print "0x%.2X" % value[j], - print "" + print smartcard.util.toHexString(value, smartcard.util.HEX) print apply( struct.pack, [ '<' + 'B' * len(value)] + value ) Modified: trunk/pyscard/src/smartcard/Examples/scard-api/sample_getStatusChange.py =================================================================== --- trunk/pyscard/src/smartcard/Examples/scard-api/sample_getStatusChange.py 2009-01-20 13:47:48 UTC (rev 260) +++ trunk/pyscard/src/smartcard/Examples/scard-api/sample_getStatusChange.py 2009-01-27 09:00:44 UTC (rev 261) @@ -25,16 +25,14 @@ """ from smartcard.scard import * +import smartcard.util srTreeATR = [0x3B, 0x77, 0x94, 0x00, 0x00, 0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22] srTreeMask= [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] def printstate (state): reader, eventstate, atr = state - print reader, - for b in atr: - print "0x%.2X" % b, - print "" + print reader + " " + smartcard.util.toHexString(atr, smartcard.util.HEX) if eventstate & SCARD_STATE_ATRMATCH: print '\tCard found' if eventstate & SCARD_STATE_UNAWARE: Modified: trunk/pyscard/src/smartcard/Examples/scard-api/sample_selectDFTelecom.py =================================================================== --- trunk/pyscard/src/smartcard/Examples/scard-api/sample_selectDFTelecom.py 2009-01-20 13:47:48 UTC (rev 260) +++ trunk/pyscard/src/smartcard/Examples/scard-api/sample_selectDFTelecom.py 2009-01-27 09:00:44 UTC (rev 261) @@ -25,8 +25,8 @@ """ from smartcard.scard import * +import smartcard.util - SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] GET_RESPONSE = [0xA0, 0xC0, 0x00, 0x00] @@ -61,17 +61,11 @@ hresult, response = SCardTransmit( hcard, SCARD_PCI_T0, SELECT + DF_TELECOM ) if hresult!=0: raise error, 'Failed to transmit: ' + SCardGetErrorMessage(hresult) - print 'Selected DF_TELECOM:', - for i in xrange(len(response)): - print "0x%.2X" % response[i], - print "" + print 'Selected DF_TELECOM: ' + smartcard.util.toHexString(response, smartcard.util.HEX) hresult, response = SCardTransmit( hcard, SCARD_PCI_T0, GET_RESPONSE + [response[1]] ) if hresult!=0: raise error, 'Failed to transmit: ' + SCardGetErrorMessage(hresult) - print 'GET_RESPONSE after SELECT DF_TELECOM:', - for i in xrange(len(response)): - print "0x%.2X" % response[i], - print "" + print 'GET_RESPONSE after SELECT DF_TELECOM: ' + smartcard.util.toHexString(response, smartcard.util.HEX) finally: hresult = SCardDisconnect( hcard, SCARD_UNPOWER_CARD ) if hresult!=0: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |