Beispiel #1
0
        class A(Service):
            deps = Needs(['b1', 'x'])

            @provides
            def a1(self):
                """returns (b1 + x)."""
                return self.deps.b1() + self.deps.x()
Beispiel #2
0
        class MyService(Service):  # Should not raise
            deps = Needs(['stuff', 'fluff'])

            @provides
            def provider_a(self):
                return self.deps.stuff() + self._fluff()

            def _fluff(self):
                return self.deps.fluff()
Beispiel #3
0
        class ServiceThatNeedsBandC(Service):
            deps = Needs(['b', 'c'])

            @provides
            def get_b(self):
                return self.deps.b()

            @provides
            def get_c(self):
                return self.deps.c()
Beispiel #4
0
        class MyService(Service):  # Should not raise
            deps = Needs(['stuff'])

            @provides
            def provider_a(self):
                return self.deps.stuff() + self._fluff()

            def _fluff(self):
                # intentional comments. do not remove.
                # self.deps.fluff()
                return 10  # + self.deps.gruff()
Beispiel #5
0
        class B(Service):
            deps = Needs(['c1', 'x', 'y'])

            @provides
            def b1(self):
                """returns (c1 * 2)."""
                return self.deps.c1() * 2

            @provides
            def b2(self):
                """return (x + y)."""
                return self.deps.x() + self.deps.y()
Beispiel #6
0
class Service(INeed, IProvide):
    __metaclass__ = ServiceMetaclass

    deps = Needs([])  # override me in subclass to define service needs

    def __init__(self):
        super(Service, self).__init__()
        self.deps = PortArray.replicate(
            self.__class__.deps
        )  # each service instance should have its own copy

    # ---- implement INeed ----
    @classmethod
    def get_needs(cls):
        return cls.deps.get_ports()

    def _is_compatible_provider(self, port_name, provider):
        return True  # no flag checking for now

    def _satisfy_need(self, port_name, func):
        self.deps.connect_port(port_name, func)

    # ---- implement IProvide ----

    @classmethod
    def get_provides(cls):
        return cls.meta.get_provides()

    def get_provider_func(self, port_name):
        meta = self.__class__.meta
        method_name = meta.get_provider_method_name(port_name)
        return getattr(self, method_name)

    @classmethod
    def get_provider_flag(cls, port_name, flag_name):
        return cls.meta.get_provider_flag(port_name, flag_name)

    @classmethod
    def get_provider_flags(cls, port_name):
        return cls.meta.get_provider_flags(port_name)
Beispiel #7
0
        class B(Service):
            deps = Needs(['b'])

            @provides
            def bbb(self):
                return self.deps.b()
Beispiel #8
0
        class MultiplierService(Service):
            deps = Needs(['a1', 'b2'])

            @provides
            def multiplied(self):
                return self.deps.a1() * self.deps.b2()
Beispiel #9
0
        class ServiceThatNeedsAandB(Service):
            deps = Needs(['a', 'b'])

            @provides
            def get_ab(self):
                return self.deps.a(), self.deps.b()
Beispiel #10
0
 class MyService(Service):
     deps = Needs(['9_bad_port_name'])
Beispiel #11
0
            class MyService(Service):
                deps = Needs(['stuff', 'fluff'])

                @provides
                def provider_a(self):
                    return self.deps.stuff()
Beispiel #12
0
 class MyService(Service):
     deps = Needs(['stuff', 'more_stuff', 'stuff'])
Beispiel #13
0
        class MyService(Service):
            deps = Needs(ports=['a', 'b'])

            @provides
            def x(self):
                return self.deps.a() + self.deps.b()
Beispiel #14
0
 class MyService(Service):
     deps = Needs(['get_needs'])
Beispiel #15
0
        class B(Service):
            deps = Needs(['b'])  # no interface, should still match

            @provides
            def bbb(self):
                return self.deps.b()
Beispiel #16
0
        class SimpleService(Service):
            deps = Needs('some_number')

            @provides
            def multiplied_number(self):
                return self.deps.some_number() * 100
Beispiel #17
0
        class Dog(Service):
            deps = Needs(['number'])

            @provides
            def bark(self):
                return ('woof ' * self.deps.number()).strip()