Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add httpout.exceptions #58

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/exc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

from httpout import run
from httpout.exceptions import WebSocketException


print('Hi')


async def main():
raise ValueError
raise WebSocketException('')


run(main())
2 changes: 1 addition & 1 deletion httpout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2024 nggit

__version__ = '0.0.65'
__version__ = '0.0.66'
__all__ = ('HTTPOut',)

from .httpout import HTTPOut # noqa: E402
7 changes: 7 additions & 0 deletions httpout/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2024 nggit

from tremolo.exceptions import ( # noqa: F401
WebSocketException,
WebSocketClientClosed,
WebSocketServerClosed
)
4 changes: 3 additions & 1 deletion httpout/httpout.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def ho_import(name, globals=None, locals=None, fromlist=(), level=0):

return module

if name == 'httpout' or name.startswith('httpout.'):
parent, _, child = name.partition('.')

if parent == 'httpout' and (child == '' or child in globals):
if '__server__' in globals:
module = globals['__main__'].__server__['modules'][
globals['__name__']
Expand Down
3 changes: 2 additions & 1 deletion tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def test_exc_after_print(self):
self.assertEqual(header[:header.find(b'\r\n')], b'HTTP/1.1 200 OK')
self.assertEqual(
body,
b'3\r\nHi\n\r\n1F\r\n<ul><li>ValueError: </li></ul>\n\r\n0\r\n\r\n'
b'3\r\nHi\n\r\n27\r\n<ul><li>WebSocketException: </li></ul>\n\r\n'
b'0\r\n\r\n'
)

def test_exit_after_print(self):
Expand Down
Loading