Skip to content

Commit

Permalink
fix transport details parse method; improve type hints (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
oberstet committed Apr 30, 2022
1 parent cec0e99 commit 655b04f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion autobahn/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#
###############################################################################

__version__ = '22.4.1.dev7'
__version__ = '22.4.1.dev8'

__build__ = '00000000-0000000'
6 changes: 2 additions & 4 deletions autobahn/twisted/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
###############################################################################

from base64 import b64encode, b64decode
from pprint import pformat
from typing import Optional

from zope.interface import implementer
Expand Down Expand Up @@ -289,10 +288,9 @@ def connectionMade(self):
self._connectionMade()

# ok, done!
self.log.info('{func} connection established for peer="{peer}", transport_details=\n{transport_details}',
self.log.info('{func} connection established for peer="{peer}"',
func=hltype(self.connectionMade),
peer=hlval(self.peer),
transport_details=pformat(self._transport_details.marshal()))
peer=hlval(self.peer))

def connectionLost(self, reason: Failure = connectionDone):
# Twisted networking framework entry point, called by Twisted
Expand Down
2 changes: 1 addition & 1 deletion autobahn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ def hluserid(oid):
return hl('"{}"'.format(oid), color='yellow', bold=True)


def hlval(val, color='green'):
def hlval(val, color='white'):
return hl('{}'.format(val), color=color, bold=True)


Expand Down
4 changes: 2 additions & 2 deletions autobahn/wamp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ def parse(data: Dict[str, Any]) -> 'TransportDetails':
raise ValueError('"is_secure" must be a bool, was {}'.format(type(data['is_secure'])))
obj.is_secure = data['is_secure']
if 'channel_id' in data and data['channel_id'] is not None:
if type(data['channel_id']) != Dict[str, Any]:
if type(data['channel_id']) != dict:
raise ValueError('"channel_id" must be a dict, was {}'.format(type(data['channel_id'])))
channel_id = {}
for binding_type in data['channel_id']:
Expand All @@ -1664,7 +1664,7 @@ def parse(data: Dict[str, Any]) -> 'TransportDetails':
raise ValueError('"websocket_protocol" must be a string, was {}'.format(type(data['websocket_protocol'])))
obj.websocket_protocol = data['websocket_protocol']
if 'websocket_extensions_in_use' in data and data['websocket_extensions_in_use'] is not None:
if type(data['websocket_extensions_in_use']) != List[str]:
if type(data['websocket_extensions_in_use']) != list:
raise ValueError('"websocket_extensions_in_use" must be a list of strings, was {}'.format(type(data['websocket_extensions_in_use'])))
obj.websocket_extensions_in_use = data['websocket_extensions_in_use']
if 'http_headers_received' in data and data['http_headers_received'] is not None:
Expand Down
12 changes: 6 additions & 6 deletions autobahn/websocket/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,8 +2585,8 @@ def _connectionLost(self, reason):
When overriding in derived class, make sure to call this base class
implementation *after* your code.
"""
self.log.info('{func}: connection lost to peer {peer}: reason={reason}',
func=hltype(self._connectionLost), peer=self.peer, reason=hlval(reason))
self.log.debug('{func}: connection lost to peer {peer}: reason={reason}',
func=hltype(self._connectionLost), peer=self.peer, reason=hlval(reason))
WebSocketProtocol._connectionLost(self, reason)
self.factory.countConnections -= 1

Expand All @@ -2601,8 +2601,8 @@ def processHandshake(self):
#
end_of_header = self.data.find(b"\x0d\x0a\x0d\x0a")
if end_of_header >= 0:
self.log.info('{func} found end of HTTP request header at byte {end_of_header}',
func=hltype(self.processHandshake), end_of_header=hlval(end_of_header))
self.log.debug('{func} found end of HTTP request header at byte {end_of_header}',
func=hltype(self.processHandshake), end_of_header=hlval(end_of_header))

self.http_request_data = self.data[:end_of_header + 4]
self.log.debug(
Expand Down Expand Up @@ -3495,8 +3495,8 @@ def _connectionLost(self, reason):
When overriding in derived class, make sure to call this base class
implementation _after_ your code.
"""
self.log.info('{func}: connection lost to peer {peer}: reason={reason}',
func=hltype(self._connectionLost), peer=self.peer, reason=hlval(reason))
self.log.debug('{func}: connection lost to peer {peer}: reason={reason}',
func=hltype(self._connectionLost), peer=self.peer, reason=hlval(reason))
WebSocketProtocol._connectionLost(self, reason)

def startProxyConnect(self):
Expand Down

0 comments on commit 655b04f

Please sign in to comment.