• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LudovicRousseau / pyscard / 11367996755

16 Oct 2024 02:39PM UTC coverage: 65.542% (+0.07%) from 65.474%
11367996755

push

github

web-flow
Merge pull request #213 from kurtmckee/rm-class-loader

Remove `ClassLoader.py`

104 of 472 branches covered (22.03%)

2 of 7 new or added lines in 1 file covered. (28.57%)

11 existing lines in 5 files now uncovered.

4295 of 6553 relevant lines covered (65.54%)

4.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.86
/src/smartcard/reader/ReaderFactory.py
1
"""ReaderFactory: creates smartcard readers.
2

3
__author__ = "gemalto https://www.gemalto.com/"
4

5
Factory pattern implementation borrowed from
6
Thinking in Python, Bruce Eckel,
7
http://mindview.net/Books/TIPython
8

9
Copyright 2001-2012 gemalto
10
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
11

12
This file is part of pyscard.
13

14
pyscard is free software; you can redistribute it and/or modify
15
it under the terms of the GNU Lesser General Public License as published by
16
the Free Software Foundation; either version 2.1 of the License, or
17
(at your option) any later version.
18

19
pyscard is distributed in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
GNU Lesser General Public License for more details.
23

24
You should have received a copy of the GNU Lesser General Public License
25
along with pyscard; if not, write to the Free Software
26
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27
"""
28

29
import importlib
20✔
30

31
from smartcard.pcsc.PCSCReader import PCSCReader
20✔
32

33

34
class ReaderFactory:
20✔
35
    """Class to create readers from reader type id."""
36

37
    factories = {}
20✔
38
    factorymethods = [PCSCReader.readers]
20✔
39

40
    # A Template Method:
41
    @staticmethod
20✔
42
    def createReader(clazz: str, readername: str):
20✔
43
        """Static method to create a reader from a reader clazz.
44

45
        @param clazz:      the reader class name
46
        @param readername: the reader name
47
        """
48

NEW
49
        if clazz not in ReaderFactory.factories:
×
NEW
50
            module_name, _, class_name = clazz.rpartition(".")
×
NEW
51
            imported_module = importlib.import_module(module_name)
×
NEW
52
            imported_class = getattr(imported_module, class_name)
×
NEW
53
            ReaderFactory.factories[clazz] = imported_class.Factory()
×
54

UNCOV
55
        return ReaderFactory.factories[clazz].create(readername)
×
56

57
    @staticmethod
20✔
58
    def readers(groups=None):
20✔
59
        if groups is None:
×
60
            groups = []
×
61
        zreaders = []
×
62
        for fm in ReaderFactory.factorymethods:
×
63
            zreaders += fm(groups)
×
64
        return zreaders
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc