def test_find_message(self): res = Message(name="foo") obj = Definitions(messages=[res]) self.assertEqual(res, obj.find_message("foo")) with self.assertRaises(DefinitionsValueError) as cm: obj.find_message("nope") self.assertEqual("Unknown Message name: nope", str(cm.exception))
def map_binding_message_parts(cls, definitions: Definitions, message: str, extended: AnyElement, ns_map: Dict) -> Iterator[Attr]: """Find a Message instance and map its parts to attributes according to the the extensible element..""" parts = [] if "part" in extended.attributes: parts.append(extended.attributes["part"]) elif "parts" in extended.attributes: parts.extend(extended.attributes["parts"].split()) if "message" in extended.attributes: message_name = local_name(extended.attributes["message"]) else: message_name = text.suffix(message) definition_message = definitions.find_message(message_name) message_parts = definition_message.parts if parts: message_parts = [ part for part in message_parts if part.name in parts ] yield from cls.build_parts_attributes(message_parts, ns_map)
def build_envelope_fault( cls, definitions: Definitions, port_type_operation: PortTypeOperation, target: Class, ): """Build inner fault class with default fields.""" ns_map: Dict = {} body = next(inner for inner in target.inner if inner.name == "Body") fault_class = cls.build_inner_class(body, "Fault", target.namespace) detail_attrs: List[Attr] = [] for fault in port_type_operation.faults: message = definitions.find_message(text.suffix(fault.message)) detail_attrs.extend( cls.build_parts_attributes(message.parts, ns_map)) default_fields = ["faultcode", "faultstring", "faultactor"] if detail_attrs: detail = cls.build_inner_class(fault_class, "detail", namespace="") detail.attrs.extend(detail_attrs) else: default_fields.append("detail") collections.prepend( fault_class.attrs, *[ cls.build_attr(f, str(DataType.STRING), native=True, namespace="") for f in default_fields ], )
def build_message_class(cls, definitions: Definitions, port_type_message: PortTypeMessage) -> Class: """Step 6.2: Build the input/output message class of an rpc style operation.""" message_name = text.suffix(port_type_message.message) definition_message = definitions.find_message(message_name) ns_map = definition_message.ns_map.copy() return Class( qname=build_qname(definitions.target_namespace, message_name), status=Status.PROCESSED, tag=Tag.ELEMENT, module=definitions.module, ns_map=ns_map, attrs=list( cls.build_parts_attributes(definition_message.parts, ns_map)), )