mirror of https://github.com/scrapy/scrapy.git
Rename "regexp" prefix to "re"
This commit is contained in:
parent
88c8a523a7
commit
827c0cf51f
|
|
@ -250,7 +250,7 @@ and come with these pre-registered namespaces to use in XPath expressions:
|
|||
====== ==================================== =======================
|
||||
prefix namespace usage
|
||||
====== ==================================== =======================
|
||||
regexp http://exslt.org/regular-expressions `regular expressions`_
|
||||
re http://exslt.org/regular-expressions `regular expressions`_
|
||||
set http://exslt.org/sets `set manipulation`_
|
||||
====== ==================================== =======================
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ Example selecting links in list item with a "class" attribute ending with a digi
|
|||
>>> sel = Selector(text=doc, type="html")
|
||||
>>> sel.xpath('//li//@href').extract()
|
||||
[u'link1.html', u'link2.html', u'link3.html', u'link4.html', u'link5.html']
|
||||
>>> sel.xpath('//li[regexp:test(@class, "item-\d$")]//@href').extract()
|
||||
>>> sel.xpath('//li[re:test(@class, "item-\d$")]//@href').extract()
|
||||
[u'link1.html', u'link2.html', u'link4.html', u'link5.html']
|
||||
>>>
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class Selector(object_ref):
|
|||
|
||||
_default_type = None
|
||||
_default_namespaces = {
|
||||
"regexp": "http://exslt.org/regular-expressions",
|
||||
"re": "http://exslt.org/regular-expressions",
|
||||
|
||||
# supported in libxslt:
|
||||
# set:difference
|
||||
|
|
|
|||
|
|
@ -352,36 +352,36 @@ class ExsltTestCase(unittest.TestCase):
|
|||
response = TextResponse(url="http://example.com", body=body)
|
||||
sel = self.sscls(response)
|
||||
|
||||
# regexp:test()
|
||||
# re:test()
|
||||
self.assertEqual(
|
||||
sel.xpath(
|
||||
'//input[regexp:test(@name, "[A-Z]+", "i")]').extract(),
|
||||
[x.extract() for x in sel.xpath('//input[regexp:test(@name, "[A-Z]+", "i")]')])
|
||||
'//input[re:test(@name, "[A-Z]+", "i")]').extract(),
|
||||
[x.extract() for x in sel.xpath('//input[re:test(@name, "[A-Z]+", "i")]')])
|
||||
self.assertEqual(
|
||||
[x.extract()
|
||||
for x in sel.xpath(
|
||||
'//a[regexp:test(@href, "\.html$")]/text()')],
|
||||
'//a[re:test(@href, "\.html$")]/text()')],
|
||||
[u'first link', u'second link'])
|
||||
self.assertEqual(
|
||||
[x.extract()
|
||||
for x in sel.xpath(
|
||||
'//a[regexp:test(@href, "first")]/text()')],
|
||||
'//a[re:test(@href, "first")]/text()')],
|
||||
[u'first link'])
|
||||
self.assertEqual(
|
||||
[x.extract()
|
||||
for x in sel.xpath(
|
||||
'//a[regexp:test(@href, "second")]/text()')],
|
||||
'//a[re:test(@href, "second")]/text()')],
|
||||
[u'second link'])
|
||||
|
||||
|
||||
# regexp:match() is rather special: it returns a node-set of <match> nodes
|
||||
# re:match() is rather special: it returns a node-set of <match> nodes
|
||||
#[u'<match>http://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.xml</match>',
|
||||
#u'<match>http</match>',
|
||||
#u'<match>www.bayes.co.uk</match>',
|
||||
#u'<match></match>',
|
||||
#u'<match>/xml/index.xml?/xml/utils/rechecker.xml</match>']
|
||||
self.assertEqual(
|
||||
sel.xpath('regexp:match(//a[regexp:test(@href, "\.xml$")]/@href,'
|
||||
sel.xpath('re:match(//a[re:test(@href, "\.xml$")]/@href,'
|
||||
'"(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)")/text()').extract(),
|
||||
[u'http://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.xml',
|
||||
u'http',
|
||||
|
|
@ -391,9 +391,9 @@ class ExsltTestCase(unittest.TestCase):
|
|||
|
||||
|
||||
|
||||
# regexp:replace()
|
||||
# re:replace()
|
||||
self.assertEqual(
|
||||
sel.xpath('regexp:replace(//a[regexp:test(@href, "\.xml$")]/@href,'
|
||||
sel.xpath('re:replace(//a[re:test(@href, "\.xml$")]/@href,'
|
||||
'"(\w+)://(.+)(\.xml)", "","https://\\2.html")').extract(),
|
||||
[u'https://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.html'])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue