From 0cb6118451a75ad7b41d120dfdcd2b0589303f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= Date: Tue, 2 Jul 2024 11:04:45 +0000 Subject: [PATCH 1/3] drop python<=3.7 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to https://endoflife.date/python python 3.7 has been EOSed 27 Jun 2023. Filter all code over `pyupgracde --py38-plus`. Signed-off-by: Tomasz Kłoczko --- docs/conf.py | 13 +++++---- examples/code39.py | 1 - examples/eu_vat_service.py | 1 - examples/http_basic_auth.py | 2 -- examples/km_to_miles.py | 1 - examples/soap_server.py | 2 +- src/zeep/__main__.py | 2 -- src/zeep/cache.py | 2 +- src/zeep/client.py | 2 +- src/zeep/exceptions.py | 12 ++++----- src/zeep/utils.py | 2 +- src/zeep/wsdl/attachments.py | 7 ++--- src/zeep/wsdl/definitions.py | 20 +++++++------- src/zeep/wsdl/messages/multiref.py | 4 +-- src/zeep/wsdl/wsdl.py | 9 +++---- src/zeep/wsse/utils.py | 2 +- src/zeep/xsd/elements/any.py | 6 ++--- src/zeep/xsd/elements/attribute.py | 2 +- src/zeep/xsd/elements/builtins.py | 2 -- src/zeep/xsd/elements/element.py | 10 +++---- src/zeep/xsd/elements/indicators.py | 20 ++++++-------- src/zeep/xsd/schema.py | 10 +++---- src/zeep/xsd/types/any.py | 5 +--- src/zeep/xsd/types/builtins.py | 2 +- src/zeep/xsd/types/complex.py | 41 +++++++++++++---------------- src/zeep/xsd/types/unresolved.py | 4 +-- src/zeep/xsd/utils.py | 7 +++-- src/zeep/xsd/valueobjects.py | 4 +-- tests/test_client.py | 2 +- tests/test_soap_xop.py | 6 ++--- tests/test_wsdl.py | 4 +-- tests/test_wsdl_arrays.py | 8 +++--- tests/test_wsdl_messages_rpc.py | 2 +- tests/test_wsdl_soap.py | 1 - tests/test_xsd_extension.py | 2 +- tests/test_xsd_schemas.py | 2 +- tests/test_xsd_union.py | 2 +- 37 files changed, 98 insertions(+), 126 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f146b9f87..8b079feba 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Zeep documentation build configuration file, created by # sphinx-quickstart on Fri Mar 4 16:51:06 2016. @@ -52,9 +51,9 @@ master_doc = 'index' # General information about the project. -project = u'Zeep' -copyright = u'2016, Michael van Tellingen' -author = u'Michael van Tellingen' +project = 'Zeep' +copyright = '2016, Michael van Tellingen' +author = 'Michael van Tellingen' # The version info for the project you're documenting, acts as replacement for @@ -249,8 +248,8 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'Zeep.tex', u'Zeep Documentation', - u'Michael van Tellingen', 'manual'), + (master_doc, 'Zeep.tex', 'Zeep Documentation', + 'Michael van Tellingen', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -293,7 +292,7 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'Zeep', u'Zeep Documentation', + (master_doc, 'Zeep', 'Zeep Documentation', author, 'Zeep', 'One line description of project.', 'Miscellaneous'), ] diff --git a/examples/code39.py b/examples/code39.py index f1c68b425..e24810dfa 100644 --- a/examples/code39.py +++ b/examples/code39.py @@ -1,4 +1,3 @@ -from __future__ import print_function import zeep client = zeep.Client( diff --git a/examples/eu_vat_service.py b/examples/eu_vat_service.py index e751e3e00..befe5df4b 100644 --- a/examples/eu_vat_service.py +++ b/examples/eu_vat_service.py @@ -1,4 +1,3 @@ -from __future__ import print_function import zeep diff --git a/examples/http_basic_auth.py b/examples/http_basic_auth.py index 0fe84dd48..c4ccd5b56 100644 --- a/examples/http_basic_auth.py +++ b/examples/http_basic_auth.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from requests import Session from requests.auth import HTTPBasicAuth diff --git a/examples/km_to_miles.py b/examples/km_to_miles.py index d8821dfc5..b5c0ddb76 100644 --- a/examples/km_to_miles.py +++ b/examples/km_to_miles.py @@ -1,4 +1,3 @@ -from __future__ import print_function import zeep diff --git a/examples/soap_server.py b/examples/soap_server.py index 7ffdd51dd..4dfb9af06 100644 --- a/examples/soap_server.py +++ b/examples/soap_server.py @@ -21,7 +21,7 @@ class ExampleService(ServiceBase): @rpc(Unicode, _returns=Unicode) def slow_request(ctx, request_id): time.sleep(1) - return u'Request: %s' % request_id + return 'Request: %s' % request_id application = Application( services=[ExampleService], diff --git a/src/zeep/__main__.py b/src/zeep/__main__.py index 33a8ceb10..d06ee7d65 100644 --- a/src/zeep/__main__.py +++ b/src/zeep/__main__.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, print_function - import argparse import logging import logging.config diff --git a/src/zeep/cache.py b/src/zeep/cache.py index 4b7b90e76..269905fe1 100644 --- a/src/zeep/cache.py +++ b/src/zeep/cache.py @@ -79,7 +79,7 @@ def add(self, url, content): logger.debug("Caching contents of %s", url) if not isinstance(content, (str, bytes)): raise TypeError( - "a bytes-like object is required, not {}".format(type(content).__name__) + f"a bytes-like object is required, not {type(content).__name__}" ) self._cache[url] = (datetime.datetime.utcnow(), content) diff --git a/src/zeep/client.py b/src/zeep/client.py index fac7ecd79..6867fc6bc 100644 --- a/src/zeep/client.py +++ b/src/zeep/client.py @@ -32,7 +32,7 @@ def __getitem__(self, key): :rtype: zeep.xsd.ComplexType or zeep.xsd.AnySimpleType """ - return self._method("{%s}%s" % (self._ns, key)) + return self._method("{{{}}}{}".format(self._ns, key)) class Client: diff --git a/src/zeep/exceptions.py b/src/zeep/exceptions.py index 632b3b088..7bb29d501 100644 --- a/src/zeep/exceptions.py +++ b/src/zeep/exceptions.py @@ -4,7 +4,7 @@ def __init__(self, message=""): self.message = message def __repr__(self): - return "%s(%r)" % (self.__class__.__name__, self.message) + return "{}({!r})".format(self.__class__.__name__, self.message) class XMLSyntaxError(Error): @@ -22,9 +22,9 @@ def __init__(self, *args, **kwargs): def __str__(self): location = None if self.filename and self.sourceline: - location = "%s:%s" % (self.filename, self.sourceline) + location = "{}:{}".format(self.filename, self.sourceline) if location: - return "%s (%s)" % (self.message, location) + return "{} ({})".format(self.message, location) return self.message @@ -77,7 +77,7 @@ def __init__(self, *args, **kwargs): def __str__(self): if self.path: path = ".".join(str(x) for x in self.path) - return "%s (%s)" % (self.message, path) + return "{} ({})".format(self.message, path) return self.message @@ -95,7 +95,7 @@ class IncompleteOperation(Error): class DTDForbidden(Error): def __init__(self, name, sysid, pubid): - super(DTDForbidden, self).__init__() + super().__init__() self.name = name self.sysid = sysid self.pubid = pubid @@ -107,7 +107,7 @@ def __str__(self): class EntitiesForbidden(Error): def __init__(self, name, content): - super(EntitiesForbidden, self).__init__() + super().__init__() self.name = name self.content = content diff --git a/src/zeep/utils.py b/src/zeep/utils.py index e08cdcd08..35c16f190 100644 --- a/src/zeep/utils.py +++ b/src/zeep/utils.py @@ -33,7 +33,7 @@ def as_qname(value: str, nsmap, target_namespace=None) -> etree.QName: namespace = nsmap.get(prefix) if not namespace: - raise XMLParseError("No namespace defined for %r (%r)" % (prefix, value)) + raise XMLParseError("No namespace defined for {!r} ({!r})".format(prefix, value)) # Workaround for https://github.com/mvantellingen/python-zeep/issues/349 if not local: diff --git a/src/zeep/wsdl/attachments.py b/src/zeep/wsdl/attachments.py index 3e91df569..0ca22a6d0 100644 --- a/src/zeep/wsdl/attachments.py +++ b/src/zeep/wsdl/attachments.py @@ -7,10 +7,7 @@ import base64 import sys -if sys.version_info >= (3, 8): - from functools import cached_property -else: - from cached_property import cached_property +from functools import cached_property from requests.structures import CaseInsensitiveDict @@ -65,7 +62,7 @@ def __init__(self, part): self._part = part def __repr__(self): - return "" % (self.content_id, self.content_type) + return "".format(self.content_id, self.content_type) @cached_property def content(self): diff --git a/src/zeep/wsdl/definitions.py b/src/zeep/wsdl/definitions.py index deb33ea99..bc871171d 100644 --- a/src/zeep/wsdl/definitions.py +++ b/src/zeep/wsdl/definitions.py @@ -49,7 +49,7 @@ def __init__(self, name): self.parts = OrderedDict() def __repr__(self): - return "<%s(name=%r)>" % (self.__class__.__name__, self.name.text) + return "<{}(name={!r})>".format(self.__class__.__name__, self.name.text) def resolve(self, definitions): pass @@ -98,7 +98,7 @@ def __init__( self.operations = operations def __repr__(self): - return "<%s(name=%r)>" % (self.__class__.__name__, self.name.text) + return "<{}(name={!r})>".format(self.__class__.__name__, self.name.text) def resolve(self, definitions): pass @@ -151,10 +151,10 @@ def _operation_add(self, operation): self._operations[operation.name] = operation def __str__(self): - return "%s: %s" % (self.__class__.__name__, self.name.text) + return "{}: {}".format(self.__class__.__name__, self.name.text) def __repr__(self): - return "<%s(name=%r, port_type=%r)>" % ( + return "<{}(name={!r}, port_type={!r})>".format( self.__class__.__name__, self.name.text, self.port_type, @@ -167,7 +167,7 @@ def get(self, key): try: return self._operations[key] except KeyError: - raise ValueError("No such operation %r on %s" % (key, self.name)) + raise ValueError("No such operation {!r} on {}".format(key, self.name)) @classmethod def match(cls, node): @@ -204,7 +204,7 @@ def resolve(self, definitions): ) def __repr__(self): - return "<%s(name=%r, style=%r)>" % ( + return "<{}(name={!r}, style={!r})>".format( self.__class__.__name__, self.name, self.style, @@ -214,7 +214,7 @@ def __str__(self): if not self.input: return "%s(missing input message)" % (self.name) - retval = "%s(%s)" % (self.name, self.input.signature()) + retval = "{}({})".format(self.name, self.input.signature()) if self.output: retval += " -> %s" % (self.output.signature(as_output=True)) return retval @@ -267,7 +267,7 @@ def __init__(self, name, binding_name, xmlelement): self.binding_options = {} def __repr__(self): - return "<%s(name=%r, binding=%r, %r)>" % ( + return "<{}(name={!r}, binding={!r}, {!r})>".format( self.__class__.__name__, self.name, self.binding, @@ -275,7 +275,7 @@ def __repr__(self): ) def __str__(self): - return "Port: %s (%s)" % (self.name, self.binding) + return "Port: {} ({})".format(self.name, self.binding) def resolve(self, definitions): if self._resolve_context is None: @@ -312,7 +312,7 @@ def __str__(self): return "Service: %s" % self.name def __repr__(self): - return "<%s(name=%r, ports=%r)>" % ( + return "<{}(name={!r}, ports={!r})>".format( self.__class__.__name__, self.name, self.ports, diff --git a/src/zeep/wsdl/messages/multiref.py b/src/zeep/wsdl/messages/multiref.py index 76d1d46a1..14c6c7154 100644 --- a/src/zeep/wsdl/messages/multiref.py +++ b/src/zeep/wsdl/messages/multiref.py @@ -122,7 +122,7 @@ def _prefix_node(node): namespace, localname = match.groups() if namespace in reverse_nsmap: - value = "%s:%s" % (reverse_nsmap.get(namespace), localname) + value = "{}:{}".format(reverse_nsmap.get(namespace), localname) node.set(key, value) @@ -151,6 +151,6 @@ def _get_attributes(node): if prefix in nsmap: namespace = nsmap[prefix] - value = "{%s}%s" % (namespace, localname) + value = "{{{}}}{}".format(namespace, localname) result[key] = value return list(result.items()) diff --git a/src/zeep/wsdl/wsdl.py b/src/zeep/wsdl/wsdl.py index f842fa439..16d9af658 100644 --- a/src/zeep/wsdl/wsdl.py +++ b/src/zeep/wsdl/wsdl.py @@ -3,7 +3,6 @@ ~~~~~~~~~~~~~~ """ -from __future__ import print_function import logging import operator @@ -110,7 +109,7 @@ def dump(self): print("") print("Prefixes:") for prefix, namespace in self.types.prefix_map.items(): - print(" " * 4, "%s: %s" % (prefix, namespace)) + print(" " * 4, "{}: {}".format(prefix, namespace)) print("") print("Global elements:") @@ -141,7 +140,7 @@ def dump(self): ) for operation in operations: - print("%s%s" % (" " * 12, str(operation))) + print("{}{}".format(" " * 12, str(operation))) print("") def _get_xml_document(self, location: typing.IO) -> etree._Element: @@ -202,7 +201,7 @@ def _load(self, doc): self.services = self.parse_service(doc) def __repr__(self): - return "<%s(location=%r)>" % (self.__class__.__name__, self.location) + return "<{}(location={!r})>".format(self.__class__.__name__, self.location) def get(self, name, key, _processed=None): container = getattr(self, name) @@ -229,7 +228,7 @@ def get(self, name, key, _processed=None): except IndexError: pass - raise IndexError("No definition %r in %r found" % (key, name)) + raise IndexError("No definition {!r} in {!r} found".format(key, name)) def resolve_imports(self) -> None: """Resolve all root elements (types, messages, etc).""" diff --git a/src/zeep/wsse/utils.py b/src/zeep/wsse/utils.py index f9de49b7e..10df895cb 100644 --- a/src/zeep/wsse/utils.py +++ b/src/zeep/wsse/utils.py @@ -37,7 +37,7 @@ def get_timestamp(timestamp=None, zulu_timestamp=None): def get_unique_id(): - return "id-{0}".format(uuid4()) + return f"id-{uuid4()}" def ensure_id(node): diff --git a/src/zeep/xsd/elements/any.py b/src/zeep/xsd/elements/any.py index 26fb2b47b..e83372ed8 100644 --- a/src/zeep/xsd/elements/any.py +++ b/src/zeep/xsd/elements/any.py @@ -44,7 +44,7 @@ def __call__(self, any_object): return any_object def __repr__(self): - return "<%s(name=%r)>" % (self.__class__.__name__, self.name) + return "<{}(name={!r})>".format(self.__class__.__name__, self.name) def accept(self, value): return True @@ -207,8 +207,8 @@ def _validate_item(self, value, render_path): ) elif not isinstance(value, tuple(expected_types)): - type_names = ["%s.%s" % (t.__module__, t.__name__) for t in expected_types] - err_message = "Any element received object of type %r, expected %s" % ( + type_names = ["{}.{}".format(t.__module__, t.__name__) for t in expected_types] + err_message = "Any element received object of type {!r}, expected {}".format( type(value).__name__, " or ".join(type_names), ) diff --git a/src/zeep/xsd/elements/attribute.py b/src/zeep/xsd/elements/attribute.py index c9099c037..8900d93da 100644 --- a/src/zeep/xsd/elements/attribute.py +++ b/src/zeep/xsd/elements/attribute.py @@ -38,7 +38,7 @@ def validate(self, value, render_path): self.type.validate(value, required=self.required) except exceptions.ValidationError as exc: raise exceptions.ValidationError( - "The attribute %s is not valid: %s" % (self.qname, exc.message), + "The attribute {} is not valid: {}".format(self.qname, exc.message), path=render_path, ) diff --git a/src/zeep/xsd/elements/builtins.py b/src/zeep/xsd/elements/builtins.py index fa639be7b..a75c07217 100644 --- a/src/zeep/xsd/elements/builtins.py +++ b/src/zeep/xsd/elements/builtins.py @@ -1,5 +1,3 @@ -from __future__ import division - from zeep.xsd.const import xsd_ns from zeep.xsd.elements.base import Base diff --git a/src/zeep/xsd/elements/element.py b/src/zeep/xsd/elements/element.py index 1650f75a9..7135b25c2 100644 --- a/src/zeep/xsd/elements/element.py +++ b/src/zeep/xsd/elements/element.py @@ -49,9 +49,9 @@ def __init__( def __str__(self): if self.type: if self.type.is_global: - return "%s(%s)" % (self.name, self.type.qname) + return "{}({})".format(self.name, self.type.qname) else: - return "%s(%s)" % (self.name, self.type.signature()) + return "{}({})".format(self.name, self.type.signature()) return "%s()" % self.name def __call__(self, *args, **kwargs): @@ -61,7 +61,7 @@ def __call__(self, *args, **kwargs): return instance def __repr__(self): - return "<%s(name=%r, type=%r)>" % ( + return "<{}(name={!r}, type={!r})>".format( self.__class__.__name__, self.name, self.type, @@ -295,7 +295,7 @@ def _validate_item(self, value, render_path): self.type.validate(value, required=True) except exceptions.ValidationError as exc: raise exceptions.ValidationError( - "The element %s is not valid: %s" % (self.qname, exc.message), + "The element {} is not valid: {}".format(self.qname, exc.message), path=render_path, ) @@ -318,7 +318,7 @@ def signature(self, schema=None, standalone=True): value = "{%s}" % value if standalone: - value = "%s(%s)" % (self.get_prefixed_name(schema), value) + value = "{}({})".format(self.get_prefixed_name(schema), value) if self.accepts_multiple: return "%s[]" % value diff --git a/src/zeep/xsd/elements/indicators.py b/src/zeep/xsd/elements/indicators.py index f56814e61..ea641fcac 100644 --- a/src/zeep/xsd/elements/indicators.py +++ b/src/zeep/xsd/elements/indicators.py @@ -17,10 +17,7 @@ import typing from collections import OrderedDict, defaultdict, deque -if sys.version_info >= (3, 8): - from functools import cached_property as threaded_cached_property -else: - from cached_property import threaded_cached_property +from functools import cached_property as threaded_cached_property from lxml import etree @@ -42,7 +39,7 @@ class Indicator(Base): """Base class for the other indicators""" def __repr__(self): - return "<%s(%s)>" % (self.__class__.__name__, super().__repr__()) + return "<{}({})>".format(self.__class__.__name__, super().__repr__()) @property def default_value(self): @@ -267,12 +264,12 @@ def signature(self, schema=None, standalone=True): parts.append(element.signature(schema, standalone=False)) else: value = element.signature(schema, standalone=False) - parts.append("%s: %s" % (name, value)) + parts.append("{}: {}".format(name, value)) part = ", ".join(parts) if self.accepts_multiple: - return "[%s]" % (part,) + return "[{}]".format(part) return part @@ -579,11 +576,11 @@ def signature(self, schema=None, standalone=True): parts.append("{%s}" % (element.signature(schema, standalone=False))) else: parts.append( - "{%s: %s}" % (name, element.signature(schema, standalone=False)) + "{{{}: {}}}".format(name, element.signature(schema, standalone=False)) ) part = "(%s)" % " | ".join(parts) if self.accepts_multiple: - return "%s[]" % (part,) + return "{}[]".format(part) return part @@ -661,8 +658,7 @@ def __str__(self): return self.signature() def __iter__(self, *args, **kwargs): - for item in self.child: - yield item + yield from self.child @threaded_cached_property def elements(self): @@ -758,6 +754,6 @@ def resolve(self): def signature(self, schema=None, standalone=True): name = create_prefixed_name(self.qname, schema) if standalone: - return "%s(%s)" % (name, self.child.signature(schema, standalone=False)) + return "{}({})".format(name, self.child.signature(schema, standalone=False)) else: return self.child.signature(schema, standalone=False) diff --git a/src/zeep/xsd/schema.py b/src/zeep/xsd/schema.py index 8f877003d..fa5eacc8b 100644 --- a/src/zeep/xsd/schema.py +++ b/src/zeep/xsd/schema.py @@ -47,7 +47,7 @@ def __init__(self, node=None, transport=None, location=None, settings=None): def __repr__(self): main_doc = self.root_document if main_doc: - return "" % ( + return "".format( main_doc._location, main_doc._target_namespace, ) @@ -303,8 +303,7 @@ def __init__(self): self._instances = OrderedDict() def __iter__(self): - for document in self.values(): - yield document + yield from self.values() def add(self, document: "SchemaDocument") -> None: """Add a schema document""" @@ -348,8 +347,7 @@ def has_schema_document_for_ns(self, namespace: str) -> bool: def values(self): for documents in self._instances.values(): - for document in documents: - yield document + yield from documents class SchemaDocument: @@ -384,7 +382,7 @@ def __init__(self, namespace, location, base_url): # self._xml_schema = None def __repr__(self): - return "" % ( + return "".format( self._location, self._target_namespace, self.is_empty, diff --git a/src/zeep/xsd/types/any.py b/src/zeep/xsd/types/any.py index 4b792fca9..d47b734fa 100644 --- a/src/zeep/xsd/types/any.py +++ b/src/zeep/xsd/types/any.py @@ -2,10 +2,7 @@ import sys import typing -if sys.version_info >= (3, 8): - from functools import cached_property as threaded_cached_property -else: - from cached_property import threaded_cached_property +from functools import cached_property as threaded_cached_property from lxml import etree diff --git a/src/zeep/xsd/types/builtins.py b/src/zeep/xsd/types/builtins.py index 18b9a66f2..fd44b2a17 100644 --- a/src/zeep/xsd/types/builtins.py +++ b/src/zeep/xsd/types/builtins.py @@ -89,7 +89,7 @@ class Decimal(BuiltinType): @check_no_collection def xmlvalue(self, value): if isinstance(value, _Decimal): - return "{:f}".format(value) + return f"{value:f}" return str(value) @treat_whitespace("collapse") diff --git a/src/zeep/xsd/types/complex.py b/src/zeep/xsd/types/complex.py index 9208e1a7c..0ca311891 100644 --- a/src/zeep/xsd/types/complex.py +++ b/src/zeep/xsd/types/complex.py @@ -8,10 +8,7 @@ from itertools import chain from typing import Optional -if sys.version_info >= (3, 8): - from functools import cached_property as threaded_cached_property -else: - from cached_property import threaded_cached_property +from functools import cached_property as threaded_cached_property from lxml import etree @@ -47,7 +44,7 @@ class ComplexType(AnyType): - _xsd_name: typing.Optional[str] = None + _xsd_name: str | None = None def __init__( self, @@ -66,7 +63,7 @@ def __init__( self._attributes = attributes or [] self._restriction = restriction self._extension = extension - self._extension_types: typing.List[typing.Type] = [] + self._extension_types: list[type] = [] super().__init__(qname=qname, is_global=is_global) def __call__(self, *args, **kwargs): @@ -75,11 +72,11 @@ def __call__(self, *args, **kwargs): return self._value_class(*args, **kwargs) @property - def accepted_types(self) -> typing.List[typing.Type]: + def accepted_types(self) -> list[type]: return [self._value_class] + self._extension_types @threaded_cached_property - def _array_class(self) -> typing.Type[ArrayValue]: + def _array_class(self) -> type[ArrayValue]: assert self._array_type return type( self.__class__.__name__, @@ -88,7 +85,7 @@ def _array_class(self) -> typing.Type[ArrayValue]: ) @threaded_cached_property - def _value_class(self) -> typing.Type[CompoundValue]: + def _value_class(self) -> type[CompoundValue]: return type( self.__class__.__name__, (CompoundValue,), @@ -96,7 +93,7 @@ def _value_class(self) -> typing.Type[CompoundValue]: ) def __str__(self): - return "%s(%s)" % (self.__class__.__name__, self.signature()) + return "{}({})".format(self.__class__.__name__, self.signature()) @threaded_cached_property def attributes(self): @@ -174,11 +171,11 @@ def _array_type(self): def parse_xmlelement( self, xmlelement: etree._Element, - schema: Optional[Schema] = None, + schema: Schema | None = None, allow_none: bool = True, context: XmlParserContext = None, - schema_type: Optional[Type] = None, - ) -> typing.Optional[typing.Union[str, CompoundValue, typing.List[etree._Element]]]: + schema_type: Type | None = None, + ) -> str | CompoundValue | list[etree._Element] | None: """Consume matching xmlelements and call parse() on each :param xmlelement: XML element objects @@ -250,8 +247,8 @@ def parse_xmlelement( def render( self, node: etree._Element, - value: typing.Union[list, dict, CompoundValue], - xsd_type: "ComplexType" = None, + value: list | dict | CompoundValue, + xsd_type: ComplexType = None, render_path=None, ) -> None: """Serialize the given value lxml.Element subelements on the node @@ -314,10 +311,10 @@ def render( def parse_kwargs( self, - kwargs: typing.Dict[str, typing.Any], + kwargs: dict[str, typing.Any], name: str, - available_kwargs: typing.Set[str], - ) -> typing.Dict[str, typing.Any]: + available_kwargs: set[str], + ) -> dict[str, typing.Any]: """Parse the kwargs for this type and return the accepted data as a dict. @@ -341,8 +338,8 @@ def parse_kwargs( return {} def _create_object( - self, value: typing.Union[list, dict, CompoundValue, None], name: str - ) -> typing.Union[CompoundValue, None, _ObjectList]: + self, value: list | dict | CompoundValue | None, name: str + ) -> CompoundValue | None | _ObjectList: """Return the value as a CompoundValue object :type value: str @@ -507,11 +504,11 @@ def signature(self, schema=None, standalone=True): parts.append(part) for name, attribute in self.attributes: - part = "%s: %s" % (name, attribute.signature(schema, standalone=False)) + part = "{}: {}".format(name, attribute.signature(schema, standalone=False)) parts.append(part) value = ", ".join(parts) if standalone: - return "%s(%s)" % (self.get_prefixed_name(schema), value) + return "{}({})".format(self.get_prefixed_name(schema), value) else: return value diff --git a/src/zeep/xsd/types/unresolved.py b/src/zeep/xsd/types/unresolved.py index 237294580..dbec0fd4f 100644 --- a/src/zeep/xsd/types/unresolved.py +++ b/src/zeep/xsd/types/unresolved.py @@ -18,7 +18,7 @@ def __init__(self, qname, schema): self.schema = schema def __repr__(self): - return "<%s(qname=%r)>" % (self.__class__.__name__, self.qname.text) + return "<{}(qname={!r})>".format(self.__class__.__name__, self.qname.text) def render( self, @@ -46,7 +46,7 @@ def __init__(self, qname, base_type, schema): self.base_type = base_type def __repr__(self): - return "<%s(qname=%r, base_type=%r)>" % ( + return "<{}(qname={!r}, base_type={!r})>".format( self.__class__.__name__, self.qname.text, self.base_type, diff --git a/src/zeep/xsd/utils.py b/src/zeep/xsd/utils.py index 7fe3ca221..a0c230a33 100644 --- a/src/zeep/xsd/utils.py +++ b/src/zeep/xsd/utils.py @@ -33,8 +33,7 @@ def max_occurs_iter(max_occurs, items=None): for i, sub_kwargs in zip(generator, items): yield sub_kwargs else: - for i in generator: - yield i + yield from generator def create_prefixed_name(qname, schema): @@ -51,10 +50,10 @@ def create_prefixed_name(qname, schema): if schema and qname.namespace: prefix = schema.get_shorthand_for_ns(qname.namespace) if prefix: - return "%s:%s" % (prefix, qname.localname) + return "{}:{}".format(prefix, qname.localname) elif qname.namespace in ns.NAMESPACE_TO_PREFIX: prefix = ns.NAMESPACE_TO_PREFIX[qname.namespace] - return "%s:%s" % (prefix, qname.localname) + return "{}:{}".format(prefix, qname.localname) if qname.namespace: return qname.text diff --git a/src/zeep/xsd/valueobjects.py b/src/zeep/xsd/valueobjects.py index ae19db5a4..8c22ddd44 100644 --- a/src/zeep/xsd/valueobjects.py +++ b/src/zeep/xsd/valueobjects.py @@ -24,7 +24,7 @@ def __init__(self, xsd_object, value): self.value = value def __repr__(self): - return "<%s(type=%r, value=%r)>" % ( + return "<{}(type={!r}, value={!r})>".format( self.__class__.__name__, self.xsd_elm, self.value, @@ -154,7 +154,7 @@ def __getattribute__(self, key): return self.__values__[key] except KeyError: raise AttributeError( - "%s instance has no attribute '%s'" % (self.__class__.__name__, key) + "{} instance has no attribute '{}'".format(self.__class__.__name__, key) ) def __deepcopy__(self, memo): diff --git a/tests/test_client.py b/tests/test_client.py index af13d9b98..313a9293f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -60,7 +60,7 @@ def test_context_manager(): def test_service_proxy_dir_operations(): client_obj = client.Client("tests/wsdl_files/soap.wsdl") operations = [op for op in dir(client_obj.service) if not op.startswith("_")] - assert set(operations) == set(["GetLastTradePrice", "GetLastTradePriceNoOutput"]) + assert set(operations) == {"GetLastTradePrice", "GetLastTradePriceNoOutput"} def test_operation_proxy_doc(): diff --git a/tests/test_soap_xop.py b/tests/test_soap_xop.py index 283672a74..9c010114d 100644 --- a/tests/test_soap_xop.py +++ b/tests/test_soap_xop.py @@ -249,7 +249,7 @@ def test_xop(): headers={"Content-Type": content_type}, ) result = service.TestOperation2("") - assert result["_value_1"] == "BINARYDATA".encode() + assert result["_value_1"] == b"BINARYDATA" m.post( "http://tests.python-zeep.org/test", @@ -257,7 +257,7 @@ def test_xop(): headers={"Content-Type": content_type}, ) result = service.TestOperation1("") - assert result == "BINARYDATA".encode() + assert result == b"BINARYDATA" def test_xop_cid_encoded(): @@ -302,4 +302,4 @@ def test_xop_cid_encoded(): headers={"Content-Type": content_type}, ) result = service.TestOperation2("") - assert result["_value_1"] == "BINARYDATA".encode() + assert result["_value_1"] == b"BINARYDATA" diff --git a/tests/test_wsdl.py b/tests/test_wsdl.py index 5013d79f3..99dc271f1 100644 --- a/tests/test_wsdl.py +++ b/tests/test_wsdl.py @@ -159,7 +159,7 @@ def test_parse_types_multiple_schemas(): def test_parse_types_nsmap_issues(): content = StringIO( - """ + r""" Date: Tue, 2 Jul 2024 11:06:08 +0000 Subject: [PATCH 2/3] update module metadata to support python>=3.8 only. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomasz Kłoczko --- setup.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 9b81ae596..67fa80102 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,6 @@ install_requires = [ "attrs>=17.2.0", - "cached-property>=1.3.0; python_version<'3.8'", "isodate>=0.5.4", "lxml>=4.6.0", "platformdirs>=1.4.0", @@ -58,7 +57,7 @@ project_urls={ "Source": "https://github.com/mvantellingen/python-zeep", }, - python_requires=">=3.7", + python_requires=">=3.8", install_requires=install_requires, tests_require=tests_require, extras_require={ @@ -75,13 +74,11 @@ classifiers=[ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ], From a4d320ba3aa01ed1454826f464a632105a3957f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= Date: Tue, 2 Jul 2024 11:09:11 +0000 Subject: [PATCH 3/3] filter all code over `ruff` to drop unused imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomasz Kłoczko --- docs/conf.py | 3 --- examples/async_client.py | 2 -- src/zeep/cache.py | 1 - src/zeep/transports.py | 2 +- src/zeep/wsdl/attachments.py | 1 - src/zeep/wsdl/wsdl.py | 1 - src/zeep/xsd/elements/indicators.py | 3 --- src/zeep/xsd/types/any.py | 1 - src/zeep/xsd/types/complex.py | 2 -- tests/conftest.py | 1 - tests/test_loader.py | 1 - tests/test_wsdl.py | 1 - tests/test_wsdl_arrays.py | 1 - tests/test_wsdl_messages_rpc.py | 1 - tests/test_wsse_signature.py | 1 - tests/test_xsd_extension.py | 1 - tests/test_xsd_schemas.py | 1 - tests/test_xsd_types.py | 2 +- 18 files changed, 2 insertions(+), 24 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 8b079feba..dd0380c22 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,9 +11,6 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys -import os -import pkg_resources # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/examples/async_client.py b/examples/async_client.py index 3bb962869..7eeebf77e 100644 --- a/examples/async_client.py +++ b/examples/async_client.py @@ -1,10 +1,8 @@ import asyncio -import httpx import time import zeep -from zeep.transports import AsyncTransport def run_async(): diff --git a/src/zeep/cache.py b/src/zeep/cache.py index 269905fe1..0a3c68b09 100644 --- a/src/zeep/cache.py +++ b/src/zeep/cache.py @@ -4,7 +4,6 @@ import logging import os import threading -import typing from contextlib import contextmanager import platformdirs diff --git a/src/zeep/transports.py b/src/zeep/transports.py index 8e6970d21..98863771c 100644 --- a/src/zeep/transports.py +++ b/src/zeep/transports.py @@ -211,7 +211,7 @@ def _load_remote_data(self, url): try: response.raise_for_status() - except httpx.HTTPStatusError as exc: + except httpx.HTTPStatusError: raise TransportError(status_code=response.status_code) return result diff --git a/src/zeep/wsdl/attachments.py b/src/zeep/wsdl/attachments.py index 0ca22a6d0..2df1051c8 100644 --- a/src/zeep/wsdl/attachments.py +++ b/src/zeep/wsdl/attachments.py @@ -5,7 +5,6 @@ """ import base64 -import sys from functools import cached_property diff --git a/src/zeep/wsdl/wsdl.py b/src/zeep/wsdl/wsdl.py index 16d9af658..777c771e7 100644 --- a/src/zeep/wsdl/wsdl.py +++ b/src/zeep/wsdl/wsdl.py @@ -18,7 +18,6 @@ absolute_location, is_relative_path, load_external, - load_external_async, ) from zeep.settings import Settings from zeep.utils import findall_multiple_ns diff --git a/src/zeep/xsd/elements/indicators.py b/src/zeep/xsd/elements/indicators.py index ea641fcac..07596cae2 100644 --- a/src/zeep/xsd/elements/indicators.py +++ b/src/zeep/xsd/elements/indicators.py @@ -13,13 +13,10 @@ """ import copy import operator -import sys -import typing from collections import OrderedDict, defaultdict, deque from functools import cached_property as threaded_cached_property -from lxml import etree from zeep.exceptions import UnexpectedElementError, ValidationError from zeep.xsd.const import NotSet, SkipValue diff --git a/src/zeep/xsd/types/any.py b/src/zeep/xsd/types/any.py index d47b734fa..44a059eb3 100644 --- a/src/zeep/xsd/types/any.py +++ b/src/zeep/xsd/types/any.py @@ -1,5 +1,4 @@ import logging -import sys import typing from functools import cached_property as threaded_cached_property diff --git a/src/zeep/xsd/types/complex.py b/src/zeep/xsd/types/complex.py index 0ca311891..3b18c1712 100644 --- a/src/zeep/xsd/types/complex.py +++ b/src/zeep/xsd/types/complex.py @@ -2,11 +2,9 @@ import copy import logging -import sys import typing from collections import OrderedDict, deque from itertools import chain -from typing import Optional from functools import cached_property as threaded_cached_property diff --git a/tests/conftest.py b/tests/conftest.py index 4bd41de06..0254be8e5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -import sys import pytest diff --git a/tests/test_loader.py b/tests/test_loader.py index 16548320d..8ef55594e 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1,5 +1,4 @@ import pytest -from pytest import raises as assert_raises from tests.utils import DummyTransport from zeep.exceptions import DTDForbidden, EntitiesForbidden diff --git a/tests/test_wsdl.py b/tests/test_wsdl.py index 99dc271f1..ddf617b18 100644 --- a/tests/test_wsdl.py +++ b/tests/test_wsdl.py @@ -1,4 +1,3 @@ -import io from io import StringIO import pytest diff --git a/tests/test_wsdl_arrays.py b/tests/test_wsdl_arrays.py index 841c9eb15..1e8af4b56 100644 --- a/tests/test_wsdl_arrays.py +++ b/tests/test_wsdl_arrays.py @@ -1,4 +1,3 @@ -import io import pytest from lxml import etree diff --git a/tests/test_wsdl_messages_rpc.py b/tests/test_wsdl_messages_rpc.py index ee81c9fee..b6c0c6202 100644 --- a/tests/test_wsdl_messages_rpc.py +++ b/tests/test_wsdl_messages_rpc.py @@ -1,4 +1,3 @@ -import io from io import StringIO from tests.utils import DummyTransport, assert_nodes_equal, load_xml diff --git a/tests/test_wsse_signature.py b/tests/test_wsse_signature.py index 487b83542..bab949570 100644 --- a/tests/test_wsse_signature.py +++ b/tests/test_wsse_signature.py @@ -2,7 +2,6 @@ import sys import pytest -from lxml import etree from lxml.etree import QName from tests.utils import load_xml diff --git a/tests/test_xsd_extension.py b/tests/test_xsd_extension.py index 689002698..6f7835ab1 100644 --- a/tests/test_xsd_extension.py +++ b/tests/test_xsd_extension.py @@ -1,5 +1,4 @@ import datetime -import io from lxml import etree diff --git a/tests/test_xsd_schemas.py b/tests/test_xsd_schemas.py index b3ce55b04..28e321d7a 100644 --- a/tests/test_xsd_schemas.py +++ b/tests/test_xsd_schemas.py @@ -1,4 +1,3 @@ -import io import pytest from lxml import etree diff --git a/tests/test_xsd_types.py b/tests/test_xsd_types.py index 2c2a983d8..489a8a3aa 100644 --- a/tests/test_xsd_types.py +++ b/tests/test_xsd_types.py @@ -1,4 +1,4 @@ -from datetime import datetime, time +from datetime import datetime from decimal import Decimal import isodate