Skip to content

Commit

Permalink
Remove ClassLoader.py
Browse files Browse the repository at this point in the history
Removed
-------

* Remove `ClassLoader.py`.

  `importlib`, in the Python standard library, is sufficient.
  This also reduces the number of licenses in use in the repo.

* Remove a reference to `ClassLoader.py` in the pre-commit config.
  • Loading branch information
kurtmckee committed Oct 16, 2024
1 parent 042ab5f commit 4210e31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 65 deletions.
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
# you'll have an opportunity to review and stage the changes made by the
# hooks.
#
# To format the files in this repo, you can run this command (but be
# aware that pyupgrade will need to be run three times because there is
# a specific line in ClassLoader.py that pyupgrade incrementally
# updates).
# To format all files in this repo, you can run this command
# (but be aware that sometimes the command must be run multiple times
# because pyupgrade has several stepping-stone upgrades to apply).
#
# pre-commit run -a
# pre-commit run -a
# pre-commit run -a
#
# I strongly recommend enabling pre-commit.ci, which -- like coveralls
# -- will automatically run an additional action against incoming PRs.
Expand Down
51 changes: 0 additions & 51 deletions src/smartcard/ClassLoader.py

This file was deleted.

18 changes: 10 additions & 8 deletions src/smartcard/reader/ReaderFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
Thinking in Python, Bruce Eckel,
http://mindview.net/Books/TIPython
The code to instantiate the reader Factory() has
been updated to dynamically load the module with
Robert Brewer ClassLoader.py.
Copyright 2001-2012 gemalto
Author: Jean-Daniel Aussel, mailto:[email protected]
Expand All @@ -30,7 +26,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""

from smartcard.ClassLoader import get_class
import importlib

from smartcard.pcsc.PCSCReader import PCSCReader


Expand All @@ -42,14 +39,19 @@ class ReaderFactory:

# A Template Method:
@staticmethod
def createReader(clazz, readername):
def createReader(clazz: str, readername: str):
"""Static method to create a reader from a reader clazz.
@param clazz: the reader class name
@param readername: the reader name
"""
if not clazz in ReaderFactory.factories:
ReaderFactory.factories[clazz] = get_class(clazz).Factory()

if clazz not in ReaderFactory.factories:
module_name, _, class_name = clazz.rpartition(".")
imported_module = importlib.import_module(module_name)
imported_class = getattr(imported_module, class_name)
ReaderFactory.factories[clazz] = imported_class.Factory()

return ReaderFactory.factories[clazz].create(readername)

@staticmethod
Expand Down

0 comments on commit 4210e31

Please sign in to comment.