diff --git a/smartcard/Card.py b/smartcard/Card.py index b82fad52..a261c744 100644 --- a/smartcard/Card.py +++ b/smartcard/Card.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import CardConnectionException, NoCardException from smartcard.reader.Reader import Reader from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/CardConnection.py b/smartcard/CardConnection.py index 607185e0..15bb52b2 100644 --- a/smartcard/CardConnection.py +++ b/smartcard/CardConnection.py @@ -24,8 +24,6 @@ """ from smartcard.CardConnectionEvent import CardConnectionEvent -from smartcard.Exceptions import SmartcardException -from smartcard.Observer import Observer from smartcard.Observer import Observable diff --git a/smartcard/CardMonitoring.py b/smartcard/CardMonitoring.py index e0273a93..30991e30 100644 --- a/smartcard/CardMonitoring.py +++ b/smartcard/CardMonitoring.py @@ -32,12 +32,9 @@ from time import sleep import traceback -from smartcard.System import readers -from smartcard.Exceptions import CardRequestTimeoutException from smartcard.Observer import Observer from smartcard.Observer import Observable -from smartcard.CardType import AnyCardType from smartcard.CardRequest import CardRequest _START_ON_DEMAND_ = False @@ -216,7 +213,6 @@ def __getattr__(self, name): if __name__ == "__main__": - from smartcard.CardMonitoring import CardMonitor print 'insert or remove cards in the next 10 seconds' # a simple card observer that prints added/removed cards diff --git a/smartcard/CardService.py b/smartcard/CardService.py index b310f19a..0a2cf27a 100644 --- a/smartcard/CardService.py +++ b/smartcard/CardService.py @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.Exceptions import SmartcardException from smartcard.scard import * diff --git a/smartcard/CardType.py b/smartcard/CardType.py index 722a1cd1..d88ad047 100644 --- a/smartcard/CardType.py +++ b/smartcard/CardType.py @@ -21,6 +21,7 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ +from smartcard.Exceptions import InvalidATRMaskLengthException from smartcard.System import readers from smartcard.util import toHexString diff --git a/smartcard/ClassLoader.py b/smartcard/ClassLoader.py index 3b232152..3cc59c56 100644 --- a/smartcard/ClassLoader.py +++ b/smartcard/ClassLoader.py @@ -9,10 +9,6 @@ License: PSF license (http://docs.python.org/license.html). """ -import sys -import types - - def get_mod(modulePath): """Import a module.""" return __import__(modulePath, globals(), locals(), ['']) diff --git a/smartcard/ExclusiveConnectCardConnection.py b/smartcard/ExclusiveConnectCardConnection.py index 8d1f0cbf..ee3524ce 100644 --- a/smartcard/ExclusiveConnectCardConnection.py +++ b/smartcard/ExclusiveConnectCardConnection.py @@ -21,7 +21,6 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardConnect, SCardDisconnect diff --git a/smartcard/ExclusiveTransmitCardConnection.py b/smartcard/ExclusiveTransmitCardConnection.py index bbffa4da..ca836373 100644 --- a/smartcard/ExclusiveTransmitCardConnection.py +++ b/smartcard/ExclusiveTransmitCardConnection.py @@ -21,13 +21,11 @@ along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator from smartcard.Exceptions import CardConnectionException from smartcard.scard import SCardBeginTransaction, SCardEndTransaction from smartcard.scard import SCARD_LEAVE_CARD from smartcard.scard import SCardGetErrorMessage -from smartcard.pcsc import PCSCCardConnection import smartcard.pcsc diff --git a/smartcard/Observer.py b/smartcard/Observer.py index b5f2b4ca..ce1d94fc 100644 --- a/smartcard/Observer.py +++ b/smartcard/Observer.py @@ -19,7 +19,7 @@ class Observer(object): - def update(observable, arg): + def update(self, observable, arg): '''Called when the observed object is modified. You call an Observable object's notifyObservers method to notify all the diff --git a/smartcard/PassThruCardService.py b/smartcard/PassThruCardService.py index d22a48a3..25715354 100644 --- a/smartcard/PassThruCardService.py +++ b/smartcard/PassThruCardService.py @@ -53,7 +53,6 @@ def supports(cardname): SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] from smartcard.System import readers - from smartcard.CardConnection import CardConnection cc = readers()[0].createConnection() cs = PassThruCardService(cc) cs.connection.connect() diff --git a/smartcard/ReaderMonitoring.py b/smartcard/ReaderMonitoring.py index 62aab450..cebcb07c 100644 --- a/smartcard/ReaderMonitoring.py +++ b/smartcard/ReaderMonitoring.py @@ -28,12 +28,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ -from threading import Thread, Event, enumerate +from threading import Thread, Event from time import sleep import traceback import smartcard.System -from smartcard.Exceptions import ListReadersException from smartcard.Observer import Observer from smartcard.Observer import Observable from smartcard.Synchronization import * @@ -196,7 +195,6 @@ def stop(self): self.join() if __name__ == "__main__": - from smartcard.ReaderMonitoring import ReaderMonitor print 'insert or remove readers in the next 20 seconds' # a simple reader observer that prints added/removed readers diff --git a/smartcard/Session.py b/smartcard/Session.py index a700eddb..78515999 100644 --- a/smartcard/Session.py +++ b/smartcard/Session.py @@ -24,7 +24,6 @@ """ from smartcard.Exceptions import InvalidReaderException, NoReadersException -from smartcard.CardConnection import CardConnection from smartcard.PassThruCardService import PassThruCardService from smartcard.System import readers @@ -110,8 +109,3 @@ def getATR(self): def __repr__(self): """Returns a string representation of the session.""" return "" % self.readerName - - -if __name__ == '__main__': - """Small sample illustrating the use of Session.py.""" - pass diff --git a/smartcard/guid.py b/smartcard/guid.py index c8715a72..497f25bf 100644 --- a/smartcard/guid.py +++ b/smartcard/guid.py @@ -60,7 +60,6 @@ def GUIDToStr(g): if __name__ == "__main__": """Small sample illustrating the use of guid.py.""" - import smartcard.guid dummycardguid1 = strToGUID('{AD4F1667-EA75-4124-84D4-641B3B197C65}') print dummycardguid1 print GUIDToStr(dummycardguid1) diff --git a/smartcard/pcsc/PCSCCardConnection.py b/smartcard/pcsc/PCSCCardConnection.py index 08ea84a9..fee3234b 100644 --- a/smartcard/pcsc/PCSCCardConnection.py +++ b/smartcard/pcsc/PCSCCardConnection.py @@ -25,7 +25,6 @@ from smartcard.CardConnection import CardConnection from smartcard.Exceptions import (CardConnectionException, NoCardException, SmartcardException) -from smartcard.Observer import Observable from smartcard.scard import * @@ -240,8 +239,8 @@ def doGetAttrib(self, attribId): """Small sample illustrating the use of CardConnection.""" SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02] DF_TELECOM = [0x7F, 0x10] - from smartcard.pcsc.PCSCReader import readers - cc = readers()[0].createConnection() + from smartcard.pcsc.PCSCReader import PCSCReader + cc = PCSCReader.readers()[0].createConnection() cc.connect() print "%r %x %x" % cc.transmit(SELECT + DF_TELECOM) diff --git a/smartcard/pcsc/PCSCPart10.py b/smartcard/pcsc/PCSCPart10.py index 927bc3a1..dbd99985 100644 --- a/smartcard/pcsc/PCSCPart10.py +++ b/smartcard/pcsc/PCSCPart10.py @@ -227,8 +227,8 @@ def getTlvProperties(cardConnection, featureList=None, controlCode=None): if __name__ == '__main__': """Small sample illustrating the use of PCSCPart10.""" - from smartcard.pcsc.PCSCReader import readers - cc = readers()[0].createConnection() + from smartcard.pcsc.PCSCReader import PCSCReader + cc = PCSCReader.readers()[0].createConnection() cc.connect(mode=SCARD_SHARE_DIRECT) #print cc.control( CM_IOCTL_GET_FEATURE_REQUEST ) diff --git a/smartcard/pyro/PyroReader.py b/smartcard/pyro/PyroReader.py index 7023cc89..a6fe396f 100644 --- a/smartcard/pyro/PyroReader.py +++ b/smartcard/pyro/PyroReader.py @@ -25,9 +25,8 @@ import Pyro.core import Pyro.naming -from smartcard.Exceptions import CardConnectionException, NoCardException +from smartcard.Exceptions import NoCardException from smartcard.reader.Reader import Reader -from smartcard.reader.ReaderFactory import ReaderFactory class PyroReader(Reader): diff --git a/smartcard/pyro/server/PyroDaemon.py b/smartcard/pyro/server/PyroDaemon.py index 89b5d1ae..90eac204 100644 --- a/smartcard/pyro/server/PyroDaemon.py +++ b/smartcard/pyro/server/PyroDaemon.py @@ -85,8 +85,8 @@ def __init__(self): Thread.__init__(self) self.setDaemon(True) self.setName('smartcard.pyro.server.PyroDaemonThread') - self.daemon = PyroDaemon() + self._daemon = PyroDaemon() def run(self): """Starts Pyro daemon.""" - self.daemon.start() + self._daemon.start() diff --git a/smartcard/pyro/server/PyroEventServer.py b/smartcard/pyro/server/PyroEventServer.py index 90c4d998..2503e082 100644 --- a/smartcard/pyro/server/PyroEventServer.py +++ b/smartcard/pyro/server/PyroEventServer.py @@ -92,7 +92,6 @@ def __call__(self, signame, sf): if __name__ == '__main__': - import sys from smartcard.pyro.server.PyroNameServer import PyroNameServer pn = PyroNameServer(sys.argv[1:]) pn.start() diff --git a/smartcard/pyro/server/RemoteCardConnection.py b/smartcard/pyro/server/RemoteCardConnection.py index 9df373ee..2b092b7c 100644 --- a/smartcard/pyro/server/RemoteCardConnection.py +++ b/smartcard/pyro/server/RemoteCardConnection.py @@ -26,10 +26,7 @@ import Pyro.core import Pyro.naming -from smartcard.CardConnection import CardConnection from smartcard.CardConnectionDecorator import CardConnectionDecorator -from smartcard.Exceptions import CardConnectionException, NoCardException -from smartcard.Observer import Observable class RemoteCardConnection(CardConnectionDecorator, Pyro.core.ObjBase): diff --git a/smartcard/pyro/server/RemoteReaderServer.py b/smartcard/pyro/server/RemoteReaderServer.py index f29096de..f3e715fe 100644 --- a/smartcard/pyro/server/RemoteReaderServer.py +++ b/smartcard/pyro/server/RemoteReaderServer.py @@ -32,10 +32,6 @@ import sys sys.exit() -import signal -import time - -import smartcard.System from smartcard.reader.Reader import Reader from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver from smartcard.pyro.server.RemoteCardConnection import RemoteCardConnection diff --git a/smartcard/reader/ReaderGroups.py b/smartcard/reader/ReaderGroups.py index 4e6cfbc1..64475944 100644 --- a/smartcard/reader/ReaderGroups.py +++ b/smartcard/reader/ReaderGroups.py @@ -67,9 +67,6 @@ def __onremoveitem__(self, item): def __iter__(self): return ulist.__iter__(self) - def next(self): - return ulist.__next__(self) - # # abstract methods implemented in subclasses # diff --git a/smartcard/sw/ErrorChecker.py b/smartcard/sw/ErrorChecker.py index d29f0478..1296ff22 100644 --- a/smartcard/sw/ErrorChecker.py +++ b/smartcard/sw/ErrorChecker.py @@ -36,7 +36,7 @@ class ErrorChecker(object): pattern. """ - def __call__(data, sw1, sw2): + def __call__(self, data, sw1, sw2): """Called to test data, sw1 and sw2 for error. @param data: apdu response data diff --git a/smartcard/util/__init__.py b/smartcard/util/__init__.py index 2a8233a8..68fe0ba6 100644 --- a/smartcard/util/__init__.py +++ b/smartcard/util/__init__.py @@ -99,7 +99,7 @@ def toBytes(bytestring): """ import struct import re - packedstring = ''.join(re.split('\W+', bytestring)) + packedstring = ''.join(re.split(r'\W+', bytestring)) try: return reduce(lambda x, y: x + [int(y, 16)], struct.unpack('2s' * (len(packedstring) / 2), @@ -204,9 +204,6 @@ def toHexString(bytes=[], format=0): from string import rstrip - for byte in tuple(bytes): - pass - if type(bytes) is not list: raise TypeError('not a list of bytes') diff --git a/smartcard/wx/APDUHexValidator.py b/smartcard/wx/APDUHexValidator.py index dd090ddf..4e16ceb6 100644 --- a/smartcard/wx/APDUHexValidator.py +++ b/smartcard/wx/APDUHexValidator.py @@ -48,7 +48,7 @@ def Clone(self): def Validate(self, win): tc = self.GetWindow() - val = tc.GetValue() + value = tc.GetValue() if not apduregexp.match(value): return False diff --git a/smartcard/wx/CardAndReaderTreePanel.py b/smartcard/wx/CardAndReaderTreePanel.py index 0841ec1d..8106ef9f 100644 --- a/smartcard/wx/CardAndReaderTreePanel.py +++ b/smartcard/wx/CardAndReaderTreePanel.py @@ -408,9 +408,9 @@ def __init__(self, parent, appstyle, clientpanel): def OnDestroy(self, event): """Called on panel destruction.""" # deregister observers - if hasattr(self, cardmonitor): + if hasattr(self, 'cardmonitor'): self.cardmonitor.deleteObserver(self.cardtreecardobserver) - if hasattr(self, readermonitor): + if hasattr(self, 'readermonitor'): self.readermonitor.deleteObserver(self.readertreereaderobserver) self.cardmonitor.deleteObserver(self.readertreecardobserver) event.Skip() diff --git a/smartcard/wx/ReaderToolbar.py b/smartcard/wx/ReaderToolbar.py index 946dfab0..fd353be8 100644 --- a/smartcard/wx/ReaderToolbar.py +++ b/smartcard/wx/ReaderToolbar.py @@ -77,12 +77,12 @@ def __init__(self, parent): bmpReader = wx.Bitmap(ICO_READER, wx.BITMAP_TYPE_ICO) else: bmpReader = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) if None != ICO_SMARTCARD: bmpCard = wx.Bitmap(ICO_SMARTCARD, wx.BITMAP_TYPE_ICO) else: bmpCard = wx.ArtProvider_GetBitmap( - wx.ART_HELP_BOOK, wx.ART_OTHER, isz) + wx.ART_HELP_BOOK, wx.ART_OTHER, tsize) self.readercombobox = ReaderComboBox(self) # create and add controls diff --git a/smartcard/wx/SimpleSCardAppFrame.py b/smartcard/wx/SimpleSCardAppFrame.py index cd5166cc..193c8a56 100644 --- a/smartcard/wx/SimpleSCardAppFrame.py +++ b/smartcard/wx/SimpleSCardAppFrame.py @@ -26,10 +26,11 @@ import os.path import wx + import smartcard.wx -import APDUTracerPanel -import CardAndReaderTreePanel -import ReaderToolbar +from smartcard.wx import APDUTracerPanel +from smartcard.wx import CardAndReaderTreePanel +from smartcard.wx import ReaderToolbar import smartcard from smartcard.wx.SimpleSCardAppEventObserver import \