laforge has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/37531?usp=email )
Change subject: pySim.apdu: Refactor cmd_to_dict() method
......................................................................
pySim.apdu: Refactor cmd_to_dict() method
Let's factor out the "automatic processing using _tlv / _construct" as a
separate method. This way we enable a derived class to first call that
automatic processing method, and then amend its output in a second step.
Change-Id: I1f066c0f1502020c88d99026c25bf2e283c3b4f5
---
M pySim/apdu/__init__.py
1 file changed, 32 insertions(+), 15 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/31/37531/1
diff --git a/pySim/apdu/__init__.py b/pySim/apdu/__init__.py
index 02ccbad..6613e91 100644
--- a/pySim/apdu/__init__.py
+++ b/pySim/apdu/__init__.py
@@ -292,22 +292,26 @@
if callable(method):
return method()
else:
- r = {}
- method = getattr(self, '_decode_p1p2', None)
- if callable(method):
- r = self._decode_p1p2()
+ return self._cmd_to_dict()
+
+ def _cmd_to_dict(self) -> Dict:
+ """back-end function performing automatic decoding using
_construct / _tlv."""
+ r = {}
+ method = getattr(self, '_decode_p1p2', None)
+ if callable(method):
+ r = self._decode_p1p2()
+ else:
+ r['p1'] = parse_construct(self._construct_p1, self.p1.to_bytes(1,
'big'))
+ r['p2'] = parse_construct(self._construct_p2, self.p2.to_bytes(1,
'big'))
+ r['p3'] = self.p3
+ if self.cmd_data:
+ if self._tlv:
+ ie = self._tlv()
+ ie.from_tlv(self.cmd_data)
+ r['body'] = ie.to_dict()
else:
- r['p1'] = parse_construct(self._construct_p1, self.p1.to_bytes(1,
'big'))
- r['p2'] = parse_construct(self._construct_p2, self.p2.to_bytes(1,
'big'))
- r['p3'] = self.p3
- if self.cmd_data:
- if self._tlv:
- ie = self._tlv()
- ie.from_tlv(self.cmd_data)
- r['body'] = ie.to_dict()
- else:
- r['body'] = parse_construct(self._construct, self.cmd_data)
- return r
+ r['body'] = parse_construct(self._construct, self.cmd_data)
+ return r
def rsp_to_dict(self) -> Dict:
"""Convert the Response part of the APDU to a
dict."""
--
To view, visit
https://gerrit.osmocom.org/c/pysim/+/37531?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I1f066c0f1502020c88d99026c25bf2e283c3b4f5
Gerrit-Change-Number: 37531
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange