Beispiel #1
0
def test_dispatch():
    global called_default
    called_default = False

    def handler_default(*args, **kwargs):
        global called_default
        called_default = True
        return

    global called
    called = False

    def handler(*args, **kwargs):
        global called
        called = True
        return args[0]

    hooks.register_default("test_hook", handler_default)
    hooks.register("test_hook", handler)

    hooks.dispatch("test_hook", 1)
    assert not called_default
    assert called
    called_default = False
    called = False
    hooks.dispatch("test_hook", None)
    assert called_default
    assert called
Beispiel #2
0
        def wrapper(**urlargs):
            fmt = urlargs.pop("fmt") if "fmt" in urlargs else "json"

            urlargs.update(bottle.request.query)

            if method in ("POST", "PUT"):
                body = bottle.request.body.read().decode("utf8")
                data = dispatch("decode_data", fmt, body)
                result = func(data, **urlargs)
            else:
                result = func(**urlargs)

            bottle.response.content_type = "application/" + fmt

            return dispatch("encode_data", fmt, result)