@@ -620,7 +620,9 @@ def send(self, soapenv):
620
620
binding = self .method .binding .input
621
621
transport = self .options .transport
622
622
retxml = self .options .retxml
623
+ nosend = self .options .nosend
623
624
prettyxml = self .options .prettyxml
625
+ timer = metrics .Timer ()
624
626
log .debug ('sending to (%s)\n message:\n %s' , location , soapenv )
625
627
try :
626
628
self .last_sent (soapenv )
@@ -631,10 +633,16 @@ def send(self, soapenv):
631
633
else :
632
634
soapenv = soapenv .plain ()
633
635
soapenv = soapenv .encode ('utf-8' )
634
- plugins .message .sending (envelope = soapenv )
636
+ ctx = plugins .message .sending (envelope = soapenv )
637
+ soapenv = ctx .envelope
638
+ if nosend :
639
+ return RequestContext (self , binding , soapenv )
635
640
request = Request (location , soapenv )
636
641
request .headers = self .headers ()
642
+ timer .start ()
637
643
reply = transport .send (request )
644
+ timer .stop ()
645
+ metrics .log .debug ('waited %s on server reply' , timer )
638
646
ctx = plugins .message .received (reply = reply .message )
639
647
reply .message = ctx .reply
640
648
if retxml :
@@ -656,6 +664,8 @@ def headers(self):
656
664
@rtype: dict
657
665
"""
658
666
action = self .method .soap .action
667
+ if isinstance (action , unicode ):
668
+ action = action .encode ('utf-8' )
659
669
stock = { 'Content-Type' : 'text/xml; charset=utf-8' , 'SOAPAction' : action }
660
670
result = dict (stock , ** self .options .headers )
661
671
log .debug ('headers = %s' , result )
@@ -783,3 +793,52 @@ def __fault(self, reply):
783
793
return (500 , p )
784
794
else :
785
795
return (500 , None )
796
+
797
+
798
+ class RequestContext :
799
+ """
800
+ A request context.
801
+ Returned when the ''nosend'' options is specified.
802
+ @ivar client: The suds client.
803
+ @type client: L{Client}
804
+ @ivar binding: The binding for this request.
805
+ @type binding: I{Binding}
806
+ @ivar envelope: The request soap envelope.
807
+ @type envelope: str
808
+ """
809
+
810
+ def __init__ (self , client , binding , envelope ):
811
+ """
812
+ @param client: The suds client.
813
+ @type client: L{Client}
814
+ @param binding: The binding for this request.
815
+ @type binding: I{Binding}
816
+ @param envelope: The request soap envelope.
817
+ @type envelope: str
818
+ """
819
+ self .client = client
820
+ self .binding = binding
821
+ self .envelope = envelope
822
+
823
+ def succeeded (self , reply ):
824
+ """
825
+ Re-entry for processing a successful reply.
826
+ @param reply: The reply soap envelope.
827
+ @type reply: str
828
+ @return: The returned value for the invoked method.
829
+ @rtype: object
830
+ """
831
+ options = self .client .options
832
+ plugins = PluginContainer (options .plugins )
833
+ ctx = plugins .message .received (reply = reply )
834
+ reply = ctx .reply
835
+ return self .client .succeeded (self .binding , reply )
836
+
837
+ def failed (self , error ):
838
+ """
839
+ Re-entry for processing a failure reply.
840
+ @param error: The error returned by the transport.
841
+ @type error: A suds I{TransportError}.
842
+ """
843
+ return self .client .failed (self .binding , error )
844
+
0 commit comments