Scrapy, a fast high-level web crawling & scraping framework for Python.
Using next() for Python 3 compatibility
alexanderlukanin13a958cb2c5df3
diff --git a/scrapy/core/engine.py b/scrapy/core/engine.pyindex fbb655651..2304a259d 100644--- a/scrapy/core/engine.py+++ b/scrapy/core/engine.py@@ -108,7 +108,7 @@ class ExecutionEngine(object):if slot.start_requests and not self._needs_backout(spider):try:- request = slot.start_requests.next()+ request = next(slot.start_requests)except StopIteration:slot.start_requests = Noneexcept Exception, exc:diff --git a/scrapy/tests/test_utils_iterators.py b/scrapy/tests/test_utils_iterators.pyindex 4ddd05693..af801804d 100644--- a/scrapy/tests/test_utils_iterators.py+++ b/scrapy/tests/test_utils_iterators.py@@ -61,7 +61,7 @@ class XmliterTestCase(unittest.TestCase):response = XmlResponse(url='http://mydummycompany.com', body=body)my_iter = self.xmliter(response, 'item')- node = my_iter.next()+ node = next(my_iter)node.register_namespace('g', 'http://base.google.com/ns/1.0')self.assertEqual(node.xpath('title/text()').extract(), ['Item 1'])self.assertEqual(node.xpath('description/text()').extract(), ['This is item 1'])@@ -77,10 +77,10 @@ class XmliterTestCase(unittest.TestCase):body = u"""<?xml version="1.0" encoding="UTF-8"?><products><product>one</product><product>two</product></products>"""iter = self.xmliter(body, 'product')- iter.next()- iter.next()+ next(iter)+ next(iter)- self.assertRaises(StopIteration, iter.next)+ self.assertRaises(StopIteration, next, iter)def test_xmliter_encoding(self):body = '<?xml version="1.0" encoding="ISO-8859-9"?>\n<xml>\n <item>Some Turkish Characters \xd6\xc7\xde\xdd\xd0\xdc \xfc\xf0\xfd\xfe\xe7\xf6</item>\n</xml>\n\n'@@ -122,9 +122,9 @@ class LxmlXmliterTestCase(XmliterTestCase):self.assertEqual(len(list(no_namespace_iter)), 0)namespace_iter = self.xmliter(response, 'image_link', 'http://base.google.com/ns/1.0')- node = namespace_iter.next()+ node = next(namespace_iter)self.assertEqual(node.xpath('text()').extract(), ['http://www.mydummycompany.com/images/item1.jpg'])- node = namespace_iter.next()+ node = next(namespace_iter)self.assertEqual(node.xpath('text()').extract(), ['http://www.mydummycompany.com/images/item2.jpg'])@@ -205,12 +205,12 @@ class UtilsCsvTestCase(unittest.TestCase):response = TextResponse(url="http://example.com/", body=body)iter = csviter(response)- iter.next()- iter.next()- iter.next()- iter.next()+ next(iter)+ next(iter)+ next(iter)+ next(iter)- self.assertRaises(StopIteration, iter.next)+ self.assertRaises(StopIteration, next, iter)def test_csviter_encoding(self):body1 = get_testdata('feeds', 'feed-sample4.csv')diff --git a/scrapy/tests/test_utils_python.py b/scrapy/tests/test_utils_python.pyindex 0e28a28e4..24e962754 100644--- a/scrapy/tests/test_utils_python.py+++ b/scrapy/tests/test_utils_python.py@@ -121,7 +121,7 @@ class UtilsPythonTestCase(unittest.TestCase):def test_weakkeycache(self):class _Weakme(object): pass_values = count()- wk = WeakKeyCache(lambda k: _values.next())+ wk = WeakKeyCache(lambda k: next(_values))k = _Weakme()v = wk[k]self.assertEqual(v, wk[k])diff --git a/scrapy/utils/defer.py b/scrapy/utils/defer.pyindex 1f37d6cd4..7d0dd77eb 100644--- a/scrapy/utils/defer.py+++ b/scrapy/utils/defer.py@@ -93,7 +93,7 @@ def iter_errback(iterable, errback, *a, **kw):it = iter(iterable)while 1:try:- yield it.next()+ yield next(it)except StopIteration:breakexcept:diff --git a/scrapy/utils/iterators.py b/scrapy/utils/iterators.pyindex 18fa56de4..03e98bbe2 100644--- a/scrapy/utils/iterators.py+++ b/scrapy/utils/iterators.py@@ -47,7 +47,7 @@ def csviter(obj, delimiter=None, headers=None, encoding=None):"""encoding = obj.encoding if isinstance(obj, TextResponse) else encoding or 'utf-8'def _getrow(csv_r):- return [str_to_unicode(field, encoding) for field in csv_r.next()]+ return [str_to_unicode(field, encoding) for field in next(csv_r)]lines = StringIO(body_or_str(obj, unicode=False))if delimiter:diff --git a/scrapy/xlib/ordereddict.py b/scrapy/xlib/ordereddict.pyindex 5b0303f5a..04e73defa 100644--- a/scrapy/xlib/ordereddict.py+++ b/scrapy/xlib/ordereddict.py@@ -1,127 +1,127 @@-# Copyright (c) 2009 Raymond Hettinger-#-# Permission is hereby granted, free of charge, to any person-# obtaining a copy of this software and associated documentation files-# (the "Software"), to deal in the Software without restriction,-# including without limitation the rights to use, copy, modify, merge,-# publish, distribute, sublicense, and/or sell copies of the Software,-# and to permit persons to whom the Software is furnished to do so,-# subject to the following conditions:-#-# The above copyright notice and this permission notice shall be-# included in all copies or substantial portions of the Software.-#-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES-# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT-# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,-# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR-# OTHER DEALINGS IN THE SOFTWARE.--from UserDict import DictMixin--class OrderedDict(dict, DictMixin):-- def __init__(self, *args, **kwds):- if len(args) > 1:- raise TypeError('expected at most 1 arguments, got %d' % len(args))- try:- self.__end- except AttributeError:- self.clear()- self.update(*args, **kwds)-- def clear(self):- self.__end = end = []- end += [None, end, end] # sentinel node for doubly linked list- self.__map = {} # key --> [key, prev, next]- dict.clear(self)-- def __setitem__(self, key, value):- if key not in self:- end = self.__end- curr = end[1]- curr[2] = end[1] = self.__map[key] = [key, curr, end]- dict.__setitem__(self, key, value)-- def __delitem__(self, key):- dict.__delitem__(self, key)- key, prev, next = self.__map.pop(key)- prev[2] = next- next[1] = prev-- def __iter__(self):- end = self.__end- curr = end[2]- while curr is not end:- yield curr[0]- curr = curr[2]-- def __reversed__(self):- end = self.__end- curr = end[1]- while curr is not end:- yield curr[0]- curr = curr[1]-- def popitem(self, last=True):- if not self:- raise KeyError('dictionary is empty')- if last:- key = reversed(self).next()- else:- key = iter(self).next()- value = self.pop(key)- return key, value-- def __reduce__(self):- items = [[k, self[k]] for k in self]- tmp = self.__map, self.__end- del self.__map, self.__end- inst_dict = vars(self).copy()- self.__map, self.__end = tmp- if inst_dict:- return (self.__class__, (items,), inst_dict)- return self.__class__, (items,)-- def keys(self):- return list(self)-- setdefault = DictMixin.setdefault- update = DictMixin.update- pop = DictMixin.pop- values = DictMixin.values- items = DictMixin.items- iterkeys = DictMixin.iterkeys- itervalues = DictMixin.itervalues- iteritems = DictMixin.iteritems-- def __repr__(self):- if not self:- return '%s()' % (self.__class__.__name__,)- return '%s(%r)' % (self.__class__.__name__, self.items())-- def copy(self):- return self.__class__(self)-- @classmethod- def fromkeys(cls, iterable, value=None):- d = cls()- for key in iterable:- d[key] = value- return d-- def __eq__(self, other):- if isinstance(other, OrderedDict):- if len(self) != len(other):- return False- for p, q in zip(self.items(), other.items()):- if p != q:- return False- return True- return dict.__eq__(self, other)-- def __ne__(self, other):- return not self == other+# Copyright (c) 2009 Raymond Hettinger+#+# Permission is hereby granted, free of charge, to any person+# obtaining a copy of this software and associated documentation files+# (the "Software"), to deal in the Software without restriction,+# including without limitation the rights to use, copy, modify, merge,+# publish, distribute, sublicense, and/or sell copies of the Software,+# and to permit persons to whom the Software is furnished to do so,+# subject to the following conditions:+#+# The above copyright notice and this permission notice shall be+# included in all copies or substantial portions of the Software.+#+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+# OTHER DEALINGS IN THE SOFTWARE.++from UserDict import DictMixin++class OrderedDict(dict, DictMixin):++ def __init__(self, *args, **kwds):+ if len(args) > 1:+ raise TypeError('expected at most 1 arguments, got %d' % len(args))+ try:+ self.__end+ except AttributeError:+ self.clear()+ self.update(*args, **kwds)++ def clear(self):+ self.__end = end = []+ end += [None, end, end] # sentinel node for doubly linked list+ self.__map = {} # key --> [key, prev, next]+ dict.clear(self)++ def __setitem__(self, key, value):+ if key not in self:+ end = self.__end+ curr = end[1]+ curr[2] = end[1] = self.__map[key] = [key, curr, end]+ dict.__setitem__(self, key, value)++ def __delitem__(self, key):+ dict.__delitem__(self, key)+ key, prev, next = self.__map.pop(key)+ prev[2] = next+ next[1] = prev++ def __iter__(self):+ end = self.__end+ curr = end[2]+ while curr is not end:+ yield curr[0]+ curr = curr[2]++ def __reversed__(self):+ end = self.__end+ curr = end[1]+ while curr is not end:+ yield curr[0]+ curr = curr[1]++ def popitem(self, last=True):+ if not self:+ raise KeyError('dictionary is empty')+ if last:+ key = next(reversed(self))+ else:+ key = next(iter(self))+ value = self.pop(key)+ return key, value++ def __reduce__(self):+ items = [[k, self[k]] for k in self]+ tmp = self.__map, self.__end+ del self.__map, self.__end+ inst_dict = vars(self).copy()+ self.__map, self.__end = tmp+ if inst_dict:+ return (self.__class__, (items,), inst_dict)+ return self.__class__, (items,)++ def keys(self):+ return list(self)++ setdefault = DictMixin.setdefault+ update = DictMixin.update+ pop = DictMixin.pop+ values = DictMixin.values+ items = DictMixin.items+ iterkeys = DictMixin.iterkeys+ itervalues = DictMixin.itervalues+ iteritems = DictMixin.iteritems++ def __repr__(self):+ if not self:+ return '%s()' % (self.__class__.__name__,)+ return '%s(%r)' % (self.__class__.__name__, self.items())++ def copy(self):+ return self.__class__(self)++ @classmethod+ def fromkeys(cls, iterable, value=None):+ d = cls()+ for key in iterable:+ d[key] = value+ return d++ def __eq__(self, other):+ if isinstance(other, OrderedDict):+ if len(self) != len(other):+ return False+ for p, q in zip(self.items(), other.items()):+ if p != q:+ return False+ return True+ return dict.__eq__(self, other)++ def __ne__(self, other):+ return not self == otherdiff --git a/scrapy/xlib/tx/endpoints.py b/scrapy/xlib/tx/endpoints.pyindex 5548dbfbf..d8a92ccd0 100644--- a/scrapy/xlib/tx/endpoints.py+++ b/scrapy/xlib/tx/endpoints.py@@ -810,7 +810,7 @@ def _tokenize(description):current = ''ops = nextOps[n]elif n == '\\':- current += description.next()+ current += next(description)else:current += nyield _STRING, current