Exemplo n.º 1
0
def test_should_return_get_bindings_from_source(mocker: MagicMock) -> None:
    bindings = [{
        'source': 'one-s',
        'destination': 'one-d',
        'routing_key': 'one-r',
        'destination_type': 'queue',
        'arguments': None
    }, {
        'source': 'two-s',
        'destination': 'two-d',
        'routing_key': 'two-r',
        'destination_type': 'exchange',
        'arguments': None
    }]
    response = mock_response(bindings)
    patch = mocker.patch('requests.get', return_value=response)
    result = map(
        lambda i: i.to_dict(),
        get_bindings_from_source(broker=fake_broker(),
                                 vhost='EA',
                                 source='test'))
    assert_that(result).is_equal_to(bindings)
    patch.assert_called_with(
        url='https://fake-broker/api/exchanges/EA/test/bindings/source',
        auth=('guest', 'guest'))
Exemplo n.º 2
0
def get_vhosts(broker: dict) -> dict:
    url = 'https://{}/api/vhosts'.format(broker['host'])
    response: requests.Response = requests.get(url=url,
                                               auth=(broker['user'],
                                                     broker['passwd']))
    if not response.ok:
        # noinspection PyTypeChecker
        raise ServerErrorException(str(response.status_code), url=url)
    return map(lambda i: i['name'], response.json())
Exemplo n.º 3
0
def test_should_return_empty_list_when_get_bindings_but_no_bindings(
        mocker: MagicMock) -> None:
    bindings: List[dict] = []
    response = mock_response(bindings)
    patch = mocker.patch('requests.get', return_value=response)
    result = map(lambda i: i.to_dict(),
                 get_bindings(broker=fake_broker(), vhost='EA'))
    assert_that(result).is_equal_to([])
    patch.assert_called_with(url='https://fake-broker/api/bindings/EA',
                             auth=('guest', 'guest'))
Exemplo n.º 4
0
 def wrapper(x):
     base_opts = pipe(prop('figures'), prop(fig_name),
                      A.andop(r.map(prop, ('x_range', 'y_range'))),
                      c.zip(('x_range', 'y_range')), dict)(x.value)
     fig = bkp.figure(**base_opts, **opts)
     df = pd.DataFrame({
         'figures': [fig],
         'circles': [None]
     },
                       index=[fig.name])
     return df
Exemplo n.º 5
0
# print one vote
# print data[0]

# list the category types
# R.pipe(
#     R.map(R.prop('category')),
#     hist_list
# )(data)

# filter data for only the amendments
amendments = R.filter(R.propEq('category', 'amendment'), data)

# all the passing amendments and the ratio of yes votes
passing = R.pipe(
    R.filter(amendment_passed),
    R.map(yes_ratio)
)(amendments)

# all the failing amendments and the ratio of yes votes
failing = R.pipe(
    R.filter(amendment_failed),
    R.map(yes_ratio)
)(amendments)

# the percent of nonconsenting voters
dissatisfied_passing = R.map(lambda x: 1 - x, passing)
dissatisfied = R.mean(dissatisfied_passing + failing)

# plot a histogram
bins = 200
bins = np.linspace(0.0, 1.0, bins)
Exemplo n.º 6
0
def get_bindings(broker: dict, vhost: str) -> List[Binding]:
    url = 'https://{}/api/bindings/{}'.format(broker['host'], vhost)
    response = requests.get(url=url, auth=(broker['user'], broker['passwd']))
    handle_rest_response(response=response, url=url)
    return map(lambda i: Binding(i), response.json())
Exemplo n.º 7
0
#!/usr/bin/env python

from bs4 import BeautifulSoup
# from urllib.request import urlopen
import re
import sys
from pyramda import map, inc

html_page = ""
for line in sys.stdin:
    html_page += line

# html_page = urlopen("https://files.d3engineering.com/stable")
soup = BeautifulSoup(html_page, features="lxml")

links = map(lambda x: x.get('href'), soup.find_all('a'))
_, *links = links
links = filter(lambda x: x.endswith('/'), links)
*links, tail = list(links)
print(tail[:-1])
Exemplo n.º 8
0
def get_users(broker: dict) -> dict:
    url = 'https://{}/api/users'.format(broker['host'])
    response = requests.get(url=url, auth=(broker['user'], broker['passwd']))
    handle_rest_response(response=response, url=url)
    return map(lambda i: i['name'], response.json())
Exemplo n.º 9
0
Arquivo: mn.py Projeto: flintc/sandbox
 def invoker(x):
     result = r.map(self.decorator(fn), self._fn(x))
     return result
Exemplo n.º 10
0
 def map(self,fn):
     return type(self)( tuple(r.map(curry(fn),self.value))  )
Exemplo n.º 11
0

@r.curry
def node_transformer(fn,data):
    print(f'f: {data!r}')
    # if not isinstance(data,Traversable) and not isinstance(data,Applicative):
    #     return fn(data)
    if isinstance(data,Traversable):
        return fn(data)
    return data

a = Applicative.of(10)
b = Applicative.of(r.add)
rand = lambda x: Applicative.of(random.random()*x)

t = Traversable( tuple(r.map(Applicative.of,(1,2,3)) ))
to = t.traverse(fmap(r.add(9)))

aps = Applicative.of( Applicative.of( Traversable( (10,11)  )) )
ts = Traversable( ( Traversable.of(9) , 8, Traversable.of(Traversable.of(1)))  )
ts2 = Traversable( ( Traversable( (9,Traversable.of(10)) ) , Traversable.of(8), Traversable.of(Traversable.of(1)))  )

ts3 = Applicative(( 
    Applicative.of( (9,) ) , 
    Applicative.of( (8,) ), 
    Applicative.of( 
        ( Applicative.of( (1,) ), )  
    )))

@r.curry
def freduce(fn,start_value,this):
Exemplo n.º 12
0
Arquivo: vhdl.py Projeto: peteut/migen
def _printexpr_operator(node, ctx):
    thint = get("thint", ctx)
    arity = len(node.operands)
    if arity == 1:
        r1 = _printexpr(node.operands[0],
                        merge(ctx, dict(lhs=False,
                                        thint=_THint.logic,
                                        lhint=None)))
        if node.op == "-":
            expr = "(-{})".format(_signed(r1))
            if thint == _THint.un_signed:
                return expr
            elif thint == _THint.integer:
                return _to_integer(expr)
            elif thint == _THint.logic:
                return _std_logic_vector(expr)
            else:
                return expr
        else:
            expr = "{} {}".format(_get_op(node), r1)
            if thint == _THint.un_signed:
                return _unsigned(expr)
            elif thint == _THint.integer:
                return _fn_call("to_integer", _unsigned(expr))
            elif thint == _THint.boolean:
                return _fn_call("\\??\\", expr)
            else:
                return "({})".format(expr)
    elif arity == 2:
        if _is_bitwise_op(node):
            r1, r2 = pipe(
                [node, ctx],
                juxt([
                    comp(attrgetter("operands"), first),
                    comp(repeat, flip(merge, dict(lhs=False,
                                                  thint=_THint.logic,
                                                  lhint=None)), second),
                ]), R.apply(zip), map(R.apply(_printexpr)))
            expr = pipe([r1, _get_op(node), r2], " ".join)
            if thint == _THint.un_signed:
                return _unsigned(expr)
            elif thint == _THint.integer:
                return _fn_call("to_integer", expr)
            else:
                return expr
        elif _is_comp_op(node):
            if pipe(node.operands, R.all_satisfy(comp(R.equals(1), len))):
                r1, r2 = pipe(
                    [node, ctx],
                    juxt([
                        comp(attrgetter("operands"), first),
                        comp(repeat, flip(merge, dict(lhs=False,
                                                      thint=_THint.logic,
                                                      lhint=None)), second),
                    ]), R.apply(zip), R.map(R.apply(_printexpr)))
            else:
                r1, r2 = pipe(
                    [node, ctx],
                    juxt([
                        comp(attrgetter("operands"), first),
                        comp(repeat, second)]), R.apply(zip),
                    map(juxt([
                        first,
                        comp(
                            R.apply(merge),
                            juxt([
                                second,
                                R.always(dict(lhs=False, lhint=None)),
                                R.if_else(
                                    comp(R.isinstance(Constant), first),
                                    R.always(dict(thint=_THint.integer)),
                                    R.always(dict(thint=_THint.un_signed)))
                            ]))])),
                    map(R.apply(_printexpr)))
            if thint == _THint.logic:
                return _fn_call(pipe(node, _get_op, "\\?{}\\".format), r1, r2)
            else:
                return pipe([r1, _get_op(node), r2], " ".join)
        elif _is_shift_op(node):
            r1, r2 = pipe(
                [node, ctx],
                juxt([
                    comp(attrgetter("operands"), first),
                    comp(repeat, second)]), R.apply(zip),
                map(juxt([
                    first,
                    comp(
                        R.apply(merge),
                        juxt([
                            second,
                            R.always(dict(lhs=False, lhint=None)),
                            R.if_else(
                                comp(R.isinstance(Constant), first),
                                R.always(dict(thint=_THint.integer)),
                                R.always(dict(thint=_THint.un_signed)))
                        ]))])),
                map(R.apply(_printexpr)))
            expr = _fn_call(_shift_op[node.op], r1, r2)
            if thint == _THint.integer:
                return _fn_call("to_integer", expr)
            elif thint == _THint.logic:
                return _std_logic_vector(expr)
            else:
                return expr
        elif _is_arith_op(node):
            r1, r2 = pipe(
                node.operands,
                map(lambda x:
                    _printexpr(x,
                               merge(ctx,
                                     dict(lhs=False,
                                          thint=_THint.integer
                                          if R.isinstance(Constant, x)
                                          else _THint.un_signed,
                                          lhint=None)))))
            expr = pipe([r1, _arith_op_map[node.op], r2], " ".join)
            if thint == _THint.integer:
                return _fn_call("to_integer", expr)
            elif thint == _THint.logic:
                return _std_logic_vector(expr)
            else:
                return expr

    raise TypeError("unkown operator: {}, arity: {}".format(node, arity))
