mirror of https://github.com/scrapy/scrapy.git
rollback xmliter functions to private, we won\'t support multiples versions of xmliter
This commit is contained in:
parent
6db5a37cdb
commit
f7fbbfec29
|
|
@ -2,7 +2,7 @@ import os
|
|||
import libxml2
|
||||
from twisted.trial import unittest
|
||||
|
||||
from scrapy.utils.iterators import csviter, xmliter, xmliter_lxml, xmliter_regex
|
||||
from scrapy.utils.iterators import csviter, xmliter, _xmliter_lxml, _xmliter_regex
|
||||
from scrapy.http import XmlResponse, TextResponse
|
||||
from scrapy.tests import get_testdata
|
||||
|
||||
|
|
@ -91,11 +91,11 @@ class XmliterTestCase(unittest.TestCase):
|
|||
|
||||
|
||||
class RegexXmliterTestCase(XmliterTestCase):
|
||||
xmliter = staticmethod(xmliter_regex)
|
||||
xmliter = staticmethod(_xmliter_regex)
|
||||
|
||||
|
||||
class LxmlXmliterTestCase(XmliterTestCase):
|
||||
xmliter = staticmethod(xmliter_lxml)
|
||||
xmliter = staticmethod(_xmliter_lxml)
|
||||
try:
|
||||
import lxml
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from scrapy.utils.python import re_rsearch, str_to_unicode
|
|||
from scrapy.utils.response import body_or_str
|
||||
|
||||
|
||||
def xmliter_regex(obj, nodename):
|
||||
def _xmliter_regex(obj, nodename):
|
||||
"""Return a iterator of XPathSelector's over all nodes of a XML document,
|
||||
given tha name of the node to iterate. Useful for parsing XML feeds.
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ def xmliter_regex(obj, nodename):
|
|||
yield XmlXPathSelector(text=nodetext).select('//' + nodename)[0]
|
||||
|
||||
|
||||
def xmliter_lxml(obj, nodename):
|
||||
def _xmliter_lxml(obj, nodename):
|
||||
reader = _StreamReader(obj)
|
||||
iterable = etree.iterparse(reader, tag=nodename, encoding=reader.encoding)
|
||||
for _, node in iterable:
|
||||
|
|
@ -66,9 +66,9 @@ class _StreamReader(object):
|
|||
|
||||
try:
|
||||
from lxml import etree
|
||||
xmliter = xmliter_lxml
|
||||
xmliter = _xmliter_lxml
|
||||
except ImportError:
|
||||
xmliter = xmliter_regex
|
||||
xmliter = _xmliter_regex
|
||||
|
||||
|
||||
def csviter(obj, delimiter=None, headers=None, encoding=None):
|
||||
|
|
|
|||
Loading…
Reference in New Issue