From 406f22c40b97ad8b978dc00b37c9c43703c3e449 Mon Sep 17 00:00:00 2001 From: Maurice Mengel Date: Sat, 10 Feb 2024 10:23:37 +0100 Subject: [PATCH] varia --- src/mpapi/data/xsd/search_1_6.xsd | 2 +- src/mpapi/data/xsd/search_1_8.xsd | 1 + src/mpapi/helper.py | 4 +++- src/mpapi/mink.py | 6 +++++- src/mpapi/module.py | 18 ++++++++++++------ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/mpapi/data/xsd/search_1_6.xsd b/src/mpapi/data/xsd/search_1_6.xsd index 5eda77c..7bf51b2 100644 --- a/src/mpapi/data/xsd/search_1_6.xsd +++ b/src/mpapi/data/xsd/search_1_6.xsd @@ -399,7 +399,7 @@ --> - + diff --git a/src/mpapi/data/xsd/search_1_8.xsd b/src/mpapi/data/xsd/search_1_8.xsd index 2340a65..801752e 100644 --- a/src/mpapi/data/xsd/search_1_8.xsd +++ b/src/mpapi/data/xsd/search_1_8.xsd @@ -443,6 +443,7 @@ the EqualsField element with fieldPath: "Surname". 3.9.2023 __orgUnit added by Maurice + 28.1.2024 __attachment added by Maurice. Cant get it to work --> diff --git a/src/mpapi/helper.py b/src/mpapi/helper.py index c608988..7c89b61 100644 --- a/src/mpapi/helper.py +++ b/src/mpapi/helper.py @@ -34,7 +34,9 @@ def toFile(self, *, path: Union[Path, str]) -> None: self._write(path=str(path), doc=doc) except: # print("WARNING: Trouble writing file") - doc = etree.ElementTree(self.etree) + doc = etree.ElementTree( + self.etree, + ) self._write(path=str(path), doc=doc) def toET(self) -> ET: diff --git a/src/mpapi/mink.py b/src/mpapi/mink.py index fd89840..d7c38bd 100644 --- a/src/mpapi/mink.py +++ b/src/mpapi/mink.py @@ -267,7 +267,11 @@ def getPack(self, args: list) -> None: def join(self, args: list) -> Path: Type = args[0] Id = args[1] - label = args[2] + try: + label = args[2] + except: + label = "nolabel" + try: since = args[4] except: diff --git a/src/mpapi/module.py b/src/mpapi/module.py index 47845cb..6174a05 100644 --- a/src/mpapi/module.py +++ b/src/mpapi/module.py @@ -521,8 +521,7 @@ def filter(self, *, xpath: str, mtype: str = "Object") -> Self: For an xpath that returns a list of moduleItems, return a new Module object with only those items. Note: You need to set the mtype manually. """ - moduleItemL = self.xpath(xpath) - ET = etree.XML( + newET = etree.XML( f""" @@ -533,14 +532,21 @@ def filter(self, *, xpath: str, mtype: str = "Object") -> Self: parser=parser, ) - moduleN: Any = ET.xpath("/m:application/m:modules/m:module", namespaces=NSMAP)[ - 0 - ] + moduleN: Any = newET.xpath( + f"/m:application/m:modules/m:module", namespaces=NSMAP + )[0] + moduleItemL = self.xpath(xpath) + print(f"FOUND ITEMS: {len(moduleItemL)}") [moduleN.append(moduleItemN) for moduleItemN in moduleItemL] - m = Module(tree=ET) + m = Module(tree=newET) m.updateTotalSize() return m + def filter2(self, *, xpath: str) -> Self: + """Version of filter that uses the first mtype from orignal module""" + mtype = self.extract_mtypes()[0] + return self.filter(xpath=xpath, mtype=mtype) + def module(self, *, name: str) -> ET: """ Return module element with that name or make a new one if it