Skip to content

Commit b251e4f

Browse files
committed
Remove deprecated lxml node.getchildren() calls
1 parent b65d462 commit b251e4f

File tree

17 files changed

+56
-55
lines changed

17 files changed

+56
-55
lines changed

src/zeep/wsdl/bindings/http.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,16 @@ def parse(cls, definitions, xmlelement, binding):
148148
location = http_operation.get('location')
149149
obj = cls(name, binding, location)
150150

151-
for node in xmlelement.getchildren():
151+
for node in xmlelement:
152152
tag_name = etree.QName(node.tag).localname
153153
if tag_name not in ('input', 'output'):
154154
continue
155155

156156
# XXX Multiple mime types may be declared as alternatives
157157
message_node = None
158-
if len(node.getchildren()) > 0:
159-
message_node = node.getchildren()[0]
158+
nodes = list(node)
159+
if len(nodes) > 0:
160+
message_node = nodes[0]
160161
message_class = None
161162
if message_node is not None:
162163
if message_node.tag == etree.QName(ns.HTTP, 'urlEncoded'):

src/zeep/wsdl/bindings/soap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def parse(cls, definitions, xmlelement, binding, nsmap):
423423
else:
424424
message_class = DocumentMessage
425425

426-
for node in xmlelement.getchildren():
426+
for node in xmlelement:
427427
tag_name = etree.QName(node.tag).localname
428428
if tag_name not in ('input', 'output', 'fault'):
429429
continue

src/zeep/wsdl/messages/mime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def serialize(self, *args, **kwargs):
110110
elif self.content_type == 'text/xml':
111111
document = etree.Element('root')
112112
self.body.render(document, value)
113-
data = etree_to_string(document.getchildren()[0])
113+
data = etree_to_string(list(document)[0])
114114

115115
return SerializedMessage(
116116
path=self.operation.location, headers=headers, content=data)

src/zeep/wsdl/messages/soap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def _deserialize_body(self, xmlelement):
407407
# TODO: For now we assume that the body only has one child since
408408
# only one part is specified in the wsdl. This should be handled
409409
# way better
410-
xmlelement = xmlelement.getchildren()[0]
410+
xmlelement = list(xmlelement)[0]
411411

412412
context = XmlParserContext(settings=self.wsdl.settings)
413413
result = self.body.parse(xmlelement, self.wsdl.types, context=context)
@@ -501,7 +501,7 @@ def _deserialize_body(self, body_element):
501501
"""
502502
process_multiref(body_element)
503503

504-
response_element = body_element.getchildren()[0]
504+
response_element = list(body_element)[0]
505505
if self.body:
506506
context = XmlParserContext(self.wsdl.settings)
507507
result = self.body.parse(

src/zeep/wsdl/parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def parse_abstract_operation(wsdl, xmlelement):
9797
'fault_messages': {}
9898
}
9999

100-
for msg_node in xmlelement.getchildren():
100+
for msg_node in xmlelement:
101101
tag_name = etree.QName(msg_node.tag).localname
102102
if tag_name not in ('input', 'output', 'fault'):
103103
continue

src/zeep/xsd/elements/any.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def parse(self, xmlelement, schema, context=None):
6262
# Try to parse the any result by iterating all the schemas
6363
for context_schema in context.schemas:
6464
try:
65-
data = context_schema.deserialize(xmlelement.getchildren()[0])
65+
data = context_schema.deserialize(list(xmlelement)[0])
6666
return data
6767
except LookupError:
6868
continue

src/zeep/xsd/types/any.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def parse_xmlelement(self, xmlelement, schema=None, allow_none=True,
5050
"""
5151
xsi_type = qname_attr(xmlelement, xsi_ns('type'))
5252
xsi_nil = xmlelement.get(xsi_ns('nil'))
53-
children = list(xmlelement.getchildren())
53+
children = list(xmlelement)
5454

5555
# Handle xsi:nil attribute
5656
if xsi_nil == 'true':

src/zeep/xsd/visitor.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def visit_element(self, node, parent):
340340
else:
341341
qname = etree.QName(node.get('name').strip())
342342

343-
children = node.getchildren()
343+
children = list(node)
344344
xsd_type = None
345345
if children:
346346
value = None
@@ -422,7 +422,7 @@ def visit_attribute(self, node, parent):
422422
else:
423423
name = etree.QName(node.get('name'))
424424

425-
annotation, items = self._pop_annotation(node.getchildren())
425+
annotation, items = self._pop_annotation(list(node))
426426
if items:
427427
xsd_type = self.visit_simple_type(items[0], node)
428428
else:
@@ -472,7 +472,7 @@ def visit_simple_type(self, node, parent):
472472
base_type = '{http://www.w3.org/2001/XMLSchema}string'
473473
qname = as_qname(name, node.nsmap, self.document._target_namespace)
474474

475-
annotation, items = self._pop_annotation(node.getchildren())
475+
annotation, items = self._pop_annotation(list(node))
476476
child = items[0]
477477
if child.tag == tags.restriction:
478478
base_type = self.visit_restriction_simple_type(child, node)
@@ -535,7 +535,7 @@ def visit_complex_type(self, node, parent):
535535
xsd_type = None
536536

537537
# Process content
538-
annotation, children = self._pop_annotation(node.getchildren())
538+
annotation, children = self._pop_annotation(list(node))
539539
first_tag = children[0].tag if children else None
540540

541541
if first_tag == tags.simpleContent:
@@ -586,8 +586,8 @@ def visit_complex_content(self, node, parent):
586586
:type parent: lxml.etree._Element
587587
588588
"""
589-
590-
child = node.getchildren()[-1]
589+
children = list(node)
590+
child = children[-1]
591591

592592
if child.tag == tags.restriction:
593593
base, element, attributes = self.visit_restriction_complex_content(
@@ -626,7 +626,8 @@ def visit_simple_content(self, node, parent):
626626
627627
"""
628628

629-
child = node.getchildren()[-1]
629+
children = list(node)
630+
child = children[-1]
630631

631632
if child.tag == tags.restriction:
632633
return self.visit_restriction_simple_content(child, node)
@@ -659,7 +660,7 @@ def visit_restriction_simple_type(self, node, parent):
659660
if base_name:
660661
return self._get_type(base_name)
661662

662-
annotation, children = self._pop_annotation(node.getchildren())
663+
annotation, children = self._pop_annotation(list(node))
663664
if children[0].tag == tags.simpleType:
664665
return self.visit_simple_type(children[0], node)
665666

@@ -710,7 +711,7 @@ def visit_restriction_complex_content(self, node, parent):
710711
"""
711712
base_name = qname_attr(node, 'base')
712713
base_type = self._get_type(base_name)
713-
annotation, children = self._pop_annotation(node.getchildren())
714+
annotation, children = self._pop_annotation(list(node))
714715

715716
element = None
716717
attributes = []
@@ -745,7 +746,7 @@ def visit_extension_complex_content(self, node, parent):
745746
"""
746747
base_name = qname_attr(node, 'base')
747748
base_type = self._get_type(base_name)
748-
annotation, children = self._pop_annotation(node.getchildren())
749+
annotation, children = self._pop_annotation(list(node))
749750

