laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33659 )
Change subject: pySim/transport: Use newly-defined ResTuple type ...................................................................... pySim/transport: Use newly-defined ResTuple type Let's use the newly-added ResTuple type annotation rather than open-coding it everywhere. Change-Id: I122589e8aec4bf66dc2e86d7602ebecb771dcb93 --- M pySim/transport/__init__.py M pySim/transport/calypso.py M pySim/transport/modem_atcmd.py M pySim/transport/pcsc.py M pySim/transport/serial.py 5 files changed, 30 insertions(+), 18 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/33659/1 diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index a16fdb3..c8079f6 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -10,12 +10,12 @@ from pySim.exceptions import * from pySim.construct import filter_dict -from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr, SwHexstr, SwMatchstr +from pySim.utils import sw_match, b2h, h2b, i2h, Hexstr, SwHexstr, SwMatchstr, ResTuple from pySim.cat import ProactiveCommand, CommandDetails, DeviceIdentities, Result # # Copyright (C) 2009-2010 Sylvain Munaut <[email protected]> -# Copyright (C) 2021-2022 Harald Welte <[email protected]> +# Copyright (C) 2021-2023 Harald Welte <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -68,7 +68,7 @@ self.proactive_handler = proactive_handler @abc.abstractmethod - def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, Hexstr]: + def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple: """Implementation specific method for sending the PDU.""" def set_sw_interpreter(self, interp): @@ -99,7 +99,7 @@ """Resets the card (power down/up) """ - def send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]: + def send_apdu_raw(self, pdu: Hexstr) -> ResTuple: """Sends an APDU with minimal processing Args: @@ -116,7 +116,7 @@ self.apdu_tracer.trace_response(pdu, sw, data) return (data, sw) - def send_apdu(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]: + def send_apdu(self, pdu: Hexstr) -> ResTuple: """Sends an APDU and auto fetch response data Args: @@ -145,7 +145,7 @@ return data, sw - def send_apdu_checksw(self, pdu: Hexstr, sw: SwMatchstr = "9000") -> Tuple[Hexstr, SwHexstr]: + def send_apdu_checksw(self, pdu: Hexstr, sw: SwMatchstr = "9000") -> ResTuple: """Sends an APDU and check returned SW Args: diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py index 4244b23..34fc646 100644 --- a/pySim/transport/calypso.py +++ b/pySim/transport/calypso.py @@ -21,11 +21,11 @@ import socket import os -from typing import Optional, Tuple +from typing import Optional from pySim.transport import LinkBase from pySim.exceptions import * -from pySim.utils import h2b, b2h, Hexstr, SwHexstr +from pySim.utils import h2b, b2h, Hexstr, ResTuple class L1CTLMessage: @@ -123,7 +123,7 @@ def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False): pass # Nothing to do really ... - def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]: + def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple: # Request FULL reset req_msg = L1CTLMessageSIM(h2b(pdu)) diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index c6f6c57..e99762d 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -20,9 +20,9 @@ import serial import time import re -from typing import Optional, Tuple +from typing import Optional -from pySim.utils import Hexstr, SwHexstr +from pySim.utils import Hexstr, ResTuple from pySim.transport import LinkBase from pySim.exceptions import * @@ -141,7 +141,7 @@ def wait_for_card(self, timeout: Optional[int] = None, newcardonly: bool = False): pass # Nothing to do really ... - def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]: + def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple: # Make sure pdu has upper case hex digits [A-F] pdu = pdu.upper() diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index 8e49716..d156dca 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -17,7 +17,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -from Typing import Optional, Tuple +from Typing import Optional from smartcard.CardConnection import CardConnection from smartcard.CardRequest import CardRequest @@ -26,7 +26,7 @@ from pySim.exceptions import NoCardError, ProtocolError, ReaderError from pySim.transport import LinkBase -from pySim.utils import h2i, i2h, Hexstr, SwHexstr +from pySim.utils import h2i, i2h, Hexstr, ResTuple class PcscSimLink(LinkBase): @@ -81,7 +81,7 @@ self.connect() return 1 - def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]: + def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple: apdu = h2i(pdu) diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index daf2eb8..998d1d8 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -19,11 +19,11 @@ import serial import time import os.path -from typing import Optional, Tuple +from typing import Optional from pySim.exceptions import NoCardError, ProtocolError from pySim.transport import LinkBase -from pySim.utils import h2b, b2h, Hexstr, SwHexstr +from pySim.utils import h2b, b2h, Hexstr, ResTuple class SerialSimLink(LinkBase): @@ -185,7 +185,7 @@ def _rx_byte(self): return self._sl.read() - def _send_apdu_raw(self, pdu: Hexstr) -> Tuple[Hexstr, SwHexstr]: + def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple: pdu = h2b(pdu) data_len = pdu[4] # P3 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/33659 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I122589e8aec4bf66dc2e86d7602ebecb771dcb93 Gerrit-Change-Number: 33659 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <[email protected]> Gerrit-MessageType: newchange
