You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(10) |
Feb
(10) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(17) |
Sep
(9) |
Oct
(10) |
Nov
(2) |
Dec
(5) |
2009 |
Jan
(17) |
Feb
(8) |
Mar
(10) |
Apr
(1) |
May
|
Jun
(11) |
Jul
(18) |
Aug
|
Sep
|
Oct
(10) |
Nov
(40) |
Dec
(4) |
2010 |
Jan
(2) |
Feb
(5) |
Mar
(13) |
Apr
(14) |
May
(27) |
Jun
(86) |
Jul
(1) |
Aug
(12) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(5) |
2011 |
Jan
|
Feb
(2) |
Mar
|
Apr
(3) |
May
|
Jun
|
Jul
(11) |
Aug
(1) |
Sep
(3) |
Oct
(65) |
Nov
|
Dec
(1) |
2012 |
Jan
(1) |
Feb
(4) |
Mar
(6) |
Apr
(6) |
May
|
Jun
(4) |
Jul
|
Aug
|
Sep
(12) |
Oct
(3) |
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
|
Dec
(1) |
2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(4) |
Oct
(1) |
Nov
(24) |
Dec
(10) |
2015 |
Jan
(1) |
Feb
(10) |
Mar
|
Apr
|
May
(1) |
Jun
(15) |
Jul
(4) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <lu...@us...> - 2010-06-09 16:16:17
|
Revision: 480 http://pyscard.svn.sourceforge.net/pyscard/?rev=480&view=rev Author: ludov Date: 2010-06-09 16:16:10 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/manual/testcase_manualCardRequest.py Modified: trunk/pyscard/src/smartcard/test/manual/testcase_manualCardRequest.py =================================================================== --- trunk/pyscard/src/smartcard/test/manual/testcase_manualCardRequest.py 2010-06-09 16:11:07 UTC (rev 479) +++ trunk/pyscard/src/smartcard/test/manual/testcase_manualCardRequest.py 2010-06-09 16:16:10 UTC (rev 480) @@ -42,8 +42,8 @@ # print 'insert two smartcard readers' while True: - readerz=readers() - if 2<=len( readerz ): + readerz = readers() + if 2 <= len(readerz): break time.sleep(.3) for reader in readerz: @@ -52,46 +52,42 @@ print 'insert two cards in the readers' cardrequest = CardRequest() while True: - cardz=cardrequest.waitforcardevent() - if 2<=len( cardz ): + cardz = cardrequest.waitforcardevent() + if 2 <= len(cardz): break time.sleep(.3) for card in cardz: print '\t', toHexString(card.atr) -# -# -# -class testcase_manualCardRequest( unittest.TestCase, CardObserver ): +class testcase_manualCardRequest(unittest.TestCase, CardObserver): """Test case for CardRequest.""" - - def setUp( self ): + def setUp(self): pass - def tearDown( self ): + def tearDown(self): pass - def removeAllCards( self ): + def removeAllCards(self): print 'please remove all inserted smart cards' cardrequest = CardRequest() while True: - cards=cardrequest.waitforcardevent() - if 0==len( cards ): + cards = cardrequest.waitforcardevent() + if 0 == len(cards): break time.sleep(.3) print 'ok' - def testcase_CardRequestNewCardAnyCardTypeInfiniteTimeOut( self ): + def testcase_CardRequestNewCardAnyCardTypeInfiniteTimeOut(self): """Test smartcard.CardRequest for any new card without time-out.""" self.removeAllCards() cardtype = AnyCardType() - cardrequest = CardRequest( timeout=None, cardType=cardtype, newcardonly=True ) + cardrequest = CardRequest(timeout=None, cardType=cardtype, newcardonly=True) print 're-insert any combination of cards six time' - count=0 - for i in range( 0, 6 ): + count = 0 + for i in range(0, 6): cardservice = cardrequest.waitforcard() try: cardservice.connection.connect() @@ -100,93 +96,94 @@ # card was removed too fast pass cardservice.connection.disconnect() - count +=1 - self.assertEquals( 6, count ) + count += 1 + self.assertEquals(6, count) + def testcase_CardRequestNewCardATRCardTypeInfiniteTimeOut(self): + """Test smartcard.CardRequest for new card with given ATR + without time-out.""" - def testcase_CardRequestNewCardATRCardTypeInfiniteTimeOut( self ): - """Test smartcard.CardRequest for new card with given ATR without time-out.""" - self.removeAllCards() - count=0 - for i in range(0,6): - card = random.choice( cardz ) - cardtype = ATRCardType( card.atr ) - cardrequest = CardRequest( timeout=None, cardType=cardtype, newcardonly=True ) - print 're-insert card', toHexString( card.atr ), 'into', card.reader + count = 0 + for i in range(0, 6): + card = random.choice(cardz) + cardtype = ATRCardType(card.atr) + cardrequest = CardRequest(timeout=None, cardType=cardtype, newcardonly=True) + print 're-insert card', toHexString(card.atr), 'into', card.reader cardservice = cardrequest.waitforcard() print 'ok' try: cardservice.connection.connect() - self.assertEquals( cardservice.connection.getATR(), card.atr ) + self.assertEquals(cardservice.connection.getATR(), card.atr) except CardConnectionException: # card was removed too fast pass cardservice.connection.disconnect() - count+=1 - self.assertEquals( 6, count ) + count += 1 + self.assertEquals(6, count) + def testcase_CardRequestNewCardAnyCardTypeFiniteTimeOutNoInsertion(self): + """Test smartcard.CardRequest for new card with time-out and no + insertion before time-out.""" - def testcase_CardRequestNewCardAnyCardTypeFiniteTimeOutNoInsertion( self ): - """Test smartcard.CardRequest for new card with time-out and no insertion before time-out.""" - self.removeAllCards() # make sure we have 6 time-outs cardtype = AnyCardType() - cardrequest = CardRequest( timeout=1, cardType=cardtype, newcardonly=True ) - count=0 - for i in range( 0, 6 ): + cardrequest = CardRequest(timeout=1, cardType=cardtype, newcardonly=True) + count = 0 + for i in range(0, 6): try: - before=time.time() + before = time.time() cardservice = cardrequest.waitforcard() - except CardRequestTimeoutException,e: - elapsed=int( 10*(time.time()-before )) + except CardRequestTimeoutException, e: + elapsed = int(10 * (time.time() - before)) print '.', - self.assert_( elapsed>=10 and elapsed<=11. ) + self.assert_(elapsed >= 10 and elapsed <= 11.) count += 1 print '\n' - self.assertEquals( 6, count ) + self.assertEquals(6, count) + def testcase_CardRequestNewCardAnyCardTypeFiniteTimeOutInsertion(self): + """Test smartcard.CardRequest for new card with time-out and + insertion before time-out.""" - def testcase_CardRequestNewCardAnyCardTypeFiniteTimeOutInsertion( self ): - """Test smartcard.CardRequest for new card with time-out and insertion before time-out.""" - self.removeAllCards() # make sure insertion is within 5s cardtype = AnyCardType() - cardrequest = CardRequest( timeout=5, cardType=cardtype, newcardonly=True ) - count=0 - for i in range( 0, 6 ): + cardrequest = CardRequest(timeout=5, cardType=cardtype, newcardonly=True) + count = 0 + for i in range(0, 6): try: print 're-insert any card within the next 5 seconds' - before=time.time() + before = time.time() cardservice = cardrequest.waitforcard() count += 1 - elapsed=int( 10*(time.time()-before )) - self.assert_( elapsed<=55. ) - except CardRequestTimeoutException,e: + elapsed = int(10 * (time.time() - before)) + self.assert_(elapsed <= 55.) + except CardRequestTimeoutException, e: print 'too slow... Test will show a failure' print '\n' - self.assertEquals( 6, count ) + self.assertEquals(6, count) - def testcase_CardRequestNewCardAnyCardTypeSpecificReaderNotPresentInfiniteTimeOut( self ): - """Test smartcard.CardRequest for any new card in a specific reader not present without time-out.""" + def testcase_CardRequestNewCardAnyCardTypeSpecificReaderNotPresentInfiniteTimeOut(self): + """Test smartcard.CardRequest for any new card in a specific + reader not present without time-out.""" print 'please remove a smart card reader' - _readerz=readers() + _readerz = readers() while True: - readerz=readers() - if len(_readerz)>len( readerz ): + readerz = readers() + if len(_readerz) > len(readerz): break time.sleep(.1) for reader in readerz: - _readerz.remove( reader ) + _readerz.remove(reader) cardtype = AnyCardType() - cardrequest = CardRequest( timeout=None, readers=[ _readerz[0] ], cardType=cardtype, newcardonly=True ) + cardrequest = CardRequest(timeout=None, readers=[_readerz[0]], cardType=cardtype, newcardonly=True) print 'Re-insert reader ', _readerz[0], 'with a card inside' cardservice = cardrequest.waitforcard() cardservice.connection.connect() @@ -194,9 +191,8 @@ cardservice.connection.disconnect() - def suite(): - suite1 = unittest.makeSuite( testcase_manualCardRequest ) + suite1 = unittest.makeSuite(testcase_manualCardRequest) return unittest.TestSuite((suite1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 16:11:18
|
Revision: 479 http://pyscard.svn.sourceforge.net/pyscard/?rev=479&view=rev Author: ludov Date: 2010-06-09 16:11:07 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py trunk/pyscard/src/smartcard/test/frameworkpcsc/testsuite_frameworkpcsc.py Modified: trunk/pyscard/src/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py =================================================================== --- trunk/pyscard/src/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py 2010-06-09 15:55:22 UTC (rev 478) +++ trunk/pyscard/src/smartcard/test/frameworkpcsc/testcase_pcscreadergroups.py 2010-06-09 16:11:07 UTC (rev 479) @@ -46,12 +46,13 @@ from smartcard.pcsc.PCSCReader import readers from smartcard.scard import resourceManager -if 'winscard'==resourceManager: +if 'winscard' == resourceManager: + class testcase_readergroups(unittest.TestCase): """Test smartcard framework readers factory methods""" - def setUp( self ): - groups=PCSCReaderGroups() + def setUp(self): + groups = PCSCReaderGroups() try: groups.remove('Pinpad$Readers') groups.remove('Biometric$Readers') @@ -60,96 +61,95 @@ def testcase_add(self): """Test for groups=groups+newgroups""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' - groups=groups+newgroup - self.assertEquals( groups, groupssnapshot+[newgroup] ) + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' + groups = groups + newgroup + self.assertEquals(groups, groupssnapshot + [newgroup]) groups.remove(newgroup) def testcase_addlist(self): """Test for groups=groups+[newgroups]""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroups=['Pinpad$Readers','Biometric$Readers'] - groups=groups+newgroups - self.assertEquals( groups, groupssnapshot+newgroups ) + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroups = ['Pinpad$Readers', 'Biometric$Readers'] + groups = groups + newgroups + self.assertEquals(groups, groupssnapshot + newgroups) for group in newgroups: groups.remove(group) def testcase_iadd(self): """Test for groups+=newgroup""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' - groups+=newgroup - self.assertEquals( groups, groupssnapshot+[newgroup] ) + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' + groups += newgroup + self.assertEquals(groups, groupssnapshot + [newgroup]) groups.remove(newgroup) def testcase_iaddlist(self): """Test for groups+=[newgroups]""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroups=['Pinpad$Readers','Biometric$Readers'] - groups+=newgroups - self.assertEquals( groups, groupssnapshot+newgroups ) + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroups = ['Pinpad$Readers', 'Biometric$Readers'] + groups += newgroups + self.assertEquals(groups, groupssnapshot + newgroups) for group in newgroups: groups.remove(group) def testcase_append(self): """Test for groups.append(newgroup)""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' groups.append(newgroup) - self.assertEquals( groups, groupssnapshot+[newgroup] ) + self.assertEquals(groups, groupssnapshot + [newgroup]) groups.remove(newgroup) def testcase_insert(self): """Test for groups.insert(newgroup)""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' - groups.insert( 0, newgroup) - self.assertEquals( groups, [newgroup]+groupssnapshot ) + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' + groups.insert(0, newgroup) + self.assertEquals(groups, [newgroup] + groupssnapshot) groups.remove(newgroup) def testcase_removereadergroup_pop(self): """Test for groups.pop()""" - groupssnapshot=list(PCSCReaderGroups()) - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' - groups.insert( 0, newgroup) - self.assertEquals( groups, [newgroup]+groupssnapshot ) + groupssnapshot = list(PCSCReaderGroups()) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' + groups.insert(0, newgroup) + self.assertEquals(groups, [newgroup] + groupssnapshot) groups.pop(0) - self.assertEquals( groups, groupssnapshot ) + self.assertEquals(groups, groupssnapshot) def testcase_addreadertogroup(self): """Test for adding readers to group""" - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' - groups.insert( 0, newgroup) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' + groups.insert(0, newgroup) for r in readers('SCard$DefaultReaders'): - r.addtoreadergroup( newgroup ) - self.assertEquals( readers('SCard$DefaultReaders'), readers(newgroup) ) + r.addtoreadergroup(newgroup) + self.assertEquals(readers('SCard$DefaultReaders'), readers(newgroup)) groups.pop(0) - self.assertEquals( [], readers(newgroup) ) + self.assertEquals([], readers(newgroup)) def testcase_removereaderfromgroup(self): """Test for removing readers from group""" - groups=PCSCReaderGroups() - newgroup='Pinpad$Readers' - groups.insert( 0, newgroup) + groups = PCSCReaderGroups() + newgroup = 'Pinpad$Readers' + groups.insert(0, newgroup) for r in readers('SCard$DefaultReaders'): - r.addtoreadergroup( newgroup ) - self.assertEquals( readers('SCard$DefaultReaders'), readers(newgroup) ) + r.addtoreadergroup(newgroup) + self.assertEquals(readers('SCard$DefaultReaders'), readers(newgroup)) for r in readers('SCard$DefaultReaders'): - r.removefromreadergroup( newgroup ) - self.assertEquals( [], readers(newgroup) ) + r.removefromreadergroup(newgroup) + self.assertEquals([], readers(newgroup)) groups.pop(0) - self.assertEquals( [], readers(newgroup) ) + self.assertEquals([], readers(newgroup)) - def suite(): suite1 = unittest.makeSuite(testcase_readergroups) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/frameworkpcsc/testsuite_frameworkpcsc.py =================================================================== --- trunk/pyscard/src/smartcard/test/frameworkpcsc/testsuite_frameworkpcsc.py 2010-06-09 15:55:22 UTC (rev 478) +++ trunk/pyscard/src/smartcard/test/frameworkpcsc/testsuite_frameworkpcsc.py 2010-06-09 16:11:07 UTC (rev 479) @@ -30,13 +30,14 @@ sys.path += ['..'] import configcheck + def suite(): modules_to_test = ( 'testcase_pcscreadergroups', ) testsuite_framework = unittest.TestSuite() for module in map(__import__, modules_to_test): - testsuite_framework.addTest( unittest.findTestCases(module) ) + testsuite_framework.addTest(unittest.findTestCases(module)) return testsuite_framework if __name__ == '__main__': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:55:28
|
Revision: 478 http://pyscard.svn.sourceforge.net/pyscard/?rev=478&view=rev Author: ludov Date: 2010-06-09 15:55:22 +0000 (Wed, 09 Jun 2010) Log Message: ----------- generate a pep8 valid file Modified Paths: -------------- trunk/pyscard/src/smartcard/test/configcheck.py Modified: trunk/pyscard/src/smartcard/test/configcheck.py =================================================================== --- trunk/pyscard/src/smartcard/test/configcheck.py 2010-06-09 15:52:06 UTC (rev 477) +++ trunk/pyscard/src/smartcard/test/configcheck.py 2010-06-09 15:55:22 UTC (rev 478) @@ -62,15 +62,15 @@ #for atr in expectedATRs: print `toHexString(atr)` f.write(`expectedATRs` + '\n') - f.write('expectedATRinReader = {} \n') - f.write('for i in xrange(len(expectedReaders)): \n') - f.write('\t' + 'expectedATRinReader[expectedReaders[i]]=expectedATRs[i] \n') + f.write('expectedATRinReader = {}\n') + f.write('for i in xrange(len(expectedReaders)):\n') + f.write(' expectedATRinReader[expectedReaders[i]] = expectedATRs[i]\n') - f.write('expectedReaderForATR = {} \n') - f.write('for i in xrange(len(expectedReaders)): \n') - f.write('\t' + 'expectedReaderForATR[toHexString(expectedATRs[i])]=expectedReaders[i] \n') + f.write('expectedReaderForATR = {}\n') + f.write('for i in xrange(len(expectedReaders)):\n') + f.write(' expectedReaderForATR[toHexString(expectedATRs[i])] = expectedReaders[i]\n') - f.write('expectedReaderGroups = [ \'SCard$DefaultReaders\' ] \n') + f.write('expectedReaderGroups = [\'SCard$DefaultReaders\']\n') f.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:52:12
|
Revision: 477 http://pyscard.svn.sourceforge.net/pyscard/?rev=477&view=rev Author: ludov Date: 2010-06-09 15:52:06 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_utils.py trunk/pyscard/src/smartcard/test/framework/testsuite_framework.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_utils.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_utils.py 2010-06-09 15:50:13 UTC (rev 476) +++ trunk/pyscard/src/smartcard/test/framework/testcase_utils.py 2010-06-09 15:52:06 UTC (rev 477) @@ -32,80 +32,75 @@ from smartcard.util import * + class testcase_utils(unittest.TestCase): """Test smartcard.utils.""" - def testcase_asciitostring(self): """tests ASCIIToString""" - self.assertEquals( toASCIIString( [0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x20, 0x31, 0x30, 0x31] ), "Number 101" ) + self.assertEquals(toASCIIString([0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x20, 0x31, 0x30, 0x31]), "Number 101") - def testcase_bytesto338(self): """tests toGSM3_38Bytes""" - self.assertEquals( toGSM3_38Bytes( "@\xF9Pascal" ), [ 0x00, 0x06, 0x50, 0x61, 0x73, 0x63, 0x61, 0x6C ] ) + self.assertEquals(toGSM3_38Bytes("@\xF9Pascal"), [0x00, 0x06, 0x50, 0x61, 0x73, 0x63, 0x61, 0x6C]) - def testcase_padd(self): """tests padd""" - self.assertEquals( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], - padd( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 16 ) ) + self.assertEquals([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], + padd([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 16)) - self.assertEquals( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3 ], - padd( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 9 ) ) + self.assertEquals([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], + padd([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 9)) - self.assertEquals( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3 ], - padd( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 8 ) ) + self.assertEquals([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], + padd([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 8)) - self.assertEquals( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3, 0xFF ], - padd( [0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3 ], 10 ) ) + self.assertEquals([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3, 0xFF], + padd([0x3B, 0x65, 0, 0, 0x9C, 0x11, 1, 1, 3], 10)) - def testcase_toasciibytes(self): """tests toASCIIBytes""" - self.assertEquals( [0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x20, 0x31, 0x30, 0x31], - toASCIIBytes( "Number 101" ) ) + self.assertEquals([0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x20, 0x31, 0x30, 0x31], + toASCIIBytes("Number 101")) - self.assertEquals( toASCIIString( toASCIIBytes( "Number 101" ) ), "Number 101" ) + self.assertEquals(toASCIIString(toASCIIBytes("Number 101")), "Number 101") - def testcase_tobytestring(self): """tests toByteString""" - self.assertEquals( [59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B 65 00 00 9C 11 01 01 03") ) - self.assertEquals( [59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B6500009C11010103") ) - self.assertEquals( [59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B65 0000 9C11 010103") ) - self.assertEquals( [59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B65 \t\t0000 \t9C11 \t0101\t03 \t\n") ) + self.assertEquals([59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B 65 00 00 9C 11 01 01 03")) + self.assertEquals([59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B6500009C11010103")) + self.assertEquals([59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B65 0000 9C11 010103")) + self.assertEquals([59, 101, 0, 0, 156, 17, 1, 1, 3], toBytes("3B65 \t\t0000 \t9C11 \t0101\t03 \t\n")) - def testcase_tohexstring(self): """tests toHexString""" - self.assertEquals( "3B 65 00 00 9C 11 01 01 03", toHexString([59, 101, 0, 0, 156, 17, 1, 1, 3]) ) + self.assertEquals("3B 65 00 00 9C 11 01 01 03", toHexString([59, 101, 0, 0, 156, 17, 1, 1, 3])) - bytes = [ 0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03 ] - self.assertEquals( "3B, 65, 00, 00, 9C, 11, 01, 01, 03", toHexString( bytes, COMMA ) ) - self.assertEquals( "3B6500009C11010103", toHexString( bytes, PACK ) ) - self.assertEquals( "0x3B 0x65 0x00 0x00 0x9C 0x11 0x01 0x01 0x03", toHexString( bytes, HEX ) ) - self.assertEquals( "0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03", toHexString( bytes, HEX | COMMA ) ) - self.assertEquals( "0X3B 0X65 0X00 0X00 0X9C 0X11 0X01 0X01 0X03", toHexString( bytes, HEX | UPPERCASE ) ) - self.assertEquals( "0X3B, 0X65, 0X00, 0X00, 0X9C, 0X11, 0X01, 0X01, 0X03", toHexString( bytes, HEX | UPPERCASE | COMMA) ) + bytes = [0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03] + self.assertEquals("3B, 65, 00, 00, 9C, 11, 01, 01, 03", toHexString(bytes, COMMA)) + self.assertEquals("3B6500009C11010103", toHexString(bytes, PACK)) + self.assertEquals("0x3B 0x65 0x00 0x00 0x9C 0x11 0x01 0x01 0x03", toHexString(bytes, HEX)) + self.assertEquals("0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03", toHexString(bytes, HEX | COMMA)) + self.assertEquals("0X3B 0X65 0X00 0X00 0X9C 0X11 0X01 0X01 0X03", toHexString(bytes, HEX | UPPERCASE)) + self.assertEquals("0X3B, 0X65, 0X00, 0X00, 0X9C, 0X11, 0X01, 0X01, 0X03", toHexString(bytes, HEX | UPPERCASE | COMMA)) bytes = [59, 101, 0, 0, 156, 17, 1, 1, 3] - self.assertEquals( "3B, 65, 00, 00, 9C, 11, 01, 01, 03", toHexString( bytes, COMMA ) ) - self.assertEquals( "3B6500009C11010103", toHexString( bytes, PACK ) ) - self.assertEquals( "0x3B 0x65 0x00 0x00 0x9C 0x11 0x01 0x01 0x03", toHexString( bytes, HEX ) ) - self.assertEquals( "0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03", toHexString( bytes, HEX | COMMA ) ) - self.assertEquals( "0X3B 0X65 0X00 0X00 0X9C 0X11 0X01 0X01 0X03", toHexString( bytes, HEX | UPPERCASE ) ) - self.assertEquals( "0X3B, 0X65, 0X00, 0X00, 0X9C, 0X11, 0X01, 0X01, 0X03", toHexString( bytes, HEX | UPPERCASE | COMMA) ) + self.assertEquals("3B, 65, 00, 00, 9C, 11, 01, 01, 03", toHexString(bytes, COMMA)) + self.assertEquals("3B6500009C11010103", toHexString(bytes, PACK)) + self.assertEquals("0x3B 0x65 0x00 0x00 0x9C 0x11 0x01 0x01 0x03", toHexString(bytes, HEX)) + self.assertEquals("0x3B, 0x65, 0x00, 0x00, 0x9C, 0x11, 0x01, 0x01, 0x03", toHexString(bytes, HEX | COMMA)) + self.assertEquals("0X3B 0X65 0X00 0X00 0X9C 0X11 0X01 0X01 0X03", toHexString(bytes, HEX | UPPERCASE)) + self.assertEquals("0X3B, 0X65, 0X00, 0X00, 0X9C, 0X11, 0X01, 0X01, 0X03", toHexString(bytes, HEX | UPPERCASE | COMMA)) def testcase_tohexstring_empty(self): """tests toHexString""" - self.assertEquals( "", toHexString() ) - self.assertEquals( "", toHexString([]) ) + self.assertEquals("", toHexString()) + self.assertEquals("", toHexString([])) def testcase_tohexstring_nobytes(self): """tests toHexString""" - self.assertRaises( TypeError, toHexString, 'bad input' ) - self.assertRaises( TypeError, toHexString, ['bad', 'input'] ) + self.assertRaises(TypeError, toHexString, 'bad input') + self.assertRaises(TypeError, toHexString, ['bad', 'input']) def suite(): Modified: trunk/pyscard/src/smartcard/test/framework/testsuite_framework.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testsuite_framework.py 2010-06-09 15:50:13 UTC (rev 476) +++ trunk/pyscard/src/smartcard/test/framework/testsuite_framework.py 2010-06-09 15:52:06 UTC (rev 477) @@ -30,6 +30,7 @@ sys.path += ['..'] import configcheck + def suite(): modules_to_test = ( 'testcase_ATR', @@ -51,7 +52,7 @@ ) testsuite_framework = unittest.TestSuite() for module in map(__import__, modules_to_test): - testsuite_framework.addTest( unittest.findTestCases(module) ) + testsuite_framework.addTest(unittest.findTestCases(module)) return testsuite_framework if __name__ == '__main__': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:50:19
|
Revision: 476 http://pyscard.svn.sourceforge.net/pyscard/?rev=476&view=rev Author: ludov Date: 2010-06-09 15:50:13 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_readers.py trunk/pyscard/src/smartcard/test/framework/testcase_ulist.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_readers.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_readers.py 2010-06-09 15:42:05 UTC (rev 475) +++ trunk/pyscard/src/smartcard/test/framework/testcase_readers.py 2010-06-09 15:50:13 UTC (rev 476) @@ -46,55 +46,57 @@ from smartcard import listReaders from smartcard.scard import resourceManager + class testcase_readers(unittest.TestCase): """Test smartcard framework readers factory methods""" def testcase_enoughreaders(self): - self.assert_( len( readers() )>1 ) + self.assert_(len(readers()) > 1) def testcase_readers(self): - foundreaders={} + foundreaders = {} for reader in readers(): - foundreaders[str(reader)]=1 + foundreaders[str(reader)] = 1 for reader in expectedReaders: - self.assert_( foundreaders.has_key( reader ) ) + self.assert_(foundreaders.has_key(reader)) def testcase_legacyreaders(self): - foundreaders={} + foundreaders = {} for reader in listReaders(): - foundreaders[reader]=1 + foundreaders[reader] = 1 for reader in expectedReaders: - self.assert_( foundreaders.has_key( reader ) ) + self.assert_(foundreaders.has_key(reader)) def testcase_readers_in_readergroup(self): - foundreaders={} + foundreaders = {} for reader in readers(['SCard$DefaultReaders']): - foundreaders[str(reader)]=1 + foundreaders[str(reader)] = 1 for reader in expectedReaders: - self.assert_( foundreaders.has_key( reader ) ) + self.assert_(foundreaders.has_key(reader)) def testcase_readers_in_readergroup_empty(self): - foundreaders={} + foundreaders = {} for reader in readers([]): - foundreaders[str(reader)]=1 + foundreaders[str(reader)] = 1 for reader in expectedReaders: - self.assert_( foundreaders.has_key( reader ) ) + self.assert_(foundreaders.has_key(reader)) - if 'winscard'==resourceManager: + if 'winscard' == resourceManager: + def testcase_readers_in_readergroup_nonexistent(self): - foundreaders={} + foundreaders = {} for reader in readers(['dummy$group']): - foundreaders[reader]=1 + foundreaders[reader] = 1 for reader in expectedReaders: - self.assert_( not foundreaders.has_key( reader ) ) - self.assertEquals( 0, len( foundreaders ) ) + self.assert_(not foundreaders.has_key(reader)) + self.assertEquals(0, len(foundreaders)) def testcase_readergroups(self): - foundreadergroups={} + foundreadergroups = {} for readergroup in readergroups(): - foundreadergroups[readergroup]=1 + foundreadergroups[readergroup] = 1 for readergroup in expectedReaderGroups: - self.assert_( foundreadergroups.has_key( readergroup ) ) + self.assert_(foundreadergroups.has_key(readergroup)) def suite(): Modified: trunk/pyscard/src/smartcard/test/framework/testcase_ulist.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_ulist.py 2010-06-09 15:42:05 UTC (rev 475) +++ trunk/pyscard/src/smartcard/test/framework/testcase_ulist.py 2010-06-09 15:50:13 UTC (rev 476) @@ -30,161 +30,155 @@ from smartcard.ulist import ulist + class C(ulist): - def __onadditem__( self, item ): + + def __onadditem__(self, item): #print '+', item pass - def __onremoveitem__( self, item ): + def __onremoveitem__(self, item): #print '-', item pass + class testcase_ulist(unittest.TestCase): """Test smartcard.ulist.""" - def testcase_ulist_init(self): """tests constructor""" - c=C([1,2,3,3,4,5,5]) - self.assertEquals( [1,2,3,4,5], c ) + c = C([1, 2, 3, 3, 4, 5, 5]) + self.assertEquals([1, 2, 3, 4, 5], c) - c=C( ['one', 'two', 'three', 'one'] ) - self.assertEquals( ['one', 'two', 'three' ], c ) + c = C(['one', 'two', 'three', 'one']) + self.assertEquals(['one', 'two', 'three'], c) - def testcase_ulist_add(self): """tests l=l+other""" - seed=[1,2,3] - c=C(seed) - self.assertEquals( seed, c ) + seed = [1, 2, 3] + c = C(seed) + self.assertEquals(seed, c) - c=c+[] - self.assertEquals( seed, c ) + c = c + [] + self.assertEquals(seed, c) - c=c+4 - self.assertEquals( seed+[4], c ) + c = c + 4 + self.assertEquals(seed + [4], c) - c=c+4 - self.assertEquals( seed+[4], c ) + c = c + 4 + self.assertEquals(seed + [4], c) - c=c+'word' - self.assertEquals( seed+[4]+['word'], c ) + c = c + 'word' + self.assertEquals(seed + [4] + ['word'], c) - seed=['one', 'two', 'three'] - c=C(seed) - self.assertEquals( seed, c ) + seed = ['one', 'two', 'three'] + c = C(seed) + self.assertEquals(seed, c) - c=c+['four','five'] - self.assertEquals( seed+['four','five'], c ) + c = c + ['four', 'five'] + self.assertEquals(seed + ['four', 'five'], c) - - def testcase_ulist_iadd(self): """tests l+=other""" + seed = [1, 2, 3] + c = C(seed) + self.assertEquals(seed, c) - seed=[1,2,3] - c=C(seed) - self.assertEquals( seed, c ) + c += [] + self.assertEquals(seed, c) - c+=[] - self.assertEquals( seed, c ) + c += 4 + self.assertEquals(seed + [4], c) - c+=4 - self.assertEquals( seed+[4], c ) + c += 4 + self.assertEquals(seed + [4], c) - c+=4 - self.assertEquals( seed+[4], c ) + c += [4, 3, 2, 1] + self.assertEquals(seed + [4], c) - c+=[4,3,2,1] - self.assertEquals( seed+[4], c ) + c += 'word' + self.assertEquals(seed + [4] + ['word'], c) - c+='word' - self.assertEquals( seed+[4]+['word'], c ) + seed = ['one', 'two', 'three'] + c = C(seed) + self.assertEquals(seed, c) - seed=['one', 'two', 'three'] - c=C(seed) - self.assertEquals( seed, c ) + c += ['four', 'five'] + self.assertEquals(seed + ['four', 'five'], c) - c+=['four','five'] - self.assertEquals( seed+['four','five'], c ) - - def testcase_ulist_radd(self): """tests l=other+l""" + seed = [1, 2, 3] + c = C(seed) + self.assertEquals(seed, c) - seed=[1,2,3] - c=C(seed) - self.assertEquals( seed, c ) + l = [] + c + self.assertEquals(seed, l) - l=[]+c - self.assertEquals( seed, l ) + l = [3] + c + self.assertEquals(seed, c) + self.assertEquals(seed, l) - l=[3]+c - self.assertEquals( seed, c ) - self.assertEquals( seed, l ) + l = [3, 3, 4, 4] + c + self.assertEquals(seed, c) + self.assertEquals(seed + [4], l) - l=[3, 3, 4, 4]+c - self.assertEquals( seed, c ) - self.assertEquals( seed+[4], l ) + l = [4] + ['word'] + c + self.assertEquals(seed, c) + self.assertEquals(seed + [4] + ['word'], l) - l=[4]+['word']+c - self.assertEquals( seed, c ) - self.assertEquals( seed+[4]+['word'], l ) - def testcase_ulist_append(self): - seed=[1,2,3] - c=C(seed) + seed = [1, 2, 3] + c = C(seed) c.append(4) - self.assertEquals( seed+[4], c ) + self.assertEquals(seed + [4], c) c.append(4) - self.assertEquals( seed+[4], c ) + self.assertEquals(seed + [4], c) c.append('word') - self.assertEquals( seed+[4]+['word'], c ) + self.assertEquals(seed + [4] + ['word'], c) def testcase_ulist_insert(self): - seed=[1,2,3] - c=C(seed) + seed = [1, 2, 3] + c = C(seed) - c.insert( 0, 0 ) - self.assertEquals( [0]+seed, c ) + c.insert(0, 0) + self.assertEquals([0] + seed, c) - c.insert( 1, 0 ) - self.assertEquals( [0]+seed, c ) + c.insert(1, 0) + self.assertEquals([0] + seed, c) def testcase_ulist_pop(self): - seed=[1,2,3] - c=C(seed) + seed = [1, 2, 3] + c = C(seed) c.pop() - self.assertEquals( c, [1,2] ) + self.assertEquals(c, [1, 2]) c.pop(1) - self.assertEquals( c, [1] ) + self.assertEquals(c, [1]) - def testcase_ulist_remove(self): - seed=[1,2,3] - c=C(seed) + seed = [1, 2, 3] + c = C(seed) - c.remove( 2 ) - self.assertEquals( c, [1,3] ) + c.remove(2) + self.assertEquals(c, [1, 3]) - c.remove( 1 ) - self.assertEquals( c, [3] ) + c.remove(1) + self.assertEquals(c, [3]) - def suite(): suite1 = unittest.makeSuite(testcase_ulist) return unittest.TestSuite((suite1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:42:11
|
Revision: 475 http://pyscard.svn.sourceforge.net/pyscard/?rev=475&view=rev Author: ludov Date: 2010-06-09 15:42:05 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_readermonitor.py trunk/pyscard/src/smartcard/test/framework/testcase_readermonitorstress.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_readermonitor.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_readermonitor.py 2010-06-09 15:37:57 UTC (rev 474) +++ trunk/pyscard/src/smartcard/test/framework/testcase_readermonitor.py 2010-06-09 15:42:05 UTC (rev 475) @@ -49,50 +49,53 @@ # a simple reader observer that prints added/removed readers -class printobserver( ReaderObserver ): - def __init__( self, obsindex, testcase ): - self.obsindex=obsindex +class printobserver(ReaderObserver): + + def __init__(self, obsindex, testcase): + self.obsindex = obsindex self.testcase = testcase - def update( self, observable, (addedreaders, removedreaders) ): - foundreaders={} - self.testcase.assertEquals( removedreaders, [] ) + def update(self, observable, (addedreaders, removedreaders)): + foundreaders = {} + self.testcase.assertEquals(removedreaders, []) for reader in addedreaders: - foundreaders[str(reader)]=1 - if {}!=foundreaders: + foundreaders[str(reader)] = 1 + if {} != foundreaders: for reader in expectedReaders: - self.testcase.assert_( foundreaders.has_key( reader ) ) + self.testcase.assert_(foundreaders.has_key(reader)) -class testthread( threading.Thread ): - def __init__(self, obsindex, testcase ): + +class testthread(threading.Thread): + + def __init__(self, obsindex, testcase): threading.Thread.__init__(self) self.obsindex = obsindex self.testcase = testcase self.readermonitor = ReaderMonitor() - self.observer=None + self.observer = None def run(self): # create and register observer - self.observer = printobserver( self.obsindex, self.testcase ) - self.readermonitor.addObserver( self.observer ) + self.observer = printobserver(self.obsindex, self.testcase) + self.readermonitor.addObserver(self.observer) time.sleep(1) self.readermonitor.deleteObserver(self.observer) - class testcase_readermonitor(unittest.TestCase): """Test smartcard framework reader monitoring methods""" def testcase_readermonitorthread(self): threads = [] - for i in range( 0, 4 ): - t = testthread( i, self ) - threads.append( t ) + for i in range(0, 4): + t = testthread(i, self) + threads.append(t) for t in threads: t.start() for t in threads: t.join() + def suite(): suite1 = unittest.makeSuite(testcase_readermonitorthread) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_readermonitorstress.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_readermonitorstress.py 2010-06-09 15:37:57 UTC (rev 474) +++ trunk/pyscard/src/smartcard/test/framework/testcase_readermonitorstress.py 2010-06-09 15:42:05 UTC (rev 475) @@ -34,15 +34,17 @@ from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver -period=.1 +period = .1 # stats on virtual reader insertion/removal -insertedreaderstats={} -removedreaderstats={} +insertedreaderstats = {} +removedreaderstats = {} # the virtual list of readers -mutexvreaders=threading.RLock() -virtualreaders=[] +mutexvreaders = threading.RLock() +virtualreaders = [] + + def getReaders(): '''Return virtual list of inserted readers. Replacement of smartcard.system.readers for testing purpose''' @@ -62,78 +64,86 @@ readerEvent.clear() # test running time in seconds -RUNNING_TIME=15 +RUNNING_TIME = 15 # the count of registered observers -OBS_COUNT=100 +OBS_COUNT = 100 -class readerInsertionThread( threading.Thread ): + +class readerInsertionThread(threading.Thread): '''Simulate reader insertion every 2 to 4 periods.''' - def __init__( self ): - threading.Thread.__init__( self ) - def run( self ): + + def __init__(self): + threading.Thread.__init__(self) + + def run(self): while not exitEvent.isSet(): - time.sleep( random.uniform( 2*period, 4*period ) ) + time.sleep(random.uniform(2 * period, 4 * period)) readerEvent.wait() - newreader=random.choice( 'abcdefghijklmnopqrstuvwxyz' ) + newreader = random.choice('abcdefghijklmnopqrstuvwxyz') try: mutexvreaders.acquire() if newreader not in virtualreaders: - virtualreaders.append( newreader ) + virtualreaders.append(newreader) if insertedreaderstats.has_key(newreader): - insertedreaderstats[newreader]+=1 + insertedreaderstats[newreader] += 1 else: - insertedreaderstats[newreader]=1 + insertedreaderstats[newreader] = 1 finally: readerEvent.clear() mutexvreaders.release() -class readerRemovalThread( threading.Thread ): +class readerRemovalThread(threading.Thread): '''Simulate reader removal every 5 to 6 periods.''' - def __init__(self ): + + def __init__(self): threading.Thread.__init__(self) + def run(self): while not exitEvent.isSet(): - time.sleep( random.uniform( 5*period, 6*period ) ) + time.sleep(random.uniform(5 * period, 6 * period)) readerEvent.wait() try: mutexvreaders.acquire() if virtualreaders: - oldreader=random.choice( virtualreaders ) + oldreader = random.choice(virtualreaders) virtualreaders.remove(oldreader) if removedreaderstats.has_key(oldreader): - removedreaderstats[oldreader]+=1 + removedreaderstats[oldreader] += 1 else: - removedreaderstats[oldreader]=1 + removedreaderstats[oldreader] = 1 finally: readerEvent.clear() mutexvreaders.release() -class countobserver( ReaderObserver ): +class countobserver(ReaderObserver): '''A simple reader observer that counts added/removed readers.''' - def __init__( self, obsindex ): - self.obsindex=obsindex - self.insertedreaderstats={} - self.removedreaderstats={} - self.countnotified=0 - def update( self, observable, (addedreaders, removedreaders) ): - self.countnotified+=1 + + def __init__(self, obsindex): + self.obsindex = obsindex + self.insertedreaderstats = {} + self.removedreaderstats = {} + self.countnotified = 0 + + def update(self, observable, (addedreaders, removedreaders)): + self.countnotified += 1 for newreader in addedreaders: if self.insertedreaderstats.has_key(newreader): - self.insertedreaderstats[newreader]+=1 + self.insertedreaderstats[newreader] += 1 else: - self.insertedreaderstats[newreader]=1 + self.insertedreaderstats[newreader] = 1 for oldreader in removedreaders: if self.removedreaderstats.has_key(oldreader): - self.removedreaderstats[oldreader]+=1 + self.removedreaderstats[oldreader] += 1 else: - self.removedreaderstats[oldreader]=1 + self.removedreaderstats[oldreader] = 1 -class testcase_readermonitorstress( unittest.TestCase ): +class testcase_readermonitorstress(unittest.TestCase): '''Test smartcard framework reader monitoring''' + def testcase_readermonitorthread(self): # create thread that simulates reader insertion @@ -142,12 +152,12 @@ # create thread that simulates reader removal removalthread = readerRemovalThread() - readermonitor = ReaderMonitor( readerProc=getReaders, period=period ) - observers=[] - for i in range( 0, OBS_COUNT ): - observer = countobserver( i ) - readermonitor.addObserver( observer ) - observers.append( observer ) + readermonitor = ReaderMonitor(readerProc=getReaders, period=period) + observers = [] + for i in range(0, OBS_COUNT): + observer = countobserver(i) + readermonitor.addObserver(observer) + observers.append(observer) # signal threads to start insertionthread.start() @@ -155,13 +165,13 @@ # let reader insertion/removal threads run for a while # then signal threads to end - time.sleep( RUNNING_TIME ) + time.sleep(RUNNING_TIME) exitEvent.set() # wait until all threads ended removalthread.join() insertionthread.join() - time.sleep( 2*period ) + time.sleep(2 * period) for observer in observers: #print observer.obsindex, observer.insertedreaderstats==insertedreaderstats, observer.countnotified @@ -170,11 +180,10 @@ #print insertedreaderstats #print observer.removedreaderstats #print removedreaderstats - self.assertEquals( observer.insertedreaderstats, insertedreaderstats ) - self.assertEquals( observer.removedreaderstats, removedreaderstats ) + self.assertEquals(observer.insertedreaderstats, insertedreaderstats) + self.assertEquals(observer.removedreaderstats, removedreaderstats) - def suite(): suite1 = unittest.makeSuite(testcase_readermonitorthread) return unittest.TestSuite((suite1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:38:03
|
Revision: 474 http://pyscard.svn.sourceforge.net/pyscard/?rev=474&view=rev Author: ludov Date: 2010-06-09 15:37:57 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py 2010-06-09 15:32:12 UTC (rev 473) +++ trunk/pyscard/src/smartcard/test/framework/testcase_ExclusiveCardConnection.py 2010-06-09 15:37:57 UTC (rev 474) @@ -34,7 +34,7 @@ import unittest # define the apdus used in this script -GET_RESPONSE = [0XA0, 0XC0, 00, 00 ] +GET_RESPONSE = [0XA0, 0XC0, 00, 00] SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] @@ -46,29 +46,33 @@ from smartcard.ExclusiveTransmitCardConnection import ExclusiveTransmitCardConnection from smartcard.util import toHexString -def signalEvent( evt ): + +def signalEvent(evt): '''A simple callback that signals an event.''' evt.set() -class testthread( threading.Thread ): - '''A test thread that repetitevely sends APDUs to a card within a transaction.''' - def __init__(self, threadindex ): + +class testthread(threading.Thread): + '''A test thread that repetitevely sends APDUs to a card within a + transaction.''' + + def __init__(self, threadindex): '''Connect to a card with an ExclusiveTransmitCardConnection.''' threading.Thread.__init__(self) - self.threadindex=threadindex + self.threadindex = threadindex # request any card type cardtype = AnyCardType() - cardrequest = CardRequest( timeout=5, cardType=cardtype ) + cardrequest = CardRequest(timeout=5, cardType=cardtype) cardservice = cardrequest.waitforcard() # attach our decorator - cardservice.connection = ExclusiveTransmitCardConnection( cardservice.connection ) + cardservice.connection = ExclusiveTransmitCardConnection(cardservice.connection) # uncomment to attach the console tracer #observer=ConsoleCardConnectionObserver() - #cardservice.connection.addObserver( observer ) + #cardservice.connection.addObserver(observer) # connect to the card cardservice.connection.connect() @@ -79,11 +83,10 @@ self.evtStop = threading.Event() # this timer will set the event stop event in 30s - timer = threading.Timer( 30, signalEvent, [self.evtStop] ) + timer = threading.Timer(30, signalEvent, [self.evtStop]) timer.start() - self.countTransmitted=0 + self.countTransmitted = 0 - def run(self): '''Transmit APDUS with a random interval to the card.''' connection = self.cardservice.connection @@ -91,16 +94,16 @@ try: connection.lock() - apdu = SELECT+DF_TELECOM - response, sw1, sw2 = connection.transmit( apdu ) + apdu = SELECT + DF_TELECOM + response, sw1, sw2 = connection.transmit(apdu) - if 0x90==(sw1 & 0xF0): + if 0x90 == (sw1 & 0xF0): apdu = GET_RESPONSE + [sw2] - response, sw1, sw2 = connection.transmit( apdu ) + response, sw1, sw2 = connection.transmit(apdu) finally: connection.unlock() - self.countTransmitted=self.countTransmitted+1 - time.sleep( float(random.uniform( 1, 3 ))*0.01) + self.countTransmitted = self.countTransmitted + 1 + time.sleep(float(random.uniform(1, 3)) * 0.01) class testcase_cardmonitor(unittest.TestCase): @@ -108,17 +111,18 @@ def testcase_cardmonitorthread(self): threads = [] - for i in range( 0, 4 ): - t = testthread( i ) - threads.append( t ) + for i in range(0, 4): + t = testthread(i) + threads.append(t) for t in threads: t.start() for t in threads: t.join() for t in threads: - if 0==1: - print 'Thread %d: transmitted %ld apdus.' % (t.threadindex, t.countTransmitted ) + if 0 == 1: + print 'Thread %d: transmitted %ld apdus.' % (t.threadindex, t.countTransmitted) + def suite(): suite1 = unittest.makeSuite(testcase_cardmonitorthread) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py 2010-06-09 15:32:12 UTC (rev 473) +++ trunk/pyscard/src/smartcard/test/framework/testcase_readergroups.py 2010-06-09 15:37:57 UTC (rev 474) @@ -32,118 +32,118 @@ from smartcard.scard import resourceManager -if 'winscard'==resourceManager: +if 'winscard' == resourceManager: + class testcase_readergroups(unittest.TestCase): """Test smartcard framework readersgroups.""" - pinpadgroup='Pinpad$Readers' - biogroup='Biometric$Readers' + pinpadgroup = 'Pinpad$Readers' + biogroup = 'Biometric$Readers' def testcase_readergroup_add(self): """tests groups=groups+[newgroups]""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups=groups+[self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups = groups + [self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time and biometric once - groups=groups+[self.biogroup,self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups = groups + [self.biogroup, self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) def testcase_readergroup_iadd(self): """test groups+=[newgroups]""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups+=[self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups += [self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time and biometric once - groups+=[self.biogroup,self.pinpadgroup] - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups += [self.biogroup, self.pinpadgroup] + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) - def testcase_readergroup_radd(self): """test groups=[newgroups]+groups""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - zgroups=[self.pinpadgroup]+groups - self.assertEquals( groups, groupssnapshot ) - self.assertEquals( zgroups, groupssnapshot+[self.pinpadgroup] ) - self.assert_( isinstance( zgroups, type([]) ) ) - self.assert_( isinstance( groups, type(readergroups()) ) ) + zgroups = [self.pinpadgroup] + groups + self.assertEquals(groups, groupssnapshot) + self.assertEquals(zgroups, groupssnapshot + [self.pinpadgroup]) + self.assert_(isinstance(zgroups, type([]))) + self.assert_(isinstance(groups, type(readergroups()))) # add pinpad a tiwce and biometric once - zgroups=[self.pinpadgroup,self.biogroup,self.pinpadgroup]+groups - self.assertEquals( groups, groupssnapshot ) - self.assertEquals( zgroups, groupssnapshot+[self.pinpadgroup,self.biogroup] ) - self.assert_( isinstance( zgroups, type([]) ) ) - self.assert_( isinstance( groups, type(readergroups()) ) ) + zgroups = [self.pinpadgroup, self.biogroup, self.pinpadgroup] + groups + self.assertEquals(groups, groupssnapshot) + self.assertEquals(zgroups, groupssnapshot + [self.pinpadgroup, self.biogroup]) + self.assert_(isinstance(zgroups, type([]))) + self.assert_(isinstance(groups, type(readergroups()))) def testcase_readergroup_append(self): """test groups.append(newgroups)""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups.append(self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.append(self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time - groups.append(self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.append(self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add biometric once - groups.append( self.biogroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups.append(self.biogroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) def testcase_readergroup_insert(self): """test groups.insert(i,newgroups)""" # take a snapshot of current groups - groupssnapshot=list( readergroups() ) - groups=readergroups() + groupssnapshot = list(readergroups()) + groups = readergroups() # add pinpad group - groups.insert(0,self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.insert(0, self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add pinpad a second time - groups.insert(1,self.pinpadgroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup] ) + groups.insert(1, self.pinpadgroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup]) # add biometric once - groups.insert( 1, self.biogroup ) - self.assertEquals( groups, groupssnapshot+[self.pinpadgroup, self.biogroup] ) + groups.insert(1, self.biogroup) + self.assertEquals(groups, groupssnapshot + [self.pinpadgroup, self.biogroup]) # clean-up - groups.remove( self.biogroup ) - groups.remove( self.pinpadgroup ) + groups.remove(self.biogroup) + groups.remove(self.pinpadgroup) def suite(): suite1 = unittest.makeSuite(testcase_readergroups) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:32:19
|
Revision: 473 http://pyscard.svn.sourceforge.net/pyscard/?rev=473&view=rev Author: ludov Date: 2010-06-09 15:32:12 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_CardService.py trunk/pyscard/src/smartcard/test/framework/testcase_CardType.py trunk/pyscard/src/smartcard/test/framework/testcase_ErrorChecking.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_CardService.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_CardService.py 2010-06-09 15:22:17 UTC (rev 472) +++ trunk/pyscard/src/smartcard/test/framework/testcase_CardService.py 2010-06-09 15:32:12 UTC (rev 473) @@ -56,18 +56,18 @@ DF_TELECOM = [0x7F, 0x10] for reader in readers(): - if []!=expectedATRinReader[str(reader)]: + if [] != expectedATRinReader[str(reader)]: cc = reader.createConnection() - cs = CardService( cc ) + cs = CardService(cc) cs.connection.connect() - response, sw1, sw2 = cs.connection.transmit( SELECT + DF_TELECOM ) - expectedSWs={ "9f 1a":1, "6e 0":2, "9f 20":3, "9f 22":4 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + response, sw1, sw2 = cs.connection.transmit(SELECT + DF_TELECOM) + expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) def suite(): - suite1 = unittest.makeSuite( testcase_CardService ) + suite1 = unittest.makeSuite(testcase_CardService) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_CardType.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_CardType.py 2010-06-09 15:22:17 UTC (rev 472) +++ trunk/pyscard/src/smartcard/test/framework/testcase_CardType.py 2010-06-09 15:32:12 UTC (rev 473) @@ -56,81 +56,79 @@ ct = AnyCardType() for reader in readers(): - if []!=expectedATRinReader[str(reader)]: + if [] != expectedATRinReader[str(reader)]: connection = reader.createConnection() connection.connect() - self.assertEquals( True, ct.matches( connection.getATR() ) ) - self.assertEquals( True, ct.matches( connection.getATR(), reader ) ) + self.assertEquals(True, ct.matches(connection.getATR())) + self.assertEquals(True, ct.matches(connection.getATR(), reader)) connection.disconnect() - def testcase_ATRCardTypeWithoutMask(self): """Test smartcard.ATRCardType without mask.""" for reader in readers(): - if []!=expectedATRinReader[str(reader)]: - ct = ATRCardType( expectedATRinReader[str(reader)] ) + if [] != expectedATRinReader[str(reader)]: + ct = ATRCardType(expectedATRinReader[str(reader)]) connection = reader.createConnection() connection.connect() - self.assertEquals( True, ct.matches( connection.getATR() ) ) - self.assertEquals( True, ct.matches( connection.getATR(), reader ) ) + self.assertEquals(True, ct.matches(connection.getATR())) + self.assertEquals(True, ct.matches(connection.getATR(), reader)) connection.disconnect() def testcase_ATRCardTypeMisMatchWithoutMask(self): """Test smartcard.ATRCardType mismatch without mask.""" for reader in readers(): - if []!=expectedATRinReader[str(reader)]: - atr = list( expectedATRinReader[str(reader)] ) + if [] != expectedATRinReader[str(reader)]: + atr = list(expectedATRinReader[str(reader)]) # change the last byte of the expected atr - atr[-1]= 0xFF - ct = ATRCardType( atr ) + atr[-1] = 0xFF + ct = ATRCardType(atr) connection = reader.createConnection() connection.connect() - self.assertEquals( False, ct.matches( connection.getATR() ) ) - self.assertEquals( False, ct.matches( connection.getATR(), reader ) ) + self.assertEquals(False, ct.matches(connection.getATR())) + self.assertEquals(False, ct.matches(connection.getATR(), reader)) connection.disconnect() - def testcase_ATRCardTypeWithMask(self): """Test smartcard.ATRCardType with mask.""" for reader in readers(): - if []!=expectedATRinReader[str(reader)]: - mask=map( lambda x: 0xFF, expectedATRinReader[str(reader)] ) + if [] != expectedATRinReader[str(reader)]: + mask = map(lambda x: 0xFF, expectedATRinReader[str(reader)]) # don't look to the last byte - mask[-1]=0x00 - ct = ATRCardType( expectedATRinReader[str(reader)], mask ) + mask[-1] = 0x00 + ct = ATRCardType(expectedATRinReader[str(reader)], mask) connection = reader.createConnection() connection.connect() - atr=connection.getATR() + atr = connection.getATR() connection.disconnect() # change a bit in the last byte atr[-1] = atr[-1] ^ 0xFF - self.assertEquals( True, ct.matches( atr ) ) - self.assertEquals( True, ct.matches( atr, reader ) ) + self.assertEquals(True, ct.matches(atr)) + self.assertEquals(True, ct.matches(atr, reader)) def testcase_ATRCardTypeWithMaskMismatch(self): """Test smartcard.ATRCardType with mask and mismatch.""" for reader in readers(): - if []!=expectedATRinReader[str(reader)]: - mask=map( lambda x: 0xFF, expectedATRinReader[str(reader)] ) + if [] != expectedATRinReader[str(reader)]: + mask = map(lambda x: 0xFF, expectedATRinReader[str(reader)]) # don't look to the last byte - mask[0]=mask[-1]=0x00 - ct = ATRCardType( expectedATRinReader[str(reader)], mask ) + mask[0] = mask[-1] = 0x00 + ct = ATRCardType(expectedATRinReader[str(reader)], mask) connection = reader.createConnection() connection.connect() - atr=connection.getATR() + atr = connection.getATR() connection.disconnect() # change a bit in the :-2 byte atr[-2] = atr[-2] ^ 0xFF - self.assertEquals( False, ct.matches( atr ) ) - self.assertEquals( False, ct.matches( atr, reader ) ) + self.assertEquals(False, ct.matches(atr)) + self.assertEquals(False, ct.matches(atr, reader)) def suite(): - suite1 = unittest.makeSuite( testcase_CardType ) + suite1 = unittest.makeSuite(testcase_CardType) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_ErrorChecking.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_ErrorChecking.py 2010-06-09 15:22:17 UTC (rev 472) +++ trunk/pyscard/src/smartcard/test/framework/testcase_ErrorChecking.py 2010-06-09 15:32:12 UTC (rev 473) @@ -53,12 +53,14 @@ sys.exit() -class CustomSWException( smartcard.sw.SWExceptions.SWException ): +class CustomSWException(smartcard.sw.SWExceptions.SWException): """Test exception raised by TestErrorChecker.""" - def __init__( self, data, sw1, sw2, message="" ): - smartcard.sw.SWExceptions.SWException.__init__( self, data, sw1, sw2 ) -class TestErrorChecker( ErrorChecker ): + def __init__(self, data, sw1, sw2, message=""): + smartcard.sw.SWExceptions.SWException.__init__(self, data, sw1, sw2) + + +class TestErrorChecker(ErrorChecker): """Test error checking checker. This checker raises the following exception: @@ -66,12 +68,14 @@ sw1: 56 sw2: 55 CustomSWException sw1: 63 sw2: any WarningProcessingException """ - def __call__( self, data, sw1, sw2 ): - if 0x56==sw1 and 0x55==sw2: - raise CustomSWException( data, sw1, sw2 ) - elif 0x63==sw1: - raise CustomSWException( data, sw1, sw2 ) + def __call__(self, data, sw1, sw2): + if 0x56 == sw1 and 0x55 == sw2: + raise CustomSWException(data, sw1, sw2) + elif 0x63 == sw1: + raise CustomSWException(data, sw1, sw2) + + class testcase_ErrorChecking(unittest.TestCase): """Test case for smartcard.sw.* error checking.""" @@ -83,200 +87,197 @@ except excClass, e: return e else: - if hasattr(excClass,'__name__'): + if hasattr(excClass, '__name__'): excName = excClass.__name__ else: excName = str(excClass) raise self.failureException, excName - def testcase_ISO7816_4SW1ErrorChecker(self): """Test ISO7816_4_SW1ErrorChecker.""" - ecs=ISO7816_4_SW1ErrorChecker() + ecs = ISO7816_4_SW1ErrorChecker() tiso7816_4SW1 = { - 0x62:smartcard.sw.SWExceptions.WarningProcessingException, - 0x63:smartcard.sw.SWExceptions.WarningProcessingException, - 0x64:smartcard.sw.SWExceptions.ExecutionErrorException, - 0x65:smartcard.sw.SWExceptions.ExecutionErrorException, - 0x66:smartcard.sw.SWExceptions.SecurityRelatedException, - 0x67:smartcard.sw.SWExceptions.CheckingErrorException, - 0x68:smartcard.sw.SWExceptions.CheckingErrorException, - 0x69:smartcard.sw.SWExceptions.CheckingErrorException, - 0x6A:smartcard.sw.SWExceptions.CheckingErrorException, - 0x6B:smartcard.sw.SWExceptions.CheckingErrorException, - 0x6C:smartcard.sw.SWExceptions.CheckingErrorException, - 0x6D:smartcard.sw.SWExceptions.CheckingErrorException, - 0x6E:smartcard.sw.SWExceptions.CheckingErrorException, - 0x6F:smartcard.sw.SWExceptions.CheckingErrorException, + 0x62: smartcard.sw.SWExceptions.WarningProcessingException, + 0x63: smartcard.sw.SWExceptions.WarningProcessingException, + 0x64: smartcard.sw.SWExceptions.ExecutionErrorException, + 0x65: smartcard.sw.SWExceptions.ExecutionErrorException, + 0x66: smartcard.sw.SWExceptions.SecurityRelatedException, + 0x67: smartcard.sw.SWExceptions.CheckingErrorException, + 0x68: smartcard.sw.SWExceptions.CheckingErrorException, + 0x69: smartcard.sw.SWExceptions.CheckingErrorException, + 0x6A: smartcard.sw.SWExceptions.CheckingErrorException, + 0x6B: smartcard.sw.SWExceptions.CheckingErrorException, + 0x6C: smartcard.sw.SWExceptions.CheckingErrorException, + 0x6D: smartcard.sw.SWExceptions.CheckingErrorException, + 0x6E: smartcard.sw.SWExceptions.CheckingErrorException, + 0x6F: smartcard.sw.SWExceptions.CheckingErrorException, } - for sw1 in range( 0x00, 0xff+1 ): - sw2range=[] - exception=None + for sw1 in range(0x00, 0xff + 1): + sw2range = [] + exception = None if tiso7816_4SW1.has_key(sw1): exception = tiso7816_4SW1[sw1] - for sw2 in range( 0x00, 0xff+1 ): - if None!=exception: - self.assertRaises( exception, ecs, [], sw1, sw2 ) + for sw2 in range(0x00, 0xff + 1): + if None != exception: + self.assertRaises(exception, ecs, [], sw1, sw2) else: - ecs( [], sw1, sw2 ) + ecs([], sw1, sw2) - def testcase_ISO7816_4ErrorChecker(self): """Test ISO7816_4ErrorChecker.""" - ecs=ISO7816_4ErrorChecker() + ecs = ISO7816_4ErrorChecker() tiso7816_4SW = { - 0x62:( smartcard.sw.SWExceptions.WarningProcessingException, [ 0x00, 0x81, 0x82, 0x83, 0x84, 0xff ] ), - 0x63:( smartcard.sw.SWExceptions.WarningProcessingException, [ 0x00, 0x81 ] + range( 0xc0, 0xcf+1 ) ), - 0x64:( smartcard.sw.SWExceptions.ExecutionErrorException, [0x00] ), - 0x67:( smartcard.sw.SWExceptions.CheckingErrorException, [0x00] ), - 0x68:( smartcard.sw.SWExceptions.CheckingErrorException, [0x81, 0x82] ), - 0x69:( smartcard.sw.SWExceptions.CheckingErrorException, range( 0x81, 0x88+1 ) ), - 0x6A:( smartcard.sw.SWExceptions.CheckingErrorException, range( 0x80, 0x88+1 ) ), - 0x6B:( smartcard.sw.SWExceptions.CheckingErrorException, [0x00] ), - 0x6D:( smartcard.sw.SWExceptions.CheckingErrorException, [0x00] ), - 0x6E:( smartcard.sw.SWExceptions.CheckingErrorException, [0x00] ), - 0x6F:( smartcard.sw.SWExceptions.CheckingErrorException, [0x00] ), + 0x62: (smartcard.sw.SWExceptions.WarningProcessingException, [0x00, 0x81, 0x82, 0x83, 0x84, 0xff]), + 0x63: (smartcard.sw.SWExceptions.WarningProcessingException, [0x00, 0x81] + range(0xc0, 0xcf + 1)), + 0x64: (smartcard.sw.SWExceptions.ExecutionErrorException, [0x00]), + 0x67: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x68: (smartcard.sw.SWExceptions.CheckingErrorException, [0x81, 0x82]), + 0x69: (smartcard.sw.SWExceptions.CheckingErrorException, range(0x81, 0x88 + 1)), + 0x6A: (smartcard.sw.SWExceptions.CheckingErrorException, range(0x80, 0x88 + 1)), + 0x6B: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x6D: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x6E: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x6F: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), } - for sw1 in range( 0x00, 0xff+1 ): - sw2range=[] + for sw1 in range(0x00, 0xff + 1): + sw2range = [] if tiso7816_4SW.has_key(sw1): exception, sw2range = tiso7816_4SW[sw1] - for sw2 in range(0x00, 0xff+1): + for sw2 in range(0x00, 0xff + 1): if sw2 in sw2range: - self.assertRaises( exception, ecs, [], sw1, sw2 ) + self.assertRaises(exception, ecs, [], sw1, sw2) else: - ecs( [], sw1, sw2 ) + ecs([], sw1, sw2) - def testcase_ISO7816_8ErrorChecker(self): """Test ISO7816_4ErrorChecker.""" - ecs=ISO7816_8ErrorChecker() + ecs = ISO7816_8ErrorChecker() tiso7816_8SW = { - 0x63:( smartcard.sw.SWExceptions.WarningProcessingException, [ 0x00 ] + range( 0xc0, 0xcf+1 ) ), - 0x65:( smartcard.sw.SWExceptions.ExecutionErrorException, [0x81] ), - 0x66:( smartcard.sw.SWExceptions.SecurityRelatedException, [ 0x00, 0x87, 0x88 ] ), - 0x67:( smartcard.sw.SWExceptions.CheckingErrorException, [0x00] ), - 0x68:( smartcard.sw.SWExceptions.CheckingErrorException, [0x83, 0x84] ), - 0x69:( smartcard.sw.SWExceptions.CheckingErrorException, range( 0x82, 0x85+1 ) ), - 0x6A:( smartcard.sw.SWExceptions.CheckingErrorException, [0x81, 0x82, 0x86, 0x88 ] ), + 0x63: (smartcard.sw.SWExceptions.WarningProcessingException, [0x00] + range(0xc0, 0xcf + 1)), + 0x65: (smartcard.sw.SWExceptions.ExecutionErrorException, [0x81]), + 0x66: (smartcard.sw.SWExceptions.SecurityRelatedException, [0x00, 0x87, 0x88]), + 0x67: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x68: (smartcard.sw.SWExceptions.CheckingErrorException, [0x83, 0x84]), + 0x69: (smartcard.sw.SWExceptions.CheckingErrorException, range(0x82, 0x85 + 1)), + 0x6A: (smartcard.sw.SWExceptions.CheckingErrorException, [0x81, 0x82, 0x86, 0x88]), } - for sw1 in range( 0x00, 0xff+1 ): - sw2range=[] + for sw1 in range(0x00, 0xff + 1): + sw2range = [] if tiso7816_8SW.has_key(sw1): exception, sw2range = tiso7816_8SW[sw1] - for sw2 in range( 0x00, 0xff+1 ): + for sw2 in range(0x00, 0xff + 1): if sw2 in sw2range: - self.assertRaises( exception, ecs, [], sw1, sw2 ) + self.assertRaises(exception, ecs, [], sw1, sw2) else: - ecs( [], sw1, sw2 ) + ecs([], sw1, sw2) def testcase_ISO7816_9ErrorChecker(self): """Test ISO7816_4ErrorChecker.""" - ecs=ISO7816_9ErrorChecker() + ecs = ISO7816_9ErrorChecker() tiso7816_9SW = { - 0x62:( smartcard.sw.SWExceptions.WarningProcessingException, [ 0x82 ] ), - 0x64:( smartcard.sw.SWExceptions.ExecutionErrorException, [ 0x00 ] ), - 0x69:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x82 ] ), - 0x6A:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x80, 0x84, 0x89, 0x8A ] ), + 0x62: (smartcard.sw.SWExceptions.WarningProcessingException, [0x82]), + 0x64: (smartcard.sw.SWExceptions.ExecutionErrorException, [0x00]), + 0x69: (smartcard.sw.SWExceptions.CheckingErrorException, [0x82]), + 0x6A: (smartcard.sw.SWExceptions.CheckingErrorException, [0x80, 0x84, 0x89, 0x8A]), } - for sw1 in range( 0x00, 0xff+1 ): - sw2range=[] + for sw1 in range(0x00, 0xff + 1): + sw2range = [] if tiso7816_9SW.has_key(sw1): exception, sw2range = tiso7816_9SW[sw1] - for sw2 in range( 0x00, 0xff+1 ): + for sw2 in range(0x00, 0xff + 1): if sw2 in sw2range: - self.assertRaises( exception, ecs, [], sw1, sw2 ) + self.assertRaises(exception, ecs, [], sw1, sw2) else: - ecs( [], sw1, sw2 ) + ecs([], sw1, sw2) def testcase_op21_ErrorChecker(self): """Test op21_ErrorChecker.""" - ecs=op21_ErrorChecker() + ecs = op21_ErrorChecker() top21_SW = { - 0x62:( smartcard.sw.SWExceptions.WarningProcessingException, [ 0x83 ] ), - 0x63:( smartcard.sw.SWExceptions.WarningProcessingException, [ 0x00 ] ), - 0x64:( smartcard.sw.SWExceptions.ExecutionErrorException, [ 0x00 ] ), - 0x65:( smartcard.sw.SWExceptions.ExecutionErrorException, [ 0x81 ] ), - 0x67:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x00 ] ), - 0x69:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x82, 0x85 ] ), - 0x6A:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x80, 0x81, 0x82, 0x84, 0x86, 0x88 ] ), - 0x6D:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x00 ] ), - 0x6E:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x00 ] ), - 0x94:( smartcard.sw.SWExceptions.CheckingErrorException, [ 0x84, 0x85 ] ), + 0x62: (smartcard.sw.SWExceptions.WarningProcessingException, [0x83]), + 0x63: (smartcard.sw.SWExceptions.WarningProcessingException, [0x00]), + 0x64: (smartcard.sw.SWExceptions.ExecutionErrorException, [0x00]), + 0x65: (smartcard.sw.SWExceptions.ExecutionErrorException, [0x81]), + 0x67: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x69: (smartcard.sw.SWExceptions.CheckingErrorException, [0x82, 0x85]), + 0x6A: (smartcard.sw.SWExceptions.CheckingErrorException, [0x80, 0x81, 0x82, 0x84, 0x86, 0x88]), + 0x6D: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x6E: (smartcard.sw.SWExceptions.CheckingErrorException, [0x00]), + 0x94: (smartcard.sw.SWExceptions.CheckingErrorException, [0x84, 0x85]), } - for sw1 in range( 0x00, 0xff+1 ): - sw2range=[] + for sw1 in range(0x00, 0xff + 1): + sw2range = [] if top21_SW.has_key(sw1): exception, sw2range = top21_SW[sw1] - for sw2 in range( 0x00, 0xff+1 ): + for sw2 in range(0x00, 0xff + 1): if sw2 in sw2range: - self.assertRaises( exception, ecs, [], sw1, sw2 ) + self.assertRaises(exception, ecs, [], sw1, sw2) else: - ecs( [], sw1, sw2 ) + ecs([], sw1, sw2) def testcase_ISO78164_Test_ErrorCheckingChain(self): """Test error chain with ISO7816-4 checker followed by Test checker.""" - errorchain=[] - errorchain=[ ErrorCheckingChain( errorchain, ISO7816_4ErrorChecker() ), - ErrorCheckingChain( errorchain, TestErrorChecker() ) ] + errorchain = [] + errorchain = [ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker()), + ErrorCheckingChain(errorchain, TestErrorChecker())] - # ISO7816-4 is answering first on the next, i.e WarningProcessingException - for sw2 in [ 0x00, 0x81 ] + range( 0xc0, 0xcf+1 ): - self.assertRaises( smartcard.sw.SWExceptions.WarningProcessingException, errorchain[0], [], 0x63, sw2 ) + # ISO7816-4 is answering first on the next, i.e + # WarningProcessingException + for sw2 in [0x00, 0x81] + range(0xc0, 0xcf + 1): + self.assertRaises(smartcard.sw.SWExceptions.WarningProcessingException, errorchain[0], [], 0x63, sw2) def testcase_Test_ISO78164_ErrorCheckingChain(self): """Test error chain with Test checker followed by ISO7816-4 checker.""" - errorchain=[] - errorchain=[ ErrorCheckingChain( errorchain, TestErrorChecker() ), - ErrorCheckingChain( errorchain, ISO7816_4ErrorChecker() ) ] + errorchain = [] + errorchain = [ErrorCheckingChain(errorchain, TestErrorChecker()), + ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker())] # TestErrorChecker is answering first, i.e. CustomSWException - for sw2 in [ 0x00, 0x81 ] + range( 0xc0, 0xcf+1 ): - self.assertRaises( CustomSWException, errorchain[0], [], 0x63, sw2 ) + for sw2 in [0x00, 0x81] + range(0xc0, 0xcf + 1): + self.assertRaises(CustomSWException, errorchain[0], [], 0x63, sw2) - def testcase_ErrorMessage( self ): + def testcase_ErrorMessage(self): """Test correct exception error message.""" - ecs=ISO7816_4ErrorChecker() + ecs = ISO7816_4ErrorChecker() - e=self.failUnlessRaises( smartcard.sw.SWExceptions.CheckingErrorException, ecs, [], 0x69, 0x85 ) - self.assertEquals( str(e), "'Status word exception: checking error - Conditions of use not satisfied!'" ) + e = self.failUnlessRaises(smartcard.sw.SWExceptions.CheckingErrorException, ecs, [], 0x69, 0x85) + self.assertEquals(str(e), "'Status word exception: checking error - Conditions of use not satisfied!'") - e=self.failUnlessRaises( smartcard.sw.SWExceptions.CheckingErrorException, ecs, [], 0x6b, 0x00 ) - self.assertEquals( str(e), "'Status word exception: checking error - Incorrect parameters P1-P2!'" ) + e = self.failUnlessRaises(smartcard.sw.SWExceptions.CheckingErrorException, ecs, [], 0x6b, 0x00) + self.assertEquals(str(e), "'Status word exception: checking error - Incorrect parameters P1-P2!'") - def testcase_ISO78164_Test_ErrorCheckingChain_filtering(self): """Test error chain with ISO7816-4 checker followed by Test checker.""" - errorchain=[] - errorchain=[ ErrorCheckingChain( errorchain, ISO7816_8ErrorChecker() ), - ErrorCheckingChain( errorchain, ISO7816_4ErrorChecker() ), - ErrorCheckingChain( errorchain, ISO7816_4_SW1ErrorChecker() ) ] + errorchain = [] + errorchain = [ErrorCheckingChain(errorchain, ISO7816_8ErrorChecker()), + ErrorCheckingChain(errorchain, ISO7816_4ErrorChecker()), + ErrorCheckingChain(errorchain, ISO7816_4_SW1ErrorChecker())] # don't care about Warning Exceptions - errorchain[0].addFilterException( smartcard.sw.SWExceptions.WarningProcessingException ) + errorchain[0].addFilterException(smartcard.sw.SWExceptions.WarningProcessingException) for sw2 in range(0x00, 0xff): # should not raise - errorchain[0]( [], 0x62, sw2 ) - errorchain[0]( [], 0x63, sw2 ) + errorchain[0]([], 0x62, sw2) + errorchain[0]([], 0x63, sw2) # should raise - self.assertRaises( smartcard.sw.SWExceptions.ExecutionErrorException, errorchain[0], [], 0x64, sw2 ) + self.assertRaises(smartcard.sw.SWExceptions.ExecutionErrorException, errorchain[0], [], 0x64, sw2) def suite(): - suite1 = unittest.makeSuite( testcase_ErrorChecking ) + suite1 = unittest.makeSuite(testcase_ErrorChecking) return unittest.TestSuite((suite1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:22:24
|
Revision: 472 http://pyscard.svn.sourceforge.net/pyscard/?rev=472&view=rev Author: ludov Date: 2010-06-09 15:22:17 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_CardMonitor.py trunk/pyscard/src/smartcard/test/framework/testcase_CardRequest.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_CardMonitor.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_CardMonitor.py 2010-06-09 15:19:46 UTC (rev 471) +++ trunk/pyscard/src/smartcard/test/framework/testcase_CardMonitor.py 2010-06-09 15:22:17 UTC (rev 472) @@ -50,32 +50,35 @@ # a simple card observer that prints inserted/removed cards -class printobserver( CardObserver ): - def __init__( self, obsindex, testcase ): - self.obsindex=obsindex +class printobserver(CardObserver): + + def __init__(self, obsindex, testcase): + self.obsindex = obsindex self.testcase = testcase - def update( self, observable, (addedcards, removedcards) ): - foundcards={} - self.testcase.assertEquals( removedcards, [] ) + def update(self, observable, (addedcards, removedcards)): + foundcards = {} + self.testcase.assertEquals(removedcards, []) for card in addedcards: - foundcards[toHexString(card.atr)]=1 + foundcards[toHexString(card.atr)] = 1 for atr in expectedATRs: - if []!=atr and {}!=foundcards: - self.testcase.assert_( foundcards.has_key( toHexString(atr) ) ) + if [] != atr and {} != foundcards: + self.testcase.assert_(foundcards.has_key(toHexString(atr))) -class testthread( threading.Thread ): - def __init__(self, obsindex, testcase ): + +class testthread(threading.Thread): + + def __init__(self, obsindex, testcase): threading.Thread.__init__(self) self.obsindex = obsindex self.testcase = testcase self.cardmonitor = CardMonitor() - self.observer=None + self.observer = None def run(self): # create and register observer - self.observer = printobserver( self.obsindex, self.testcase ) - self.cardmonitor.addObserver( self.observer ) + self.observer = printobserver(self.obsindex, self.testcase) + self.cardmonitor.addObserver(self.observer) time.sleep(1) self.cardmonitor.deleteObserver(self.observer) @@ -85,14 +88,15 @@ def testcase_cardmonitorthread(self): threads = [] - for i in range( 0, 4 ): - t = testthread( i, self ) - threads.append( t ) + for i in range(0, 4): + t = testthread(i, self) + threads.append(t) for t in threads: t.start() for t in threads: t.join() + def suite(): suite1 = unittest.makeSuite(testcase_cardmonitorthread) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_CardRequest.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_CardRequest.py 2010-06-09 15:19:46 UTC (rev 471) +++ trunk/pyscard/src/smartcard/test/framework/testcase_CardRequest.py 2010-06-09 15:22:17 UTC (rev 472) @@ -58,75 +58,73 @@ """Test smartcard.AnyCardType.""" for atr in expectedATRs: - if []!=atr: - ct = ATRCardType( atr ) - cr=CardRequest( timeout=10, cardType=ct ) + if [] != atr: + ct = ATRCardType(atr) + cr = CardRequest(timeout=10, cardType=ct) cs = cr.waitforcard() cs.connection.connect() - self.assertEquals( atr, cs.connection.getATR() ) - self.assertEquals( cs.connection.getReader(), expectedReaderForATR[toHexString(atr)] ) + self.assertEquals(atr, cs.connection.getATR()) + self.assertEquals(cs.connection.getReader(), expectedReaderForATR[toHexString(atr)]) cs.connection.disconnect() def testcase_CardRequestAnyCardTypeInSelectedReader(self): """Test smartcard.AnyCardType.""" for reader in expectedReaders: - atr=expectedATRinReader[reader] - if []!=atr: + atr = expectedATRinReader[reader] + if [] != atr: ct = AnyCardType() - cr=CardRequest( timeout=10.6, readers=[reader], cardType=ct ) + cr = CardRequest(timeout=10.6, readers=[reader], cardType=ct) cs = cr.waitforcard() cs.connection.connect() - self.assertEquals( atr, cs.connection.getATR() ) - self.assertEquals( cs.connection.getReader(), expectedReaderForATR[toHexString(atr)] ) + self.assertEquals(atr, cs.connection.getATR()) + self.assertEquals(cs.connection.getReader(), expectedReaderForATR[toHexString(atr)]) def testcase_CardRequestATRCardTypeTimeout(self): """Test smartcard.AnyCardType.""" for reader in expectedReaders: - atr=expectedATRinReader[reader][:-1] - ct = ATRCardType( atr ) - cr=CardRequest( timeout=1, readers=[reader], cardType=ct ) - self.assertRaises( CardRequestTimeoutException, cr.waitforcard ) + atr = expectedATRinReader[reader][:-1] + ct = ATRCardType(atr) + cr = CardRequest(timeout=1, readers=[reader], cardType=ct) + self.assertRaises(CardRequestTimeoutException, cr.waitforcard) def testcase_CardRequestATRCardTypeTimeoutAnyReader(self): """Test smartcard.AnyCardType.""" readers = smartcard.System.readers() - atr=expectedATRs[0][:-1] - ct = ATRCardType( atr ) - cr=CardRequest( timeout=1.5, readers=readers, cardType=ct ) - self.assertRaises( CardRequestTimeoutException, cr.waitforcard ) + atr = expectedATRs[0][:-1] + ct = ATRCardType(atr) + cr = CardRequest(timeout=1.5, readers=readers, cardType=ct) + self.assertRaises(CardRequestTimeoutException, cr.waitforcard) - def testcase_CardRequestAnyCardTypeAnyReaderPassThru(self): """Test smartcard.AnyCardType.""" for reader in expectedReaders: - atr=expectedATRinReader[reader] - if []!=atr: + atr = expectedATRinReader[reader] + if [] != atr: ct = AnyCardType() cardservice = smartcard.PassThruCardService.PassThruCardService - cr=CardRequest( timeout=10.6, readers=[reader], cardType=ct, cardServiceClass=cardservice ) + cr = CardRequest(timeout=10.6, readers=[reader], cardType=ct, cardServiceClass=cardservice) cs = cr.waitforcard() cs.connection.connect() - self.assertEquals( cs.__class__, smartcard.PassThruCardService.PassThruCardService ) - self.assertEquals( atr, cs.connection.getATR() ) - self.assertEquals( cs.connection.getReader(), expectedReaderForATR[toHexString(atr)] ) + self.assertEquals(cs.__class__, smartcard.PassThruCardService.PassThruCardService) + self.assertEquals(atr, cs.connection.getATR()) + self.assertEquals(cs.connection.getReader(), expectedReaderForATR[toHexString(atr)]) - def testcase_CardRequestAnyCardTypeInSelectedReaderNewCard(self): """Test smartcard.AnyCardType.""" for reader in expectedReaders: - atr=expectedATRinReader[reader] + atr = expectedATRinReader[reader] ct = AnyCardType() - cr=CardRequest( newcardonly=True, timeout=1, readers=[reader], cardType=ct ) - self.assertRaises( CardRequestTimeoutException, cr.waitforcard ) + cr = CardRequest(newcardonly=True, timeout=1, readers=[reader], cardType=ct) + self.assertRaises(CardRequestTimeoutException, cr.waitforcard) def suite(): - suite1 = unittest.makeSuite( testcase_CardRequest ) + suite1 = unittest.makeSuite(testcase_CardRequest) return unittest.TestSuite((suite1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:19:52
|
Revision: 471 http://pyscard.svn.sourceforge.net/pyscard/?rev=471&view=rev Author: ludov Date: 2010-06-09 15:19:46 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_Card.py trunk/pyscard/src/smartcard/test/framework/testcase_CardConnection.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_Card.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_Card.py 2010-06-09 15:14:47 UTC (rev 470) +++ trunk/pyscard/src/smartcard/test/framework/testcase_Card.py 2010-06-09 15:19:46 UTC (rev 471) @@ -58,16 +58,16 @@ DF_TELECOM = [0x7F, 0x10] for reader in readers(): - card = Card( reader, expectedATRinReader[str(reader)] ) + card = Card(reader, expectedATRinReader[str(reader)]) cc = card.createConnection() - if []!=expectedATRinReader[str(reader)]: + if [] != expectedATRinReader[str(reader)]: cc.connect() - response, sw1, sw2 = cc.transmit( SELECT + DF_TELECOM ) - expectedSWs={ "9f 1a":1, "9f 20":2, "6e 0":3 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM) + expectedSWs = {"9f 1a": 1, "9f 20": 2, "6e 0": 3} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) def testcase_Card_FromReaderStrings(self): """Create a Card from reader strings and test that the response @@ -76,33 +76,34 @@ DF_TELECOM = [0x7F, 0x10] for reader in readers(): - card = Card( str(reader), expectedATRinReader[str(reader)] ) + card = Card(str(reader), expectedATRinReader[str(reader)]) cc = card.createConnection() - if []!=expectedATRinReader[str(reader)]: + if [] != expectedATRinReader[str(reader)]: cc.connect() - response, sw1, sw2 = cc.transmit( SELECT + DF_TELECOM ) - expectedSWs={ "9f 1a":1, "9f 20":2, "6e 0":3 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM) + expectedSWs = {"9f 1a": 1, "9f 20": 2, "6e 0": 3} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) def testcase_Card_Eq_NotEq(self): """Test == and != for Cards.""" for reader in readers(): - card = Card( str(reader), expectedATRinReader[str(reader)] ) - cardcopy = Card( str(reader), expectedATRinReader[str(reader)] ) - self.assertEquals( True, card==cardcopy ) - self.assertEquals( True, not card!=cardcopy ) + card = Card(str(reader), expectedATRinReader[str(reader)]) + cardcopy = Card(str(reader), expectedATRinReader[str(reader)]) + self.assertEquals(True, card == cardcopy) + self.assertEquals(True, not card != cardcopy) for reader in readers(): - card = Card( str(reader), expectedATRinReader[str(reader)] ) - cardcopy = Card( str(reader), [0,0] ) - self.assertEquals( True, card!=cardcopy ) - self.assertEquals( True, not card==cardcopy ) + card = Card(str(reader), expectedATRinReader[str(reader)]) + cardcopy = Card(str(reader), [0, 0]) + self.assertEquals(True, card != cardcopy) + self.assertEquals(True, not card == cardcopy) + def suite(): - suite1 = unittest.makeSuite( testcase_CardConnection ) + suite1 = unittest.makeSuite(testcase_CardConnection) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_CardConnection.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_CardConnection.py 2010-06-09 15:14:47 UTC (rev 470) +++ trunk/pyscard/src/smartcard/test/framework/testcase_CardConnection.py 2010-06-09 15:19:46 UTC (rev 471) @@ -59,14 +59,14 @@ for reader in readers(): cc = reader.createConnection() - if []!=expectedATRinReader[str(reader)]: + if [] != expectedATRinReader[str(reader)]: cc.connect() - response, sw1, sw2 = cc.transmit( SELECT + DF_TELECOM ) - expectedSWs={ "9f 1a":1, "6e 0":2, "9f 20":3, "9f 22":4 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM) + expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() def testcase_CardConnectionT0(self): @@ -76,14 +76,14 @@ for reader in readers(): cc = reader.createConnection() - if []!=expectedATRinReader[str(reader)]: - cc.connect( CardConnection.T0_protocol ) - response, sw1, sw2 = cc.transmit( SELECT + DF_TELECOM ) - expectedSWs={ "9f 1a":1, "6e 0":2, "9f 20":3, "9f 22":4 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + if [] != expectedATRinReader[str(reader)]: + cc.connect(CardConnection.T0_protocol) + response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM) + expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() def testcase_CardConnectionT1inConnect(self): @@ -92,15 +92,14 @@ for reader in readers(): cc = reader.createConnection() # on Mac OS X Tiger, trying to connect with T=1 protocol does not except - if not 'pcsclite-tiger'==resourceManagerSubType: - if []!=expectedATRinReader[str(reader)]: + if not 'pcsclite-tiger' == resourceManagerSubType: + if [] != expectedATRinReader[str(reader)]: # should fail since the test card does not support T1 - self.assertRaises( CardConnectionException, cc.connect, CardConnection.T1_protocol ) + self.assertRaises(CardConnectionException, cc.connect, CardConnection.T1_protocol) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() - def testcase_CardConnectionT1inTransmit(self): """Test that T1 in transmit for a T0 card fails.""" SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] @@ -108,11 +107,11 @@ for reader in readers(): cc = reader.createConnection() - if []!=expectedATRinReader[str(reader)]: + if [] != expectedATRinReader[str(reader)]: cc.connect() - self.assertRaises( CardConnectionException, cc.transmit, SELECT + DF_TELECOM, CardConnection.T1_protocol ) + self.assertRaises(CardConnectionException, cc.transmit, SELECT + DF_TELECOM, CardConnection.T1_protocol) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() def testcase_CardConnectionT0T1(self): @@ -122,17 +121,16 @@ for reader in readers(): cc = reader.createConnection() - if []!=expectedATRinReader[str(reader)]: - cc.connect( CardConnection.T0_protocol | CardConnection.T1_protocol ) - response, sw1, sw2 = cc.transmit( SELECT + DF_TELECOM ) - expectedSWs={ "9f 1a":1, "6e 0":2, "9f 20":3, "9f 22":4 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + if [] != expectedATRinReader[str(reader)]: + cc.connect(CardConnection.T0_protocol | CardConnection.T1_protocol) + response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM) + expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() - def testcase_CardConnectionT0inTransmit(self): """Test with T0 in transmit the response to SELECT DF_TELECOM.""" SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] @@ -140,34 +138,34 @@ for reader in readers(): cc = reader.createConnection() - if []!=expectedATRinReader[str(reader)]: - cc.connect( CardConnection.T0_protocol ) - response, sw1, sw2 = cc.transmit( SELECT + DF_TELECOM, CardConnection.T0_protocol ) - expectedSWs={ "9f 1a":1, "6e 0":2, "9f 20":3, "9f 22":4 } - self.assertEquals( [], response ) - self.assert_( expectedSWs.has_key( "%x %x" % (sw1, sw2 ) ) or "9f"== "%x" % sw1 ) + if [] != expectedATRinReader[str(reader)]: + cc.connect(CardConnection.T0_protocol) + response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM, CardConnection.T0_protocol) + expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4} + self.assertEquals([], response) + self.assert_(expectedSWs.has_key("%x %x" % (sw1, sw2)) or "9f" == "%x" % sw1) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() - def testcase_CardConnectionT0T1inTransmitMustFail(self): - """Test with bad parameter in transmit the response to SELECT DF_TELECOM.""" + """Test with bad parameter in transmit the response to SELECT + DF_TELECOM.""" SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] for reader in readers(): cc = reader.createConnection() - if []!=expectedATRinReader[str(reader)]: - cc.connect( CardConnection.T0_protocol | CardConnection.T1_protocol ) - self.assertRaises( CardConnectionException, cc.transmit, SELECT + DF_TELECOM, CardConnection.T0_protocol | CardConnection.T1_protocol ) + if [] != expectedATRinReader[str(reader)]: + cc.connect(CardConnection.T0_protocol | CardConnection.T1_protocol) + self.assertRaises(CardConnectionException, cc.transmit, SELECT + DF_TELECOM, CardConnection.T0_protocol | CardConnection.T1_protocol) else: - self.assertRaises( NoCardException, cc.connect ) + self.assertRaises(NoCardException, cc.connect) cc.disconnect() def suite(): - suite1 = unittest.makeSuite( testcase_CardConnection ) + suite1 = unittest.makeSuite(testcase_CardConnection) return unittest.TestSuite((suite1)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:14:54
|
Revision: 470 http://pyscard.svn.sourceforge.net/pyscard/?rev=470&view=rev Author: ludov Date: 2010-06-09 15:14:47 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/framework/testcase_ATR.py trunk/pyscard/src/smartcard/test/framework/testcase_CAtr.py Modified: trunk/pyscard/src/smartcard/test/framework/testcase_ATR.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_ATR.py 2010-06-09 15:10:25 UTC (rev 469) +++ trunk/pyscard/src/smartcard/test/framework/testcase_ATR.py 2010-06-09 15:14:47 UTC (rev 470) @@ -52,15 +52,16 @@ def testcase_ATRconfig(self): # we have at list 2 readers (one is the simulator), e.g. # two potential ATRs - self.assert_( len(expectedATRs) > 1 ) + self.assert_(len(expectedATRs) > 1) # we have at least two non empty ATRs - count=0 + count = 0 for atr in expectedATRs: - if atr!=[]: - count+=1 - self.assert_( count>1 ) + if atr != []: + count += 1 + self.assert_(count > 1) + def suite(): suite1 = unittest.makeSuite(testcase_ATR) return unittest.TestSuite((suite1)) Modified: trunk/pyscard/src/smartcard/test/framework/testcase_CAtr.py =================================================================== --- trunk/pyscard/src/smartcard/test/framework/testcase_CAtr.py 2010-06-09 15:10:25 UTC (rev 469) +++ trunk/pyscard/src/smartcard/test/framework/testcase_CAtr.py 2010-06-09 15:14:47 UTC (rev 470) @@ -32,84 +32,87 @@ # gemalto jython from smartcard.ATR import ATR + class testcase_CAtr(unittest.TestCase): """Test APDU class and utilities""" def testcase_ATR1(self): """Usimera Classic 2.""" - a = ATR([ 0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, - 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9 ] ) - historicalbytes = [ 0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), 0xB9 ) - self.assert_( a.checksumOK ) - self.assert_( a.isT0Supported() ) - self.assert_( not a.isT1Supported() ) - self.assert_( a.isT15Supported() ) + a = ATR([0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, + 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9]) + historicalbytes = [0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, + 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), 0xB9) + self.assert_(a.checksumOK) + self.assert_(a.isT0Supported()) + self.assert_(not a.isT1Supported()) + self.assert_(a.isT15Supported()) def testcase_ATR2(self): """Palmera Protect V2.""" - a = ATR( [ 0x3B, 0x65, 0x00, 0x00, 0x9C, 0x02, 0x02, 0x01, 0x02 ] ) - historicalbytes = [ 0x9C, 0x02, 0x02, 0x01, 0x02 ] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), None ) - self.assert_( a.isT0Supported() ) - self.assert_( not a.isT1Supported() ) - self.assert_( not a.isT15Supported() ) + a = ATR([0x3B, 0x65, 0x00, 0x00, 0x9C, 0x02, 0x02, 0x01, 0x02]) + historicalbytes = [0x9C, 0x02, 0x02, 0x01, 0x02] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), None) + self.assert_(a.isT0Supported()) + self.assert_(not a.isT1Supported()) + self.assert_(not a.isT15Supported()) def testcase_ATR3(self): """Simera 3.13.""" - a = ATR( [ 0x3B, 0x16, 0x18, 0x20, 0x02, 0x01, 0x00, 0x80, 0x0D ] ) - historicalbytes = [ 0x20, 0x02, 0x01, 0x00, 0x80, 0x0D ] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), None ) - self.assert_( a.isT0Supported() ) - self.assert_( not a.isT1Supported() ) - self.assert_( not a.isT15Supported() ) + a = ATR([0x3B, 0x16, 0x18, 0x20, 0x02, 0x01, 0x00, 0x80, 0x0D]) + historicalbytes = [0x20, 0x02, 0x01, 0x00, 0x80, 0x0D] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), None) + self.assert_(a.isT0Supported()) + self.assert_(not a.isT1Supported()) + self.assert_(not a.isT15Supported()) def testcase_ATR4(self): """SIMRock'n Tree""" - a = ATR( [ 0x3B, 0x77, 0x94, 0x00, 0x00, 0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22] ) - historicalbytes = [ 0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), None ) - self.assert_( a.isT0Supported() ) - self.assert_( not a.isT1Supported() ) - self.assert_( not a.isT15Supported() ) + a = ATR([0x3B, 0x77, 0x94, 0x00, 0x00, 0x82, 0x30, 0x00, 0x13, + 0x6C, 0x9F, 0x22]) + historicalbytes = [0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), None) + self.assert_(a.isT0Supported()) + self.assert_(not a.isT1Supported()) + self.assert_(not a.isT15Supported()) def testcase_ATR5(self): """Demo Vitale online IGEA340""" - a = ATR( [ 0x3F, 0x65, 0x25, 0x00, 0x52, 0x09, 0x6A, 0x90, 0x00] ) - historicalbytes = [ 0x52, 0x09, 0x6A, 0x90, 0x00] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), None ) - self.assert_( a.isT0Supported() ) - self.assert_( not a.isT1Supported() ) - self.assert_( not a.isT15Supported() ) + a = ATR([0x3F, 0x65, 0x25, 0x00, 0x52, 0x09, 0x6A, 0x90, 0x00]) + historicalbytes = [0x52, 0x09, 0x6A, 0x90, 0x00] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), None) + self.assert_(a.isT0Supported()) + self.assert_(not a.isT1Supported()) + self.assert_(not a.isT15Supported()) def testcase_ATR6(self): """Simagine 2002""" - a = ATR( [ 0x3B, 0x16, 0x94, 0x20, 0x02, 0x01, 0x00, 0x00, 0x0D ] ) - historicalbytes = [ 0x20, 0x02, 0x01, 0x00, 0x00, 0x0D ] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), None ) + a = ATR([0x3B, 0x16, 0x94, 0x20, 0x02, 0x01, 0x00, 0x00, 0x0D]) + historicalbytes = [0x20, 0x02, 0x01, 0x00, 0x00, 0x0D] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), None) - def testcase_ATR7(self): """Protect V3 T=1""" - a = ATR( [ 0x3B, 0xE5, 0x00, 0x00, 0x81, 0x21, 0x45, 0x9C, 0x10, 0x01, 0x00, 0x80, 0x0D ] ) - historicalbytes = [ 0x9C, 0x10, 0x01, 0x00, 0x80 ] - self.assertEquals( a.getHistoricalBytes(), historicalbytes ) - self.assertEquals( a.getChecksum(), 0x0D ) - self.assert_( not a.isT0Supported() ) - self.assert_( a.isT1Supported() ) - self.assert_( not a.isT15Supported() ) - self.assert_( a.checksumOK ) - self.assert_( a.getTB1()==0x00 ) - self.assert_( a.getTC1()==0x00 ) - self.assert_( a.getTD1()==0x81 ) - self.assert_( a.TD[2-1]==0x21 ) # TD2 - self.assert_( a.TB[3-1]==0x45 ) # TB3 + a = ATR([0x3B, 0xE5, 0x00, 0x00, 0x81, 0x21, 0x45, 0x9C, 0x10, + 0x01, 0x00, 0x80, 0x0D]) + historicalbytes = [0x9C, 0x10, 0x01, 0x00, 0x80] + self.assertEquals(a.getHistoricalBytes(), historicalbytes) + self.assertEquals(a.getChecksum(), 0x0D) + self.assert_(not a.isT0Supported()) + self.assert_(a.isT1Supported()) + self.assert_(not a.isT15Supported()) + self.assert_(a.checksumOK) + self.assert_(a.getTB1() == 0x00) + self.assert_(a.getTC1() == 0x00) + self.assert_(a.getTD1() == 0x81) + self.assert_(a.TD[2 - 1] == 0x21) # TD2 + self.assert_(a.TB[3 - 1] == 0x45) # TB3 def suite(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:10:31
|
Revision: 469 http://pyscard.svn.sourceforge.net/pyscard/?rev=469&view=rev Author: ludov Date: 2010-06-09 15:10:25 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/test/configcheck.py Modified: trunk/pyscard/src/smartcard/test/configcheck.py =================================================================== --- trunk/pyscard/src/smartcard/test/configcheck.py 2010-06-09 15:07:58 UTC (rev 468) +++ trunk/pyscard/src/smartcard/test/configcheck.py 2010-06-09 15:10:25 UTC (rev 469) @@ -31,44 +31,46 @@ from smartcard.Exceptions import NoCardException from smartcard.util import toHexString + def getATR(reader): cc = reader.createConnection() cc.connect() - atr=cc.getATR() + atr = cc.getATR() cc.disconnect() return atr + def checklocalconfig(): try: - f=open('local_config.py', 'r') + f = open('local_config.py', 'r') except IOError: print 'local_config.py not found; generating local_config.py...' # generate local configuration - f=open('local_config.py', 'w+') + f = open('local_config.py', 'w+') - f.write( 'from smartcard.util import toHexString\n' ) - f.write( 'expectedReaders = ' ) - f.write( str(readers()) + '\n') + f.write('from smartcard.util import toHexString\n') + f.write('expectedReaders = ') + f.write(str(readers()) + '\n') expectedATRs = [] for reader in readers(): try: - expectedATRs.append( getATR( reader ) ) + expectedATRs.append(getATR(reader)) except NoCardException: - expectedATRs.append( [] ) - f.write( 'expectedATRs = ' ) + expectedATRs.append([]) + f.write('expectedATRs = ') #for atr in expectedATRs: print `toHexString(atr)` - f.write( `expectedATRs` + '\n' ) + f.write(`expectedATRs` + '\n') - f.write( 'expectedATRinReader = {} \n') - f.write( 'for i in xrange(len(expectedReaders)): \n') - f.write( '\t' + 'expectedATRinReader[expectedReaders[i]]=expectedATRs[i] \n') + f.write('expectedATRinReader = {} \n') + f.write('for i in xrange(len(expectedReaders)): \n') + f.write('\t' + 'expectedATRinReader[expectedReaders[i]]=expectedATRs[i] \n') - f.write( 'expectedReaderForATR = {} \n') - f.write( 'for i in xrange(len(expectedReaders)): \n') - f.write( '\t' + 'expectedReaderForATR[toHexString(expectedATRs[i])]=expectedReaders[i] \n') + f.write('expectedReaderForATR = {} \n') + f.write('for i in xrange(len(expectedReaders)): \n') + f.write('\t' + 'expectedReaderForATR[toHexString(expectedATRs[i])]=expectedReaders[i] \n') - f.write( 'expectedReaderGroups = [ \'SCard$DefaultReaders\' ] \n') + f.write('expectedReaderGroups = [ \'SCard$DefaultReaders\' ] \n') f.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:08:04
|
Revision: 468 http://pyscard.svn.sourceforge.net/pyscard/?rev=468&view=rev Author: ludov Date: 2010-06-09 15:07:58 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/pcsc/PCSCReaderGroups.py Modified: trunk/pyscard/src/smartcard/pcsc/PCSCReaderGroups.py =================================================================== --- trunk/pyscard/src/smartcard/pcsc/PCSCReaderGroups.py 2010-06-09 15:07:00 UTC (rev 467) +++ trunk/pyscard/src/smartcard/pcsc/PCSCReaderGroups.py 2010-06-09 15:07:58 UTC (rev 468) @@ -85,7 +85,7 @@ raise error, 'Failed to establish context: ' + SCardGetErrorMessage(hresult) try: hresult = SCardForgetReaderGroup(hcontext, group) - if hresult!=0: + if hresult != 0: raise error, 'Unable to forget reader group: ' + SCardGetErrorMessage(hresult) finally: hresult = SCardReleaseContext(hcontext) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:07:06
|
Revision: 467 http://pyscard.svn.sourceforge.net/pyscard/?rev=467&view=rev Author: ludov Date: 2010-06-09 15:07:00 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/System.py Modified: trunk/pyscard/src/smartcard/System.py =================================================================== --- trunk/pyscard/src/smartcard/System.py 2010-06-09 15:06:00 UTC (rev 466) +++ trunk/pyscard/src/smartcard/System.py 2010-06-09 15:07:00 UTC (rev 467) @@ -27,7 +27,8 @@ import smartcard.pcsc.PCSCReader import smartcard.pcsc.PCSCReaderGroups -def readers( groups=[] ): + +def readers(groups=[]): """Returns the list of smartcard readers in groups. If group is not specified, returns the list of all smartcard readers. @@ -37,22 +38,24 @@ r=smartcard.readers(['SCard$DefaultReaders', 'MyReaderGroup']) """ - return smartcard.pcsc.PCSCReader.readers( groups ) + return smartcard.pcsc.PCSCReader.readers(groups) + def readergroups(): """Returns the list of reader groups.""" return smartcard.pcsc.PCSCReaderGroups.PCSCReaderGroups() + # for legacy only def listReaders(): """Returns the list of smartcard readers. Deprecated - Use smartcard.System.readers() instead. """ - zreaders=[] + zreaders = [] for reader in readers(): - zreaders.append( str(reader) ) + zreaders.append(str(reader)) return zreaders This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:06:06
|
Revision: 466 http://pyscard.svn.sourceforge.net/pyscard/?rev=466&view=rev Author: ludov Date: 2010-06-09 15:06:00 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/Synchronization.py Modified: trunk/pyscard/src/smartcard/Synchronization.py =================================================================== --- trunk/pyscard/src/smartcard/Synchronization.py 2010-06-09 15:04:13 UTC (rev 465) +++ trunk/pyscard/src/smartcard/Synchronization.py 2010-06-09 15:06:00 UTC (rev 466) @@ -8,7 +8,9 @@ from threading import RLock + def synchronized(method): + def f(*args): self = args[0] self.mutex.acquire() @@ -20,11 +22,12 @@ # print method.__name__, 'released' return f + def synchronize(klass, names=None): """Synchronize methods in the given class. Only synchronize the methods whose names are given, or all methods if names=None.""" - if type(names)==type(''): + if type(names) == type(''): names = names.split() for (name, val) in klass.__dict__.items(): if callable(val) and name != '__init__' and \ @@ -32,9 +35,9 @@ # print "synchronizing", name klass.__dict__[name] = synchronized(val) -# You can create your own self.mutex, or inherit -# from this class: + class Synchronization: + # You can create your own self.mutex, or inherit from this class: + def __init__(self): self.mutex = RLock() -#:~ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:04:19
|
Revision: 465 http://pyscard.svn.sourceforge.net/pyscard/?rev=465&view=rev Author: ludov Date: 2010-06-09 15:04:13 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/CardConnectionObserver.py Modified: trunk/pyscard/src/smartcard/CardConnectionObserver.py =================================================================== --- trunk/pyscard/src/smartcard/CardConnectionObserver.py 2010-06-09 15:01:18 UTC (rev 464) +++ trunk/pyscard/src/smartcard/CardConnectionObserver.py 2010-06-09 15:04:13 UTC (rev 465) @@ -28,14 +28,15 @@ from smartcard.util import toHexString from smartcard.Observer import Observer + # ReaderObserver interface -class CardConnectionObserver( Observer ): +class CardConnectionObserver(Observer): """ CardConnectionObserver is a base class for objects that are to be notified upon CardConnection events. """ - def update( self, cardconnection, cardconnectionevent ): + def update(self, cardconnection, cardconnectionevent): """Called upon CardConnection event. cardconnection: the observed card connection object @@ -44,20 +45,21 @@ pass -class ConsoleCardConnectionObserver( CardConnectionObserver ): - def update( self, cardconnection, ccevent ): +class ConsoleCardConnectionObserver(CardConnectionObserver): - if 'connect'==ccevent.type: + def update(self, cardconnection, ccevent): + + if 'connect' == ccevent.type: print 'connecting to ' + cardconnection.getReader() - elif 'disconnect'==ccevent.type: + elif 'disconnect' == ccevent.type: print 'disconnecting from ' + cardconnection.getReader() - elif 'command'==ccevent.type: - print '> ', toHexString( ccevent.args[0] ) + elif 'command' == ccevent.type: + print '> ', toHexString(ccevent.args[0]) - elif 'response'==ccevent.type: - if []==ccevent.args[0]: + elif 'response' == ccevent.type: + if [] == ccevent.args[0]: print '< [] ', "%-2X %-2X" % tuple(ccevent.args[-2:]) else: print '< ', toHexString(ccevent.args[0]), "%-2X %-2X" % tuple(ccevent.args[-2:]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 15:01:24
|
Revision: 464 http://pyscard.svn.sourceforge.net/pyscard/?rev=464&view=rev Author: ludov Date: 2010-06-09 15:01:18 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/ulist.py Modified: trunk/pyscard/src/smartcard/ulist.py =================================================================== --- trunk/pyscard/src/smartcard/ulist.py 2010-06-09 14:53:07 UTC (rev 463) +++ trunk/pyscard/src/smartcard/ulist.py 2010-06-09 15:01:18 UTC (rev 464) @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ + class ulist(list): """ulist ensures that all items are unique and provides an __onadditem__ hook to perform custom action in subclasses.""" @@ -31,88 +32,92 @@ # # override list methods # + def __init__(self, initlist=None): - if initlist is not None and initlist!=[]: - list.__init__( self, [initlist[0]] ) + if initlist is not None and initlist != []: + list.__init__(self, [initlist[0]]) for item in initlist[1:]: - if not list.__contains__( self, item ): - list.append( self, item ) + if not list.__contains__(self, item): + list.append(self, item) else: - list.__init__( self, initlist ) + list.__init__(self, initlist) def __add__(self, other): - newother = self.__remove_duplicates( other ) - self.__appendother__( newother ) - return self.__class__( list(self)+list(newother) ) + newother = self.__remove_duplicates(other) + self.__appendother__(newother) + return self.__class__(list(self) + list(newother)) def __iadd__(self, other): - newother = self.__remove_duplicates( other ) - self.__appendother__( newother ) - list.__iadd__( self, newother ) + newother = self.__remove_duplicates(other) + self.__appendother__(newother) + list.__iadd__(self, newother) return self def __radd__(self, other): - newother = self.__remove_duplicates( other ) - return list.__add__( self, newother ) + newother = self.__remove_duplicates(other) + return list.__add__(self, newother) def append(self, item): - if not list.__contains__( self, item ): - list.append( self, item ) - self.__onadditem__( item ) + if not list.__contains__(self, item): + list.append(self, item) + self.__onadditem__(item) def insert(self, i, item): - if not list.__contains__( self, item ): - list.insert( self, i, item ) - self.__onadditem__( item ) + if not list.__contains__(self, item): + list.insert(self, i, item) + self.__onadditem__(item) def pop(self, i=-1): - item = list.pop( self, i ) - self.__onremoveitem__( item ) + item = list.pop(self, i) + self.__onremoveitem__(item) return item def remove(self, item): - list.remove( self, item ) - self.__onremoveitem__( item ) + list.remove(self, item) + self.__onremoveitem__(item) # # non list methods # - def __remove_duplicates( self, _other ): + + def __remove_duplicates(self, _other): """Remove from other items already in list.""" - if not isinstance( _other, type(self) ) \ - and not isinstance( _other, type(list)) \ - and not isinstance( _other, type([])): - other=[_other] + if not isinstance(_other, type(self)) \ + and not isinstance(_other, type(list)) \ + and not isinstance(_other, type([])): + other = [_other] else: - other=list(_other) + other = list(_other) # remove items already in self - newother=[] - for i in range(0, len(other) ): + newother = [] + for i in range(0, len(other)): item = other.pop(0) - if not list.__contains__( self, item ): - newother.append( item ) + if not list.__contains__(self, item): + newother.append(item) # remove duplicate items in other - other=[] - if newother!=[]: + other = [] + if newother != []: other.append(newother[0]) - for i in range( 1, len( newother ) ): + for i in range(1, len(newother)): item = newother.pop() - if not other.__contains__( item ): - other.append( item ) + if not other.__contains__(item): + other.append(item) return other - def __appendother__( self, other ): + def __appendother__(self, other): """Append other to object.""" for item in other: - self.__onadditem__( item ) + self.__onadditem__(item) - def __onadditem__( self, item ): - """Called for each item added. Override in subclasses for adding custom action.""" + def __onadditem__(self, item): + """Called for each item added. Override in subclasses for adding + custom action.""" pass - def __onremoveitem__( self, item ): - """Called for each item removed. Override in subclasses for adding custom action.""" + def __onremoveitem__(self, item): + """Called for each item removed. Override in subclasses for + adding custom action.""" pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 14:53:14
|
Revision: 463 http://pyscard.svn.sourceforge.net/pyscard/?rev=463&view=rev Author: ludov Date: 2010-06-09 14:53:07 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/Session.py Modified: trunk/pyscard/src/smartcard/Session.py =================================================================== --- trunk/pyscard/src/smartcard/Session.py 2010-06-09 14:51:38 UTC (rev 462) +++ trunk/pyscard/src/smartcard/Session.py 2010-06-09 14:53:07 UTC (rev 463) @@ -28,6 +28,7 @@ from smartcard.PassThruCardService import PassThruCardService from smartcard.System import readers + class Session: """The Session object enables programmers to transmit APDU to smartcards. @@ -45,39 +46,40 @@ """ def __init__(self, readerName=None, cardServiceClass=None): - """Session constructor. Initializes a smart card session and connect to the card. + """Session constructor. Initializes a smart card session and + connect to the card. readerName: reader to connect to; default is first PCSC reader - cardServiceClass: card service to bind the session to; default is None + cardServiceClass: card service to bind the session to; default + is None """ # if reader name not given, select first reader - if readerName==None: - if len( readers() ) > 0: - self.reader=readers()[0] - self.readerName=`self.reader` + if readerName == None: + if len(readers()) > 0: + self.reader = readers()[0] + self.readerName = `self.reader` else: raise NoReadersException() # otherwise select reader from name else: - self.readerName=readerName + self.readerName = readerName for reader in readers(): - if readerName==str(reader): - self.reader=reader - self.readerName=`self.reader` + if readerName == str(reader): + self.reader = reader + self.readerName = `self.reader` try: self.reader except AttributeError: - raise InvalidReaderException( self.readerName ) + raise InvalidReaderException(self.readerName) # open card connection and bind PassThruCardService cc = self.reader.createConnection() - self.cs = PassThruCardService( cc ) + self.cs = PassThruCardService(cc) self.cs.connection.connect() - def close(self): """Close the smartcard session. @@ -89,16 +91,16 @@ command: list of APDU bytes, e.g. [0xA0, 0xA4, 0x00, 0x00, 0x02] - returns a tuple (response, sw1, sw2 ) where + returns a tuple (response, sw1, sw2) where response is the APDU response sw1, sw2 are the two status words """ - response, sw1, sw2 = self.cs.connection.transmit( command ) + response, sw1, sw2 = self.cs.connection.transmit(command) - if len(response)>2: - response.append( sw1 ) - response.append( sw2 ) + if len(response) > 2: + response.append(sw1) + response.append(sw2) return response, sw1, sw2 def getATR(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 14:51:45
|
Revision: 462 http://pyscard.svn.sourceforge.net/pyscard/?rev=462&view=rev Author: ludov Date: 2010-06-09 14:51:38 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/ReaderMonitoring.py Modified: trunk/pyscard/src/smartcard/ReaderMonitoring.py =================================================================== --- trunk/pyscard/src/smartcard/ReaderMonitoring.py 2010-06-09 14:48:26 UTC (rev 461) +++ trunk/pyscard/src/smartcard/ReaderMonitoring.py 2010-06-09 14:51:38 UTC (rev 462) @@ -45,9 +45,11 @@ ReaderObserver is a base abstract class for objects that are to be notified upon smartcard reader insertion/removal. """ + def __init__(self): pass - def update( self, observable, (addedreaders, removedreaders) ): + + def update(self, observable, (addedreaders, removedreaders)): """Called upon reader insertion/removal. observable: @@ -56,7 +58,8 @@ """ pass -class ReaderMonitor( Observable ): + +class ReaderMonitor(Observable): """Class that monitors reader insertion/removal. and notify observers @@ -70,47 +73,50 @@ the shared state pattern logics. """ - __shared_state = {} - def __init__( self, startOnDemand=True, readerProc=smartcard.System.readers, period=1 ): + def __init__(self, startOnDemand=True, readerProc=smartcard.System.readers, + period=1): self.__dict__ = self.__shared_state - Observable.__init__( self ) + Observable.__init__(self) self.startOnDemand = startOnDemand self.readerProc = readerProc self.period = period if self.startOnDemand: - self.rmthread=None + self.rmthread = None else: - self.rmthread = ReaderMonitoringThread( self, self.readerProc, self.period ) + self.rmthread = ReaderMonitoringThread(self, self.readerProc, + self.period) self.rmthread.start() - def addObserver( self, observer ): + def addObserver(self, observer): """Add an observer.""" - Observable.addObserver( self, observer ) + Observable.addObserver(self, observer) - # If self.startOnDemand is True, the reader monitoring + # If self.startOnDemand is True, the reader monitoring # thread only runs when there are observers. if self.startOnDemand: - if 0<self.countObservers(): + if 0 < self.countObservers(): if not self.rmthread: - self.rmthread = ReaderMonitoringThread( self, self.readerProc, self.period ) + self.rmthread = ReaderMonitoringThread(self, + self.readerProc, self.period) # start reader monitoring thread in another thread to # avoid a deadlock; addObserver and notifyObservers called - # in the ReaderMonitoringThread run() method are synchronized + # in the ReaderMonitoringThread run() method are + # synchronized import thread - thread.start_new_thread( self.rmthread.start, () ) + thread.start_new_thread(self.rmthread.start, ()) else: - observer.update( self, (self.rmthread.readers, []) ) + observer.update(self, (self.rmthread.readers, [])) - def deleteObserver( self, observer ): + def deleteObserver(self, observer): """Remove an observer.""" - Observable.deleteObserver( self, observer ) - # If self.startOnDemand is True, the reader monitoring + Observable.deleteObserver(self, observer) + # If self.startOnDemand is True, the reader monitoring # thread is stopped when there are no more observers. if self.startOnDemand: - if 0==self.countObservers(): + if 0 == self.countObservers(): self.rmthread.stop() del self.rmthread self.rmthread = None @@ -118,7 +124,7 @@ def __str__(self): return self.__class__.__name__ -synchronize( ReaderMonitor, +synchronize(ReaderMonitor, "addObserver deleteObserver deleteObservers " + "setChanged clearChanged hasChanged " + "countObservers") @@ -130,20 +136,20 @@ reader insertion event is available in pcsc. """ + __shared_state = {} - __shared_state = {} - def __init__( self, observable, readerProc, period ): + def __init__(self, observable, readerProc, period): self.__dict__ = self.__shared_state - Thread.__init__( self ) + Thread.__init__(self) self.observable = observable self.stopEvent = Event() self.stopEvent.clear() self.readers = [] - self.setDaemon( True ) - self.setName( 'smartcard.ReaderMonitoringThread' ) + self.setDaemon(True) + self.setName('smartcard.ReaderMonitoringThread') self.readerProc = readerProc self.period = period - + def run(self): """Runs until stopEvent is notified, and notify observers of all reader insertion/removal. @@ -151,27 +157,28 @@ while not self.stopEvent.isSet(): try: # no need to monitor if no observers - if 0<self.observable.countObservers(): + if 0 < self.observable.countObservers(): currentReaders = self.readerProc() addedReaders = [] removedReaders = [] - if currentReaders!=self.readers: + if currentReaders != self.readers: for reader in currentReaders: if not reader in self.readers: addedReaders.append(reader) for reader in self.readers: if not reader in currentReaders: removedReaders.append(reader) - + if addedReaders or removedReaders: # Notify observers - self.readers=[] + self.readers = [] for r in currentReaders: self.readers.append(r) self.observable.setChanged() - self.observable.notifyObservers((addedReaders, removedReaders)) - + self.observable.notifyObservers((addedReaders, + removedReaders)) + # wait every second on stopEvent self.stopEvent.wait(self.period) @@ -191,24 +198,26 @@ print 'insert or remove readers in the next 20 seconds' # a simple reader observer that prints added/removed readers - class printobserver( ReaderObserver ): - def __init__( self, obsindex ): - self.obsindex=obsindex + class printobserver(ReaderObserver): - def update( self, observable, (addedreaders, removedreaders) ): + def __init__(self, obsindex): + self.obsindex = obsindex + + def update(self, observable, (addedreaders, removedreaders)): print "%d - added: " % self.obsindex, addedreaders print "%d - removed: " % self.obsindex, removedreaders - class testthread( Thread ): - def __init__(self, obsindex ): + class testthread(Thread): + + def __init__(self, obsindex): Thread.__init__(self) self.readermonitor = ReaderMonitor() self.obsindex = obsindex - self.observer=None + self.observer = None def run(self): # create and register observer - self.observer = printobserver( self.obsindex ) + self.observer = printobserver(self.obsindex) self.readermonitor.addObserver(self.observer) sleep(20) self.readermonitor.deleteObserver(self.observer) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 14:48:32
|
Revision: 461 http://pyscard.svn.sourceforge.net/pyscard/?rev=461&view=rev Author: ludov Date: 2010-06-09 14:48:26 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/PassThruCardService.py Modified: trunk/pyscard/src/smartcard/PassThruCardService.py =================================================================== --- trunk/pyscard/src/smartcard/PassThruCardService.py 2010-06-09 14:47:44 UTC (rev 460) +++ trunk/pyscard/src/smartcard/PassThruCardService.py 2010-06-09 14:48:26 UTC (rev 461) @@ -29,23 +29,25 @@ from smartcard import CardService + class PassThruCardService(CardService.CardService): """Pass-thru card service class.""" - def __init__( self, connection, cardname=None ): + def __init__(self, connection, cardname=None): """Construct a pass-thru card service. connection: the CardConnection used to access the smart card """ - CardService.CardService.__init__( self, connection, cardname ) + CardService.CardService.__init__(self, connection, cardname) - - def supports( cardname ): + def supports(cardname): """Returns True if the cardname is supported by the card service. - The PassThruCardService supports all cardnames and always returns True.""" + The PassThruCardService supports all cardnames and always + returns True.""" return True - supports = staticmethod( supports ) + supports = staticmethod(supports) + if __name__ == '__main__': """Small sample illustrating the use of CardService.""" SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] @@ -53,8 +55,8 @@ from smartcard.System import readers from smartcard.CardConnection import CardConnection cc = readers()[0].createConnection() - cs = PassThruCardService( cc ) + cs = PassThruCardService(cc) cs.connection.connect() - data, sw1, sw2 = cs.connection.transmit( SELECT + DF_TELECOM ) + data, sw1, sw2 = cs.connection.transmit(SELECT + DF_TELECOM) print "%X %X" % (sw1, sw2) cs.connection.disconnect() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 14:47:50
|
Revision: 460 http://pyscard.svn.sourceforge.net/pyscard/?rev=460&view=rev Author: ludov Date: 2010-06-09 14:47:44 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/Observer.py Modified: trunk/pyscard/src/smartcard/Observer.py =================================================================== --- trunk/pyscard/src/smartcard/Observer.py 2010-06-09 14:47:00 UTC (rev 459) +++ trunk/pyscard/src/smartcard/Observer.py 2010-06-09 14:47:44 UTC (rev 460) @@ -14,7 +14,9 @@ from smartcard.Synchronization import * + class Observer: + def update(observable, arg): '''Called when the observed object is modified. You call an Observable object's @@ -22,7 +24,9 @@ object's observers of the change.''' pass + class Observable(Synchronization): + def __init__(self): self.obs = [] self.changed = 0 @@ -58,12 +62,16 @@ def deleteObservers(self): self.obs = [] + def setChanged(self): self.changed = 1 + def clearChanged(self): self.changed = 0 + def hasChanged(self): return self.changed + def countObservers(self): return len(self.obs) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 14:47:07
|
Revision: 459 http://pyscard.svn.sourceforge.net/pyscard/?rev=459&view=rev Author: ludov Date: 2010-06-09 14:47:00 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/guid.py Modified: trunk/pyscard/src/smartcard/guid.py =================================================================== --- trunk/pyscard/src/smartcard/guid.py 2010-06-09 11:49:32 UTC (rev 458) +++ trunk/pyscard/src/smartcard/guid.py 2010-06-09 14:47:00 UTC (rev 459) @@ -27,21 +27,24 @@ # guid is ulong+ushort+ushort+uchar[8]; we need a map because bytes # are swappted for the first three -map={ 0:3, 1:2, 2:1, 3:0, 4:5, 5:4, 6:7, 7:6, 8:8, 9:9, 10:10, 11:11, 12:12, 13:13, 14:14, 15:15 } +map = {0: 3, 1: 2, 2: 1, 3: 0, 4: 5, 5: 4, 6: 7, 7: 6, 8: 8, 9: 9, + 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15} -def strToGUID( s ): + +def strToGUID(s): """Converts a GUID string into a list of bytes.""" - l=[] - for i in unpack( 'x' + '2s'*4 + 'x' + '2s2sx'*3 + '2s'*6 + 'x', s ): - l += [ int( i, 16) ] - zr=[] + l = [] + for i in unpack('x' + '2s' * 4 + 'x' + '2s2sx' * 3 + '2s' * 6 + 'x', s): + l += [int(i, 16)] + zr = [] for i in xrange(len(l)): zr.append(l[map[i]]) return zr -def GUIDToStr( g ): + +def GUIDToStr(g): """Converts a GUID sequence of bytes into a string.""" - zr=[] + zr = [] for i in xrange(len(g)): zr.append(g[map[i]]) return "{%2X%2X%2X%2X-%2X%2X-%2X%2X-%2X%2X-%2X%2X%2X%2X%2X%2X}" % tuple(zr) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 11:49:38
|
Revision: 458 http://pyscard.svn.sourceforge.net/pyscard/?rev=458&view=rev Author: ludov Date: 2010-06-09 11:49:32 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/ExclusiveTransmitCardConnection.py Modified: trunk/pyscard/src/smartcard/ExclusiveTransmitCardConnection.py =================================================================== --- trunk/pyscard/src/smartcard/ExclusiveTransmitCardConnection.py 2010-06-09 11:47:51 UTC (rev 457) +++ trunk/pyscard/src/smartcard/ExclusiveTransmitCardConnection.py 2010-06-09 11:49:32 UTC (rev 458) @@ -29,50 +29,52 @@ from smartcard.pcsc import PCSCCardConnection import smartcard.pcsc -class ExclusiveTransmitCardConnection( CardConnectionDecorator ): - '''This decorator uses SCardBeginTransaction/SCardEndTransaction - to preserve other processes of threads to access the card during transmit().''' - def __init__( self, cardconnection ): - CardConnectionDecorator.__init__( self, cardconnection ) - def lock( self ): +class ExclusiveTransmitCardConnection(CardConnectionDecorator): + '''This decorator uses SCardBeginTransaction/SCardEndTransaction to + preserve other processes of threads to access the card during + transmit().''' + + def __init__(self, cardconnection): + CardConnectionDecorator.__init__(self, cardconnection) + + def lock(self): '''Lock card with SCardBeginTransaction.''' - component=self.component + component = self.component while True: - if isinstance( component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection ): - hresult = SCardBeginTransaction( component.hcard ) - if 0!=hresult: - raise CardConnectionException( 'Failed to lock with SCardBeginTransaction' + SCardGetErrorMessage(hresult) ) + if isinstance(component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection): + hresult = SCardBeginTransaction(component.hcard) + if 0 != hresult: + raise CardConnectionException('Failed to lock with SCardBeginTransaction' + SCardGetErrorMessage(hresult)) else: #print 'locked' pass break - if hasattr( component, 'component' ): - component=component.component + if hasattr(component, 'component'): + component = component.component else: break - def unlock( self ): + def unlock(self): '''Unlock card with SCardEndTransaction.''' - component=self.component + component = self.component while True: - if isinstance( component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection ): - hresult = SCardEndTransaction( component.hcard, SCARD_LEAVE_CARD ) - if 0!=hresult: - raise CardConnectionException( 'Failed to unlock with SCardEndTransaction' + SCardGetErrorMessage(hresult) ) + if isinstance(component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection): + hresult = SCardEndTransaction(component.hcard, SCARD_LEAVE_CARD) + if 0 != hresult: + raise CardConnectionException('Failed to unlock with SCardEndTransaction' + SCardGetErrorMessage(hresult)) else: #print 'unlocked' pass break - if hasattr( component, 'component' ): - component=component.component + if hasattr(component, 'component'): + component = component.component else: break - - def transmit( self, bytes, protocol=None ): + def transmit(self, bytes, protocol=None): '''Gain exclusive access to card during APDU transmission for if this decorator decorates a PCSCCardConnection.''' - data, sw1, sw2 = CardConnectionDecorator.transmit( self, bytes, protocol ) + data, sw1, sw2 = CardConnectionDecorator.transmit(self, bytes, protocol) return data, sw1, sw2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 11:47:57
|
Revision: 457 http://pyscard.svn.sourceforge.net/pyscard/?rev=457&view=rev Author: ludov Date: 2010-06-09 11:47:51 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/ExclusiveConnectCardConnection.py Modified: trunk/pyscard/src/smartcard/ExclusiveConnectCardConnection.py =================================================================== --- trunk/pyscard/src/smartcard/ExclusiveConnectCardConnection.py 2010-06-09 11:46:00 UTC (rev 456) +++ trunk/pyscard/src/smartcard/ExclusiveConnectCardConnection.py 2010-06-09 11:47:51 UTC (rev 457) @@ -29,33 +29,37 @@ from smartcard.pcsc import PCSCCardConnection import smartcard.pcsc -class ExclusiveConnectCardConnection( CardConnectionDecorator ): - '''This decorator uses exclusive access to the card during connection to prevent other - processes to connect to this card.''' - def __init__( self, cardconnection ): - CardConnectionDecorator.__init__( self, cardconnection ) - def connect( self, protocol=None, mode=None, disposition=None ): +class ExclusiveConnectCardConnection(CardConnectionDecorator): + '''This decorator uses exclusive access to the card during + connection to prevent other processes to connect to this card.''' + + def __init__(self, cardconnection): + CardConnectionDecorator.__init__(self, cardconnection) + + def connect(self, protocol=None, mode=None, disposition=None): '''Disconnect and reconnect in exclusive mode PCSCCardconnections.''' - CardConnectionDecorator.connect( self, protocol, mode, disposition ) - component=self.component + CardConnectionDecorator.connect(self, protocol, mode, disposition) + component = self.component while True: - if isinstance( component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection ): - pcscprotocol = PCSCCardConnection.translateprotocolmask( protocol ) - if 0==pcscprotocol: + if isinstance(component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection): + pcscprotocol = PCSCCardConnection.translateprotocolmask(protocol) + if 0 == pcscprotocol: pcscprotocol = component.getProtocol() - if None!=component.hcard: - hresult = SCardDisconnect( component.hcard, SCARD_LEAVE_CARD ) - if hresult!=0: - raise CardConnectionException( 'Failed to disconnect: ' + SCardGetErrorMessage(hresult) ) + if None != component.hcard: + hresult = SCardDisconnect(component.hcard, SCARD_LEAVE_CARD) + if hresult != 0: + raise CardConnectionException('Failed to disconnect: ' + + SCardGetErrorMessage(hresult)) hresult, component.hcard, dwActiveProtocol = SCardConnect( - component.hcontext, str(component.reader), SCARD_SHARE_EXCLUSIVE, pcscprotocol ) - if hresult!=0: - raise CardConnectionException( 'Failed to connect with SCARD_SHARE_EXCLUSIVE' + SCardGetErrorMessage(hresult) ) + component.hcontext, str(component.reader), + SCARD_SHARE_EXCLUSIVE, pcscprotocol) + if hresult != 0: + raise CardConnectionException('Failed to connect with SCARD_SHARE_EXCLUSIVE' + SCardGetErrorMessage(hresult)) # print 'reconnected exclusive' break - if hasattr( component, 'component' ): - component=component.component + if hasattr(component, 'component'): + component = component.component else: break This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2010-06-09 11:46:09
|
Revision: 456 http://pyscard.svn.sourceforge.net/pyscard/?rev=456&view=rev Author: ludov Date: 2010-06-09 11:46:00 +0000 (Wed, 09 Jun 2010) Log Message: ----------- make pep8 happy Modified Paths: -------------- trunk/pyscard/src/smartcard/Exceptions.py Modified: trunk/pyscard/src/smartcard/Exceptions.py =================================================================== --- trunk/pyscard/src/smartcard/Exceptions.py 2010-06-09 11:43:38 UTC (rev 455) +++ trunk/pyscard/src/smartcard/Exceptions.py 2010-06-09 11:46:00 UTC (rev 456) @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ + class SmartcardException: """Base class for smartcard exceptions. @@ -31,52 +32,73 @@ shield scard (i.e. PCSC) exceptions raised by the scard module. """ - def __init__( self, message="" ): + + def __init__(self, message=""): self.message = message + def __str__(self): - return repr( 'Smartcard Exception: ' + self.message + '!' ) + return repr('Smartcard Exception: ' + self.message + '!') + class CardConnectionException(SmartcardException): """Raised when a CardConnection class method fails.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, message ) + def __init__(self, message=""): + SmartcardException.__init__(self, message) + + class CardRequestException(SmartcardException): """Raised when a CardRequest wait fails.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, message ) + def __init__(self, message=""): + SmartcardException.__init__(self, message) + + class CardRequestTimeoutException(SmartcardException): """Raised when a CardRequest times out.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, "Time-out during card request" ) + def __init__(self, message=""): + SmartcardException.__init__(self, "Time-out during card request") + + class CardServiceException(SmartcardException): """Raised when a CardService class method fails.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, message ) + def __init__(self, message=""): + SmartcardException.__init__(self, message) + + class InvalidATRMaskLengthException(SmartcardException): """Raised when an ATR mask does not match an ATR length.""" - def __init__( self, mask="" ): - SmartcardException.__init__( self, 'Invalid ATR mask length: ' + mask ) + def __init__(self, mask=""): + SmartcardException.__init__(self, 'Invalid ATR mask length: ' + mask) + + class InvalidReaderException(SmartcardException): """Raised when trying to acces an invalid smartcard reader.""" - def __init__( self, readername="" ): - SmartcardException.__init__( self, 'Invalid reader: ' + readername ) + def __init__(self, readername=""): + SmartcardException.__init__(self, 'Invalid reader: ' + readername) + + class ListReadersException(SmartcardException): """Raised when smartcard readers cannot be listed.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, 'failed to list readers' ) + def __init__(self, message=""): + SmartcardException.__init__(self, 'failed to list readers') + + class NoCardException(SmartcardException): """Raised when no card in is present in reader.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, 'Unable to connect to card or no card in reader' ) + def __init__(self, message=""): + SmartcardException.__init__(self, + 'Unable to connect to card or no card in reader') + + class NoReadersException(SmartcardException): """Raised when the system has no smartcard reader.""" - def __init__( self, message="" ): - SmartcardException.__init__( self, 'no readers found' ) + + def __init__(self, message=""): + SmartcardException.__init__(self, 'no readers found') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |