Skip to content

Commit

Permalink
Migrate to staticmethod decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtmckee authored and LudovicRousseau committed Oct 3, 2024
1 parent d276747 commit 0f335b3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/smartcard/CardService.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ def __del__(self):
"""Destructor. Disconnect card and destroy card service resources."""
self.connection.disconnect()

@staticmethod
def supports(cardname):
pass

supports = staticmethod(supports)


if __name__ == "__main__":
"""Small sample illustrating the use of CardService."""
Expand Down
3 changes: 1 addition & 2 deletions src/smartcard/PassThruCardService.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ def __init__(self, connection, cardname=None):
"""
CardService.CardService.__init__(self, connection, cardname)

@staticmethod
def supports(cardname):
"""Returns True if the cardname is supported by the card service.
The PassThruCardService supports all cardnames and always
returns True."""
return True

supports = staticmethod(supports)


if __name__ == "__main__":
"""Small sample illustrating the use of CardService."""
Expand Down
3 changes: 1 addition & 2 deletions src/smartcard/pcsc/PCSCContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __getattr__(self, name):
if self.instance:
return getattr(self.instance, name)

@staticmethod
def renewContext():
PCSCContext.mutex.acquire()
try:
Expand All @@ -72,5 +73,3 @@ def renewContext():
PCSCContext.mutex.release()

return PCSCContext.instance.getContext()

renewContext = staticmethod(renewContext)
7 changes: 2 additions & 5 deletions src/smartcard/pcsc/PCSCReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ def createConnection(self):
return CardConnectionDecorator(PCSCCardConnection(self.name))

class Factory:

@staticmethod
def create(readername):
return PCSCReader(readername)

create = staticmethod(create)

@staticmethod
def readers(groups=[]):
creaders = []
hcontext = PCSCContext().getContext()
Expand All @@ -119,8 +118,6 @@ def readers(groups=[]):
creaders.append(PCSCReader.Factory.create(reader))
return creaders

readers = staticmethod(readers)


if __name__ == "__main__":
from smartcard.util import *
Expand Down
6 changes: 2 additions & 4 deletions src/smartcard/reader/ReaderFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ReaderFactory:
factorymethods = [PCSCReader.readers]

# A Template Method:
@staticmethod
def createReader(clazz, readername):
"""Static method to create a reader from a reader clazz.
Expand All @@ -51,12 +52,9 @@ def createReader(clazz, readername):
ReaderFactory.factories[clazz] = get_class(clazz).Factory()
return ReaderFactory.factories[clazz].create(readername)

createReader = staticmethod(createReader)

@staticmethod
def readers(groups=[]):
zreaders = []
for fm in ReaderFactory.factorymethods:
zreaders += fm(groups)
return zreaders

readers = staticmethod(readers)

0 comments on commit 0f335b3

Please sign in to comment.