This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections.abc import Mapping | |
class DictView(Mapping): | |
# sentinel value used to check when a KeyError should be raised rather than returning a value | |
_no_default = object() | |
def __init__(self, source, separator='.'): | |
self._source = source | |
self._separator = separator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import RawIOBase | |
class ChunkedResponseIO(RawIOBase): | |
""" | |
Turns a generator of chunks into raw I/O, which can in turn be fed to | |
something like an `io.BufferedReader`. | |
.. code-block:: python | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class drain(object): | |
""" | |
Context manager to make sure a `Response` object is drained of content. | |
Can be used to return a connection used to retrieve a response back to the | |
connection pool it came from in case the actual response content of the | |
response is not needed, e.g.: | |
.. code-block:: python | |
response = session.get('https://example.com/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
def call_periodic(interval, callback, *args, **kwargs): | |
# get loop as a kwarg or take the default one | |
loop = kwargs.get('loop') or asyncio.get_event_loop() | |
# record the loop's time when call_periodic was called | |
start = loop.time() | |
def run(handle): |