From 9d7caef810813ad4d747e71f6e85f75d5a06bfe0 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 22 Nov 2024 21:02:35 +0100 Subject: [PATCH] esim.saip.FsProfileElement: Add create_file() method So far we mainly created File() instances when parsing existing profiles. However, sometimes we want to programmatically create Files and we should offer a convenience helper to do so, rather than asking API users to worry about low-level details. Change-Id: I0817819af40f3d0dc0c3d2b91039c5748dd31ee2 --- pySim/esim/saip/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pySim/esim/saip/__init__.py b/pySim/esim/saip/__init__.py index 94df4532..2552c8e5 100644 --- a/pySim/esim/saip/__init__.py +++ b/pySim/esim/saip/__init__.py @@ -643,6 +643,14 @@ class FsProfileElement(ProfileElement): file = File(k, v, template.files_by_pename.get(k, None)) self.add_file(file) + def create_file(self, pename: str) -> File: + """Programatically create a file by its PE-Name.""" + template = templates.ProfileTemplateRegistry.get_by_oid(self.templateID) + file = File(pename, None, template.files_by_pename.get(pename, None)) + self.add_file(file) + self.decoded[pename] = [] + return file + def _post_decode(self): # not entirely sure about doing this this automatism self.pe2files()