File tree 3 files changed +7
-58
lines changed
3 files changed +7
-58
lines changed Original file line number Diff line number Diff line change 1
1
import typing
2
2
from typing import Optional
3
3
4
- from .._synchronization import current_async_library
4
+ from .._synchronization import current_async_backend
5
5
from .base import SOCKET_OPTION , AsyncNetworkBackend , AsyncNetworkStream
6
6
7
7
8
8
class AutoBackend (AsyncNetworkBackend ):
9
9
async def _init_backend (self ) -> None :
10
10
if not (hasattr (self , "_backend" )):
11
- backend = current_async_library ()
11
+ backend = current_async_backend ()
12
12
if backend == "trio" :
13
13
from .trio import TrioBackend
14
14
Original file line number Diff line number Diff line change 1
1
import asyncio
2
- import os
3
2
import threading
4
3
from types import TracebackType
5
4
from typing import (
31
30
32
31
33
32
AsyncBackend = Literal ["asyncio" , "trio" ]
34
- AsyncLibrary = Literal ["asyncio" , "trio" , "anyio" ]
35
33
36
34
37
35
def current_async_backend () -> AsyncBackend :
@@ -47,6 +45,11 @@ def current_async_backend() -> AsyncBackend:
47
45
if environment not in ("asyncio" , "trio" ): # pragma: nocover
48
46
raise RuntimeError ("Running under an unsupported async environment." )
49
47
48
+ if environment == "asyncio" and anyio is None : # pragma: nocover
49
+ raise RuntimeError (
50
+ "Running with asyncio requires installation of 'httpcore[asyncio]'."
51
+ )
52
+
50
53
if environment == "trio" and trio is None : # pragma: nocover
51
54
raise RuntimeError (
52
55
"Running with trio requires installation of 'httpcore[trio]'."
@@ -55,18 +58,6 @@ def current_async_backend() -> AsyncBackend:
55
58
return environment
56
59
57
60
58
- def current_async_library () -> AsyncLibrary :
59
- if current_async_backend () == "trio" :
60
- return "trio"
61
-
62
- if anyio is not None :
63
- anyio_env = os .environ .get ("HTTPCORE_PREFER_ANYIO" , "true" ).lower ()
64
- if anyio_env in ("true" , "1" ):
65
- return "anyio"
66
-
67
- return "asyncio"
68
-
69
-
70
61
class _LockProto (Protocol ):
71
62
async def acquire (self ) -> Any : ...
72
63
def release (self ) -> None : ...
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments