Exemplo n.º 1
0
 def raw_execute(self, source):
     transport = Transport.from_source(source)
     args = [bender(source) for bender in self._positional_benders]
     kwargs = {k: bender(source)
               for k, bender in iteritems(self._named_benders)}
     value = self._format_str.format(*args, **kwargs)
     return Transport(value, transport.context)
Exemplo n.º 2
0
 def raw_execute(self, source):
     transport = Transport.from_source(source)
     args = [bender(source) for bender in self._positional_benders]
     kwargs = {
         k: bender(source)
         for k, bender in iteritems(self._named_benders)
     }
     value = self._format_str.format(*args, **kwargs)
     return Transport(value, transport.context)
Exemplo n.º 3
0
def _bend(mapping, transport):
    res = {}
    for k, value in iteritems(mapping):
        if isinstance(value, Bender):
            try:
                newv = value(transport)
            except Exception as e:
                m = 'Error for key {}: {}'.format(k, str(e))
                raise BendingException(m)
        elif isinstance(value, list):
            newv = list(map(lambda v: _bend(v, transport), value))
        elif isinstance(value, dict):
            newv = _bend(value, transport)
        else:
            newv = value
        res[k] = newv
    return res
Exemplo n.º 4
0
def _bend(mapping, transport):
    res = {}
    for k, value in iteritems(mapping):
        if isinstance(value, Bender):
            try:
                newv = value(transport)
            except Exception as e:
                m = "Error for key {}: {}".format(k, str(e))
                raise BendingException(m)
        elif isinstance(value, list):
            newv = map(lambda v: _bend(v, transport), value)
        elif isinstance(value, dict):
            newv = _bend(value, transport)
        else:
            newv = value
        res[k] = newv
    return res
Exemplo n.º 5
0
def _bend(mapping, transport):
    if isinstance(mapping, list):
        return [_bend(v, transport) for v in mapping]

    elif isinstance(mapping, dict):
        res = {}
        for k, v in iteritems(mapping):
            try:
                res[k] = _bend(v, transport)
            except Exception as e:
                m = 'Error for key {}: {}'.format(k, str(e))
                raise BendingException(m)
        return res

    elif isinstance(mapping, Bender):
        return mapping(transport)

    else:
        return mapping