Scrapy, a fast high-level web crawling & scraping framework for Python.
Move MutableChain to scrapy.utils.python
Eugenio Lacuesta58f5565357ed
diff --git a/scrapy/core/spidermw.py b/scrapy/core/spidermw.pyindex 4268c91d6..d776430e5 100644--- a/scrapy/core/spidermw.py+++ b/scrapy/core/spidermw.py@@ -11,32 +11,13 @@ from scrapy.exceptions import _InvalidOutputfrom scrapy.middleware import MiddlewareManagerfrom scrapy.utils.defer import mustbe_deferredfrom scrapy.utils.conf import build_component_list+from scrapy.utils.python import MutableChaindef _isiterable(possible_iterator):return hasattr(possible_iterator, '__iter__')-class MutableChain:- """- Thin wrapper around itertools.chain, allowing to add iterables "in-place"- """- def __init__(self, *args):- self.data = chain(*args)-- def extend(self, *iterables):- self.data = chain(self.data, *iterables)-- def __iter__(self):- return self.data.__iter__()-- def __next__(self): # py3- return self.data.__next__()-- def next(self): # py2- return self.data.next()--class SpiderMiddlewareManager(MiddlewareManager):component_name = 'spider middleware'diff --git a/scrapy/utils/python.py b/scrapy/utils/python.pyindex 732ca13a0..7971b4dde 100644--- a/scrapy/utils/python.py+++ b/scrapy/utils/python.py@@ -9,6 +9,7 @@ import weakrefimport errnoimport sixfrom functools import partial, wraps+from itertools import chainimport sysfrom scrapy.utils.decorators import deprecated@@ -387,3 +388,23 @@ if hasattr(sys, "pypy_version_info"):else:def garbage_collect():gc.collect()+++class MutableChain(object):+ """+ Thin wrapper around itertools.chain, allowing to add iterables "in-place"+ """+ def __init__(self, *args):+ self.data = chain(*args)++ def extend(self, *iterables):+ self.data = chain(self.data, *iterables)++ def __iter__(self):+ return self.data.__iter__()++ def __next__(self): # py3+ return self.data.__next__()++ def next(self): # py2+ return self.data.next()