Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a329d98a8 | ||
|
|
93411c6a9f | ||
|
|
5550b20cdd | ||
|
|
d8d2667053 | ||
|
|
3943a69374 | ||
|
|
a2f6985d01 | ||
|
|
4238aa4cd4 | ||
|
|
744548f8dc | ||
|
|
d46d2950c8 | ||
|
|
2e4911d108 | ||
|
|
3eb57d0fcf | ||
|
|
42406cef42 | ||
|
|
e09e9830f4 | ||
|
|
304ca2ef68 | ||
|
|
d99df2c401 | ||
|
|
3554bc91cb | ||
|
|
51f910087a | ||
|
|
e0f0565551 | ||
|
|
2a6e76c685 |
16
.readthedocs.yaml
Normal file
16
.readthedocs.yaml
Normal file
@@ -0,0 +1,16 @@
|
||||
version: 2
|
||||
|
||||
build:
|
||||
os: ubuntu-22.04
|
||||
tools:
|
||||
python: "3.11"
|
||||
|
||||
sphinx:
|
||||
configuration: docs/conf.py
|
||||
|
||||
python:
|
||||
install:
|
||||
- method: pip
|
||||
path: .
|
||||
extra_requirements:
|
||||
- docs
|
||||
14
CHANGES.md
14
CHANGES.md
@@ -1,5 +1,19 @@
|
||||
# Microdot change log
|
||||
|
||||
**Release 1.3.4** - 2023-11-08
|
||||
|
||||
- Handle change in `wait_closed()` behavior in Python 3.12 [#177](https://github.com/miguelgrinberg/microdot/issues/177) ([commit](https://github.com/miguelgrinberg/microdot/commit/5550b20cdd347d59e2aa68f6ebf9e9abffaff9fc))
|
||||
- Added missing request argument in some documentation examples [#163](https://github.com/miguelgrinberg/microdot/issues/163) ([commit](https://github.com/miguelgrinberg/microdot/commit/744548f8dc33a72512b34c4001ee9c6c1edd22ee))
|
||||
- Fix minor documentation typos [#161](https://github.com/miguelgrinberg/microdot/issues/161) ([commit](https://github.com/miguelgrinberg/microdot/commit/2e4911d10826cbb3914de4a45e495c3be36543fa)) (thanks **Andy Piper**!)
|
||||
|
||||
**Release 1.3.3** - 2023-07-16
|
||||
|
||||
- Handle query string arguments without value [#149](https://github.com/miguelgrinberg/microdot/issues/149) ([commit](https://github.com/miguelgrinberg/microdot/commit/3554bc91cb1523efa5b66fe3ef173f8e86e8c2a0))
|
||||
- Support empty responses with ASGI adapter ([commit](https://github.com/miguelgrinberg/microdot/commit/e09e9830f43af41d38775547637558494151a385))
|
||||
- Added CORS extension to Python package ([commit](https://github.com/miguelgrinberg/microdot/commit/304ca2ef6881fe718126b3e308211e760109d519))
|
||||
- Document access to WSGI and ASGI attributes [#153](https://github.com/miguelgrinberg/microdot/issues/153) ([commit](https://github.com/miguelgrinberg/microdot/commit/d99df2c4010ab70c60b86ab334d656903e04eb26))
|
||||
- Upgrade micropython tests to use v1.20 ([commit](https://github.com/miguelgrinberg/microdot/commit/e0f0565551966ee0238a5a1819c78a13639ad704))
|
||||
|
||||
**Release 1.3.2** - 2023-06-13
|
||||
|
||||
- In ASGI, return headers as strings and not binary [#144](https://github.com/miguelgrinberg/microdot/issues/144) ([commit](https://github.com/miguelgrinberg/microdot/commit/e92310fa55bbffcdcbb33f560e27c3579d7ac451))
|
||||
|
||||
5
MANIFEST.in
Normal file
5
MANIFEST.in
Normal file
@@ -0,0 +1,5 @@
|
||||
include README.md LICENSE tox.ini
|
||||
recursive-include docs *
|
||||
recursive-exclude docs/_build *
|
||||
recursive-include tests *
|
||||
exclude **/*.pyc
|
||||
BIN
bin/micropython
BIN
bin/micropython
Binary file not shown.
@@ -137,8 +137,8 @@ subdirectory. This location can be changed with the
|
||||
.. note::
|
||||
The Jinja extension is not compatible with MicroPython.
|
||||
|
||||
Maintaing Secure User Sessions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Maintaining Secure User Sessions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. list-table::
|
||||
:align: left
|
||||
@@ -486,6 +486,9 @@ web application using the Gunicorn web server::
|
||||
|
||||
gunicorn test:app
|
||||
|
||||
When using this WSGI adapter, the ``environ`` dictionary provided by the web
|
||||
server is available to request handlers as ``request.environ``.
|
||||
|
||||
Using an ASGI Web Server
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -529,3 +532,5 @@ web application using the Uvicorn web server::
|
||||
|
||||
uvicorn test:app
|
||||
|
||||
When using this ASGI adapter, the ``scope`` dictionary provided by the web
|
||||
server is available to request handlers as ``request.asgi_scope``.
|
||||
|
||||
@@ -301,7 +301,7 @@ expected to return an updated response object.
|
||||
|
||||
.. note::
|
||||
The :ref:`request.g <The "g" Object>` object is a special object that allows
|
||||
the before and after request handlers, as well sa the route function to
|
||||
the before and after request handlers, as well as the route function to
|
||||
share data during the life of the request.
|
||||
|
||||
Error Handlers
|
||||
@@ -500,7 +500,7 @@ contents as a file-like object.
|
||||
Cookies
|
||||
^^^^^^^
|
||||
|
||||
Cookies that are sent by the client are made available throught the
|
||||
Cookies that are sent by the client are made available through the
|
||||
:attr:`cookies <microdot.Request.cookies>` attribute of the request object in
|
||||
dictionary form.
|
||||
|
||||
@@ -595,7 +595,7 @@ always returned to the client in the response body::
|
||||
In the above example, Microdot issues a standard 200 status code response, and
|
||||
inserts the necessary headers.
|
||||
|
||||
The applicaton can provide its own status code as a second value returned from
|
||||
The application can provide its own status code as a second value returned from
|
||||
the route. The example below returns a 202 status code::
|
||||
|
||||
@app.get('/')
|
||||
@@ -611,7 +611,7 @@ The next example returns an HTML response, instead of a default text response::
|
||||
return '<h1>Hello, World!</h1>', 202, {'Content-Type': 'text/html'}
|
||||
|
||||
If the application needs to return custom headers, but does not need to change
|
||||
the default status code, then it can return two values, omitting the stauts
|
||||
the default status code, then it can return two values, omitting the status
|
||||
code::
|
||||
|
||||
@app.get('/')
|
||||
@@ -753,7 +753,7 @@ Another option is to create a response object directly in the route function::
|
||||
Standard cookies do not offer sufficient privacy and security controls, so
|
||||
never store sensitive information in them unless you are adding additional
|
||||
protection mechanisms such as encryption or cryptographic signing. The
|
||||
:ref:`session <Maintaing Secure User Sessions>` extension implements signed
|
||||
:ref:`session <Maintaining Secure User Sessions>` extension implements signed
|
||||
cookies that prevent tampering by malicious actors.
|
||||
|
||||
Concurrency
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
aiofiles==0.8.0
|
||||
anyio==3.6.1
|
||||
blinker==1.5
|
||||
certifi==2022.12.7
|
||||
certifi==2023.7.22
|
||||
charset-normalizer==2.1.0
|
||||
click==8.1.3
|
||||
fastapi==0.79.0
|
||||
Flask==2.2.1
|
||||
Flask==2.3.2
|
||||
gunicorn==20.1.0
|
||||
h11==0.13.0
|
||||
h2==4.1.0
|
||||
@@ -27,7 +27,7 @@ sniffio==1.2.0
|
||||
starlette==0.27.0
|
||||
toml==0.10.2
|
||||
typing_extensions==4.3.0
|
||||
urllib3==1.26.11
|
||||
urllib3==1.26.18
|
||||
uvicorn==0.18.2
|
||||
Werkzeug==2.2.3
|
||||
wsproto==1.1.0
|
||||
|
||||
@@ -1,6 +1,57 @@
|
||||
[project]
|
||||
name = "microdot"
|
||||
version = "1.3.5.dev0"
|
||||
authors = [
|
||||
{ name = "Miguel Grinberg", email = "miguel.grinberg@gmail.com" },
|
||||
]
|
||||
description = "The impossibly small web framework for MicroPython"
|
||||
classifiers = [
|
||||
"Environment :: Web Environment",
|
||||
"Intended Audience :: Developers",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: Implementation :: MicroPython",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
]
|
||||
|
||||
[project.readme]
|
||||
file = "README.md"
|
||||
content-type = "text/markdown"
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/miguelgrinberg/microdot"
|
||||
"Bug Tracker" = "https://github.com/miguelgrinberg/microdot/issues"
|
||||
|
||||
[project.optional-dependencies]
|
||||
docs = [
|
||||
"sphinx",
|
||||
]
|
||||
|
||||
[tool.setuptools]
|
||||
zip-safe = false
|
||||
include-package-data = true
|
||||
py-modules = [
|
||||
"microdot",
|
||||
"microdot_asyncio",
|
||||
"microdot_utemplate",
|
||||
"microdot_jinja",
|
||||
"microdot_session",
|
||||
"microdot_cors",
|
||||
"microdot_websocket",
|
||||
"microdot_websocket_alt",
|
||||
"microdot_asyncio_websocket",
|
||||
"microdot_test_client",
|
||||
"microdot_asyncio_test_client",
|
||||
"microdot_wsgi",
|
||||
"microdot_asgi",
|
||||
"microdot_asgi_websocket",
|
||||
]
|
||||
|
||||
[tool.setuptools.package-dir]
|
||||
"" = "src"
|
||||
|
||||
[build-system]
|
||||
requires = [
|
||||
"setuptools>=42",
|
||||
"wheel"
|
||||
"setuptools>=61.2",
|
||||
]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
38
setup.cfg
38
setup.cfg
@@ -1,38 +0,0 @@
|
||||
[metadata]
|
||||
name = microdot
|
||||
version = 1.3.2
|
||||
author = Miguel Grinberg
|
||||
author_email = miguel.grinberg@gmail.com
|
||||
description = The impossibly small web framework for MicroPython
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://github.com/miguelgrinberg/microdot
|
||||
project_urls =
|
||||
Bug Tracker = https://github.com/miguelgrinberg/microdot/issues
|
||||
classifiers =
|
||||
Environment :: Web Environment
|
||||
Intended Audience :: Developers
|
||||
Programming Language :: Python :: 3
|
||||
Programming Language :: Python :: Implementation :: MicroPython
|
||||
License :: OSI Approved :: MIT License
|
||||
Operating System :: OS Independent
|
||||
|
||||
[options]
|
||||
zip_safe = False
|
||||
include_package_data = True
|
||||
package_dir =
|
||||
= src
|
||||
py_modules =
|
||||
microdot
|
||||
microdot_asyncio
|
||||
microdot_utemplate
|
||||
microdot_jinja
|
||||
microdot_session
|
||||
microdot_websocket
|
||||
microdot_websocket_alt
|
||||
microdot_asyncio_websocket
|
||||
microdot_test_client
|
||||
microdot_asyncio_test_client
|
||||
microdot_wsgi
|
||||
microdot_asgi
|
||||
microdot_asgi_websocket
|
||||
@@ -404,13 +404,15 @@ class Request():
|
||||
data = MultiDict()
|
||||
if len(urlencoded) > 0:
|
||||
if isinstance(urlencoded, str):
|
||||
for k, v in [pair.split('=', 1)
|
||||
for pair in urlencoded.split('&') if pair]:
|
||||
data[urldecode_str(k)] = urldecode_str(v)
|
||||
for kv in [pair.split('=', 1)
|
||||
for pair in urlencoded.split('&') if pair]:
|
||||
data[urldecode_str(kv[0])] = urldecode_str(kv[1]) \
|
||||
if len(kv) > 1 else ''
|
||||
elif isinstance(urlencoded, bytes): # pragma: no branch
|
||||
for k, v in [pair.split(b'=', 1)
|
||||
for pair in urlencoded.split(b'&') if pair]:
|
||||
data[urldecode_bytes(k)] = urldecode_bytes(v)
|
||||
for kv in [pair.split(b'=', 1)
|
||||
for pair in urlencoded.split(b'&') if pair]:
|
||||
data[urldecode_bytes(kv[0])] = urldecode_bytes(kv[1]) \
|
||||
if len(kv) > 1 else b''
|
||||
return data
|
||||
|
||||
@property
|
||||
@@ -1072,7 +1074,7 @@ class Microdot():
|
||||
app = Microdot()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
def index(request):
|
||||
return 'Hello, world!'
|
||||
|
||||
app.run(debug=True)
|
||||
|
||||
@@ -120,17 +120,18 @@ class Microdot(BaseMicrodot):
|
||||
asyncio.ensure_future(cancel_monitor())
|
||||
|
||||
body_iter = res.body_iter().__aiter__()
|
||||
res_body = b''
|
||||
try:
|
||||
body = await body_iter.__anext__()
|
||||
res_body = await body_iter.__anext__()
|
||||
while not cancelled: # pragma: no branch
|
||||
next_body = await body_iter.__anext__()
|
||||
await send({'type': 'http.response.body',
|
||||
'body': body,
|
||||
'body': res_body,
|
||||
'more_body': True})
|
||||
body = next_body
|
||||
res_body = next_body
|
||||
except StopAsyncIteration:
|
||||
await send({'type': 'http.response.body',
|
||||
'body': body,
|
||||
'body': res_body,
|
||||
'more_body': False})
|
||||
|
||||
async def __call__(self, scope, receive, send):
|
||||
|
||||
@@ -241,7 +241,7 @@ class Microdot(BaseMicrodot):
|
||||
app = Microdot()
|
||||
|
||||
@app.route('/')
|
||||
async def index():
|
||||
async def index(request):
|
||||
return 'Hello, world!'
|
||||
|
||||
async def main():
|
||||
@@ -280,6 +280,11 @@ class Microdot(BaseMicrodot):
|
||||
|
||||
while True:
|
||||
try:
|
||||
if hasattr(self.server, 'serve_forever'): # pragma: no cover
|
||||
try:
|
||||
await self.server.serve_forever()
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
await self.server.wait_closed()
|
||||
break
|
||||
except AttributeError: # pragma: no cover
|
||||
@@ -313,7 +318,7 @@ class Microdot(BaseMicrodot):
|
||||
app = Microdot()
|
||||
|
||||
@app.route('/')
|
||||
async def index():
|
||||
async def index(request):
|
||||
return 'Hello, world!'
|
||||
|
||||
app.run(debug=True)
|
||||
|
||||
@@ -39,11 +39,12 @@ class TestRequest(unittest.TestCase):
|
||||
self.assertEqual(req.body, b'aaa')
|
||||
|
||||
def test_args(self):
|
||||
fd = get_request_fd('GET', '/?foo=bar&abc=def&x=%2f%%')
|
||||
fd = get_request_fd('GET', '/?foo=bar&abc=def&foo&x=%2f%%')
|
||||
req = Request.create('app', fd, 'addr')
|
||||
self.assertEqual(req.query_string, 'foo=bar&abc=def&x=%2f%%')
|
||||
self.assertEqual(req.args, MultiDict(
|
||||
{'foo': 'bar', 'abc': 'def', 'x': '/%%'}))
|
||||
self.assertEqual(req.query_string, 'foo=bar&abc=def&foo&x=%2f%%')
|
||||
md = MultiDict({'foo': 'bar', 'abc': 'def', 'x': '/%%'})
|
||||
md['foo'] = ''
|
||||
self.assertEqual(req.args, md)
|
||||
|
||||
def test_badly_formatted_args(self):
|
||||
fd = get_request_fd('GET', '/?&foo=bar&abc=def&&&x=%2f%%')
|
||||
|
||||
@@ -49,11 +49,12 @@ class TestRequestAsync(unittest.TestCase):
|
||||
self.assertEqual(req.body, b'aaa')
|
||||
|
||||
def test_args(self):
|
||||
fd = get_async_request_fd('GET', '/?foo=bar&abc=def&x=%2f%%')
|
||||
fd = get_async_request_fd('GET', '/?foo=bar&abc=def&foo&x=%2f%%')
|
||||
req = _run(Request.create('app', fd, 'writer', 'addr'))
|
||||
self.assertEqual(req.query_string, 'foo=bar&abc=def&x=%2f%%')
|
||||
self.assertEqual(req.args, MultiDict(
|
||||
{'foo': 'bar', 'abc': 'def', 'x': '/%%'}))
|
||||
self.assertEqual(req.query_string, 'foo=bar&abc=def&foo&x=%2f%%')
|
||||
md = MultiDict({'foo': 'bar', 'abc': 'def', 'x': '/%%'})
|
||||
md['foo'] = ''
|
||||
self.assertEqual(req.args, md)
|
||||
|
||||
def test_json(self):
|
||||
fd = get_async_request_fd('GET', '/foo', headers={
|
||||
|
||||
Reference in New Issue
Block a user