Skip to content

Commit

Permalink
Merge branch 'master' into 122_crlf_in_header_field
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Sep 28, 2024
2 parents 3736a53 + 851a026 commit 50e82c7
Show file tree
Hide file tree
Showing 16 changed files with 1,189 additions and 184 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy Documentation

on:
push:
tags:
- "**"

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "0.4.12"
enable-cache: true

- name: Set up Python
run: uv python install 3.12

- name: Install dependencies
run: uv sync --frozen

- run: uv run mkdocs gh-deploy --force
46 changes: 28 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,40 @@ on:
pull_request:
branches: ["master"]


jobs:
build:

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

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

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: ${{ matrix.python-version }}
version: "0.4.12"
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Lint
if: matrix.python-version == '3.8'
run: |
ruff multipart tests
- name: Test with pytest
run: |
inv test
run: uv sync --python ${{ matrix.python-version }} --frozen

- name: Run tests
run: scripts/test

- name: Run linters
run: scripts/lint

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check:
if: always()
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
81 changes: 49 additions & 32 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package
name: Publish Python Package

on:
push:
tags:
- '*'

permissions:
contents: read
- "**"

jobs:
deploy:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.inspect_package.outputs.version }}
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
version: "0.4.12"
enable-cache: true

- name: Set up Python
run: uv python install 3.12

- name: Build package
run: uv build

- name: Inspect package version
id: inspect_package
run: |
version=$(uvx hatchling version)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: package-distributions
path: dist/

pypi-publish:
runs-on: ubuntu-latest
needs: build

permissions:
id-token: write

environment:
name: pypi
url: https://pypi.org/project/python-multipart/${{ needs.build.outputs.version }}

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install -e '.[docs]'
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/[email protected]
- name: Download package
uses: actions/download-artifact@v4
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Publish docs
run: mkdocs gh-deploy --force
name: package-distributions
path: dist/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.0.10 (2024-09-21)

