anycorn 0.16.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. anycorn-0.16.0/LICENSE +22 -0
  2. anycorn-0.16.0/PKG-INFO +159 -0
  3. anycorn-0.16.0/README.rst +115 -0
  4. anycorn-0.16.0/pyproject.toml +103 -0
  5. anycorn-0.16.0/src/anycorn/__init__.py +54 -0
  6. anycorn-0.16.0/src/anycorn/__main__.py +297 -0
  7. anycorn-0.16.0/src/anycorn/app_wrappers.py +167 -0
  8. anycorn-0.16.0/src/anycorn/config.py +403 -0
  9. anycorn-0.16.0/src/anycorn/events.py +25 -0
  10. anycorn-0.16.0/src/anycorn/lifespan.py +97 -0
  11. anycorn-0.16.0/src/anycorn/logging.py +202 -0
  12. anycorn-0.16.0/src/anycorn/middleware/__init__.py +13 -0
  13. anycorn-0.16.0/src/anycorn/middleware/dispatcher.py +68 -0
  14. anycorn-0.16.0/src/anycorn/middleware/http_to_https.py +67 -0
  15. anycorn-0.16.0/src/anycorn/middleware/proxy_fix.py +79 -0
  16. anycorn-0.16.0/src/anycorn/middleware/wsgi.py +35 -0
  17. anycorn-0.16.0/src/anycorn/protocol/__init__.py +90 -0
  18. anycorn-0.16.0/src/anycorn/protocol/events.py +58 -0
  19. anycorn-0.16.0/src/anycorn/protocol/h11.py +317 -0
  20. anycorn-0.16.0/src/anycorn/protocol/h2.py +389 -0
  21. anycorn-0.16.0/src/anycorn/protocol/h3.py +149 -0
  22. anycorn-0.16.0/src/anycorn/protocol/http_stream.py +206 -0
  23. anycorn-0.16.0/src/anycorn/protocol/quic.py +135 -0
  24. anycorn-0.16.0/src/anycorn/protocol/ws_stream.py +379 -0
  25. anycorn-0.16.0/src/anycorn/py.typed +1 -0
  26. anycorn-0.16.0/src/anycorn/run.py +256 -0
  27. anycorn-0.16.0/src/anycorn/statsd.py +109 -0
  28. anycorn-0.16.0/src/anycorn/task_group.py +79 -0
  29. anycorn-0.16.0/src/anycorn/tcp_server.py +161 -0
  30. anycorn-0.16.0/src/anycorn/typing.py +342 -0
  31. anycorn-0.16.0/src/anycorn/udp_server.py +46 -0
  32. anycorn-0.16.0/src/anycorn/utils.py +219 -0
  33. anycorn-0.16.0/src/anycorn/worker_context.py +50 -0
