neels has posted comments on this change by neels. (
https://gerrit.osmocom.org/c/python/pyosmocom/+/39600?usp=email )
Change subject: utils: add unrpad()
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
It turns out there *is* a surprising difference!
The rstrip() version causes this error in pySim.esim.saip, can you guess why:
File
"/home/moi/s/esim/sysmo_esim_mgr/venv/lib/python3.13/site-packages/pySim/esim/saip/personalization.py",
line 560, in decimal_hex_to_str
return val.to_bytes().decode('ascii')
^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'to_bytes'
I stared for a while until I realized this code is using hexstr.to_bytes(). (hexstr is
also here from pyosmocom.)
hexstr has a magic trick:
def __getitem__(self, val) -> 'hexstr':
# make sure slicing a hexstr will return a hexstr
return hexstr(super().__getitem__(val))
so with the unrpad() implementation from this patch, a hexstr stays a hexstr.
When using val.rstrip('f'), the hexstr becomes a str, and then there is no
to_bytes() function.
For now I solved it in the calling code as a local function
def unrpad(s: hexstr, c='f') -> hexstr:
return hexstr(s.rstrip(c))
but something like this next to rpad() now seems useful again... what do you think?
--
To view, visit
https://gerrit.osmocom.org/c/python/pyosmocom/+/39600?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: I48c23390926f8c9412624edb4481e7f4cd3f4b46
Gerrit-Change-Number: 39600
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Sat, 01 Mar 2025 01:46:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No