本文整理汇总了Python中eulexistdb.query.Xquery类的典型用法代码示例。如果您正苦于以下问题:Python Xquery类的具体用法?Python Xquery怎么用?Python Xquery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Xquery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_namespaces
def test_namespaces(self):
xq = Xquery(xpath='/foo:el', namespaces={'foo': 'urn:foo#'})
ns_declaration = '''declare namespace foo='urn:foo#';'''
# xpath-only xquery should have namespace declaration
self.assert_(ns_declaration in xq.getQuery())
# full FLOWR xquery should also have declaration
xq.return_only({'id': '@id'})
self.assert_(ns_declaration in xq.getQuery())
示例2: test_filter_in
def test_filter_in(self):
xq = Xquery(xpath='/el')
xq.add_filter('@id', 'in', ['a', 'b', 'c'])
self.assertEquals('/el[contains(("a","b","c"), @id)]', xq.getQuery())
# filter on a 'special' field - requires let & where statements
xq = Xquery(xpath='/el')
xq.add_filter('document_name', 'in', ['a.xml', 'b.xml'])
self.assert_('let $document_name' in xq.getQuery())
self.assert_('where contains(("a.xml","b.xml"), $document_name)' in xq.getQuery())
示例3: test_filter_in
def test_filter_in(self):
xq = Xquery(xpath='/el')
xq.add_filter('@id', 'in', ['a', 'b', 'c'])
self.assertEquals('/el[@id="a" or @id="b" or @id="c"]', xq.getQuery())
# filter on a 'special' field - requires let & where statements
xq = Xquery(xpath='/el')
xq.add_filter('document_name', 'in', ['a.xml', 'b.xml'])
self.assert_('let $document_name' in xq.getQuery())
self.assert_('where $document_name="a.xml" or $document_name="b.xml"'
in xq.getQuery())
示例4: test_filter_exists
def test_filter_exists(self):
xq = Xquery(xpath='/el')
xq.add_filter('@id', 'exists', True)
self.assertEquals('/el[@id]', xq.getQuery())
xq = Xquery(xpath='/el')
xq.add_filter('@id', 'exists', False)
self.assertEquals('/el[not(@id)]', xq.getQuery())
示例5: test_not_filters
def test_not_filters(self):
xq = Xquery(xpath='/el')
xq.add_filter('.', 'contains', 'dog', mode='NOT')
self.assertEquals('/el[not(contains(., "dog"))]', xq.getQuery())
xq = Xquery(xpath='/el')
xq.add_filter('.', 'contains', 'dog', mode='NOT')
xq.add_filter('.', 'startswith', 'S', mode='NOT')
self.assertEquals('/el[not(contains(., "dog") or starts-with(., "S"))]',
xq.getQuery())
示例6: test_filters
def test_filters(self):
xq = Xquery(xpath='/el')
xq.add_filter('.', 'contains', 'dog')
self.assertEquals('/el[contains(., "dog")]', xq.getQuery())
# filters are additive
xq.add_filter('.', 'startswith', 'S')
self.assertEquals('/el[contains(., "dog")][starts-with(., "S")]', xq.getQuery())
示例7: test_return_only
def test_return_only(self):
xq = Xquery(xpath='/el')
xq.xq_var = '$n'
xq.return_only({'myid': '@id', 'some_name': 'name',
'first_letter': 'substring(@n,1,1)'})
xq_return = xq._constructReturn()
self.assert_('return <el>' in xq_return)
self.assert_('<field>{$n/@id}</field>' in xq_return)
self.assert_('<field>{$n/name}</field>' in xq_return)
self.assert_('<field>{substring($n/@n,1,1)}</field>' in xq_return)
self.assert_('</el>' in xq_return)
xq = Xquery(xpath='/some/el/notroot')
xq.return_only({'id': '@id'})
self.assert_('return <notroot>' in xq._constructReturn())
示例8: test_return_also
def test_return_also(self):
xq = Xquery(xpath='/el')
xq.xq_var = '$n'
xq.return_also({'myid': '@id', 'some_name': 'name'})
self.assert_('{$n}' in xq._constructReturn())
self.assert_('<field>{$n/@id}</field>' in xq._constructReturn())
示例9: test_xpath
def test_xpath(self):
xq = Xquery(xpath='/path/to/el')
self.assertEquals('/path/to/el', xq.getQuery())
示例10: test_prep_xpath
def test_prep_xpath(self):
xq = Xquery()
xq.xq_var = '$n'
# handle attributes
self.assertEqual('<field>{$n/@id}</field>', xq.prep_xpath('@id', return_field=True))
self.assertEqual('<field>{$n/../@id}</field>', xq.prep_xpath('../@id', return_field=True))
self.assertEqual('<field>{$n/parent::root/@id}</field>', xq.prep_xpath('parent::root/@id', return_field=True))
# handle regular nodes
self.assertEqual('<field>{$n/title}</field>', xq.prep_xpath('title', return_field=True))
# function call - regular node
self.assertEqual('substring($n/title,1,1)', xq.prep_xpath('substring(title,1,1)'))
# function call - abbreviated step
self.assertEqual('substring($n/.,1,1)', xq.prep_xpath('substring(.,1,1)'))
# xpath with OR - absolute paths
self.assertEqual('<field>{$n/name|$n/title}</field>', xq.prep_xpath('/name|/title', return_field=True))
# xpath with OR - relative paths
self.assertEqual('<field>{$n/name|$n/title}</field>', xq.prep_xpath('name|title', return_field=True))
# xpath with OR - mixed absolute and relative paths
self.assertEqual('<field>{$n/name|$n/title}</field>', xq.prep_xpath('/name|title', return_field=True))
# multiple ORs
self.assertEqual('<field>{$n/name|$n/title|$n/@year}</field>',
xq.prep_xpath('/name|/title|@year', return_field=True))
# .//node inside a function call
self.assertEqual('<field>{normalize-space($n/.//name)}</field>',
xq.prep_xpath('normalize-space($n/.//name)', return_field=True))
# node|node inside a function call
self.assertEqual('fn:lower-case($n/name|$n/title)',
xq.prep_xpath('fn:lower-case(name|title)'))
示例11: test_clear_limits
def test_clear_limits(self):
xq = Xquery(xpath='/el')
xq.set_limits(low=2, high=5)
xq.clear_limits()
self.assertEqual('/el', xq.getQuery())
示例12: test_return_also_raw
def test_return_also_raw(self):
xq = Xquery(xpath='/el')
xq.xq_var = '$n'
xq._raw_prefix = 'r_'
xq.return_also({'myid': 'count(util:expand(%(xq_var)s/@id))'}, raw=True)
self.assert_('<r_myid>{count(util:expand($n/@id))}</r_myid>' in xq._constructReturn())
xq = Xquery(xpath='/el')
xq.xq_var = '$n'
xq._raw_prefix = 'r_'
xq.return_also({'myid': '@id'}, raw=True)
self.assert_('<r_myid>{@id}</r_myid>' in xq._constructReturn())
示例13: test_fulltext_options
def test_fulltext_options(self):
# pass in options for a full-text query
xq = Xquery(xpath='/el', fulltext_options={'default-operator': 'and'})
xq.add_filter('.', 'fulltext_terms', 'dog')
self.assert_('<default-operator>and</default-operator>' in xq.getQuery())
self.assert_('/el[ft:query(., "dog", $ft_options)]', xq.getQuery())
示例14: test_filters_fulltext
def test_filters_fulltext(self):
xq = Xquery(xpath='/el')
xq.add_filter('.', 'fulltext_terms', 'dog')
self.assertEquals('/el[ft:query(., "dog")]', xq.getQuery())
示例15: test_sort
def test_sort(self):
xq = Xquery(collection="mycoll")
xq.xq_var = '$n'
xq.sort('@id')
self.assert_('order by $n/@id ascending' in xq.getQuery())
self.assert_('collection("/db/mycoll")' in xq.getQuery())
# prep_xpath function should clean up more complicated xpaths
xq.sort('name|@id')
self.assert_('order by $n/name|$n/@id' in xq.getQuery())
# sort descending
xq.sort('@id', ascending=False)
self.assert_('order by $n/@id descending' in xq.getQuery())
# sort case-insensitive
xq.sort('@id', case_insensitive=True)
self.assert_('order by fn:lower-case($n/@id) ascending' in xq.getQuery())
# case-insensitive and descending
xq.sort('@id', case_insensitive=True, ascending=False)
self.assert_('order by fn:lower-case($n/@id) descending' in xq.getQuery())