Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function Client.wsdl.dump() was modified to allow to put the print output to a file or other stream. #1213

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/zeep/wsdl/wsdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging
import operator
import sys
import os
import typing
import warnings
Expand Down Expand Up @@ -106,43 +107,43 @@ def load(self, location):
def __repr__(self):
return "<WSDL(location=%r)>" % self.location

def dump(self):
print("")
print("Prefixes:")
def dump(self, output=sys.stdout):
print("", file=output)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use local redefinition of print to avoid to set multiple file=output:

from functools import partial

print = partial(print, file=output)

print("")
print("Prefixes:")

and file (as used in print) is better than output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frost-nzcr4 I will performe the changes and submit another pull request.

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
Expand Down