Skip to content
Merged
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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ include docs/source/index.rst
include LICENSE
include docs/source/changelog.rst
recursive-include flask_inputfilter *.py *.pyx *.c *.cpp
recursive-include flask_inputfilter/include *.h
prune tests
recursive-prune __pycache__
10 changes: 10 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Changelog

All notable changes to this project will be documented in this file.

[0.4.1] - 2025-04-24
--------------------

Changed
^^^^^^^
- Introduced first c++ vector in ``InputFilter`` to improve performance.
- Updated required ``cython`` version to 3.0 or higher for python 3.7 - 3.11.
- Moved static methods outside of pure InputFilter class.


[0.4.0] - 2025-04-20
--------------------

Expand Down
15 changes: 7 additions & 8 deletions docs/source/guides/create_own_components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Example implementation

.. code-block:: python

from typing import Any, Dict
from typing import Any

from flask_inputfilter.Condition import BaseCondition

Expand All @@ -45,7 +45,7 @@ Example implementation
self.first_field = first_field
self.second_field = second_field

def check(self, data: Dict[str, Any]) -> bool:
def check(self, data: dict[str, Any]) -> bool:
return data.get(self.first_field) == data.get(self.second_field)


Expand All @@ -69,7 +69,7 @@ Example implementation
.. code-block:: python

from datetime import date, datetime
from typing import Any, Union
from typing import Any

from flask_inputfilter.Filter import BaseFilter

