File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
flask_parameter_validation Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change 1+ import asyncio
2+ import functools
13import inspect
24import re
35from inspect import signature
@@ -40,7 +42,8 @@ def __call__(self, f):
4042 }
4143 fn_list [fsig ] = fdocs
4244
43- def nested_func (** kwargs ):
45+ @functools .wraps (f )
46+ async def nested_func (** kwargs ):
4447 # Step 1 - Combine all flask input types to one dict
4548 json_input = None
4649 if request .headers .get ("Content-Type" ) is not None :
@@ -78,7 +81,11 @@ def nested_func(**kwargs):
7881 except Exception as e :
7982 return self .custom_error_handler (e )
8083 validated_inputs [expected .name ] = new_input
81- return f (** validated_inputs )
84+
85+ if asyncio .iscoroutinefunction (f ):
86+ return await f (** validated_inputs )
87+ else :
88+ return f (** validated_inputs )
8289
8390 nested_func .__name__ = f .__name__
8491 return nested_func
Original file line number Diff line number Diff line change 2828 platforms = 'any' ,
2929 install_requires = [
3030 'Flask' ,
31+ 'flask[async]' ,
3132 'python-dateutil' ,
3233 ],
3334 classifiers = [
You can’t perform that action at this time.
0 commit comments