pySim.filesystem: Permit Path object construction from FID integer list

we so far supported construction of the Path object from a string or
a list of strings.  Let's also add the option of constructing it from a
path consisting of a list of integer FID values.

Change-Id: Ia7e9375b3258d1fbfdc892cefba3e3bbe841c550
This commit is contained in:
Harald Welte
2024-08-16 17:20:49 +02:00
parent 022d562ae1
commit 97dfcaa9c7

View File

@@ -1481,10 +1481,12 @@ class CardModel(abc.ABC):
class Path:
"""Representation of a file-system path."""
def __init__(self, p: Union[str, List[str]]):
def __init__(self, p: Union[str, List[str], List[int]]):
# split if given as single string with slahes
if isinstance(p, str):
p = p.split('/')
elif len(p) and isinstance(p[0], int):
p = ['%04x' % x for x in p]
# make sure internal representation alwas is uppercase only
self.list = [x.upper() for x in p]
@@ -1514,7 +1516,7 @@ class Path:
def relative_to_mf(self) -> 'Path':
"""Return a path relative to MF, i.e. without initial explicit MF."""
if self.list[0] == 'MF':
if len(self.list) and self.list[0] in ['MF', '3F00']:
return Path(self.list[1:])
return self