laforge has uploaded this change for review.

View Change

pylint: transport/pcsc.py

pySim/transport/pcsc.py:26:0: W0404: Reimport 'CardConnectionException' (imported line 26) (reimported)
pySim/transport/pcsc.py:60:4: R1711: Useless return at end of function or method (useless-return)
pySim/transport/pcsc.py:74:12: W0707: Consider explicitly re-raising using 'except CardRequestTimeoutException as exc' and 'raise NoCardError() from exc' (raise-missing-from)
pySim/transport/pcsc.py:86:12: W0707: Consider explicitly re-raising using 'except CardConnectionException as exc' and 'raise ProtocolError() from exc' (raise-missing-from)
pySim/transport/pcsc.py:88:12: W0707: Consider explicitly re-raising using 'except NoCardException as exc' and 'raise NoCardError() from exc' (raise-missing-from)
pySim/transport/pcsc.py:22:0: W0611: Unused Union imported from typing (unused-import)

Change-Id: I0ef440d8825300d6efb8959a67da095ab5623f9c
---
M pySim/transport/pcsc.py
1 file changed, 24 insertions(+), 9 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/22/35822/1
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index a6714d5..47976ae 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -19,11 +19,11 @@

import argparse
import re
-from typing import Optional, Union
+from typing import Optional

from smartcard.CardConnection import CardConnection
from smartcard.CardRequest import CardRequest
-from smartcard.Exceptions import NoCardException, CardRequestTimeoutException, CardConnectionException, CardConnectionException
+from smartcard.Exceptions import NoCardException, CardRequestTimeoutException, CardConnectionException
from smartcard.System import readers

from pySim.exceptions import NoCardError, ProtocolError, ReaderError
@@ -63,15 +63,14 @@
self._con.disconnect()
except:
pass
- return

def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False):
cr = CardRequest(readers=[self._reader],
timeout=timeout, newcardonly=newcardonly)
try:
cr.waitforcard()
- except CardRequestTimeoutException:
- raise NoCardError()
+ except CardRequestTimeoutException as exc:
+ raise NoCardError() from exc
self.connect()

def connect(self):
@@ -82,10 +81,10 @@

# Explicitly select T=0 communication protocol
self._con.connect(CardConnection.T0_protocol)
- except CardConnectionException:
- raise ProtocolError()
- except NoCardException:
- raise NoCardError()
+ except CardConnectionException as exc:
+ raise ProtocolError() from exc
+ except NoCardException as exc:
+ raise NoCardError() from exc

def get_atr(self) -> Hexstr:
return self._con.getATR()

To view, visit change 35822. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I0ef440d8825300d6efb8959a67da095ab5623f9c
Gerrit-Change-Number: 35822
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange