Skip to content

Commit 636acaf

Browse files
author
Sebastian Molenda
committed
Should work
1 parent 8e4e711 commit 636acaf

23 files changed

+140
-1786
lines changed

pubnub/pubnub_asyncio.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from asyncio import Event, Queue, Semaphore
1010
from yarl import URL
11+
from httpx import AsyncHTTPTransport
1112
from pubnub.event_engine.containers import PresenceStateContainer
1213
from pubnub.event_engine.models import events, states
1314

@@ -33,6 +34,14 @@
3334
logger = logging.getLogger("pubnub")
3435

3536

37+
class PubNubAsyncHTTPTransport(AsyncHTTPTransport):
38+
is_closed: bool = False
39+
40+
def close(self):
41+
self.is_closed = True
42+
super().aclose()
43+
44+
3645
class PubNubAsyncio(PubNubCore):
3746
"""
3847
PubNub Python SDK for asyncio framework
@@ -45,10 +54,7 @@ def __init__(self, config, custom_event_loop=None, subscription_manager=None):
4554
self._connector = None
4655
self._session = None
4756

48-
self._connector = httpx.AsyncHTTPTransport()
49-
50-
if not hasattr(self._connector, 'close'):
51-
self._connector.close = self._connector.aclose
57+
self._connector = PubNubAsyncHTTPTransport()
5258

5359
if not subscription_manager:
5460
subscription_manager = EventEngineSubscriptionManager
@@ -150,6 +156,8 @@ async def _request_helper(self, options_func, cancellation_event):
150156
:param cancellation_event:
151157
:return:
152158
"""
159+
if self._connector and self._connector.is_closed:
160+
raise RuntimeError('Session is closed')
153161
if cancellation_event is not None:
154162
assert isinstance(cancellation_event, Event)
155163

requirements-dev.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ pycryptodomex
44
flake8
55
pytest
66
pytest-asyncio
7-
aiohttp
8-
requests
7+
httpx
98
cbor2
109
behave
1110
vcrpy

tests/integrational/asyncio/test_invocations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def test_publish_future_raises_pubnub_error(event_loop):
5555
async def test_publish_future_raises_lower_level_error(event_loop):
5656
pubnub = PubNubAsyncio(corrupted_keys, custom_event_loop=event_loop)
5757

58-
pubnub._connector.aclose()
58+
pubnub._connector.close()
5959

6060
with pytest.raises(RuntimeError) as exinfo:
6161
await pubnub.publish().message('hey').channel('blah').result()
@@ -102,7 +102,7 @@ async def test_publish_envelope_raises(event_loop):
102102
async def test_publish_envelope_raises_lower_level_error(event_loop):
103103
pubnub = PubNubAsyncio(corrupted_keys, custom_event_loop=event_loop)
104104

105-
pubnub._connector.aclose()
105+
pubnub._connector.close()
106106

107107
e = await pubnub.publish().message('hey').channel('blah').future()
108108
assert isinstance(e, PubNubAsyncioException)

tests/integrational/fixtures/asyncio/file_upload/delete_file.yaml

Lines changed: 0 additions & 511 deletions
This file was deleted.

tests/integrational/fixtures/asyncio/file_upload/fetch_s3_upload_data.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)