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

LudovicRousseau / pyscard / 14132208658

28 Mar 2025 03:17PM UTC coverage: 66.175% (+0.05%) from 66.13%
14132208658

push

github

LudovicRousseau
Remove obsolete issue template

103 of 480 branches covered (21.46%)

4441 of 6711 relevant lines covered (66.17%)

4.63 hits per line

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

100.0
/src/smartcard/Exceptions.py
1
"""Smartcard module exceptions.
2

3
This module defines the exceptions raised by the smartcard module.
4

5
__author__ = "https://www.gemalto.com/"
6

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

10
This file is part of pyscard.
11

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

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

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

27
from smartcard.scard import SCardGetErrorMessage
20✔
28

29

30
class SmartcardException(Exception):
20✔
31
    """Base class for smartcard exceptions.
32

33
    smartcard exceptions are generated by the smartcard module and
34
    shield scard (i.e. PCSC) exceptions raised by the scard module.
35

36
    """
37

38
    def __init__(self, message="", hresult=-1, *args):
20✔
39
        super().__init__(message, *args)
19✔
40
        self.hresult = int(hresult)
19✔
41

42
    def __str__(self):
20✔
43
        text = super().__str__()
19✔
44
        if self.hresult != -1:
19✔
45
            hresult = self.hresult
19✔
46
            if hresult < 0:
19✔
47
                # convert 0x-7FEFFFE3 into 0x8010001D
48
                hresult += 0x100000000
15✔
49
            text += f": {SCardGetErrorMessage(self.hresult)} (0x{hresult:08X})"
19✔
50

51
        return text
19✔
52

53

54
class CardConnectionException(SmartcardException):
20✔
55
    """Raised when a CardConnection class method fails."""
56

57
    pass
20✔
58

59

60
class CardRequestException(SmartcardException):
20✔
61
    """Raised when a CardRequest wait fails."""
62

63
    pass
20✔
64

65

66
class CardRequestTimeoutException(SmartcardException):
20✔
67
    """Raised when a CardRequest times out."""
68

69
    def __init__(self, hresult=-1, *args):
20✔
70
        SmartcardException.__init__(
19✔
71
            self, "Time-out during card request", hresult=hresult, *args
72
        )
73

74

75
class CardServiceException(SmartcardException):
20✔
76
    """Raised when a CardService class method fails."""
77

78
    pass
20✔
79

80

81
class CardServiceStoppedException(SmartcardException):
20✔
82
    """Raised when the CardService was stopped"""
83

84
    pass
20✔
85

86

87
class CardServiceNotFoundException(SmartcardException):
20✔
88
    """Raised when the CardService is not found"""
89

90
    pass
20✔
91

92

93
class InvalidATRMaskLengthException(SmartcardException):
20✔
94
    """Raised when an ATR mask does not match an ATR length."""
95

96
    def __init__(self, mask):
20✔
97
        SmartcardException.__init__(self, "Invalid ATR mask length: %s" % mask)
19✔
98

99

100
class InvalidReaderException(SmartcardException):
20✔
101
    """Raised when trying to access an invalid smartcard reader."""
102

103
    def __init__(self, readername):
20✔
104
        SmartcardException.__init__(self, "Invalid reader: %s" % readername)
19✔
105

106

107
class ListReadersException(SmartcardException):
20✔
108
    """Raised when smartcard readers cannot be listed."""
109

110
    def __init__(self, hresult):
20✔
111
        SmartcardException.__init__(self, "Failed to list readers", hresult=hresult)
19✔
112

113

114
class NoCardException(SmartcardException):
20✔
115
    """Raised when no card in is present in reader."""
116

117
    def __init__(self, message, hresult):
20✔
118
        SmartcardException.__init__(self, message, hresult=hresult)
19✔
119

120

121
class NoReadersException(SmartcardException):
20✔
122
    """Raised when the system has no smartcard reader."""
123

124
    def __init__(self, *args):
20✔
125
        SmartcardException.__init__(self, "No reader found", *args)
19✔
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