Expand All @@ -80,7 +80,7 @@ Example implementation
Supports ISO 8601 formatted strings.
"""

def apply(self, value: Any) -> Union[datetime, Any]:
def apply(self, value: Any) -> datetime|Any:
if isinstance(value, datetime):
return value

Expand All @@ -94,8 +94,7 @@ Example implementation
except ValueError:
return value

else:
return value
return value


Validator
Expand All @@ -116,7 +115,7 @@ Example implementation

.. code-block:: python

from typing import Any, List, Optional
from typing import Any, Optional

from flask_inputfilter.Exception import ValidationError
from flask_inputfilter.Validator import BaseValidator
Expand All @@ -129,7 +128,7 @@ Example implementation

def __init__(
self,
haystack: List[Any],
haystack: list[Any],
strict: bool = False,
error_message: Optional[str] = None,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion docs/source/options/copy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Basic Copy Integration
def test_route():
validated_data = g.validated_data

# Cotains the same value as username but escaped eg. "very-important-user"
# Contains the same value as username but escaped eg. "very-important-user"
print(validated_data["escapedUsername"])


Expand Down
4 changes: 3 additions & 1 deletion env_configs/cython.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM python:3.7-slim

WORKDIR /app

RUN apt-get update && apt-get install -y g++ git
RUN apt-get update \
&& apt-get install -y g++ git \
&& apt-get clean

COPY pyproject.toml /app

Expand Down
52 changes: 27 additions & 25 deletions env_configs/env.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@ FROM debian:buster-slim

WORKDIR /app

RUN apt-get update && apt-get install -y \
build-essential \
curl \
g++ \
git \
libbz2-dev \
libffi-dev \
libjpeg-dev \
liblzma-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
llvm \
make \
python3-dev \
tk-dev \
wget \
xz-utils \
zlib1g-dev
RUN apt-get update \
&& apt-get install -y \
build-essential \
curl \
g++ \
git \
libbz2-dev \
libffi-dev \
libjpeg-dev \
liblzma-dev \
libncurses5-dev \
libncursesw5-dev \
libreadline-dev \
libsqlite3-dev \
libssl-dev \
llvm \
make \
python3-dev \
tk-dev \
wget \
xz-utils \
zlib1g-dev \
&& apt-get clean

RUN curl https://pyenv.run | bash

ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:/root/.pyenv/versions/3.7.12/bin:$PATH"
RUN echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
RUN echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
RUN echo 'eval "$(pyenv init -)"' >> ~/.bashrc
RUN echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
RUN echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc \
&& echo 'eval "$(pyenv init --path)"' >> ~/.bashrc \
&& echo 'eval "$(pyenv init -)"' >> ~/.bashrc \
&& echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc

RUN /root/.pyenv/bin/pyenv install 3.7.12
RUN /root/.pyenv/bin/pyenv install 3.8.12
Expand Down
4 changes: 3 additions & 1 deletion env_configs/pure.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM python:3.7-slim

WORKDIR /app

RUN apt-get update && apt-get install -y git
RUN apt-get update \
&& apt-get install -y git \
&& apt-get clean

COPY pyproject.toml /app

Expand Down
2 changes: 1 addition & 1 deletion env_configs/requirements-py310.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cython==0.29.24
cython==3.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major version jump may cause compatibility issues

Upgrading from Cython 0.29.24 to 3.0 is a major version jump that may cause compatibility issues. Cython 3.0 introduced breaking changes that could affect existing code.

Code suggestion
Check the AI-generated fix before applying
Suggested change
cython==3.0
cython>=0.29.24,<1.0.0

Code Review Run #48b91c


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

flask==2.1
pillow==8.0.0
pytest
Expand Down
2 changes: 1 addition & 1 deletion env_configs/requirements-py311.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cython==0.29.32
cython==3.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major version upgrade may break compatibility

Upgrading from Cython 0.29.32 to 3.0 is a major version jump that may introduce breaking changes. Cython 3.0 has significant API changes that could affect existing code.

Code suggestion
Check the AI-generated fix before applying
Suggested change
cython==3.0
cython>=0.29.32,<1.0.0

Code Review Run #48b91c


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

flask==2.1
pillow==8.0.0
pytest
Expand Down
2 changes: 1 addition & 1 deletion env_configs/requirements-py37.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cython==0.29
cython==3.0
flask==2.1
pillow==8.0.0
pytest
Expand Down
2 changes: 1 addition & 1 deletion env_configs/requirements-py38.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cython==0.29
cython==3.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major version upgrade with breaking changes

Upgrading from Cython 0.29 to 3.0 is a major version jump that may cause compatibility issues. Cython 3.0 introduced breaking changes that could affect existing code.

Code suggestion
Check the AI-generated fix before applying
Suggested change
cython==3.0
cython>=0.29,<1.0

Code Review Run #48b91c


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

flask==2.1
pillow==8.0.0
pytest
Expand Down
2 changes: 1 addition & 1 deletion env_configs/requirements-py39.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cython==0.29.21
cython==3.0
flask==2.1
pillow==8.0.0
pytest
Expand Down
3 changes: 2 additions & 1 deletion flask_inputfilter/Condition/CustomCondition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Any, Callable, Dict
from collections.abc import Callable
from typing import Any, Dict

from flask_inputfilter.Condition import BaseCondition

Expand Down
11 changes: 2 additions & 9 deletions flask_inputfilter/Filter/Base64ImageDownscaleFilter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

import base64
import binascii
import io
from typing import Any, Optional

from PIL import Image, UnidentifiedImageError
from PIL import Image

from flask_inputfilter.Filter import BaseFilter

Expand Down Expand Up @@ -39,13 +38,7 @@ def apply(self, value: Any) -> Any:
image = Image.open(io.BytesIO(base64.b64decode(value)))
return self.resize_picture(image)

except (
binascii.Error,
UnidentifiedImageError,
OSError,
ValueError,
TypeError,
):
except (OSError, ValueError, TypeError):
return value

def resize_picture(self, image: Image) -> str:
Expand Down
11 changes: 2 additions & 9 deletions flask_inputfilter/Filter/Base64ImageResizeFilter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

import base64
import binascii
import io
from typing import Any

from PIL import Image, UnidentifiedImageError
from PIL import Image

from flask_inputfilter.Enum import ImageFormatEnum
from flask_inputfilter.Filter import BaseFilter
Expand Down Expand Up @@ -46,13 +45,7 @@ def apply(self, value: Any) -> Any:

value = Image.open(io.BytesIO(base64.b64decode(value)))
return self.reduce_image(value)
except (
binascii.Error,
UnidentifiedImageError,
OSError,
ValueError,
TypeError,
):
except (OSError, ValueError, TypeError):
return value

def reduce_image(self, image: Image) -> Image:
Expand Down
5 changes: 1 addition & 4 deletions flask_inputfilter/Filter/ToEnumFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ def __init__(self, enum_class: Type[Enum]) -> None:
self.enum_class = enum_class

def apply(self, value: Any) -> Union[Enum, Any]:
if not isinstance(value, (str, int)):
return value

elif isinstance(value, Enum):
if not isinstance(value, (str, int)) or isinstance(value, Enum):
return value

try:
Expand Down
5 changes: 1 addition & 4 deletions flask_inputfilter/Filter/ToIsoFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ class ToIsoFilter(BaseFilter):
"""

def apply(self, value: Any) -> Union[str, Any]:
if isinstance(value, datetime):
return value.isoformat()

elif isinstance(value, date):
if isinstance(value, (datetime, date)):
return value.isoformat()

return value
Loading