This file contains hidden or 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
| # This file is intended to be sourced by a shell, not doing anything by | |
| # default, but adding functions "full-monty" and "no-monty" as enabler and | |
| # disabler respectfully of some useful features in Python through environment | |
| # variables. Put it somewhere like /etc/profile.d/ or the likes. Or don't 🤷 | |
| # | |
| # See https://docs.python.org/3/using/cmdline.html#environment-variables | |
| full-monty() { | |
| # run in optimized mode, removing assert and debug code | |
| export PYTHONOPTIMIZE=1 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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): |