def __init__(self, transport=None, loader=None): self.transport = transport or RequestsTransport() self.loader = loader or ResourceLoader(self.transport) self.types = QNameRegistry() self.messages = QNameRegistry() self.port_types = QNameRegistry() self.bindings = QNameRegistry() self.services = QNameRegistry()
class Context(object): def __init__(self, transport=None, loader=None): self.transport = transport or RequestsTransport() self.loader = loader or ResourceLoader(self.transport) self.types = QNameRegistry() self.messages = QNameRegistry() self.port_types = QNameRegistry() self.bindings = QNameRegistry() self.services = QNameRegistry() def read_wsdl_from_url(self, url): return self.read_wsdl_tree(self.loader.load_xml(url)) def read_wsdl_tree(self, wsdl_tree): reader = WSDLReader(self, wsdl_tree) reader.parse() def resolve_type(self, qname): type = self.types.get(qname) or BASIC_TYPES.get(qname) if type: return type else: raise KeyError("Type '%s' is not known to this context." % qname) def _dump(self, dumper, with_service=False): for kind, source in ( ("types", self.types), ("messages", self.messages), ("port types", self.port_types), ("bindings", self.bindings), ("services", self.services), ): dumper.enter("Known %s:" % kind) for qname, obj in sorted(source.iteritems()): dumper.write(qname) odump = getattr(obj, "_dump", None) if odump: with dumper: odump(dumper) dumper.exit() if with_service: dumper.enter("Service Selector description:") self.service._dump(dumper) dumper.exit() def dump(self, stream, with_service=False): return self._dump(Dumper(stream), with_service=with_service) def _get_service(self): return ServiceSelector(self) service = property(_get_service) def dispatch(self, port, operation, message): req = port.envelope_message(message, operation) resp = self.transport.dispatch(req) if operation.output: resp = port.unenvelope_message(resp.data, operation) return resp else: return