* Support `on_header_begin` [#103](https://github.com/Kludex/python-multipart/pull/103).
* Improve type hints on `FormParser` [#104](https://github.com/Kludex/python-multipart/pull/104).
* Fix `OnFileCallback` type [#106](https://github.com/Kludex/python-multipart/pull/106).
* Improve type hints [#110](https://github.com/Kludex/python-multipart/pull/110).
* Improve type hints on `File` [#111](https://github.com/Kludex/python-multipart/pull/111).
* Add type hint to helper functions [#112](https://github.com/Kludex/python-multipart/pull/112).
* Minor fix for Field.__repr__ [#114](https://github.com/Kludex/python-multipart/pull/114).
* Fix use of chunk_size parameter [#136](https://github.com/Kludex/python-multipart/pull/136).
* Allow digits and valid token chars in headers [#134](https://github.com/Kludex/python-multipart/pull/134).
* Fix headers being carried between parts [#135](https://github.com/Kludex/python-multipart/pull/135).

## 0.0.9 (2024-02-10)

* Add support for Python 3.12 [#85](https://github.com/Kludex/python-multipart/pull/85).
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# [Python-Multipart](https://kludex.github.io/python-multipart/)

[![Build Status](https://github.com/Kludex/python-multipart/workflows/CI/badge.svg)](https://github.com/Kludex/python-multipart/actions)
[![Package version](https://badge.fury.io/py/python-multipart.svg)](https://pypi.python.org/pypi/python-multipart)
[![Supported Python Version](https://img.shields.io/pypi/pyversions/python-multipart.svg?color=%2334D058)](https://pypi.org/project/python-multipart)

Expand Down
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
multipart.fastapiexpert.com
4 changes: 3 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
:::multipart
::: multipart

::: multipart.exceptions
13 changes: 11 additions & 2 deletions multipart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
__author__ = "Andrew Dunham"
__license__ = "Apache"
__copyright__ = "Copyright (c) 2012-2013, Andrew Dunham"
__version__ = "0.0.9"
__version__ = "0.0.10"

from .multipart import FormParser, MultipartParser, OctetStreamParser, QuerystringParser, create_form_parser, parse_form
from .multipart import (
BaseParser,
FormParser,
MultipartParser,
OctetStreamParser,
QuerystringParser,
create_form_parser,
parse_form,
)

__all__ = (
"BaseParser",
"FormParser",
"MultipartParser",
"OctetStreamParser",
Expand Down
22 changes: 9 additions & 13 deletions multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,19 @@ class FileConfig(TypedDict, total=False):
MAX_MEMORY_FILE_SIZE: int

class _FormProtocol(Protocol):
def write(self, data: bytes) -> int:
...
def write(self, data: bytes) -> int: ...

def finalize(self) -> None:
...
def finalize(self) -> None: ...

def close(self) -> None:
...
def close(self) -> None: ...

class FieldProtocol(_FormProtocol, Protocol):
def __init__(self, name: bytes) -> None:
...
def __init__(self, name: bytes) -> None: ...

def set_none(self) -> None:
...
def set_none(self) -> None: ...

class FileProtocol(_FormProtocol, Protocol):
def __init__(self, file_name: bytes | None, field_name: bytes | None, config: FileConfig) -> None:
...
def __init__(self, file_name: bytes | None, field_name: bytes | None, config: FileConfig) -> None: ...

OnFieldCallback = Callable[[FieldProtocol], None]
OnFileCallback = Callable[[FileProtocol], None]
Expand Down Expand Up @@ -136,14 +130,16 @@ class MultipartState(IntEnum):
LOWER_Z = b"z"[0]
NULL = b"\x00"[0]

# fmt: off
# Mask for ASCII characters that can be http tokens.
# Per RFC7230 - 3.2.6, this is all alpha-numeric characters
# Per RFC7230 - 3.2.6, this is all alpha-numeric characters
# and these: !#$%&'*+-.^_`|~
TOKEN_CHARS_SET = frozenset(
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b"abcdefghijklmnopqrstuvwxyz"
b"0123456789"
b"!#$%&'*+-.^_`|~")
# fmt: on


def ord_char(c: int) -> int:
Expand Down
22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ classifiers = [
]
dependencies = []

[project.optional-dependencies]
dev = [
[tool.uv]
dev-dependencies = [
"atomicwrites==1.4.1",
"attrs==23.2.0",
"coverage==7.4.4",
Expand All @@ -45,15 +45,12 @@ dev = [
"invoke==2.2.0",
"pytest-timeout==2.3.1",
"ruff==0.3.4",
"hatch",
"atheris==2.3.0; python_version != '3.12'",
]
docs = [
"mkdocs==1.5.3",
"mkdocs-material==9.5.16",
"mkdocstrings==0.24.1",
"mkdocstrings-python==1.9.0",
"mkdocs-autorefs==1.0.1",
# Documentation
"mkdocs",
"mkdocs-material",
"mkdocstrings-python",
"mkdocs-autorefs",
]

[project.urls]
Expand All @@ -69,7 +66,7 @@ path = "multipart/__init__.py"
packages = ["multipart"]

[tool.hatch.build.targets.sdist]
include = ["/multipart", "/tests"]
include = ["/multipart", "/tests", "CHANGELOG.md", "LICENSE.txt"]

[tool.ruff]
line-length = 120
Expand All @@ -90,6 +87,9 @@ branch = false
omit = ["tests/*"]

[tool.coverage.report]
# fail_under = 100
skip_covered = true
show_missing = true
exclude_lines = [
"pragma: no cover",
"raise NotImplementedError",
Expand Down
11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

6 changes: 6 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -e

set -x

uvx ruff check --fix
uvx ruff format
6 changes: 6 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -e

set -x # print executed commands to the terminal

uv run coverage run -m pytest "${@}"
uv run coverage report
Loading

0 comments on commit 50e82c7

Please sign in to comment.