<p><a href="https://gerrit.osmocom.org/c/pysim/+/23541">View Change</a></p><p>1 comment:</p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0;"><p><a href="https://gerrit.osmocom.org/c/pysim/+/23541/1/pySim/commands.py">File pySim/commands.py:</a></p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.osmocom.org/c/pysim/+/23541/1/pySim/commands.py@245">Patch Set #1, Line 245:</a> <code style="font-family:monospace,monospace">RuntimeError('Failed to change chv_no 0x%02X with code 0x%s, %i tries left.' % (chv_no, b2h(pin_code).upper(), int(sw[3])))</code></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">I'm seeing so many repetitions of this line and the arguments, and the functions converting the arguments.  It may make sense to create a derived ChvRuntimeError class, to which you simply pass arguments without conversion, like<br>    raise ChvRuntimeError('change', chv_no, pin_code, sw)</pre><p style="white-space: pre-wrap; word-wrap: break-word;">and leaving all the conversion and string formatting to the Exception class. Looks much more structured, IMHO.</p><p style="white-space: pre-wrap; word-wrap: break-word;">Actually, all of the surrounding code (if sw_match ... elsif 9000, ...) is copy+pasted, too.  So rather than the above (or in addition to it) you can create a function that does all of this  something like </p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">def _chv_process_sw(chv_no, pin_code, sw):<br>   if sw_match(sw, '63xcx'):<br>       ....<br>   elif (sw != '9000'):<br>       raise ...<br>   return (data, sw)</pre><p style="white-space: pre-wrap; word-wrap: break-word;">And then use return _chv_process_sw(chv_no, pin_code, sw) in all of these functions.</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/23541">change 23541</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/23541"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ic89446e6bd2021095e579fb6b20458df48ba6413 </div>
<div style="display:none"> Gerrit-Change-Number: 23541 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-CC: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Comment-Date: Mon, 29 Mar 2021 20:55:45 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>
<div style="display:none"> Gerrit-Has-Labels: No </div>
<div style="display:none"> Gerrit-MessageType: comment </div>