Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: third_party/google-endpoints/urllib3/util/wait.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 from .selectors import (
2 HAS_SELECT,
3 DefaultSelector,
4 EVENT_READ,
5 EVENT_WRITE
6 )
7
8
9 def _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
29 def 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
36 def 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)
OLDNEW
« no previous file with comments | « third_party/google-endpoints/urllib3/util/url.py ('k') | third_party/google-endpoints/winreg/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698