././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/0000775000175000017500000000000000000000000016072 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/.coveragerc0000664000175000017500000000016100000000000020211 0ustar00sethmlarsonsethmlarson00000000000000[run] branch=True source=sniffio [report] precision = 1 exclude_lines = pragma: no cover abc.abstractmethod ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/.style.yapf0000664000175000017500000001237500000000000020201 0ustar00sethmlarsonsethmlarson00000000000000[style] # Align closing bracket with visual indentation. align_closing_bracket_with_visual_indent=True # Allow dictionary keys to exist on multiple lines. For example: # # x = { # ('this is the first element of a tuple', # 'this is the second element of a tuple'): # value, # } allow_multiline_dictionary_keys=False # Allow lambdas to be formatted on more than one line. allow_multiline_lambdas=False # Insert a blank line before a class-level docstring. blank_line_before_class_docstring=False # Insert a blank line before a 'def' or 'class' immediately nested # within another 'def' or 'class'. For example: # # class Foo: # # <------ this blank line # def method(): # ... blank_line_before_nested_class_or_def=False # Do not split consecutive brackets. Only relevant when # dedent_closing_brackets is set. For example: # # call_func_that_takes_a_dict( # { # 'key1': 'value1', # 'key2': 'value2', # } # ) # # would reformat to: # # call_func_that_takes_a_dict({ # 'key1': 'value1', # 'key2': 'value2', # }) coalesce_brackets=False # The column limit. column_limit=79 # Indent width used for line continuations. continuation_indent_width=4 # Put closing brackets on a separate line, dedented, if the bracketed # expression can't fit in a single line. Applies to all kinds of brackets, # including function definitions and calls. For example: # # config = { # 'key1': 'value1', # 'key2': 'value2', # } # <--- this bracket is dedented and on a separate line # # time_series = self.remote_client.query_entity_counters( # entity='dev3246.region1', # key='dns.query_latency_tcp', # transform=Transformation.AVERAGE(window=timedelta(seconds=60)), # start_ts=now()-timedelta(days=3), # end_ts=now(), # ) # <--- this bracket is dedented and on a separate line dedent_closing_brackets=True # Place each dictionary entry onto its own line. each_dict_entry_on_separate_line=True # The regex for an i18n comment. The presence of this comment stops # reformatting of that line, because the comments are required to be # next to the string they translate. i18n_comment= # The i18n function call names. The presence of this function stops # reformattting on that line, because the string it has cannot be moved # away from the i18n comment. i18n_function_call= # Indent the dictionary value if it cannot fit on the same line as the # dictionary key. For example: # # config = { # 'key1': # 'value1', # 'key2': value1 + # value2, # } indent_dictionary_value=True # The number of columns to use for indentation. indent_width=4 # Join short lines into one line. E.g., single line 'if' statements. join_multiple_lines=False # Use spaces around default or named assigns. spaces_around_default_or_named_assign=False # Use spaces around the power operator. spaces_around_power_operator=False # The number of spaces required before a trailing comment. spaces_before_comment=2 # Insert a space between the ending comma and closing bracket of a list, # etc. space_between_ending_comma_and_closing_bracket=False # Split before arguments if the argument list is terminated by a # comma. split_arguments_when_comma_terminated=True # Set to True to prefer splitting before '&', '|' or '^' rather than # after. split_before_bitwise_operator=True # Split before a dictionary or set generator (comp_for). For example, note # the split before the 'for': # # foo = { # variable: 'Hello world, have a nice day!' # for variable in bar if variable != 42 # } split_before_dict_set_generator=True # If an argument / parameter list is going to be split, then split before # the first argument. split_before_first_argument=True # Set to True to prefer splitting before 'and' or 'or' rather than # after. split_before_logical_operator=True # Split named assignments onto individual lines. split_before_named_assigns=True # The penalty for splitting right after the opening bracket. split_penalty_after_opening_bracket=30 # The penalty for splitting the line after a unary operator. split_penalty_after_unary_operator=10000 # The penalty for splitting right before an if expression. split_penalty_before_if_expr=0 # The penalty of splitting the line around the '&', '|', and '^' # operators. split_penalty_bitwise_operator=300 # The penalty for characters over the column limit. split_penalty_excess_character=4500 # The penalty incurred by adding a line split to the unwrapped line. The # more line splits added the higher the penalty. split_penalty_for_added_line_split=30 # The penalty of splitting a list of "import as" names. For example: # # from a_very_long_or_indented_module_name_yada_yad import (long_argument_1, # long_argument_2, # long_argument_3) # # would reformat to something like: # # from a_very_long_or_indented_module_name_yada_yad import ( # long_argument_1, long_argument_2, long_argument_3) split_penalty_import_names=0 # The penalty of splitting the line around the 'and' and 'or' # operators. split_penalty_logical_operator=0 # Use the Tab character for indentation. use_tabs=False ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/CHEATSHEET.rst0000664000175000017500000000143100000000000020240 0ustar00sethmlarsonsethmlarson00000000000000Tips ==== To run tests ------------ * Install requirements: ``pip install -r test-requirements.txt`` (possibly in a virtualenv) * Actually run the tests: ``pytest sniffio`` To run yapf ----------- * Show what changes yapf wants to make: ``yapf -rpd setup.py sniffio`` * Apply all changes directly to the source tree: ``yapf -rpi setup.py sniffio`` To make a release ----------------- * Update the version in ``sniffio/_version.py`` * Run ``towncrier`` to collect your release notes. * Review your release notes. * Check everything in. * Double-check it all works, docs build, etc. * Build your sdist and wheel: ``python setup.py sdist bdist_wheel`` * Upload to PyPI: ``twine upload dist/*`` * Use ``git tag`` to tag your version. * Don't forget to ``git push --tags``. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/CODE_OF_CONDUCT.md0000664000175000017500000000014200000000000020666 0ustar00sethmlarsonsethmlarson00000000000000For the Trio code of conduct, see: https://trio.readthedocs.io/en/latest/code-of-conduct.html ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/CONTRIBUTING.md0000664000175000017500000000014200000000000020320 0ustar00sethmlarsonsethmlarson00000000000000For the Trio contributing guide, see: https://trio.readthedocs.io/en/latest/contributing.html ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/LICENSE0000664000175000017500000000027100000000000017077 0ustar00sethmlarsonsethmlarson00000000000000This software is made available under the terms of *either* of the licenses found in LICENSE.APACHE2 or LICENSE.MIT. Contributions to are made under the terms of *both* these licenses. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/LICENSE.APACHE20000664000175000017500000002613600000000000020111 0ustar00sethmlarsonsethmlarson00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/LICENSE.MIT0000664000175000017500000000202600000000000017527 0ustar00sethmlarsonsethmlarson00000000000000The MIT License (MIT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/MANIFEST.in0000664000175000017500000000026200000000000017630 0ustar00sethmlarsonsethmlarson00000000000000include README.rst CHEATSHEET.rst LICENSE* CODE_OF_CONDUCT* CONTRIBUTING* include .coveragerc .style.yapf include test-requirements.txt recursive-include docs * prune docs/build ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/PKG-INFO0000664000175000017500000001007700000000000017174 0ustar00sethmlarsonsethmlarson00000000000000Metadata-Version: 1.2 Name: sniffio Version: 1.2.0 Summary: Sniff out which async library your code is running under Home-page: https://github.com/python-trio/sniffio Author: Nathaniel J. Smith Author-email: njs@pobox.com License: MIT -or- Apache License 2.0 Description: .. image:: https://img.shields.io/badge/chat-join%20now-blue.svg :target: https://gitter.im/python-trio/general :alt: Join chatroom .. image:: https://img.shields.io/badge/docs-read%20now-blue.svg :target: https://sniffio.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status .. image:: https://img.shields.io/pypi/v/sniffio.svg :target: https://pypi.org/project/sniffio :alt: Latest PyPi version .. image:: https://img.shields.io/conda/vn/conda-forge/sniffio.svg :target: https://anaconda.org/conda-forge/sniffio :alt: Latest conda-forge version .. image:: https://travis-ci.org/python-trio/sniffio.svg?branch=master :target: https://travis-ci.org/python-trio/sniffio :alt: Automated test status .. image:: https://codecov.io/gh/python-trio/sniffio/branch/master/graph/badge.svg :target: https://codecov.io/gh/python-trio/sniffio :alt: Test coverage ================================================================= sniffio: Sniff out which async library your code is running under ================================================================= You're writing a library. You've decided to be ambitious, and support multiple async I/O packages, like `Trio `__, and `asyncio `__, and ... You've written a bunch of clever code to handle all the differences. But... how do you know *which* piece of clever code to run? This is a tiny package whose only purpose is to let you detect which async library your code is running under. * Documentation: https://sniffio.readthedocs.io * Bug tracker and source code: https://github.com/python-trio/sniffio * License: MIT or Apache License 2.0, your choice * Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html * Code of conduct: Contributors are requested to follow our `code of conduct `_ in all project spaces. This library is maintained by the Trio project, as a service to the async Python community as a whole. Quickstart ---------- .. code-block:: python3 from sniffio import current_async_library import trio import asyncio async def print_library(): library = current_async_library() print("This is:", library) # Prints "This is trio" trio.run(print_library) # Prints "This is asyncio" asyncio.run(print_library()) For more details, including how to add support to new async libraries, `please peruse our fine manual `__. Keywords: async,trio,asyncio Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: License :: OSI Approved :: Apache Software License Classifier: Framework :: Trio Classifier: Framework :: AsyncIO Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Intended Audience :: Developers Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.5 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/README.rst0000664000175000017500000000503100000000000017560 0ustar00sethmlarsonsethmlarson00000000000000.. image:: https://img.shields.io/badge/chat-join%20now-blue.svg :target: https://gitter.im/python-trio/general :alt: Join chatroom .. image:: https://img.shields.io/badge/docs-read%20now-blue.svg :target: https://sniffio.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status .. image:: https://img.shields.io/pypi/v/sniffio.svg :target: https://pypi.org/project/sniffio :alt: Latest PyPi version .. image:: https://img.shields.io/conda/vn/conda-forge/sniffio.svg :target: https://anaconda.org/conda-forge/sniffio :alt: Latest conda-forge version .. image:: https://travis-ci.org/python-trio/sniffio.svg?branch=master :target: https://travis-ci.org/python-trio/sniffio :alt: Automated test status .. image:: https://codecov.io/gh/python-trio/sniffio/branch/master/graph/badge.svg :target: https://codecov.io/gh/python-trio/sniffio :alt: Test coverage ================================================================= sniffio: Sniff out which async library your code is running under ================================================================= You're writing a library. You've decided to be ambitious, and support multiple async I/O packages, like `Trio `__, and `asyncio `__, and ... You've written a bunch of clever code to handle all the differences. But... how do you know *which* piece of clever code to run? This is a tiny package whose only purpose is to let you detect which async library your code is running under. * Documentation: https://sniffio.readthedocs.io * Bug tracker and source code: https://github.com/python-trio/sniffio * License: MIT or Apache License 2.0, your choice * Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html * Code of conduct: Contributors are requested to follow our `code of conduct `_ in all project spaces. This library is maintained by the Trio project, as a service to the async Python community as a whole. Quickstart ---------- .. code-block:: python3 from sniffio import current_async_library import trio import asyncio async def print_library(): library = current_async_library() print("This is:", library) # Prints "This is trio" trio.run(print_library) # Prints "This is asyncio" asyncio.run(print_library()) For more details, including how to add support to new async libraries, `please peruse our fine manual `__. ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/docs/0000775000175000017500000000000000000000000017022 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/docs/Makefile0000664000175000017500000000114100000000000020457 0ustar00sethmlarsonsethmlarson00000000000000# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build SPHINXPROJ = sniffio SOURCEDIR = source BUILDDIR = build # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/docs/make.bat0000664000175000017500000000141300000000000020426 0ustar00sethmlarsonsethmlarson00000000000000@ECHO OFF pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set SOURCEDIR=source set BUILDDIR=build set SPHINXPROJ=sniffio if "%1" == "" goto help %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( echo. echo.The 'sphinx-build' command was not found. Make sure you have Sphinx echo.installed, then set the SPHINXBUILD environment variable to point echo.to the full path of the 'sphinx-build' executable. Alternatively you echo.may add the Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% goto end :help %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% :end popd ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/docs/source/0000775000175000017500000000000000000000000020322 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/docs/source/_static/0000775000175000017500000000000000000000000021750 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/docs/source/_static/.gitkeep0000664000175000017500000000000000000000000023367 0ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/docs/source/conf.py0000664000175000017500000001344100000000000021624 0ustar00sethmlarsonsethmlarson00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Documentation build configuration file, created by # sphinx-quickstart on Sat Jan 21 19:11:14 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # import os import sys # So autodoc can import our package sys.path.insert(0, os.path.abspath('../..')) # Warn about all references to unknown targets nitpicky = True # Except for these ones, which we expect to point to unknown targets: nitpick_ignore = [ # Format is ("sphinx reference type", "string"), e.g.: ("py:obj", "bytes-like"), ] # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.coverage', 'sphinx.ext.napoleon', 'sphinxcontrib_trio', ] intersphinx_mapping = { "python": ('https://docs.python.org/3', None), "trio": ('https://trio.readthedocs.io/en/stable', None), } autodoc_member_order = "bysource" # Add any paths that contain templates here, relative to this directory. templates_path = [] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = 'sniffio' copyright = 'The sniffio authors' author = 'The sniffio authors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. import sniffio version = sniffio.__version__ # The full version, including alpha/beta/rc tags. release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # The default language for :: blocks highlight_language = 'python3' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # #html_theme = 'alabaster' # We have to set this ourselves, not only because it's useful for local # testing, but also because if we don't then RTD will throw away our # html_theme_options. import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # html_theme_options = { # default is 2 # show deeper nesting in the RTD theme's sidebar TOC # https://stackoverflow.com/questions/27669376/ # I'm not 100% sure this actually does anything with our current # versions/settings... "navigation_depth": 4, "logo_only": True, } # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = 'sniffiodoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'sniffio.tex', 'Trio Documentation', author, 'manual'), ] # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'sniffio', 'sniffio Documentation', [author], 1) ] # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'sniffio', 'sniffio Documentation', author, 'sniffio', 'Sniff out which async library your code is running under', 'Miscellaneous'), ] ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440489.0 sniffio-1.2.0/docs/source/history.rst0000664000175000017500000000073500000000000022562 0ustar00sethmlarsonsethmlarson00000000000000Release history =============== .. currentmodule:: sniffio .. towncrier release notes start sniffio 1.2.0 (2020-10-11) -------------------------- Features ~~~~~~~~ - Include type hints (`#17 `__) sniffio 1.1.0 (2019-04-19) -------------------------- Features ~~~~~~~~ - Sniff for curio. (`#5 `__) sniffio 1.0.0 (2018-07-31) -------------------------- Initial release. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/docs/source/index.rst0000664000175000017500000000661600000000000022174 0ustar00sethmlarsonsethmlarson00000000000000.. documentation master file, created by sphinx-quickstart on Sat Jan 21 19:11:14 2017. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. ================================================================= sniffio: Sniff out which async library your code is running under ================================================================= You're writing a library. You've decided to be ambitious, and support multiple async I/O packages, like `Trio `__, and `asyncio `__, and ... You've written a bunch of clever code to handle all the differences. But... how do you know *which* piece of clever code to run? This is a tiny package whose only purpose is to let you detect which async library your code is running under. * Documentation: https://sniffio.readthedocs.io * Bug tracker and source code: https://github.com/python-trio/sniffio * License: MIT or Apache License 2.0, your choice * Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html * Code of conduct: Contributors are requested to follow our `code of conduct `_ in all project spaces. This library is maintained by the Trio project, as a service to the async Python community as a whole. .. module:: sniffio Usage ===== .. autofunction:: current_async_library .. autoexception:: AsyncLibraryNotFoundError Adding support to a new async library ===================================== If you'd like your library to be detected by ``sniffio``, it's pretty easy. **Step 1:** Pick the magic string that will identify your library. To avoid collisions, this should match your library's name on PyPI. **Step 2:** There's a special :class:`contextvars.ContextVar` object: .. data:: current_async_library_cvar Make sure that whenever your library is running, this is set to your identifier string. In most cases, this will be as simple as: .. code-block:: python3 from sniffio import current_async_library_cvar # Your library's run function def run(...): token = current_async_library_cvar.set("my-library's-PyPI-name") try: # The actual body of your run() function: ... finally: current_async_library_cvar.reset(token) **Step 3:** Send us a PR to add your library to the list of supported libraries above. That's it! Notes: On older Pythons without native contextvars support, sniffio transparently uses `the official contextvars backport `__, so you don't need to worry about that. There are libraries that can switch back and forth between different async modes within a single call-task – like ``trio_asyncio`` or Twisted's asyncio operability. These libraries should make sure to set the value back and forth at appropriate points. The general rule of thumb: :data:`current_async_library_cvar` should be set to X exactly at those moments when ``await X.sleep(...)`` will work. .. warning:: You shouldn't attempt to read the value of ``current_async_library_cvar`` directly – :func:`current_async_library` has a little bit more cleverness than that. .. toctree:: :maxdepth: 1 history.rst ==================== Indices and tables ==================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` * :ref:`glossary` ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/pyproject.toml0000664000175000017500000000033100000000000021003 0ustar00sethmlarsonsethmlarson00000000000000[tool.towncrier] package = "sniffio" filename = "docs/source/history.rst" directory = "newsfragments" underlines = ["-", "~", "^"] issue_format = "`#{issue} `__" ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/setup.cfg0000664000175000017500000000004600000000000017713 0ustar00sethmlarsonsethmlarson00000000000000[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440190.0 sniffio-1.2.0/setup.py0000664000175000017500000000261500000000000017610 0ustar00sethmlarsonsethmlarson00000000000000from setuptools import setup, find_packages exec(open("sniffio/_version.py", encoding="utf-8").read()) LONG_DESC = open("README.rst", encoding="utf-8").read() setup( name="sniffio", version=__version__, description="Sniff out which async library your code is running under", url="https://github.com/python-trio/sniffio", long_description=LONG_DESC, author="Nathaniel J. Smith", author_email="njs@pobox.com", license="MIT -or- Apache License 2.0", packages=find_packages(), package_data={"sniffio": ["py.typed"]}, install_requires=[], keywords=[ "async", "trio", "asyncio", ], extras_require={":python_version < '3.7'": ["contextvars>=2.1"]}, python_requires=">=3.5", tests_require=['curio'], classifiers=[ "License :: OSI Approved :: MIT License", "License :: OSI Approved :: Apache Software License", "Framework :: Trio", "Framework :: AsyncIO", "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Intended Audience :: Developers", "Development Status :: 5 - Production/Stable", ], ) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/sniffio/0000775000175000017500000000000000000000000017527 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/sniffio/__init__.py0000664000175000017500000000044400000000000021642 0ustar00sethmlarsonsethmlarson00000000000000"""Top-level package for sniffio.""" __all__ = [ "current_async_library", "AsyncLibraryNotFoundError", "current_async_library_cvar" ] from ._version import __version__ from ._impl import ( current_async_library, AsyncLibraryNotFoundError, current_async_library_cvar, ) ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/sniffio/_impl.py0000664000175000017500000000524100000000000021203 0ustar00sethmlarsonsethmlarson00000000000000from contextvars import ContextVar from typing import Optional import sys current_async_library_cvar = ContextVar( "current_async_library_cvar", default=None ) # type: ContextVar[Optional[str]] class AsyncLibraryNotFoundError(RuntimeError): pass def current_async_library() -> str: """Detect which async library is currently running. The following libraries are currently supported: ================ =========== ============================ Library Requires Magic string ================ =========== ============================ **Trio** Trio v0.6+ ``"trio"`` **Curio** - ``"curio"`` **asyncio** ``"asyncio"`` **Trio-asyncio** v0.8.2+ ``"trio"`` or ``"asyncio"``, depending on current mode ================ =========== ============================ Returns: A string like ``"trio"``. Raises: AsyncLibraryNotFoundError: if called from synchronous context, or if the current async library was not recognized. Examples: .. code-block:: python3 from sniffio import current_async_library async def generic_sleep(seconds): library = current_async_library() if library == "trio": import trio await trio.sleep(seconds) elif library == "asyncio": import asyncio await asyncio.sleep(seconds) # ... and so on ... else: raise RuntimeError(f"Unsupported library {library!r}") """ value = current_async_library_cvar.get() if value is not None: return value # Sniff for curio (for now) if 'curio' in sys.modules: from curio.meta import curio_running if curio_running(): return 'curio' # Need to sniff for asyncio if "asyncio" in sys.modules: import asyncio try: current_task = asyncio.current_task # type: ignore[attr-defined] except AttributeError: current_task = asyncio.Task.current_task # type: ignore[attr-defined] try: if current_task() is not None: if (3, 7) <= sys.version_info: # asyncio has contextvars support, and we're in a task, so # we can safely cache the sniffed value current_async_library_cvar.set("asyncio") return "asyncio" except RuntimeError: pass raise AsyncLibraryNotFoundError( "unknown async library, or not in async context" ) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/sniffio/_tests/0000775000175000017500000000000000000000000021030 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/sniffio/_tests/__init__.py0000664000175000017500000000000000000000000023127 0ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/sniffio/_tests/test_sniffio.py0000664000175000017500000000316000000000000024076 0ustar00sethmlarsonsethmlarson00000000000000import sys import pytest from .. import ( current_async_library, AsyncLibraryNotFoundError, current_async_library_cvar ) def test_basics(): with pytest.raises(AsyncLibraryNotFoundError): current_async_library() token = current_async_library_cvar.set("generic-lib") try: assert current_async_library() == "generic-lib" finally: current_async_library_cvar.reset(token) with pytest.raises(AsyncLibraryNotFoundError): current_async_library() def test_asyncio(): import asyncio with pytest.raises(AsyncLibraryNotFoundError): current_async_library() ran = [] async def this_is_asyncio(): assert current_async_library() == "asyncio" # Call it a second time to exercise the caching logic assert current_async_library() == "asyncio" ran.append(True) loop = asyncio.get_event_loop() loop.run_until_complete(this_is_asyncio()) assert ran == [True] loop.close() with pytest.raises(AsyncLibraryNotFoundError): current_async_library() @pytest.mark.skipif(sys.version_info < (3, 6), reason='Curio requires 3.6+') def test_curio(): import curio with pytest.raises(AsyncLibraryNotFoundError): current_async_library() ran = [] async def this_is_curio(): assert current_async_library() == "curio" # Call it a second time to exercise the caching logic assert current_async_library() == "curio" ran.append(True) curio.run(this_is_curio) assert ran == [True] with pytest.raises(AsyncLibraryNotFoundError): current_async_library() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440556.0 sniffio-1.2.0/sniffio/_version.py0000664000175000017500000000013100000000000021720 0ustar00sethmlarsonsethmlarson00000000000000# This file is imported from __init__.py and exec'd from setup.py __version__ = "1.2.0" ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/sniffio/py.typed0000664000175000017500000000000000000000000021214 0ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1602440568.6707938 sniffio-1.2.0/sniffio.egg-info/0000775000175000017500000000000000000000000021221 5ustar00sethmlarsonsethmlarson00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440568.0 sniffio-1.2.0/sniffio.egg-info/PKG-INFO0000664000175000017500000001007700000000000022323 0ustar00sethmlarsonsethmlarson00000000000000Metadata-Version: 1.2 Name: sniffio Version: 1.2.0 Summary: Sniff out which async library your code is running under Home-page: https://github.com/python-trio/sniffio Author: Nathaniel J. Smith Author-email: njs@pobox.com License: MIT -or- Apache License 2.0 Description: .. image:: https://img.shields.io/badge/chat-join%20now-blue.svg :target: https://gitter.im/python-trio/general :alt: Join chatroom .. image:: https://img.shields.io/badge/docs-read%20now-blue.svg :target: https://sniffio.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status .. image:: https://img.shields.io/pypi/v/sniffio.svg :target: https://pypi.org/project/sniffio :alt: Latest PyPi version .. image:: https://img.shields.io/conda/vn/conda-forge/sniffio.svg :target: https://anaconda.org/conda-forge/sniffio :alt: Latest conda-forge version .. image:: https://travis-ci.org/python-trio/sniffio.svg?branch=master :target: https://travis-ci.org/python-trio/sniffio :alt: Automated test status .. image:: https://codecov.io/gh/python-trio/sniffio/branch/master/graph/badge.svg :target: https://codecov.io/gh/python-trio/sniffio :alt: Test coverage ================================================================= sniffio: Sniff out which async library your code is running under ================================================================= You're writing a library. You've decided to be ambitious, and support multiple async I/O packages, like `Trio `__, and `asyncio `__, and ... You've written a bunch of clever code to handle all the differences. But... how do you know *which* piece of clever code to run? This is a tiny package whose only purpose is to let you detect which async library your code is running under. * Documentation: https://sniffio.readthedocs.io * Bug tracker and source code: https://github.com/python-trio/sniffio * License: MIT or Apache License 2.0, your choice * Contributor guide: https://trio.readthedocs.io/en/latest/contributing.html * Code of conduct: Contributors are requested to follow our `code of conduct `_ in all project spaces. This library is maintained by the Trio project, as a service to the async Python community as a whole. Quickstart ---------- .. code-block:: python3 from sniffio import current_async_library import trio import asyncio async def print_library(): library = current_async_library() print("This is:", library) # Prints "This is trio" trio.run(print_library) # Prints "This is asyncio" asyncio.run(print_library()) For more details, including how to add support to new async libraries, `please peruse our fine manual `__. Keywords: async,trio,asyncio Platform: UNKNOWN Classifier: License :: OSI Approved :: MIT License Classifier: License :: OSI Approved :: Apache Software License Classifier: Framework :: Trio Classifier: Framework :: AsyncIO Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Intended Audience :: Developers Classifier: Development Status :: 5 - Production/Stable Requires-Python: >=3.5 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440568.0 sniffio-1.2.0/sniffio.egg-info/SOURCES.txt0000664000175000017500000000111300000000000023101 0ustar00sethmlarsonsethmlarson00000000000000.coveragerc .style.yapf CHEATSHEET.rst CODE_OF_CONDUCT.md CONTRIBUTING.md LICENSE LICENSE.APACHE2 LICENSE.MIT MANIFEST.in README.rst pyproject.toml setup.py test-requirements.txt docs/Makefile docs/make.bat docs/source/conf.py docs/source/history.rst docs/source/index.rst docs/source/_static/.gitkeep sniffio/__init__.py sniffio/_impl.py sniffio/_version.py sniffio/py.typed sniffio.egg-info/PKG-INFO sniffio.egg-info/SOURCES.txt sniffio.egg-info/dependency_links.txt sniffio.egg-info/requires.txt sniffio.egg-info/top_level.txt sniffio/_tests/__init__.py sniffio/_tests/test_sniffio.py././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440568.0 sniffio-1.2.0/sniffio.egg-info/dependency_links.txt0000664000175000017500000000000100000000000025267 0ustar00sethmlarsonsethmlarson00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440568.0 sniffio-1.2.0/sniffio.egg-info/requires.txt0000664000175000017500000000005400000000000023620 0ustar00sethmlarsonsethmlarson00000000000000 [:python_version < '3.7'] contextvars>=2.1 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440568.0 sniffio-1.2.0/sniffio.egg-info/top_level.txt0000664000175000017500000000001000000000000023742 0ustar00sethmlarsonsethmlarson00000000000000sniffio ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1602440014.0 sniffio-1.2.0/test-requirements.txt0000664000175000017500000000003000000000000022324 0ustar00sethmlarsonsethmlarson00000000000000pytest pytest-cov curio