From 97dfcaa9c72447d04390f48432baa7ba939bc96f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 16 Aug 2024 17:20:49 +0200 Subject: [PATCH] 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 --- pySim/filesystem.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pySim/filesystem.py b/pySim/filesystem.py index 624619b0..805983be 100644 --- a/pySim/filesystem.py +++ b/pySim/filesystem.py @@ -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