예제 #1
0
    def combine(self, cases):
        strict = [strategy.ordered_signatures,strategy.safe_methods]
        loose  = [strategy.ordered_signatures,strategy.all_methods]

        primary_names = ['primary%d' % order for order in self.order_when]
        around_names = ['around%d' % order for order in self.order_around]

        cases = strategy.separate_qualifiers(
            cases,
            before = loose, after =loose,
            **dict(izip(ichain(primary_names, around_names), repeat(strict)))
        )

        primary = strategy.method_chain(ichain(
                    *[cases.get(primary, []) for primary in primary_names]))

        if cases.get('after') or cases.get('before'):

            befores = strategy.method_list(cases.get('before',[]))
            afters = strategy.method_list(list(cases.get('after',[]))[::-1])

            def chain(*args,**kw):
                for tmp in befores(*args,**kw): pass  # toss return values
                result = primary(*args,**kw)
                for tmp in afters(*args,**kw): pass  # toss return values
                return result

        else:
            chain = primary

        if (self.order_around):
            chain = strategy.method_chain(ichain(*([cases.get(around, [])
                                    for around in around_names] + [[chain]])))

        return chain
예제 #2
0
 def combine(self, cases):
     strict = [strategy.ordered_signatures, strategy.safe_methods]
     cases = strategy.separate_qualifiers(
         cases,
         primary=strict,
     )
     primary = strategy.method_chain(cases.get('primary', []))
     if type(primary) != types.FunctionType:
         for i in primary:
             for y in i:
                 return y[1]
     return primary
예제 #3
0
 def combine(self, cases):
     strict = [strategy.ordered_signatures, strategy.safe_methods]
     cases = strategy.separate_qualifiers(
         cases,
         primary = strict,
     )
     primary = strategy.method_chain(cases.get('primary', []))
     if type(primary) != types.FunctionType:
         for i in primary:
             for y in i:
                 return y[1]
     return primary
예제 #4
0
    def combine(self, cases):
        strict = [strategy.ordered_signatures, strategy.safe_methods]
        loose = [strategy.ordered_signatures, strategy.all_methods]

        primary_names = ['primary%d' % order for order in self.order_when]
        around_names = ['around%d' % order for order in self.order_around]

        cases = strategy.separate_qualifiers(
            cases,
            before=loose,
            after=loose,
            **dict(izip(ichain(primary_names, around_names), repeat(strict))))

        primary = strategy.method_chain(
            ichain(*[cases.get(primary, []) for primary in primary_names]))

        if cases.get('after') or cases.get('before'):

            befores = strategy.method_list(cases.get('before', []))
            afters = strategy.method_list(list(cases.get('after', []))[::-1])

            def chain(*args, **kw):
                for tmp in befores(*args, **kw):
                    pass  # toss return values
                result = primary(*args, **kw)
                for tmp in afters(*args, **kw):
                    pass  # toss return values
                return result

        else:
            chain = primary

        if (self.order_around):
            chain = strategy.method_chain(
                ichain(*([cases.get(around, [])
                          for around in around_names] + [[chain]])))

        return chain