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

LudovicRousseau / pyscard / 16375184806

18 Jul 2025 04:07PM UTC coverage: 66.048% (+0.08%) from 65.964%
16375184806

push

github

LudovicRousseau
Fix pylint warning: R0401

smartcard/reader/Reader.py:1:0: R0401: Cyclic import (smartcard.pcsc.PCSCCardConnection -> smartcard.pcsc.PCSCPart10 -> smartcard.pcsc.PCSCReader) (cyclic-import)
smartcard/reader/Reader.py:1:0: R0401: Cyclic import (smartcard.pcsc.PCSCCardConnection -> smartcard.pcsc.PCSCReader) (cyclic-import)

103 of 481 branches covered (21.41%)

4445 of 6730 relevant lines covered (66.05%)

4.69 hits per line

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

0.0
/src/smartcard/ExclusiveTransmitCardConnection.py
1
"""Sample CardConnectionDecorator that provides exclusive transmit()
2

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

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

8
This file is part of pyscard.
9

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

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

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

25
import smartcard.pcsc
×
26
from smartcard.CardConnectionDecorator import CardConnectionDecorator
×
27
from smartcard.Exceptions import CardConnectionException
×
28
from smartcard.scard import (
×
29
    SCARD_LEAVE_CARD,
30
    SCARD_S_SUCCESS,
31
    SCardBeginTransaction,
32
    SCardEndTransaction,
33
    SCardGetErrorMessage,
34
)
35

36

37
class ExclusiveTransmitCardConnection(CardConnectionDecorator):
×
38
    """This decorator uses
39
    L{SCardBeginTransaction}/L{SCardEndTransaction} to preserve other
40
    processes of threads to access the card during transmit()."""
41

42
    def __init__(self, cardconnection):
×
43
        CardConnectionDecorator.__init__(self, cardconnection)
×
44

45
    def lock(self):
×
46
        """Lock card with L{SCardBeginTransaction}."""
47

48
        # pylint: disable=duplicate-code
49

50
        component = self.component
×
51
        while True:
52
            if isinstance(
×
53
                component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection
54
            ):
55
                hresult = SCardBeginTransaction(component.hcard)
×
56
                if SCARD_S_SUCCESS != hresult:
×
57
                    raise CardConnectionException(
×
58
                        "Failed to lock with SCardBeginTransaction: "
59
                        + SCardGetErrorMessage(hresult)
60
                    )
61
                break
×
62
            if hasattr(component, "component"):
×
63
                component = component.component
×
64
            else:
65
                break
×
66

67
    def unlock(self):
×
68
        """Unlock card with L{SCardEndTransaction}."""
69

70
        # pylint: disable=duplicate-code
71

72
        component = self.component
×
73
        while True:
74
            if isinstance(
×
75
                component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection
76
            ):
77
                hresult = SCardEndTransaction(component.hcard, SCARD_LEAVE_CARD)
×
78
                if SCARD_S_SUCCESS != hresult:
×
79
                    raise CardConnectionException(
×
80
                        "Failed to unlock with SCardEndTransaction: "
81
                        + SCardGetErrorMessage(hresult)
82
                    )
83
                break
×
84
            if hasattr(component, "component"):
×
85
                component = component.component
×
86
            else:
87
                break
×
88

89
    def transmit(self, command, protocol=None):
×
90
        """Gain exclusive access to card during APDU transmission for if this
91
        decorator decorates a PCSCCardConnection."""
92
        data, sw1, sw2 = CardConnectionDecorator.transmit(self, command, protocol)
×
93
        return data, sw1, sw2
×
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