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

LudovicRousseau / pyscard / 11323269743

14 Oct 2024 07:55AM UTC coverage: 64.919% (+0.3%) from 64.591%
11323269743

push

github

LudovicRousseau
Test and improve the synchronization code

Added
-----

* Add tests to bring `Synchronization.py` to 100% coverage
* Add type annotations to the synchronization primitives
* Add `typing_extensions` as a Python 3.9 requirement;
  this is needed to annotate that the `synchronized()` decorator
  takes a function with a certain set of parameter and return types
  and returns a function with the same parameter and return types

Changed
-------

* Make the synchronized function's `self` parameter explicit;
  this allows the `self` parameter to be type-annotated
  so the dependency on the `self.mutex` attribute is explicit
* Use the `self.mutex` lock as a context manager
* Support keyword arguments to synchronized functions

Fixed
-----

* Wrap synchronized functions correctly;
  previous behavior was to lose the function name and docstring

Removed
-------

* Remove `print()` lines that are commented out
* Remove a `bytes` instance check; method names can only be strings

100 of 466 branches covered (21.46%)

21 of 22 new or added lines in 1 file covered. (95.45%)

34 existing lines in 22 files now uncovered.

4210 of 6485 relevant lines covered (64.92%)

4.16 hits per line

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

0.0
/src/smartcard/sw/SWExceptions.py
1
"""Status Word (SW) Exceptions
2

3
This module defines the exceptions raised by status word errors or warnings.
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

28
class SWException(Exception):
×
29
    """Base class for status word exceptions.
30

31
    Status word exceptions are generated when errors and warnings are detected
32
    in the sw1 and sw2 bytes of the response apdu.
33

34
    """
35

36
    def __init__(self, data, sw1, sw2, message=""):
×
37
        self.message = message
×
UNCOV
38
        """response apdu data"""
39
        self.data = data
×
UNCOV
40
        """response apdu sw1"""
41
        self.sw1 = sw1
×
UNCOV
42
        """response apdu sw2"""
43
        self.sw2 = sw2
×
44

45
    def __str__(self):
×
46
        return repr("Status word exception: " + self.message + "!")
×
47

48

49
class WarningProcessingException(SWException):
×
50
    """Raised when a warning processing is detected from sw1, sw2.
51
    Examples of warning processing exception: sw1=62 or sw=63 (ISO7816-4)."""
52

53
    def __init__(self, data, sw1, sw2, message=""):
×
54
        SWException.__init__(self, data, sw1, sw2, "warning processing - " + message)
×
55

56

57
class ExecutionErrorException(SWException):
×
58
    """Raised when an execution error is detected from sw1, sw2.
59
    Examples of execution error: sw1=64 or sw=65 (ISO7816-4)."""
60

61
    def __init__(self, data, sw1, sw2, message=""):
×
62
        SWException.__init__(self, data, sw1, sw2, "execution error - " + message)
×
63

64

65
class SecurityRelatedException(SWException):
×
66
    """Raised when a security issue is detected from sw1, sw2.
67
    Examples of security issue: sw1=66 (ISO7816-4)."""
68

69
    def __init__(self, data, sw1, sw2, message=""):
×
70
        SWException.__init__(self, data, sw1, sw2, "security issue - " + message)
×
71

72

73
class CheckingErrorException(SWException):
×
74
    """Raised when a checking error is detected from sw1, sw2.
75
    Examples of checking error: sw1=67 to 6F (ISO781604)."""
76

77
    def __init__(self, data, sw1, sw2, message=""):
×
78
        SWException.__init__(self, data, sw1, sw2, "checking error - " + message)
×
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

© 2025 Coveralls, Inc