From 4eb6d5c00b52638b172137fe2b58da6ebaa0ed23 Mon Sep 17 00:00:00 2001 From: renatodamas Date: Fri, 16 Apr 2021 15:21:06 -0300 Subject: [PATCH 1/2] The function Client.wsdl.dump() was modified to allow to put the print output to a file or other stream. To the interface of the function was add a default parameter output=sys.stdout that keeps the current usability and permits flexility to change the output. --- src/zeep/wsdl/wsdl.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/zeep/wsdl/wsdl.py b/src/zeep/wsdl/wsdl.py index bb87664e9..a88d01be5 100644 --- a/src/zeep/wsdl/wsdl.py +++ b/src/zeep/wsdl/wsdl.py @@ -7,6 +7,7 @@ import logging import operator +import sys import os import typing import warnings @@ -106,43 +107,43 @@ def load(self, location): def __repr__(self): return "" % self.location - def dump(self): - print("") - print("Prefixes:") + def dump(self, output=sys.stdout): + print("", file=output) + print("Prefixes:", file=output) for prefix, namespace in self.types.prefix_map.items(): - print(" " * 4, "%s: %s" % (prefix, namespace)) + print(" " * 4, "%s: %s" % (prefix, namespace), file=output) - print("") - print("Global elements:") + print("", file=output) + print("Global elements:", file=output) for elm_obj in sorted(self.types.elements, key=lambda k: k.qname): value = elm_obj.signature(schema=self.types) - print(" " * 4, value) + print(" " * 4, value, file=output) - print("") - print("Global types:") + print("", file=output) + print("Global types:", file=output) for type_obj in sorted(self.types.types, key=lambda k: k.qname or ""): value = type_obj.signature(schema=self.types) - print(" " * 4, value) + print(" " * 4, value, file=output) - print("") - print("Bindings:") + print("", file=output) + print("Bindings:", file=output) for binding_obj in sorted(self.bindings.values(), key=lambda k: str(k)): - print(" " * 4, str(binding_obj)) + print(" " * 4, str(binding_obj), file=output) - print("") + print("", file=output) for service in self.services.values(): - print(str(service)) + print(str(service), file=output) for port in service.ports.values(): - print(" " * 4, str(port)) - print(" " * 8, "Operations:") + print(" " * 4, str(port), file=output) + print(" " * 8, "Operations:", file=output) operations = sorted( port.binding._operations.values(), key=operator.attrgetter("name") ) for operation in operations: - print("%s%s" % (" " * 12, str(operation))) - print("") + print("%s%s" % (" " * 12, str(operation)), file=output) + print("", file=output) def _get_xml_document(self, location: typing.IO) -> etree._Element: """Load the XML content from the given location and return an From 1ebe15fd0359ad3b83801cc6ed3a8ad1c3d01aeb Mon Sep 17 00:00:00 2001 From: renatodamas Date: Thu, 16 Jun 2022 20:55:01 -0300 Subject: [PATCH 2/2] Implement suggestion of @frost-nzcr4 on PR #1213 comments. Close #1212 --- src/zeep/wsdl/wsdl.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/zeep/wsdl/wsdl.py b/src/zeep/wsdl/wsdl.py index a88d01be5..d37b72202 100644 --- a/src/zeep/wsdl/wsdl.py +++ b/src/zeep/wsdl/wsdl.py @@ -12,6 +12,7 @@ import typing import warnings from collections import OrderedDict +from functools import partial from lxml import etree @@ -108,42 +109,43 @@ def __repr__(self): return "" % self.location def dump(self, output=sys.stdout): - print("", file=output) - print("Prefixes:", file=output) + print = partial(print, file=output) + print("") + print("Prefixes:") for prefix, namespace in self.types.prefix_map.items(): - print(" " * 4, "%s: %s" % (prefix, namespace), file=output) + print(" " * 4, "%s: %s" % (prefix, namespace)) - print("", file=output) - print("Global elements:", file=output) + print("") + print("Global elements:") for elm_obj in sorted(self.types.elements, key=lambda k: k.qname): value = elm_obj.signature(schema=self.types) - print(" " * 4, value, file=output) + print(" " * 4, value) - print("", file=output) - print("Global types:", file=output) + print("") + print("Global types:") for type_obj in sorted(self.types.types, key=lambda k: k.qname or ""): value = type_obj.signature(schema=self.types) - print(" " * 4, value, file=output) + print(" " * 4, value) - print("", file=output) - print("Bindings:", file=output) + print("") + print("Bindings:") for binding_obj in sorted(self.bindings.values(), key=lambda k: str(k)): - print(" " * 4, str(binding_obj), file=output) + print(" " * 4, str(binding_obj)) - print("", file=output) + print("") for service in self.services.values(): - print(str(service), file=output) + print(str(service)) for port in service.ports.values(): - print(" " * 4, str(port), file=output) - print(" " * 8, "Operations:", file=output) + print(" " * 4, str(port)) + print(" " * 8, "Operations:") operations = sorted( port.binding._operations.values(), key=operator.attrgetter("name") ) for operation in operations: - print("%s%s" % (" " * 12, str(operation)), file=output) - print("", file=output) + print("%s%s" % (" " * 12, str(operation))) + print("") def _get_xml_document(self, location: typing.IO) -> etree._Element: """Load the XML content from the given location and return an