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

LudovicRousseau / pyscard / 16621389771

30 Jul 2025 11:33AM UTC coverage: 66.181% (+0.1%) from 66.048%
16621389771

push

github

LudovicRousseau
Release 2.3.0

Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>

108 of 485 branches covered (22.27%)

4452 of 6727 relevant lines covered (66.18%)

4.77 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

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

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

57
    @staticmethod
20✔
58
    def readers(groups=None):
20✔
59
        """Return the list of readers"""
60
        if groups is None:
×
61
            groups = []
×
62
        zreaders = []
×
63
        for fm in ReaderFactory.factorymethods:
×
64
            zreaders += fm(groups)
×
65
        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