Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the bytes type during build OpenAPI Specification #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
runs-on: windows-latest
if: github.event_name == 'pull_request' || github.event_name == 'push'

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 9
submodules: false

- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install cython==3.0.2
pip install -r requirements.txt
pip install flake8

Expand Down Expand Up @@ -77,24 +76,24 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 9
submodules: false

- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install black==24.2.0 isort==5.13.2 flake8==7.0.0
pip install black==24.8.0 isort==5.13.2 flake8==7.1.1

- name: Compile Cython extensions
run: |
Expand All @@ -104,10 +103,10 @@ jobs:
run: |
pytest --doctest-modules --junitxml=junit/pytest-results-${{ matrix.os }}-${{ matrix.python-version }}.xml --cov=$PROJECT_NAME --cov-report=xml

- name: Run tests with Pydantic v2
- name: Run tests with Pydantic v1
run: |
echo "[*] The previous tests used Pydantic v1, now running with v2"
pip install -U pydantic==2.4.2
echo "[*] The previous tests used Pydantic v2, now running with v1"
pip install -U "pydantic<2"
pytest

- name: Run linters
Expand Down Expand Up @@ -167,22 +166,22 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 9

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install build dependencies
run: |
pip install cython==3.0.2
pip install cython==3.0.11
pip install --upgrade build

- name: Compile Cython extensions
Expand Down Expand Up @@ -229,7 +228,7 @@ jobs:
path: dist

- name: Use Python 3.11
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.8] - 2025-01-??

- Fix type error in `blacksheep/server/compression.py` `is_handled_encoding`;
contributed by @bymoye and @ChenyangGao.
- Fix issue where the host is not the proxy address when there is a proxy by
@ChenyangGao.

## [2.0.7] - 2024-02-17 :tulip:

- Fixes bug [#38](https://github.com/Neoteroi/BlackSheep-Docs/issues/38),
Expand Down
12 changes: 10 additions & 2 deletions blacksheep/server/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ def get_request_url_from_scope(
try:
path = scope["path"]
protocol = scope["scheme"]
host, port = scope["server"]
for key, val in scope["headers"]:
if key.lower() in (b"host", b"x-forwarded-host", b"x-original-host"):
host = val.decode("latin-1")
port = 0
break
else:
host, port = scope["server"]
except KeyError as key_error:
raise ValueError(f"Invalid scope: {key_error}")

if protocol == "http" and port == 80:
if not port:
port_part = ""
elif protocol == "http" and port == 80:
port_part = ""
elif protocol == "https" and port == 443:
port_part = ""
Expand Down
2 changes: 1 addition & 1 deletion blacksheep/server/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _is_handled_type(content_type) -> bool:
return any(_type in content_type for _type in self.handled_types)

def is_handled_encoding() -> bool:
return b"gzip" in (request.get_first_header(b"accept-encoding") or "")
return b"gzip" in (request.get_first_header(b"accept-encoding") or b"")

def is_handled_response_content() -> bool:
if response is None or response.content is None:
Expand Down
3 changes: 3 additions & 0 deletions blacksheep/server/openapi/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ def _try_get_schema_for_simple_type(self, object_type: Type) -> Optional[Schema]
if object_type is str:
return Schema(type=ValueType.STRING)

if object_type is bytes:
return Schema(type=ValueType.STRING, format=ValueFormat.BINARY)

if object_type is int:
return Schema(type=ValueType.INTEGER, format=ValueFormat.INT64)

Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Environment :: Web Environment",
"Operating System :: OS Independent",
"Framework :: AsyncIO",
Expand All @@ -25,13 +26,13 @@ keywords = ["blacksheep", "web framework", "asyncio"]
dependencies = [
"httptools>=0.5",
"certifi>=2022.9.24",
"charset-normalizer~=3.1.0",
"charset-normalizer~=3.4.0",
"guardpost>=1.0.2",
"rodi~=2.0.2",
"essentials>=1.1.4,<2.0",
"essentials-openapi>=1.0.6,<1.1",
"python-dateutil~=2.8.2",
"itsdangerous~=2.1.2",
"python-dateutil~=2.9.0",
"itsdangerous~=2.2.0",
]

[tool.setuptools]
Expand All @@ -42,7 +43,7 @@ version = { attr = "blacksheep.__version__" }

[project.optional-dependencies]
jinja = ["Jinja2~=3.1.2"]
full = ["cryptography>=38.0.1,<41.1.0", "PyJWT~=2.6.0", "websockets~=10.3"]
full = ["cryptography>=44.0.0,<45.0.0", "PyJWT~=2.9.0", "websockets~=13.1"]

[project.urls]
"Homepage" = "https://github.com/Neoteroi/BlackSheep"
Expand Down
87 changes: 44 additions & 43 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
annotated-types==0.6.0
asgiref==3.7.2
attrs==23.1.0
blinker==1.6.3
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==3.3.1
annotated-types==0.7.0
asgiref==3.8.1
attrs==24.2.0
blinker==1.8.2
certifi==2024.12.14
cffi==1.17.1
charset-normalizer==3.4.0
click==8.1.7
coverage==7.3.2
cryptography==41.0.6
Cython==3.0.4; platform_system != "Windows"
coverage==7.6.1
cryptography==44.0.0
Cython==3.0.11
essentials==1.1.5
essentials-openapi==1.0.8
Flask==3.0.0
gevent==23.9.1
greenlet==3.0.0
essentials-openapi==1.0.9
Flask==3.0.3
gevent==24.2.1
greenlet==3.1.1
guardpost==1.0.2
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httptools==0.6.1
httptools==0.6.4
hypercorn==0.14.4
hyperframe==6.0.1
idna==3.4
idna==3.10
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.3
MarkupSafe==2.1.3
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
mccabe==0.7.0
packaging==23.2
pluggy==1.3.0
packaging==24.2
pluggy==1.5.0
priority==2.0.0
py==1.11.0
pycparser==2.21
pydantic==2.4.2
pydantic_core==2.10.1
PyJWT==2.8.0
pyparsing==3.1.1
pytest==7.4.2
pycparser==2.22
pydantic==2.10.3
pydantic-core==2.27.1
PyJWT==2.9.0
pyparsing==3.1.4
pytest==8.3.4
pytest-asyncio==0.21.1
pytest-cov==4.1.0
python-dateutil==2.8.2
PyYAML==6.0.1
regex==2023.10.3
requests==2.31.0
rodi==2.0.3
setuptools==68.2.2
six==1.16.0
pytest-cov==5.0.0
python-dateutil==2.9.0.post0
PyYAML==6.0.2
regex==2024.11.6
requests==2.32.3
rodi==2.0.6
setuptools==75.3.0
six==1.17.0
toml==0.10.2
tomli==2.0.1
typing_extensions==4.8.0
urllib3==2.0.7
uvicorn==0.23.2
wcwidth==0.2.8
websockets==12.0
Werkzeug==3.0.1
tomli==2.2.1
typing-extensions==4.12.2
urllib3==2.2.3
uvicorn==0.33.0
wcwidth==0.2.13
websockets==13.1
Werkzeug==3.0.6
wsproto==1.2.0
zope.event==5.0
zope.interface==6.1
zope.interface==7.2
build==1.2.2.post1
Loading
Loading