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

Expose local_address and remote_address. #63

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 14 additions & 0 deletions trio_websocket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,20 @@ def is_server(self):
def path(self):
"""Returns the path from the HTTP handshake."""
return self._path

@property
def local_address(self):
"""
Local address of the connection. This is a ``(host, port)`` tuple.
"""
return self._stream.socket.getsockname()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this PR but a few requests:

  1. Not all streams have a socket, and we shouldn't leak an AttributeError. Returning None seems reasonable.
  2. There is a ListenPort class in this file that combines an IP address and a port number and exposes them in a nice little object. Maybe we can reuse that here if it is renamed to something like SocketInfo or something like that.
  3. Please add test coverage.

Also,


@property
def remote_address(self):
"""
Remote address of the connection. This is a ``(host, port)`` tuple.
"""
return self._stream.socket.getpeername()

async def aclose(self, code=1000, reason=None):
'''
Expand Down