From b5946695e98ccaf7cc0ec7396c7b0482d09bf07b Mon Sep 17 00:00:00 2001 From: Nigel Metheringham Date: Mon, 14 Feb 2022 16:25:48 +0000 Subject: [PATCH] fix: ensure session_id is put into received objects --- broadworks_ocip/api.py | 8 ++++++-- broadworks_ocip/base.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/broadworks_ocip/api.py b/broadworks_ocip/api.py index b57683f..b70614d 100644 --- a/broadworks_ocip/api.py +++ b/broadworks_ocip/api.py @@ -10,6 +10,7 @@ import socket import sys import uuid +from typing import Any from typing import Dict from typing import Type @@ -272,15 +273,18 @@ def decode_xml(self, xml) -> broadworks_ocip.base.OCICommand: Class instance object """ root = etree.fromstring(xml) + extras: Dict[str, Any] = {} if root.tag != "{C}BroadsoftDocument": raise ValueError self.logger.debug("Decoding BroadsoftDocument") for element in root: - if element.tag == "command": + if element.tag == "sessionId": + extras["session_id"] = element.text + elif element.tag == "command": command = element.get("{http://www.w3.org/2001/XMLSchema-instance}type") self.logger.debug(f"Decoding command {command}") cls = self._despatch_table[command] - result = cls.build_from_etree_(element) + result = cls.build_from_etree_(element, extras) self.logger.info(f"<<< {result.type_}") result.post_xml_decode_() return result diff --git a/broadworks_ocip/base.py b/broadworks_ocip/base.py index e8b0041..0f2d2bc 100644 --- a/broadworks_ocip/base.py +++ b/broadworks_ocip/base.py @@ -315,7 +315,7 @@ def build_from_node_(cls, elem: ElementInfo, node: etree._Element) -> Any: return None @classmethod - def build_from_etree_(cls, element: etree._Element): + def build_from_etree_(cls, element: etree._Element, extras: Dict[str, Any] = {}): """ Create an OciType based instance from an XML etree element @@ -325,7 +325,7 @@ def build_from_etree_(cls, element: etree._Element): Returns: results: Object instance for this class """ - initialiser = {} + initialiser = extras.copy() for elem in cls._elements(): if elem.is_array: result = []