HowToCreateAServiceInAPythonModule

Creating Services in Python module

To create a service from Python module, all you need to do is create a component and register it as a service my calling the provideService method of the ComponentArchitecture package. You call provideService with a service name and a component. There must be a service type defined for the given name and the component that you register must implement the intrface defined for the service. A service type is defined by calling defineService with a service name and an interface.

For example, suppose we wanted to define and provide an mail delivery service. We might do so with Python code like the following:

     import ComponentArchitecture, Interface

     # define the email interface:
     class EmailDeliveryService(Interface.Base):

        def validateAddress(address):
          "Check whether an address is valid"

        def send(message):
          "Deliver a message"

     # Define the service
     ComponentArchitecture.defineService('EmailDelivery', EmailDeliveryService)

     # Define a component that implements the service:
     class SMTPDelivery:

        __implements__=EmailDeliveryService

        def __init__(self, host): ....
        def validateAddress(self, address): ...
        def send(self, message): ...

        ...

     # Provide the service
     s = SMTPDelivery('localhost')
     ComponentArchitecture.provideService('EmailDelivery', s)

  Note that unlike adapters and utilities, service components are
  registered directly.

  IsIncorrect -- 

     - Need to update interface style

     - Need to mention delegation to higher-level services.



( 96 subscribers )