Exemplo n.º 13
0
Arquivo: vhdl.py Projeto: peteut/migen
def _printexpr_operator(node, ctx):
    thint = get("thint", ctx)
    arity = len(node.operands)
    if arity == 1:
        r1 = _printexpr(
            node.operands[0],
            merge(ctx, dict(lhs=False, thint=_THint.logic, lhint=None)))
        if node.op == "-":
            expr = "(-{})".format(_signed(r1))
            if thint == _THint.un_signed:
                return expr
            elif thint == _THint.integer:
                return _to_integer(expr)
            elif thint == _THint.logic:
                return _std_logic_vector(expr)
            else:
                return expr
        else:
            expr = "{} {}".format(_get_op(node), r1)
            if thint == _THint.un_signed:
                return _unsigned(expr)
            elif thint == _THint.integer:
                return _fn_call("to_integer", _unsigned(expr))
            elif thint == _THint.boolean:
                return _fn_call("\\??\\", expr)
            else:
                return "({})".format(expr)
    elif arity == 2:
        if _is_bitwise_op(node):
            r1, r2 = pipe([node, ctx],
                          juxt([
                              comp(attrgetter("operands"), first),
                              comp(
                                  repeat,
                                  flip(
                                      merge,
                                      dict(lhs=False,
                                           thint=_THint.logic,
                                           lhint=None)), second),
                          ]), R.apply(zip), map(R.apply(_printexpr)))
            expr = pipe([r1, _get_op(node), r2], " ".join)
            if thint == _THint.un_signed:
                return _unsigned(expr)
            elif thint == _THint.integer:
                return _fn_call("to_integer", expr)
            else:
                return expr
        elif _is_comp_op(node):
            if pipe(node.operands, R.all_satisfy(comp(R.equals(1), len))):
                r1, r2 = pipe([node, ctx],
                              juxt([
                                  comp(attrgetter("operands"), first),
                                  comp(
                                      repeat,
                                      flip(
                                          merge,
                                          dict(lhs=False,
                                               thint=_THint.logic,
                                               lhint=None)), second),
                              ]), R.apply(zip), R.map(R.apply(_printexpr)))
            else:
                r1, r2 = pipe(
                    [node, ctx],
                    juxt([
                        comp(attrgetter("operands"), first),
                        comp(repeat, second)
                    ]), R.apply(zip),
                    map(
                        juxt([
                            first,
                            comp(
                                R.apply(merge),
                                juxt([
                                    second,
                                    R.always(dict(lhs=False, lhint=None)),
                                    R.if_else(
                                        comp(R.isinstance(Constant), first),
                                        R.always(dict(thint=_THint.integer)),
                                        R.always(dict(thint=_THint.un_signed)))
                                ]))
                        ])), map(R.apply(_printexpr)))
            if thint == _THint.logic:
                return _fn_call(pipe(node, _get_op, "\\?{}\\".format), r1, r2)
            else:
                return pipe([r1, _get_op(node), r2], " ".join)
        elif _is_shift_op(node):
            r1, r2 = pipe(
                [node, ctx],
                juxt([
                    comp(attrgetter("operands"), first),
                    comp(repeat, second)
                ]), R.apply(zip),
                map(
                    juxt([
                        first,
                        comp(
                            R.apply(merge),
                            juxt([
                                second,
                                R.always(dict(lhs=False, lhint=None)),
                                R.if_else(
                                    comp(R.isinstance(Constant), first),
                                    R.always(dict(thint=_THint.integer)),
                                    R.always(dict(thint=_THint.un_signed)))
                            ]))
                    ])), map(R.apply(_printexpr)))
            expr = _fn_call(_shift_op[node.op], r1, r2)
            if thint == _THint.integer:
                return _fn_call("to_integer", expr)
            elif thint == _THint.logic:
                return _std_logic_vector(expr)
            else:
                return expr
        elif _is_arith_op(node):
            r1, r2 = pipe(
                node.operands,
                map(lambda x: _printexpr(
                    x,
                    merge(
                        ctx,
                        dict(lhs=False,
                             thint=_THint.integer if R.isinstance(Constant, x)
                             else _THint.un_signed,
                             lhint=None)))))
            expr = pipe([r1, _arith_op_map[node.op], r2], " ".join)
            if thint == _THint.integer:
                return _fn_call("to_integer", expr)
            elif thint == _THint.logic:
                return _std_logic_vector(expr)
            else:
                return expr

    raise TypeError("unkown operator: {}, arity: {}".format(node, arity))