Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
document WTF import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
oliland committed May 1, 2018
1 parent 4ceb08f commit 1a73eff
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
54 changes: 54 additions & 0 deletions urllib3/_backends/_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import logging

from urllib3.packages import six


def load_trio_backend():
if not six.PY3:
raise ValueError("trio backend requires Python 3")
from .trio_backend import TrioBackend
return TrioBackend


def load_twisted_backend():
if not six.PY3:
raise ValueError("twisted backend requires Python 3")
from .twisted_backend import TwistedBackend
return TwistedBackend


def load_sync_backend():
from .sync_backend import SyncBackend
return SyncBackend


BACKENDS = {
"sync": load_sync_backend,
"trio": load_trio_backend,
"twisted": load_twisted_backend,
}


def available_backends():
"""
Returns a list of backend names that we are able to successfully import.
"""
output = []
for backend_name, load_backend_fn in sorted(BACKENDS.items()):
try:
load_backend_fn()
output.append(backend_name)
except: # noqa
logging.exception("{} not available".format(backend_name))
return output


def load_backend(backend_name, backend_args):
_backend_args = backend_args or {}
if backend_name is None:
return load_sync_backend()(**_backend_args)
elif backend_name in BACKENDS:
return BACKENDS[backend_name]()(**_backend_args)
else:
valid_backends = ", ".join(sorted(BACKENDS.keys()))
raise ValueError("Backend must be one of: {}".format(valid_backends))
14 changes: 12 additions & 2 deletions urllib3/_backends/sync_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,18 @@ def send_and_receive_for_a_while(

if not made_progress:
self._wait(want_read, want_write, read_timeout)
except LoopAbort:
pass
except Exception as e:
# XX Somehow, LoopAbort != the LoopAbort that we have raised!
if not isinstance(e, LoopAbort):
raise ValueError("""
WTF1: {} != {}
WTF2: {} != {}
""".format(
LoopAbort, type(e),
id(LoopAbort), id(type(e)),
))
else:
pass

def forceful_close(self):
self._sock.close()
Expand Down

0 comments on commit 1a73eff

Please sign in to comment.