mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-22 21:46:17 +03:00
Upgrade exclusion filter
This commit is contained in:
parent
75e346cbdb
commit
5daa64284c
|
@ -42,6 +42,12 @@ except ImportError:
|
||||||
fastapi = None
|
fastapi = None
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
import starlette.requests
|
||||||
|
except ImportError:
|
||||||
|
starlette = None
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import werkzeug.local
|
import werkzeug.local
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -257,7 +263,7 @@ class InspectFilter:
|
||||||
def is_excluded(self, instance: object) -> bool:
|
def is_excluded(self, instance: object) -> bool:
|
||||||
if self._is_werkzeug_local_proxy(instance):
|
if self._is_werkzeug_local_proxy(instance):
|
||||||
return True
|
return True
|
||||||
elif self._is_fastapi_request(instance):
|
elif self._is_starlette_request_cls(instance):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -265,8 +271,10 @@ class InspectFilter:
|
||||||
def _is_werkzeug_local_proxy(self, instance: object) -> bool:
|
def _is_werkzeug_local_proxy(self, instance: object) -> bool:
|
||||||
return werkzeug and isinstance(instance, werkzeug.local.LocalProxy)
|
return werkzeug and isinstance(instance, werkzeug.local.LocalProxy)
|
||||||
|
|
||||||
def _is_fastapi_request(self, instance: object) -> bool:
|
def _is_starlette_request_cls(self, instance: object) -> bool:
|
||||||
return fastapi and isinstance(instance, fastapi.Request)
|
return starlette \
|
||||||
|
and isinstance(instance, type) \
|
||||||
|
and issubclass(instance, starlette.requests.Request)
|
||||||
|
|
||||||
|
|
||||||
inspect_filter = InspectFilter()
|
inspect_filter = InspectFilter()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user