Skip to content

Commit

Permalink
Merge branch 'master' into cache-stream-in-basehttpmiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Jan 15, 2023
2 parents 2347ac1 + 33f46a1 commit 0fa5897
Show file tree
Hide file tree
Showing 32 changed files with 507 additions and 449 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: "actions/checkout@v3"
Expand Down
2 changes: 2 additions & 0 deletions docs/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ The following arguments are supported:

* `minimum_size` - Do not GZip responses that are smaller than this minimum size in bytes. Defaults to `500`.

The middleware won't GZip responses that already have a `Content-Encoding` set, to prevent them from being encoded twice.

## BaseHTTPMiddleware

An abstract class that allows you to write ASGI middleware against a request/response
Expand Down
32 changes: 32 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
## 0.23.1

December 9, 2022

### Fixed
* Only stop receiving stream on `body_stream` if body is empty on the `BaseHTTPMiddleware` [#1940](https://github.com/encode/starlette/pull/1940).

## 0.23.0

December 5, 2022

### Added
* Add `headers` parameter to the `TestClient` [#1966](https://github.com/encode/starlette/pull/1966).

### Deprecated
* Deprecate `Starlette` and `Router` decorators [#1897](https://github.com/encode/starlette/pull/1897).

### Fixed
* Fix bug on `FloatConvertor` regex [#1973](https://github.com/encode/starlette/pull/1973).

## 0.22.0

November 17, 2022

### Changed
* Bypass `GZipMiddleware` when response includes `Content-Encoding` [#1901](https://github.com/encode/starlette/pull/1901).

### Fixed
* Remove unneeded `unquote()` from query parameters on the `TestClient` [#1953](https://github.com/encode/starlette/pull/1953).
* Make sure `MutableHeaders._list` is actually a `list` [#1917](https://github.com/encode/starlette/pull/1917).
* Import compatibility with the next version of `AnyIO` [#1936](https://github.com/encode/starlette/pull/1936).

## 0.21.0

September 26, 2022
Expand Down
43 changes: 41 additions & 2 deletions docs/templates.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Starlette is not *strictly* coupled to any particular templating engine, but
Starlette is not _strictly_ coupled to any particular templating engine, but
Jinja2 provides an excellent choice.

Starlette provides a simple way to get `jinja2` configured. This is probably
Expand Down Expand Up @@ -33,7 +33,7 @@ so we can correctly hyperlink to other pages within the application.
For example, we can link to static files from within our HTML templates:

```html
<link href="{{ url_for('static', path='/css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', path='/css/bootstrap.min.css') }}" rel="stylesheet" />
```

If you want to use [custom filters][jinja2], you will need to update the `env`
Expand All @@ -50,12 +50,51 @@ templates = Jinja2Templates(directory='templates')
templates.env.filters['marked'] = marked_filter
```

## Context processors

A context processor is a function that returns a dictionary to be merged into a template context.
Every function takes only one argument `request` and must return a dictionary to add to the context.

A common use case of template processors is to extend the template context with shared variables.

```python
import typing
from starlette.requests import Request

def app_context(request: Request) -> typing.Dict[str, typing.Any]:
return {'app': request.app}
```

### Registering context templates

Pass context processors to `context_processors` argument of the `Jinja2Templates` class.

```python
import typing

from starlette.requests import Request
from starlette.templating import Jinja2Templates

def app_context(request: Request) -> typing.Dict[str, typing.Any]:
return {'app': request.app}

templates = Jinja2Templates(
directory='templates', context_processors=[app_context]
)
```

!!! info
Asynchronous functions as context processors are not supported.

## Testing template responses

When using the test client, template responses include `.template` and `.context`
attributes.

```python
from starlette.testclient import TestClient


def test_homepage():
client = TestClient(app)
response = client.get("/")
Expand Down
2 changes: 1 addition & 1 deletion docs/testclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ with open("example.txt", "rb") as f1:
response = client.post("/form", files=files)
```

For more information you can check the `requests` [documentation](https://requests.readthedocs.io/en/master/user/advanced/).
For more information you can check the `httpx` [documentation](https://www.python-httpx.org/advanced/).

By default the `TestClient` will raise any exceptions that occur in the
application. Occasionally you might want to test the content of 500 error
Expand Down
18 changes: 17 additions & 1 deletion docs/third-party-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ Built with [Tabler](https://tabler.io/) and [Datatables](https://datatables.net/
to quickly generate fully customizable admin interface for your models. You can export your data to many formats (*CSV*, *PDF*,
*Excel*, etc), filter your data with complex query including `AND` and `OR` conditions, upload files, ...


## Frameworks

### FastAPI
Expand All @@ -158,6 +157,17 @@ to quickly generate fully customizable admin interface for your models. You can
High performance, easy to learn, fast to code, ready for production web API framework.
Inspired by **APIStar**'s previous server system with type declarations for route parameters, based on the OpenAPI specification version 3.0.0+ (with JSON Schema), powered by **Pydantic** for the data handling.

### Esmerald

<a href="https://github.com/dymmond/esmerald" target="_blank">GitHub</a> |
<a href="https://esmerald.dymmond.com/" target="_blank">Documentation</a>

Highly scalable, performant, easy to learn, easy to code and for every application web framework.
Inspired by a lot of frameworks out there, Esmerald provides what every application needs, from the
smallest to complex. Includes, routes, middlewares, permissions, scheduler, interceptors and lot more.

Powered by **Starlette** and **Pydantic** with OpenAPI specification.

### Flama

<a href="https://github.com/perdy/flama/" target="_blank">GitHub</a> |
Expand Down Expand Up @@ -209,3 +219,9 @@ A flexible and extendable web framework built on top of Starlette, Pydantic and
An extension to integrate Swagger/OpenAPI document easily for Starlette project and provide [SwaggerUI](http://swagger.io/swagger-ui/) and [RedocUI](https://rebilly.github.io/ReDoc/).

<a href="https://github.com/strongbugman/apiman" target="_blank">GitHub</a>

### Starlette-Babel

Provides translations, localization, and timezone support via Babel integration.

<a href="https://github.com/alex-oleshkevich/starlette_babel" target="_blank">GitHub</a>
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ theme:
toggle:
icon: 'material/lightbulb-outline'
name: 'Switch to light mode'
icon:
repo: fontawesome/brands/github

repo_name: encode/starlette
repo_url: https://github.com/encode/starlette
edit_uri: ""
edit_uri: edit/master/docs/

nav:
- Introduction: 'index.md'
Expand Down
23 changes: 10 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@

# Testing
autoflake==1.5.3
black==22.8.0
coverage==6.4.2
databases[sqlite]==0.6.1
black==22.12.0
coverage==7.0.1
flake8==3.9.2
importlib-metadata==4.13.0
isort==5.10.1
mypy==0.971
typing_extensions==4.3.0
mypy==0.991
typing_extensions==4.4.0
types-contextvars==2.4.7
types-PyYAML==6.0.12
types-PyYAML==6.0.12.2
types-dataclasses==0.6.6
pytest==7.1.3
pytest==7.2.0
trio==0.21.0
# NOTE: Remove once greenlet releases 2.0.0.
greenlet==2.0.0a2; python_version >= "3.11"

# Documentation
mkdocs==1.4.0
mkdocs-material==8.5.5
mkdocs==1.4.2
mkdocs-material==8.5.7
mkautodoc==0.2.0

# Packaging
build==0.8.0
twine==4.0.1
build==0.9.0
twine==4.0.2
2 changes: 1 addition & 1 deletion scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ else
PIP="pip"
fi

"$PIP" install -U pip
"$PIP" install -r "$REQUIREMENTS"
"$PIP" install -e .
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ disallow_untyped_defs = True
ignore_missing_imports = True
no_implicit_optional = True
show_error_codes = True
enable_error_code = ignore-without-code

[mypy-starlette.testclient]
no_implicit_optional = False
Expand Down Expand Up @@ -35,6 +36,7 @@ filterwarnings=
ignore: Use 'content=<...>' to upload raw bytes/text content.:DeprecationWarning
ignore: The `allow_redirects` argument is deprecated. Use `follow_redirects` instead.:DeprecationWarning
ignore: 'cgi' is deprecated and slated for removal in Python 3\.13:DeprecationWarning
ignore: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.:RuntimeWarning

[coverage:run]
source_pkgs = starlette, tests
Expand Down
29 changes: 0 additions & 29 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion starlette/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.21.0"
__version__ = "0.23.1"

0 comments on commit 0fa5897

Please sign in to comment.