summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/util/wait.py
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/util/wait.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/util/wait.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/util/wait.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/util/wait.py
new file mode 100644
index 0000000..46392f2
--- /dev/null
+++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/urllib3/util/wait.py
@@ -0,0 +1,40 @@
1from .selectors import (
2 HAS_SELECT,
3 DefaultSelector,
4 EVENT_READ,
5 EVENT_WRITE
6)
7
8
9def _wait_for_io_events(socks, events, timeout=None):
10 """ Waits for IO events to be available from a list of sockets
11 or optionally a single socket if passed in. Returns a list of
12 sockets that can be interacted with immediately. """
13 if not HAS_SELECT:
14 raise ValueError('Platform does not have a selector')
15 if not isinstance(socks, list):
16 # Probably just a single socket.
17 if hasattr(socks, "fileno"):
18 socks = [socks]
19 # Otherwise it might be a non-list iterable.
20 else:
21 socks = list(socks)
22 with DefaultSelector() as selector:
23 for sock in socks:
24 selector.register(sock, events)
25 return [key[0].fileobj for key in
26 selector.select(timeout) if key[1] & events]
27
28
29def wait_for_read(socks, timeout=None):
30 """ Waits for reading to be available from a list of sockets
31 or optionally a single socket if passed in. Returns a list of
32 sockets that can be read from immediately. """
33 return _wait_for_io_events(socks, EVENT_READ, timeout)
34
35
36def wait_for_write(socks, timeout=None):
37 """ Waits for writing to be available from a list of sockets
38 or optionally a single socket if passed in. Returns a list of
39 sockets that can be written to immediately. """
40 return _wait_for_io_events(socks, EVENT_WRITE, timeout)