Skip to content

Commit

Permalink
fix: ensure session_id is put into received objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelm committed Feb 14, 2022
1 parent 6797801 commit b594669
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions broadworks_ocip/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import socket
import sys
import uuid
from typing import Any
from typing import Dict
from typing import Type

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions broadworks_ocip/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand Down

0 comments on commit b594669

Please sign in to comment.