mirror of
https://github.com/laurentS/slowapi.git
synced 2026-03-13 09:10:20 +08:00
Merge pull request #125 from sanders41/python311
Update dev dependencies to support python 3.11
This commit is contained in:
4
.github/workflows/python-package.yml
vendored
4
.github/workflows/python-package.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ['3.7', '3.8', '3.9', '3.10']
|
||||
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@@ -49,4 +49,4 @@ jobs:
|
||||
poetry run coverage run --omit="tests*" -m pytest
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
poetry run coverage report
|
||||
poetry run coverage report
|
||||
|
||||
1808
poetry.lock
generated
1808
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -21,9 +21,9 @@ limits = "^2.3"
|
||||
isort = "^4.3.21"
|
||||
mypy = "^0.910"
|
||||
black = "^22.3.0"
|
||||
fastapi = "^0.61.0"
|
||||
fastapi = "^0.89.0"
|
||||
lxml = "^4.9.1"
|
||||
starlette = "^0.13.6"
|
||||
starlette = "^0.22.0"
|
||||
mock = "^4.0.1"
|
||||
hiro = "^0.5.1"
|
||||
requests = "^2.22.0"
|
||||
@@ -34,6 +34,7 @@ types-redis = "^3.5.6"
|
||||
coverage = "^6.3"
|
||||
flake8 = "^4.0.1"
|
||||
setuptools = "^65.5.0"
|
||||
httpx = "^0.23.3"
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
|
||||
@@ -23,10 +23,8 @@ from typing import (
|
||||
)
|
||||
|
||||
from limits import RateLimitItem # type: ignore
|
||||
from limits.aio.storage import Storage as AsyncStorage # type: ignore
|
||||
from limits.errors import ConfigurationError # type: ignore
|
||||
from limits.storage import MemoryStorage, storage_from_string # type: ignore
|
||||
from limits.storage import Storage # type: ignore
|
||||
from limits.strategies import STRATEGIES, RateLimiter # type: ignore
|
||||
from starlette.config import Config
|
||||
from starlette.datastructures import MutableHeaders
|
||||
@@ -237,7 +235,7 @@ class Limiter:
|
||||
C.HEADERS_ENABLED, False
|
||||
)
|
||||
self._storage_options.update(self.get_app_config(C.STORAGE_OPTIONS, {}))
|
||||
self._storage: Union[Storage, AsyncStorage] = storage_from_string(
|
||||
self._storage = storage_from_string(
|
||||
self._storage_uri or self.get_app_config(C.STORAGE_URL, "memory://"),
|
||||
**self._storage_options,
|
||||
)
|
||||
@@ -334,7 +332,11 @@ class Limiter:
|
||||
"""
|
||||
Place holder until we find a better way to load config from app
|
||||
"""
|
||||
return self.app_config(key, default=default_value, cast=type(default_value))
|
||||
return (
|
||||
self.app_config(key, default=default_value, cast=type(default_value))
|
||||
if default_value
|
||||
else self.app_config(key, default=default_value)
|
||||
)
|
||||
|
||||
def __should_check_backend(self) -> bool:
|
||||
if self.__check_backend_count > MAX_BACKEND_CHECKS:
|
||||
|
||||
@@ -11,11 +11,17 @@ def get_ipaddr(request: Request) -> str:
|
||||
if "X_FORWARDED_FOR" in request.headers:
|
||||
return request.headers["X_FORWARDED_FOR"]
|
||||
else:
|
||||
return request.client.host or "127.0.0.1"
|
||||
if not request.client or not request.client.host:
|
||||
return "127.0.0.1"
|
||||
|
||||
return request.client.host
|
||||
|
||||
|
||||
def get_remote_address(request: Request) -> str:
|
||||
"""
|
||||
Returns the ip address for the current request (or 127.0.0.1 if none found)
|
||||
"""
|
||||
return request.client.host or "127.0.0.1"
|
||||
if not request.client or not request.client.host:
|
||||
return "127.0.0.1"
|
||||
|
||||
return request.client.host
|
||||
|
||||
Reference in New Issue
Block a user