Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to staticmethod decorators #204

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)