anycorn-0.16.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright P G Jones 2018.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.1
2
+ Name: anycorn
3
+ Version: 0.16.0
4
+ Summary: A ASGI Server based on Hyper libraries and inspired by Gunicorn
5
+ Home-page: https://github.com/davidbrochart/anycorn/
6
+ License: MIT
7
+ Author: pgjones
8
+ Author-email: philip.graham.jones@googlemail.com
9
+ Requires-Python: >=3.8
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Web Environment
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Provides-Extra: docs
25
+ Provides-Extra: h3
26
+ Provides-Extra: trio
27
+ Provides-Extra: uvloop
28
+ Requires-Dist: aioquic (>=0.9.0,<1.0) ; extra == "h3"
29
+ Requires-Dist: anyio (>=4.0,<5.0)
30
+ Requires-Dist: exceptiongroup (>=1.1.0) ; extra == "trio"
31
+ Requires-Dist: h11
32
+ Requires-Dist: h2 (>=3.1.0)
33
+ Requires-Dist: priority
34
+ Requires-Dist: pydata_sphinx_theme ; extra == "docs"
35
+ Requires-Dist: sphinxcontrib_mermaid ; extra == "docs"
36
+ Requires-Dist: taskgroup ; python_version < "3.11"
37
+ Requires-Dist: tomli ; python_version < "3.11"
38
+ Requires-Dist: uvloop ; (platform_system != "Windows") and (extra == "uvloop")
39
+ Requires-Dist: wsproto (>=0.14.0)
40
+ Project-URL: Documentation, https://hypercorn.readthedocs.io
41
+ Project-URL: Repository, https://github.com/davidbrochart/anycorn/
42
+ Description-Content-Type: text/x-rst
43
+
44
+ Anycorn
45
+ =======
46
+
47
+ .. image:: https://github.com/davidbrochart/anycorn/raw/main/artwork/logo.png
48
+ :alt: Hypercorn logo
49
+
50
+ |Build Status| |docs| |pypi| |http| |python| |license|
51
+
52
+ Anycorn is an `ASGI
53
+ <https://github.com/django/asgiref/blob/main/specs/asgi.rst>`_ and
54
+ WSGI web server based on the sans-io hyper, `h11
55
+ <https://github.com/python-hyper/h11>`_, `h2
56
+ <https://github.com/python-hyper/hyper-h2>`_, and `wsproto
57
+ <https://github.com/python-hyper/wsproto>`_ libraries and inspired by
58
+ Gunicorn. Anycorn supports HTTP/1, HTTP/2, WebSockets (over HTTP/1
59
+ and HTTP/2), ASGI, and WSGI specifications. Anycorn utilises
60
+ anyio worker types.
61
+
62
+ Anycorn can optionally serve the current draft of the HTTP/3
63
+ specification using the `aioquic
64
+ <https://github.com/aiortc/aioquic/>`_ library. To enable this install
65
+ the ``h3`` optional extra, ``pip install anycorn[h3]`` and then
66
+ choose a quic binding e.g. ``anycorn --quic-bind localhost:4433
67
+ ...``.
68
+
69
+ Anycorn is a fork of `Hypercorn
70
+ <https://github.com/pgjones/hypercorn>`_ that replaces asyncio where
71
+ asyncio and Trio implementations are replaced with AnyIO.
72
+ Anycorn forked from version 0.16.0 of Hypercorn.
73
+
74
+ Quickstart
75
+ ----------
76
+
77
+ Anycorn can be installed via `pip
78
+ <https://docs.python.org/3/installing/index.html>`_,
79
+
80
+ .. code-block:: console
81
+
82
+ $ pip install anycorn
83
+
84
+ and requires Python 3.8 or higher.
85
+
86
+ With anycorn installed ASGI frameworks (or apps) can be served via
87
+ Anycorn via the command line,
88
+
89
+ .. code-block:: console
90
+
91
+ $ anycorn module:app
92
+
93
+ Alternatively Anycorn can be used programatically,
94
+
95
+ .. code-block:: python
96
+
97
+ import anyio
98
+ from anycorn.config import Config
99
+ from anycorn import serve
100
+
101
+ from module import app
102
+
103
+ anyio.run(serve, app, Config())
104
+
105
+ learn more in the `API usage
106
+ <https://hypercorn.readthedocs.io/en/latest/how_to_guides/api_usage.html>`_
107
+ docs.
108
+
109
+ Contributing
110
+ ------------
111
+
112
+ Anycorn is developed on `Github
113
+ <https://github.com/davidbrochart/anycorn>`_. If you come across an issue,
114
+ or have a feature request please open an `issue
115
+ <https://github.com/davidbrochart/anycorn/issues>`_. If you want to
116
+ contribute a fix or the feature-implementation please do (typo fixes
117
+ welcome), by proposing a `pull request
118
+ <https://github.com/davidbrochart/anycorn/merge_requests>`_.
119
+
120
+ Testing
121
+ ~~~~~~~
122
+
123
+ The best way to test Anycorn is with `Tox
124
+ <https://tox.readthedocs.io>`_,
125
+
126
+ .. code-block:: console
127
+
128
+ $ pipenv install tox
129
+ $ tox
130
+
131
+ this will check the code style and run the tests.
132
+
133
+ Help
134
+ ----
135
+
136
+ The Anycorn `documentation <https://hypercorn.readthedocs.io>`_ is
137
+ the best place to start, after that try searching stack overflow, if
138
+ you still can't find an answer please `open an issue
139
+ <https://github.com/davidbrochart/anycorn/issues>`_.
140
+
141
+
142
+ .. |Build Status| image:: https://github.com/davidbrochart/anycorn/actions/workflows/ci.yml/badge.svg
143
+ :target: https://github.com/davidbrochart/anycorn/commits/main
144
+
145
+ .. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg
146
+ :target: https://hypercorn.readthedocs.io
147
+
148
+ .. |pypi| image:: https://img.shields.io/pypi/v/hypercorn.svg
149
+ :target: https://pypi.python.org/pypi/anycorn/
150
+
151
+ .. |http| image:: https://img.shields.io/badge/http-1.0,1.1,2-orange.svg
152
+ :target: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
153
+
154
+ .. |python| image:: https://img.shields.io/pypi/pyversions/hypercorn.svg
155
+ :target: https://pypi.python.org/pypi/anycorn/
156
+
157
+ .. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
158
+ :target: https://github.com/davidbrochart/anycorn/blob/main/LICENSE
159
+
@@ -0,0 +1,115 @@
1
+ Anycorn
2
+ =======
3
+
4
+ .. image:: https://github.com/davidbrochart/anycorn/raw/main/artwork/logo.png
5
+ :alt: Hypercorn logo
6
+
7
+ |Build Status| |docs| |pypi| |http| |python| |license|
8
+
9
+ Anycorn is an `ASGI
10
+ <https://github.com/django/asgiref/blob/main/specs/asgi.rst>`_ and
11
+ WSGI web server based on the sans-io hyper, `h11
12
+ <https://github.com/python-hyper/h11>`_, `h2
13
+ <https://github.com/python-hyper/hyper-h2>`_, and `wsproto
14
+ <https://github.com/python-hyper/wsproto>`_ libraries and inspired by
15
+ Gunicorn. Anycorn supports HTTP/1, HTTP/2, WebSockets (over HTTP/1
16
+ and HTTP/2), ASGI, and WSGI specifications. Anycorn utilises
17
+ anyio worker types.
18
+
19
+ Anycorn can optionally serve the current draft of the HTTP/3
20
+ specification using the `aioquic
21
+ <https://github.com/aiortc/aioquic/>`_ library. To enable this install
22
+ the ``h3`` optional extra, ``pip install anycorn[h3]`` and then
23
+ choose a quic binding e.g. ``anycorn --quic-bind localhost:4433
24
+ ...``.
25
+
26
+ Anycorn is a fork of `Hypercorn
27
+ <https://github.com/pgjones/hypercorn>`_ that replaces asyncio where
28
+ asyncio and Trio implementations are replaced with AnyIO.
29
+ Anycorn forked from version 0.16.0 of Hypercorn.
30
+
31
+ Quickstart
32
+ ----------
33
+
34
+ Anycorn can be installed via `pip
35
+ <https://docs.python.org/3/installing/index.html>`_,
36
+
37
+ .. code-block:: console
38
+
39
+ $ pip install anycorn
40
+
41
+ and requires Python 3.8 or higher.
42
+
43
+ With anycorn installed ASGI frameworks (or apps) can be served via
44
+ Anycorn via the command line,
45
+
46
+ .. code-block:: console
47
+
48
+ $ anycorn module:app
49
+
50
+ Alternatively Anycorn can be used programatically,
51
+
52
+ .. code-block:: python
53
+
54
+ import anyio
55
+ from anycorn.config import Config
56
+ from anycorn import serve
57
+
58
+ from module import app
59
+
60
+ anyio.run(serve, app, Config())
61
+
62
+ learn more in the `API usage
63
+ <https://hypercorn.readthedocs.io/en/latest/how_to_guides/api_usage.html>`_
64
+ docs.
65
+
66
+ Contributing
67
+ ------------
68
+
69
+ Anycorn is developed on `Github
70
+ <https://github.com/davidbrochart/anycorn>`_. If you come across an issue,
71
+ or have a feature request please open an `issue
72
+ <https://github.com/davidbrochart/anycorn/issues>`_. If you want to
73
+ contribute a fix or the feature-implementation please do (typo fixes
74
+ welcome), by proposing a `pull request
75
+ <https://github.com/davidbrochart/anycorn/merge_requests>`_.
76
+
77
+ Testing
78
+ ~~~~~~~
79
+
80
+ The best way to test Anycorn is with `Tox
81
+ <https://tox.readthedocs.io>`_,
82
+
83
+ .. code-block:: console
84
+
85
+ $ pipenv install tox
86
+ $ tox
87
+
88
+ this will check the code style and run the tests.
89
+
90
+ Help
91
+ ----
92
+
93
+ The Anycorn `documentation <https://hypercorn.readthedocs.io>`_ is
94
+ the best place to start, after that try searching stack overflow, if
95
+ you still can't find an answer please `open an issue
96
+ <https://github.com/davidbrochart/anycorn/issues>`_.
97
+
98
+
99
+ .. |Build Status| image:: https://github.com/davidbrochart/anycorn/actions/workflows/ci.yml/badge.svg
100
+ :target: https://github.com/davidbrochart/anycorn/commits/main
101
+
102
+ .. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg
103
+ :target: https://hypercorn.readthedocs.io
104
+
105
+ .. |pypi| image:: https://img.shields.io/pypi/v/hypercorn.svg
106
+ :target: https://pypi.python.org/pypi/anycorn/
107
+
108
+ .. |http| image:: https://img.shields.io/badge/http-1.0,1.1,2-orange.svg
109
+ :target: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
110
+
111
+ .. |python| image:: https://img.shields.io/pypi/pyversions/hypercorn.svg
112
+ :target: https://pypi.python.org/pypi/anycorn/
113
+
114
+ .. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
115
+ :target: https://github.com/davidbrochart/anycorn/blob/main/LICENSE
@@ -0,0 +1,103 @@
1
+ [tool.poetry]
2
+ name = "anycorn"
3
+ version = "0.16.0"
4
+ description = "A ASGI Server based on Hyper libraries and inspired by Gunicorn"
5
+ authors = ["pgjones <philip.graham.jones@googlemail.com>", "David Brochart <david.brochart@gmail.com>"]
6
+ classifiers = [
7
+ "Development Status :: 4 - Beta",
8
+ "Environment :: Web Environment",
9
+ "Intended Audience :: Developers",
10
+ "License :: OSI Approved :: MIT License",
11
+ "Operating System :: OS Independent",
12
+ "Programming Language :: Python",
13
+ "Programming Language :: Python :: 3",
14
+ "Programming Language :: Python :: 3.8",
15
+ "Programming Language :: Python :: 3.9",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ ]
22
+ include = ["src/anycorn/py.typed"]
23
+ license = "MIT"
24
+ readme = "README.rst"
25
+ repository = "https://github.com/davidbrochart/anycorn/"
26
+ documentation = "https://hypercorn.readthedocs.io"
27
+
28
+ [tool.poetry.dependencies]
29
+ python = ">=3.8"
30
+ aioquic = { version = ">= 0.9.0, < 1.0", optional = true }
31
+ exceptiongroup = ">= 1.1.0"
32
+ h11 = "*"
33
+ h2 = ">=3.1.0"
34
+ anyio = ">=4.0, <5.0"
35
+ priority = "*"
36
+ pydata_sphinx_theme = { version = "*", optional = true }
37
+ sphinxcontrib_mermaid = { version = "*", optional = true }
38
+ taskgroup = { version = "*", python = "<3.11", allow-prereleases = true }
39
+ tomli = { version = "*", python = "<3.11" }
40
+ uvloop = { version = "*", markers = "platform_system != 'Windows'", optional = true }
41
+ wsproto = ">=0.14.0"
42
+
43
+ [tool.poetry.dev-dependencies]
44
+ hypothesis = "*"
45
+ mock = "*"
46
+ pytest = "*"
47
+ pytest-asyncio = "*"
48
+ pytest-trio = "*"
49
+ trio = "*"
50
+
51
+ [tool.poetry.scripts]
52
+ anycorn = "anycorn.__main__:main"
53
+
54
+ [tool.poetry.extras]
55
+ docs = ["pydata_sphinx_theme", "sphinxcontrib_mermaid"]
56
+ h3 = ["aioquic"]
57
+ trio = ["exceptiongroup", "trio"]
58
+ uvloop = ["uvloop"]
59
+
60
+ [tool.black]
61
+ line-length = 100
62
+ target-version = ["py38"]
63
+
64
+ [tool.isort]
65
+ combine_as_imports = true
66
+ force_grid_wrap = 0
67
+ include_trailing_comma = true
68
+ known_first_party = "anycorn, tests"
69
+ line_length = 100
70
+ multi_line_output = 3
71
+ no_lines_before = "LOCALFOLDER"
72
+ order_by_type = false
73
+ reverse_relative = true
74
+
75
+ [tool.mypy]
76
+ allow_redefinition = true
77
+ disallow_any_generics = false
78
+ disallow_subclassing_any = true
79
+ disallow_untyped_calls = false
80
+ disallow_untyped_defs = true
81
+ implicit_reexport = true
82
+ no_implicit_optional = true
83
+ show_error_codes = true
84
+ strict = true
85
+ strict_equality = true
86
+ strict_optional = false
87
+ warn_redundant_casts = true
88
+ warn_return_any = false
89
+ warn_unused_configs = true
90
+ warn_unused_ignores = true
91
+
92
+ [[tool.mypy.overrides]]
93
+ module =["aioquic.*", "cryptography.*", "h11.*", "h2.*", "priority.*", "pytest_asyncio.*", "trio.*", "uvloop.*"]
94
+ ignore_missing_imports = true
95
+
96
+ [tool.pytest.ini_options]
97
+ addopts = "--no-cov-on-fail --showlocals --strict-markers"
98
+ asyncio_mode = "strict"
99
+ testpaths = ["tests"]
100
+
101
+ [build-system]
102
+ requires = ["poetry-core>=1.0.0"]
103
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,54 @@
1
+ from __future__ import annotations
2
+
3
+ import warnings
4
+ from typing import Awaitable, Callable, Literal, Optional
5
+
6
+ import anyio
7
+
8
+ from .config import Config
9
+ from .run import worker_serve
10
+ from .typing import Framework
11
+ from .utils import wrap_app
12
+
13
+ __all__ = ("Config", "serve")
14
+
15
+
16
+ async def serve(
17
+ app: Framework,
18
+ config: Config,
19
+ *,
20
+ shutdown_trigger: Optional[Callable[..., Awaitable[None]]] = None,
21
+ task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
22
+ mode: Optional[Literal["asgi", "wsgi"]] = None,
23
+ ) -> None:
24
+ """Serve an ASGI framework app given the config.
25
+
26
+ This allows for a programmatic way to serve an ASGI framework, it
27
+ can be used via,
28
+
29
+ .. code-block:: python
30
+
31
+ anyio.run(serve, app, config)
32
+
33
+ It is assumed that the event-loop is configured before calling
34
+ this function, therefore configuration values that relate to loop
35
+ setup or process setup are ignored.
36
+
37
+ Arguments:
38
+ app: The ASGI application to serve.
39
+ config: A Hypercorn configuration object.
40
+ shutdown_trigger: This should return to trigger a graceful
41
+ shutdown.
42
+ mode: Specify if the app is WSGI or ASGI.
43
+ """
44
+ if config.debug:
45
+ warnings.warn("The config `debug` has no affect when using serve", Warning)
46
+ if config.workers != 1:
47
+ warnings.warn("The config `workers` has no affect when using serve", Warning)
48
+
49
+ await worker_serve(
50
+ wrap_app(app, config.wsgi_max_body_size, mode),
51
+ config,
52
+ shutdown_trigger=shutdown_trigger,
53
+ task_status=task_status,
54
+ )