示例#1
0
    class Bookshelf(XMLDoc):
        class Iterable(XMLDoc):
            __name__ = "Book"
            __query__ = "/bookshelf/book"

            class Iterable(XMLDoc):
                __query__ = "chapter"

                id = QueryAttr("@id")
                text = QueryAttr("text()")

            isbn = QueryAttr("isbn/text()")
            title = QueryAttr("title/text()")
            author = QueryAttr("author/text()")
            chapters = QueryAttr("chapter[@id]/text()")

            @QueryAttr("author/text()")
            def author_first_name(self, value):
                return value.split(", ")[1]

            @QueryAttr("author/text()")
            def author_last_name(self, value):
                return value.split(", ")[0]

        name = QueryAttr("/bookshelf/name/text()")
        undefined = QueryAttr("/bookshelf/undefined/text()")
示例#2
0
    class Bookshelf(TextDoc):
        class Iterable(TextDoc):
            __query__ = "<book>(.*?)</book>"

            class Iterable(TextDoc):
                __query__ = "<chapter[^>]*>.*?</chapter>"

                id = QueryAttr('<chapter[^>]+id="([^\"]*)"')
                text = QueryAttr(">(.*)</chapter>")

            isbn = QueryAttr("<isbn>(.*?)</isbn>")
            title = QueryAttr("<title>(.*?)</title>")
            author = QueryAttr("<author>(.*?)</author>")
            revisions = QueryAttr("<rev>(\d+)</rev>")
            name_tuple = QueryAttr("<author>([^,]+),\s*(.+?)</author>")
            name_dict = QueryAttr(
                "<author>(?P<lastname>[^,]+),\s*(?P<firstname>.+?)</author>")

            @QueryAttr("<author>(.*?)</author>")
            def author_first_name(self, value):
                return value.split(", ")[1]

            @QueryAttr("<author>(.*?)</author>")
            def author_last_name(self, value):
                return value.split(", ")[0]

        name = QueryAttr("<name>(.*?)</name>")
        undefined = QueryAttr("<undefined>(.*?)</undefined>")
示例#3
0
            class Iterable(YAMLDoc):
                __query__ = "$.books"

                isbn = QueryAttr("$.isbn")
                title = QueryAttr("$.title")
                author = QueryAttr("$.author")

                @QueryAttr("$.author")
                def author_first_name(self, value):
                    return value.split(", ")[1]

                @QueryAttr("$.author")
                def author_last_name(self, value):
                    return value.split(", ")[0]
示例#4
0
    def test_should_return_return_of_decorated_function(self):
        def foo(self, value):
            return value.upper()

        self.Data.foo = QueryAttr("bar")(foo)

        self.assertEqual(self.Data().foo, "FOOBAR")
示例#5
0
            class Iterable(TextDoc):
                __query__ = "<chapter[^>]*>.*?</chapter>"

                id = QueryAttr('<chapter[^>]+id="([^\"]*)"')
                text = QueryAttr(">(.*)</chapter>")
示例#6
0
        class MyDoc(CsvRow):
            @QueryAttr("Foo")
            def foo(self, value):
                return int(value)

            bar = QueryAttr("Bar", factory=float)
示例#7
0
 class MyDoc(CsvRow):
     foo = QueryAttr(0)
     bar = QueryAttr(1)
示例#8
0
            class Iterable(XMLDoc):
                __query__ = "chapter"

                id = QueryAttr("@id")
                text = QueryAttr("text()")
示例#9
0
    def test_should_return_query_of_obj(self):
        self.Data.foo = QueryAttr("bar")

        self.assertEqual(self.Data().foo, "foobar")