Question

I have been trying to modify the Reply class of suds.transport.

I tried with the following approach:

import suds.transport
old_reply = suds.transport.Reply

class Reply2:
    """
    A transport reply
    @ivar code: The http code returned.
    @type code: int
    @ivar message: The message to be sent in a POST request.
    @type message: str
    @ivar headers: The http headers to be used for the request.
    @type headers: dict
    """

    def __init__(self, code, headers, message):
        """
        @param code: The http code returned.
        @type code: int
        @param headers: The http returned headers.
        @type headers: dict
        @param message: The (optional) reply message received.
        @type message: str
        """
        print 'hello, i patched the class'
        self.code = code
        self.headers = headers
        self.message = message

    def __str__(self):
        s = []
        s.append('CODE: %s' % self.code)
        s.append('HEADERS: %s' % self.headers)
        s.append('MESSAGE:')
        s.append(self.message)
        return '\n'.join(s)

suds.transport.Reply = Reply2

When executing a client request (as you would normally with Suds), the default Reply is used instead of the patched one.

What could be a reason that this approach is failing?

Note: it seems that patching the __init__ separately does give better results. But I need to modify more behaviour in the class. In the end, I'm trying to override Reply to get incoming attachments, like asked on SO and the solution here

Était-ce utile?

La solution

The suds.transport.http module imports Reply with the line:

from suds.transport import *

and does this before you can patch it. You need to update that reference too:

import suds.transport.http
suds.transport.http.Reply = Reply2
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top