Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
news
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sartika Aritonang
news
Commits
e57f3032
Commit
e57f3032
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
9c9678c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
compatibility.py
stbi/Lib/site-packages/asgiref/compatibility.py
+47
-0
No files found.
stbi/Lib/site-packages/asgiref/compatibility.py
0 → 100644
View file @
e57f3032
import
asyncio
import
inspect
def
is_double_callable
(
application
):
"""
Tests to see if an application is a legacy-style (double-callable) application.
"""
# Look for a hint on the object first
if
getattr
(
application
,
"_asgi_single_callable"
,
False
):
return
False
if
getattr
(
application
,
"_asgi_double_callable"
,
False
):
return
True
# Uninstanted classes are double-callable
if
inspect
.
isclass
(
application
):
return
True
# Instanted classes depend on their __call__
if
hasattr
(
application
,
"__call__"
):
# We only check to see if its __call__ is a coroutine function -
# if it's not, it still might be a coroutine function itself.
if
asyncio
.
iscoroutinefunction
(
application
.
__call__
):
return
False
# Non-classes we just check directly
return
not
asyncio
.
iscoroutinefunction
(
application
)
def
double_to_single_callable
(
application
):
"""
Transforms a double-callable ASGI application into a single-callable one.
"""
async
def
new_application
(
scope
,
receive
,
send
):
instance
=
application
(
scope
)
return
await
instance
(
receive
,
send
)
return
new_application
def
guarantee_single_callable
(
application
):
"""
Takes either a single- or double-callable application and always returns it
in single-callable style. Use this to add backwards compatibility for ASGI
2.0 applications to your server/test harness/etc.
"""
if
is_double_callable
(
application
):
application
=
double_to_single_callable
(
application
)
return
application
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment