mirror of https://github.com/scrapy/scrapy.git
Move MutableChain to scrapy.utils.python
This commit is contained in:
parent
2396356a82
commit
58f5565357
|
|
@ -11,32 +11,13 @@ from scrapy.exceptions import _InvalidOutput
|
|||
from scrapy.middleware import MiddlewareManager
|
||||
from scrapy.utils.defer import mustbe_deferred
|
||||
from scrapy.utils.conf import build_component_list
|
||||
from scrapy.utils.python import MutableChain
|
||||
|
||||
|
||||
def _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'
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import weakref
|
|||
import errno
|
||||
import six
|
||||
from functools import partial, wraps
|
||||
from itertools import chain
|
||||
import sys
|
||||
|
||||
from 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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue