Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Remove deferred_from_coro from this PR.

Andrey Rakhmatullin40697dcbfa17
diff --git a/scrapy/utils/defer.py b/scrapy/utils/defer.py
index 530bf0e9d..20ce59297 100644
--- a/scrapy/utils/defer.py
+++ b/scrapy/utils/defer.py
@@ -1,14 +1,10 @@
"""
Helper functions for dealing with Twisted deferreds
"""
-import asyncio
-import inspect
-
from twisted.internet import defer, task
from twisted.python import failure
from scrapy.exceptions import IgnoreRequest
-from scrapy.utils.asyncio import is_asyncio_reactor_installed
def defer_fail(_failure):
@@ -118,27 +114,3 @@ def iter_errback(iterable, errback, *a, **kw):
break
except Exception:
errback(failure.Failure(), *a, **kw)
-
-
-def _isfuture(o):
- # workaround for Python before 3.5.3 not having asyncio.isfuture
- if hasattr(asyncio, 'isfuture'):
- return asyncio.isfuture(o)
- return isinstance(o, asyncio.Future)
-
-
-def deferred_from_coro(o, asyncio_enabled=False):
- """Converts a coroutine into a Deferred, or returns the object as is if it isn't a coroutine"""
- if isinstance(o, defer.Deferred):
- return o
- if _isfuture(o) or inspect.isawaitable(o):
- if not asyncio_enabled:
- # wrapping the coroutine directly into a Deferred, this doesn't work correctly with coroutines
- # that use asyncio, e.g. "await asyncio.sleep(1)"
- return defer.ensureDeferred(o)
- else:
- # wrapping the coroutine into a Future and then into a Deferred, this requires AsyncioSelectorReactor
- if not is_asyncio_reactor_installed():
- raise TypeError('Using coroutines requires installing AsyncioSelectorReactor')
- return defer.Deferred.fromFuture(asyncio.ensure_future(o))
- return o