[Soap-Python] multiple services with soaplib-0.9.1-alpha1

Burak Arslan burak.arslan at arskom.com.tr
Tue Aug 3 13:33:11 CEST 2010


 On 08/03/10 14:13, Burak Arslan wrote:
>  On 08/03/10 13:08, Luca Dariz wrote:
>>> i just made a new release that lets you give an iterable of service
>>> definitions (not instances) to wsgi.Application. this helps complex
>>> applications that want to provide web services under the same
>>> targetNamespace but want them defined under different classes.
>>>
>>>    
>> Hi,
>>
>> I am wondering if wouldn't be better to have instances of services
>> instead of definitions.
>>
>> This way would be easier to subclass DefinitionBase, maybe defining a
>> __call__ method and pass there the http environment, and one could
>> write something like:
>>
>> class MyService(DefinitionBase):
>>     def __init__(self, data):
>>         DefinitionBase.__init__(self)
>>         self._something_needed = data
>>
>> services = [MyService(something_heavy)]
>> application = Application(services, 'ServiceTNS')
>>
>> Here something_needed could be for example some database connection,
>> or something that could be nice to have persistent into the service,
>> since the methods are called on it.
>>
>> To me it looks like this way services would be more customizable, what
>> do you think?
> Hi Luca,
>
> The way i designed it was to have service object instantiated for every
> request. This gives you an elegant way to store request-level
> information like soap or http headers.
>
> But you can pass any kind of callable as a service to the
> wsgi.Application object, provided it implements the same interface.
>
> I'd do what you describe by overriding the wsgi.Application.get_service
> method.
>
> class MyApplication(wsgi.Application):
>     def __init__(self, services, tns, data):
>         self.__data = data
>
>         wsgi.Application.__init__(self, service, tns)
>
>     def get_service(self, method_name, http_env):
>         return self.call_routes[method_name](http_env, self.__data)
>
> application = MyApplication([MyService], data, tns=__name__)
>
> hth
> burak

but i guess the magic

self.call_routes[method_name]

statement is not of interest to users. i'm going to hide it so
subclasses are less prone to errors, like so:

    def get_service(self, service, http_env):
        return service(http_env, self.__data)



what do you think?

burak





More information about the Soap mailing list