示例#1
0
    def input(self):
        """
        Request content that has been parsed into a python object.
        This is a read-only property.
        """
        parsed = tryeach([getattr(ctx.resource, "parser", Parser()), ctx.dispatcher.parser], self.data)[1]

        process = DataPipe(getattr(ctx.resource, "pre_processor", None), ctx.dispatcher.pre_processor)

        return process(parsed)
示例#2
0
def test_correct_parser_chosen(app, content_type, parser_args, expected, opts):
    builder = EnvironBuilder(content_type=content_type)
    results = []

    parsers = []
    for pa in parser_args:
        p = Parser()
        for mime in pa:
            @p.register(mime)
            def do_parse(data, **opts):
                results.append(opts)
        parsers.append(p)

    parse = lambda s: tryeach(parsers, s)

    with app.build_context(builder.get_environ()):
        if isinstance(expected, type) and issubclass(expected, Exception):
            with pytest.raises(expected):
                print(parse(""))

        else:
            mime, parser = parse("")
            assert mime == expected
            assert opts == results.pop()