-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,12 +127,7 @@ def process(self): | |
# Remove our HTTP reply channel association | ||
logger.debug("Upgraded connection %s to WebSocket", self.client_addr) | ||
# Resume the producer so we keep getting data, if it's available as a method | ||
# 17.1 version | ||
if hasattr(self.channel, "_networkProducer"): | ||
self.channel._networkProducer.resumeProducing() | ||
# 16.x version | ||
elif hasattr(self.channel, "resumeProducing"): | ||
self.channel.resumeProducing() | ||
self.channel._networkProducer.resumeProducing() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
andrewgodwin
Author
Member
|
||
|
||
# Boring old HTTP. | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import msgpack | ||
import os | ||
import tempfile | ||
|
||
|
||
class TestApplication: | ||
""" | ||
An application that receives one or more messages, sends a response, | ||
and then quits the server. For testing. | ||
""" | ||
|
||
setup_storage = os.path.join(tempfile.gettempdir(), "setup.testio") | ||
result_storage = os.path.join(tempfile.gettempdir(), "result.testio") | ||
|
||
def __init__(self, scope): | ||
self.scope = scope | ||
self.messages = [] | ||
|
||
async def __call__(self, send, receive): | ||
# Load setup info | ||
setup = self.load_setup() | ||
try: | ||
for _ in range(setup["receive_messages"]): | ||
self.messages.append(await receive()) | ||
for message in setup["response_messages"]: | ||
await send(message) | ||
finally: | ||
self.save_result() | ||
|
||
@classmethod | ||
def save_setup(cls, response_messages, receive_messages=1): | ||
""" | ||
Stores setup information. | ||
""" | ||
with open(cls.setup_storage, "wb") as fh: | ||
fh.write(msgpack.packb( | ||
{ | ||
"response_messages": response_messages, | ||
"receive_messages": receive_messages, | ||
}, | ||
use_bin_type=True, | ||
)) | ||
|
||
@classmethod | ||
def load_setup(cls): | ||
""" | ||
Returns setup details. | ||
""" | ||
with open(cls.setup_storage, "rb") as fh: | ||
return msgpack.unpackb(fh.read(), encoding="utf-8") | ||
|
||
def save_result(self): | ||
""" | ||
Saves details of what happened to the result storage. | ||
We could use pickle here, but that seems wrong, still, somehow. | ||
""" | ||
with open(self.result_storage, "wb") as fh: | ||
fh.write(msgpack.packb( | ||
{ | ||
"scope": self.scope, | ||
"messages": self.messages, | ||
}, | ||
use_bin_type=True, | ||
)) | ||
|
||
@classmethod | ||
def load_result(cls): | ||
""" | ||
Returns result details. | ||
""" | ||
with open(cls.result_storage, "rb") as fh: | ||
return msgpack.unpackb(fh.read(), encoding="utf-8") | ||
|
||
@classmethod | ||
def clear_storage(cls): | ||
""" | ||
Clears storage files. | ||
""" | ||
try: | ||
os.unlink(cls.setup_storage) | ||
except OSError: | ||
pass | ||
try: | ||
os.unlink(cls.result_storage) | ||
except OSError: | ||
pass |
This file was deleted.
Hey @andrewgodwin — you're never going to remember this I guess (and rightly so) but I don't suppose I can trick your grey cells into recall Why it was OK to remove the conditional check here?
We have a new report in #535 that
AttributeError: 'HTTPChannel' object has no attribute '_networkProducer'
in the latest twisted 24.10.I will continue finding the update here. (Min version 18 I'm guessing.)
Thanks/Sorry 😔