750751
element = None
751752
attributes = []
@@ -773,7 +774,7 @@ def visit_extension_simple_content(self, node, parent):
773774
"""
774775
base_name = qname_attr(node, 'base')
775776
base_type = self._get_type(base_name)
776-
annotation, children = self._pop_annotation(node.getchildren())
777+
annotation, children = self._pop_annotation(list(node))
777778
attributes = self._process_attributes(node, children)
778779

779780
return base_type, attributes
@@ -853,8 +854,8 @@ def visit_sequence(self, node, parent):
853854
result = xsd_elements.Sequence(
854855
min_occurs=min_occurs, max_occurs=max_occurs)
855856

856-
annotation, items = self._pop_annotation(node.getchildren())
857-
for child in items:
857+
annotation, children = self._pop_annotation(list(node))
858+
for child in children:
858859
if child.tag not in sub_types:
859860
raise self._create_error(
860861
"Unexpected element %s in xsd:sequence" % child.tag, child)
@@ -892,8 +893,8 @@ def visit_all(self, node, parent):
892893
]
893894
result = xsd_elements.All()
894895

895-
annotation, items = self._pop_annotation(node.getchildren())
896-
for child in items:
896+
annotation, children = self._pop_annotation(list(node))
897+
for child in children:
897898
assert child.tag in sub_types, child
898899
item = self.process(child, node)
899900
result.append(item)
@@ -934,7 +935,7 @@ def visit_group(self, node, parent):
934935
qname = qname_attr(node, 'name', self.document._target_namespace)
935936

936937
# There should be only max nodes, first node (annotation) is irrelevant
937-
annotation, children = self._pop_annotation(node.getchildren())
938+
annotation, children = self._pop_annotation(list(node))
938939
child = children[0]
939940

940941
item = self.process(child, parent)
@@ -969,7 +970,7 @@ def visit_list(self, node, parent):
969970
if item_type:
970971
sub_type = self._get_type(item_type.text)
971972
else:
972-
subnodes = node.getchildren()
973+
subnodes = list(node)
973974
child = subnodes[-1] # skip annotation
974975
sub_type = self.visit_simple_type(child, node)
975976
return xsd_types.ListType(sub_type)
@@ -988,8 +989,7 @@ def visit_choice(self, node, parent):
988989
"""
989990
min_occurs, max_occurs = _process_occurs_attrs(node)
990991

991-
children = node.getchildren()
992-
annotation, children = self._pop_annotation(children)
992+
annotation, children = self._pop_annotation(list(node))
993993

994994
choices = []
995995
for child in children:
@@ -1025,7 +1025,7 @@ def visit_union(self, node, parent):
10251025
xsd_type = self._get_type(qname)
10261026
types.append(xsd_type)
10271027
else:
1028-
annotation, types = self._pop_annotation(node.getchildren())
1028+
annotation, types = self._pop_annotation(list(node))
10291029
types = [self.visit_simple_type(t, node) for t in types]
10301030
return xsd_types.UnionType(types)
10311031

@@ -1076,7 +1076,7 @@ def visit_attribute_group(self, node, parent):
10761076
return ref
10771077

10781078
qname = qname_attr(node, 'name', self.document._target_namespace)
1079-
annotation, children = self._pop_annotation(node.getchildren())
1079+
annotation, children = self._pop_annotation(list(node))
10801080

10811081
attributes = self._process_attributes(node, children)
10821082
attribute_group = xsd_elements.AttributeGroup(qname, attributes)

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_default_soap_headers():
218218
doc = load_xml(m.request_history[0].body)
219219
header = doc.find('{http://schemas.xmlsoap.org/soap/envelope/}Header')
220220
assert header is not None
221-
assert len(header.getchildren()) == 2
221+
assert len(list(header)) == 2
222222

223223

224224
@pytest.mark.requests
@@ -263,4 +263,4 @@ def test_default_soap_headers_extra():
263263
doc = load_xml(m.request_history[0].body)
264264
header = doc.find('{http://schemas.xmlsoap.org/soap/envelope/}Header')
265265
assert header is not None
266-
assert len(header.getchildren()) == 4
266+
assert len(list(header)) == 4

tests/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_serialize_any_array():
144144
assert_nodes_equal(expected, node)
145145

146146
schema = xsd.Schema()
147-
obj = custom_type.parse(node.getchildren()[0], schema=schema)
147+
obj = custom_type.parse(list(node)[0], schema=schema)
148148
result = serialize_object(obj)
149149

150150
assert result == {

0 commit comments

Comments
 (0)