Skip to content

Commit f7ef428

Browse files
committed
Change the signature of Client.create_message() to be more friendly
1 parent bd017cf commit f7ef428

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
2.0.0 (unreleased)
22
------------------
33
- Default values of optional elements are not set by default anymore (#423)
4-
4+
- The call signature for Client.create_message() was changed. It now requires
5+
the service argument:
6+
``Client.create_message(service, operation_name, *args, **kwargs)``
57

68
1.6.0 (2017-04-27)
79
------------------

docs/client.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ Caching of WSDL and XSD files
1818
------------------------------
1919
When the client is initialised it will automaticaly retrieve the wsdl file
2020
passed as argument. This wsdl file generally references various other wsdl and
21-
xsd files. By default Zeep doesn't cache these files but it is however
21+
xsd files. By default Zeep doesn't cache these files but it is however
2222
advised to enable this for performance reasons.
2323

2424
Please see :ref:`transport_caching` how to enable this. To make it easy to
25-
use the ``zeep.CachingClient()`` automatically creates a Transport object
25+
use the ``zeep.CachingClient()`` automatically creates a Transport object
2626
with SqliteCache enabled.
2727

2828

@@ -49,7 +49,7 @@ For example to let zeep return the raw response directly instead of processing
4949
it you can do the following:
5050

5151
.. code-block:: python
52-
52+
5353
from zeep import Client
5454
from zeep import xsd
5555
@@ -69,7 +69,7 @@ The ServiceProxy object
6969
The ServiceProxy object is a simple object which will check if an operation
7070
exists for attribute or item requested. If the operation exists then it will
7171
return an OperationProxy object (callable) which is responsible for calling the
72-
operation on the binding.
72+
operation on the binding.
7373

7474

7575
.. code-block:: python
@@ -82,12 +82,12 @@ operation on the binding.
8282
# service is a ServiceProxy object. It will check if there
8383
# is an operation with the name `X` defined in the binding
8484
# and if that is the case it will return an OperationProxy
85-
client.service.X()
85+
client.service.X()
8686
87-
# The operation can also be called via an __getitem__ call.
88-
# This is usefull if the operation name is not a valid
87+
# The operation can also be called via an __getitem__ call.
88+
# This is usefull if the operation name is not a valid
8989
# python attribute name.
90-
client.service['X-Y']()
90+
client.service['X-Y']()
9191
9292
9393
Using non-default bindings
@@ -112,7 +112,7 @@ Creating new ServiceProxy objects
112112
---------------------------------
113113
There are situations where you either need to change the SOAP address from the
114114
one which is defined within the WSDL or the WSDL doesn't define any service
115-
elements. This can be done by creating a new ServiceProxy using the
115+
elements. This can be done by creating a new ServiceProxy using the
116116
``Client.create_service()`` method.
117117

118118
.. code-block:: python
@@ -125,4 +125,19 @@ elements. This can be done by creating a new ServiceProxy using the
125125
'{http://my-target-namespace-here}myBinding',
126126
'http://my-endpoint.com/acceptance/')
127127
128-
service.submit('something')
128+
service.submit('something')
129+
130+
131+
Creating the raw XML documents
132+
------------------------------
133+
When you want zeep to build and return the XML instead of sending it to the
134+
server you can use the ``Client.create_message()`` call. It requires then
135+
ServiceProxy as first argument and the operation name as second argument.
136+
137+
138+
.. code-block:: python
139+
140+
from zeep import Client
141+
142+
client = Client('http://my-endpoint.com/production.svc?wsdl')
143+
node = client.create_message(client.service, 'myOperation', user='hi')

docs/reporting_bugs.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ There are basically three majors parts where bugs can happen, these are:
1919
3. Parsing the XML from the response
2020

2121

22-
The first one is usually pretty easy to debug if the WSDL is publicly
22+
The first one is usually pretty easy to debug if the WSDL is publicly
2323
accessible. If that isn't the case then you might be able to make it anonymous.
2424

2525

@@ -47,9 +47,9 @@ args / kwargs you normally pass.
4747
4848
client = Client('YOUR-WSDL')
4949
50-
# client.service.OPERATION_NAME(args, kwargs) becomes
51-
node = client.service._binding.create_message(
52-
'OPERATION_NAME', args, kwargs)
50+
# client.service.OPERATION_NAME(*args, **kwargs) becomes
51+
node = client.create_message(
52+
client.service, 'OPERATION_NAME', *args, **kwargs)
5353
5454
print(etree.tostring(node, pretty_print=True))
5555
@@ -62,7 +62,7 @@ The first step is to retrieve the XML which is returned from the server, You
6262
need to enable debugging for this. Please see :ref:`debugging` for a detailed
6363
description.
6464

65-
The next step is to create a python script which exposes the problem, an
65+
The next step is to create a python script which exposes the problem, an
6666
example is the following.
6767

6868
.. code-block:: python
@@ -72,7 +72,7 @@ example is the following.
7272
from zeep import Client
7373
from zeep.transports import Transport
7474
75-
# Replace YOUR-WSDL and OPERATION_NAME with the wsdl url
75+
# Replace YOUR-WSDL and OPERATION_NAME with the wsdl url
7676
# and the method name you are calling. The response
7777
# needs to be set in the content=""" """ var.
7878

src/zeep/client.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import logging
33
from contextlib import contextmanager
44

5-
from zeep.xsd.const import NotSet
65
from zeep.transports import Transport
76
from zeep.wsdl import Document
8-
7+
from zeep.xsd.const import NotSet
98

109
logger = logging.getLogger(__name__)
1110

@@ -215,19 +214,14 @@ def create_service(self, binding_name, address):
215214
"are: %s" % (', '.join(self.wsdl.bindings.keys())))
216215
return ServiceProxy(self, binding, address=address)
217216

218-
def create_message(self, operation, service_name=None, port_name=None,
219-
args=None, kwargs=None):
217+
def create_message(self, service, operation_name, *args, **kwargs):
220218
"""Create the payload for the given operation.
221219
222220
:rtype: lxml.etree._Element
223221
224222
"""
225-
service = self._get_service(service_name)
226-
port = self._get_port(service, port_name)
227-
228-
args = args or tuple()
229-
kwargs = kwargs or {}
230-
envelope, http_headers = port.binding._create(operation, args, kwargs)
223+
envelope, http_headers = service._binding._create(
224+
operation_name, args, kwargs)
231225
return envelope
232226

233227
def type_factory(self, namespace):

0 commit comments

Comments
 (0)